- Posts: 18
- Thank you received: 2
Listing categories a product belongs to.
13 years 3 months ago #106708
by MonkeyT
Listing categories a product belongs to. was created by MonkeyT
I understand that as long as products can belong to multiple categories, a return link to whatever category list a shopper used to view a product is a problematic request.
What I would like to add to the template is a collection of links to ALL of the categories to which a product belongs. The product item itself does not appear to contain that list. How would I go about grabbing that list so that I can build my own collection of links?
What I would like to add to the template is a collection of links to ALL of the categories to which a product belongs. The product item itself does not appear to contain that list. How would I go about grabbing that list so that I can build my own collection of links?
Please Log in or Create an account to join the conversation.
13 years 3 months ago #106777
by nicolas
Replied by nicolas on topic Listing categories a product belongs to.
A return link is actually not a problem:
www.hikashop.com/en/forum/2-general-talk...on-product-page.html
To get all the categories of a product, you can use that code:
$productClass = hikashop_get('class.product');
$productClass->getProducts(18);
var_dump( $productClass->products[18]->categories);
where 18 is the id of the product.
www.hikashop.com/en/forum/2-general-talk...on-product-page.html
To get all the categories of a product, you can use that code:
$productClass = hikashop_get('class.product');
$productClass->getProducts(18);
var_dump( $productClass->products[18]->categories);
where 18 is the id of the product.
Please Log in or Create an account to join the conversation.
13 years 3 months ago #106927
by MonkeyT
Replied by MonkeyT on topic Listing categories a product belongs to.
Thank you for your help! You led me to precisely the right places.
Here's the solution I'm going with for the moment (my customer has declared that each of his products will belong to only one category). I will be storing your information about the multiple categories for later use, because I am sure other customers' inventories will not be so well-defined.
I added this to the product->show template. It adds a 'Continue Shopping' button using the cart's current CSS style.
$link = hikashop_completeLink( 'category&cid=' . $this->element->category_id );
echo $this->cart->displayButton( JText::_('Continue Shopping'), 'category', $this->params, $link );
Here's the solution I'm going with for the moment (my customer has declared that each of his products will belong to only one category). I will be storing your information about the multiple categories for later use, because I am sure other customers' inventories will not be so well-defined.
I added this to the product->show template. It adds a 'Continue Shopping' button using the cart's current CSS style.
$link = hikashop_completeLink( 'category&cid=' . $this->element->category_id );
echo $this->cart->displayButton( JText::_('Continue Shopping'), 'category', $this->params, $link );
Please Log in or Create an account to join the conversation.
13 years 3 months ago #106930
by MonkeyT
Replied by MonkeyT on topic Listing categories a product belongs to.
After digging into it, I changed my mind and decided to complete the multiple category option.
Here is the code:
Here is the code:
Code:
$productClass = hikashop_get('class.product');
$productClass->getProducts( $this->element->product_id );
$categories = $productClass->products[ $this->element->product_id ]->categories;
if( is_array( $categories ) AND count( $categories ) )
{
foreach( $categories as $c )
{
$categoryClass = hikashop_get('class.category');
$category = $categoryClass->get( $c );
$link = hikashop_completeLink( 'category&cid=' . $category->category_id );
echo $this->cart->displayButton( JText::_('Return to ' . $category->category_name ), 'category' . $category->category_id, $this->params, $link );
}
}
The following user(s) said Thank You: nicolas
Please Log in or Create an account to join the conversation.
Time to create page: 0.167 seconds