Product List Field Type

A field type for selecting products from the official Perch Shop app.

Installation

Requirements

Usage

You can use the field type in any namespace (perch:blog, perch:shop, perch:content, etc). To do so, set the type attribute to productlist.

There isn’t much use to it inside the template for output, so it’s a good idea to disable the output with suppress="true". Instead you would bypass the template processing to get the value of the field, an array of product slug(s), and utilise it there.

Example

This is an example of how the field type can be used to add products as accessories to another product and display them in a list on the product page.

Product template:

<perch:shop id="accessories" type="productlist" label="Accessories" suppress="true" />

Product page:

$product = perch_shop_product(perch_get('s'), [
    'skip-template'=> true
]);

if(is_array($product)) {
    $accessories = $product[0]['accessories'];
    $accessory_slugs = implode(',', $accessories);
}

perch_shop_products([
    'template' => 'products/list',
    'filter' => 'productSlug',
    'match' => 'in',
    'value' => $accessory_slugs,
]);

Attributes

Attribute Description
max The maximum number of products that can be added.
placeholder Placeholder text displayed on the field when no products selected.
<perch:shop id="accessories" type="productlist" label="Accessories" max="4" placeholder="Select accessories" />
link