get_related_product_ids
Returns all product IDs related to the provided product ID.
Introduction
The get_related_product_ids function returns an array of product IDs that are related to the provided product_id
.
You may provide an order_by_filter
param which sorts the returned IDs by the attribute given. If no order_by_filter
is given then the sort order will be according to the ordering of the related products to the product with id product_id
Parameters
Parameter | Values | Default | Description | Required? |
---|---|---|---|---|
item | non-space string | related_product_ids | This is the name of the variable that the product ids will be loaded into for use in the template and must conform to all of the usual restrictions of any Smarty variable name. | No |
product_id | Integer | The Internal ID Aurora uses to identify a Product. This should be any one product ID that you wish to check for related products. | Yes | |
order_by_filter | String | False | The abbreviation of the Filter by which to sort the returned products. The Filter abbreviation is the 2 to 3 character string used in the URL and configured in the Aurora Back-end under Products > Fields > Filter Abbreviation. For example, "co" is commonly used for the Colour Filter. The Filter values are sorted by the Order number assigned to each of the values, in ascending order. | No |
Examples
Product Swatches using get_related_product_ids
A usable 'swatch' image filename can be obtained from each product in the array of ids using the template snippet below:
{get_related_product_ids product_id=$product.id order_by_filter="co"}
{if $related_product_ids}
<ul class="productlist_grid_swatches">
{foreach from=$related_product_ids item=related_product_id}
{get_product_field_values product_id=$related_product_id field_name="Colour" item="product_swatch_value"}
<li>
<a href="{get_product_url id=$related_product_id}" rel="{$related_product_id}" class="custom_change_image">
<img src="/templates/{$templates_dir}/_images/swatches/{$product_swatch_value|convertToGet}.gif" alt="" width="20" height="20" class="details_attribute_colour{if $related_product_id == $product.id} selected{/if}" />
<div class="listing_colour_tooltip">{$product_swatch_value}</div>
</a>
</li>
{/foreach}
</ul>
{/if}
Updated 11 months ago