For Dev - Product List Customization (App Lib V2)

For how our app's customization works, please read: Customization overview

To understand how product item works, please read: Product List Component

This instruction is appropriate for App Lib V2 only. The app lib V3 associated documents will be available soon. Please contact us for further assistance.


1. Functions to override

Override function ProductGridItem.prototype.compileTemplate and ProductListItem.prototype.compileTemplate (if any) in boost-pfs-filter.js

ProductGridItem.prototype.compileTemplate = function(data)

{

if (!data) data = this.data;

// Get Template var itemHtml = boostPFSTemplate.productGridItemHtml;

// Get the theme settings

var themeSettings = boostPFSThemeConfig;

// You custom code here //...

return itemHtml;}

  • data: the product data returned from filter API.
  • itemHtml: the product item HTML rebuilt based on the data
  • boostPFSTemplate: the HTML template declared at the end of sections/collection-template.liquid or sections/collection-template-boost-pfs-filter.liquid
  • boostPFSThemeConfig: the theme config, declared at the end of sections/collection-template.liquid or sections/collection-template-boost-pfs-filter.liquid

2. Example use case

In the  boost-pfs-filter.js file, you will find the product item template as below.

https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48ac2d2c7d3a352e917ae6/file-sgAD7aYKHI.png

Attention: If the boostPFSTemplate variable does not exist in boost-pfs-filter.js, please look at the collection.liquid or collection-template.liquid. In this case, the main code of the product item layout will be in the boost-pfs-filter-html.liquid

https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48ab852c7d3a352e917ae1/file-LooGy6jcJC.png

The above image is just an example. Each theme will have a different template. You will find a function which builds the product item in the template below:

The function is named ProductGridItem.prototype.compileTemplate

https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/5f48acf52c7d3a352e917aed/file-ZmcMAYXHyA.png

The  data parameter is the data of a single product (JSON data type). The structure is similar to the product Liquid object (Get more information about our API here):

https://d33v4339jhl8k0.cloudfront.net/docs/assets/590652f62c7d3a057f88b05d/images/59a29a63042863033a1c5260/file-tKsPpnVzal.png

The  ProductGridItem.prototype.compileTemplate function will build the product HTML code based on the mentioned template. In the function, you will find that we replace the variables in the template with the product JSON data. For example, in the below code, we replace the Title in the template with the product's title.

itemHtml = itemHtml.replace(/{{itemTitle}}/g, data.title);

While modifying the template and the ProductGridItem.prototype.compileTemplate function, you could customize the display and the function of the product item as you wish.