get_products_parent_categories
Overview
This function finds the 'deepest' category to which the specified product belongs to, and then returns all Categories from the same level as this categories parent. For example, if the lowest category was Men's > Men's T-Shirts > Latest Fashion > Cool Trends, it would look for Cool Trends, go up to Latest Fashion and find all other categories on the same level as Latest Fashion.
Accepted Parameters
Parameter | Values | Default | Description | Required | Sample |
---|---|---|---|---|---|
product_id | Positive Integer | The Internal ID Aurora uses to identify a Product. | Yes | 1 | |
limit | Positive Integer | 5 | The number of product categories to return in this request. | No | 5 |
parent_categories | Comma separated strings | If you want to force the categories to be from specific parent categories, e.g only return categories that have a parent category of "Mens" | No | mens |
Data Returned
Field | Values | Description |
---|---|---|
product_count | Numeric | The total number of products within this category that are enabled and have stock, or are allocated to a Stock Action on Zero that allows out of stock products to appear. |
category_name | String | The name of the category. |
category_complete_url | String | The full URL of the category. |
Example template code
You can add the following to the product details page:
{get_products_parent_categories limit="5" item="smarty_function_get_product_categories" id=$product.id}
{foreach from = $smarty_function_get_product_categories item=parent_category}
<a href="/{$parent_category.category_complete_url}/">{$parent_category.category_name}</a>
{/foreach}
Updated over 2 years ago