Getting Grouped Product Data or IDs (productsFindGroupedProductsByProductId)

The "productsFindGroupedProductsByProductId" and "productsFindGroupedProductIdsByProductId" functions return an array of products or product IDs that have been grouped together on the Product Listings page due to the use of the Grouping Products by Retailer (Style) Code system (including the product to which the provided ID belongs).

This article describes what these functions do, how then should be used, and which should be used when.

👍

These functions only return data when either one of the two things are true:

  • The Group products by Style Code? setting is active in the Aurora Back-end under Store > Settings > Front-end.
  • The Always return alternate Style Code products? setting is active in the Aurora Back-end under Store > Settings > Front-end.

Introduction

The productsFindGroupedProductsByProductId function returns an array of products with all accompanying details fully loaded, while the productsFindGroupedProductIdsByProductId function return only the ID of the products.

Both these functions return the same selection of products, based on whether they are grouped together on the Product Listings page due to the use of the Grouping Products by Retailer (Style) Code system (including the product to which the provided ID belongs).

The data this function returns is most frequently used to list alternate product options on both the Product Details and (Category) Listing pages, but is in fact accessible across the entire front-end and so can be used to add this data to anywhere you are in possession of an Aurora Product ID.

👍

The array returned by this function (whether it returns all Product Details or just the Product IDs) is indexed by Aurora's Internal Product ID allowing you to gain access to a specific product should you wish to for display, e.g. in combination with the "$product.grouped_product_images_to_product_ids" array detailed in the "Images" section of the Product Details guide (i.e. to perhaps access the filename and link information for a particular product image to allow link-throughs).

Which function should be used and when?

Before answering this, it's important to understand the difference between the two functions:

  • productsFindGroupedProductsByProductId : This function loads all product details into memory, sometimes requiring considerably more resources to run than the alternative function.
  • productsFindGroupedProductIdsByProductId : This function loads only the Product IDs into memory, allowing you to choose which of these you load the full details of (using the get_product_details function described in the Product Functions support article). This can save considerable resources at runtime since not all of the product details will be loaded into memory (unless you require them).

👍

If you are not going to use all of the product's details, e.g. perhaps you are just creating some swatches based on the Product's colour, then you should use the productsFindGroupedProductIdsByProductId and get_product_field_values functions as this greatly reduces the resources required to complete the process.

How to call these functions

Example Aurora Template: templates/example.com/products/listings-grid.tpl.html

Both these functions are identical in the way they are called and so all of the parameters described below are applicable to them both.

Parameters

ParameterValuesDefaultDescriptionRequired?
itemnon-space stringgrouped_productsThis is the name of the variable that the products 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_idIntegerThe Internal ID Aurora uses to identify a Product.

This should be any one product ID that you wish to check for alternate products in the group.
Yes
order_by_filterStringFalseThe 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

Data Returned

For productsFindGroupedProductsByProductId

The data returned by this function is an Indexed Array of product details. The index for this array uses the Product ID of the product it contains, allowing you to access any particular product, or perhaps 'skip' the product for which you already had the details more easily (i.e. the product you passed the ID of in the first place).

The data contained in each array element follows the same format as all other product data issued to the front-end and is described in more detail in the Product Details section.

For productsFindGroupedProductIdsByProductId

The data returned by this function is an Indexed Array of product IDs. The index for this array uses the Product ID of the product it contains, allowing you to access any particular product or perhaps 'skip' the product for which you already had the details more easily (i.e. the product you passed the ID of in the first place).

👍

The data returned by this function can be used by the get_product_details, get_product_url and get_product_field_values functions (as described in the Product Functions support article) to generate complete product lists, product details sections, navigation blocks, or swatches.

Examples

Example Aurora Template: templates/example.com/products/listings-grid.tpl.html

Product Swatches using productsFindGroupedProductIdsByProductId

A usable 'swatch' image filename can be obtained from each product in the array of grouped products using the "{$grouped_product.fields.colour|convertToGet}" method as shown below.

{productsFindGroupedProductIdsByProductId product_id=$product.id order_by_filter="co"}
{if $grouped_products}
<ul class="productlist_grid_swatches">
  {foreach from=$grouped_products item=grouped_product_id}
    {get_product_field_values product_id=$grouped_product_id field_name="Colour" item="product_swatch_value"}
  <li>
    <a href="{get_product_url id=$grouped_product_id}" rel="{$grouped_product_id}" class="custom_change_image">
      <img src="/templates/{$templates_dir}/_images/swatches/{$grouped_product.fields.colour|convertToGet}.g    if" alt="" width="20" height="20" class="details_attribute_colour{if $grouped_product_id == $product.id} selected{/if}" />
      <div class="listing_colour_tooltip">{$product_swatch_value}</div>
    </a>
  </li>
  {/foreach}
</ul>
{/if}

Related Aurora Demo Templates
products/listings-grid.tpl.html