Pipit Catalog v1.5-beta
Pipit Catalog v1.5-beta is now available.
Runtime functions
This is the first version of Catalog that includes runtime features. So you need to add pipit_catalog
to your runtime app lists in perch/config/apps.php
. You can view the functions docs on GitHub at the moment. Once the beta phase is over the docs will be added on this website.
Reorder products within a brand or category
You can now reorder products within a Shop Brand or a Category via the control panel. To output the ordered products you can use pipit_catalog_products():
pipit_catalog_products('category', 'products/shoes/', [
'template' => 'products/list.html',
]);
pipit_catalog_products('brand', 'brand-slug', [
'template' => 'products/list.html'
]);
Key variants data
pipit_catalog_get_variants() is a new function introduced in this update. It returns an array containing the product’s key variants data, which can be used in JS for the add-to-cart form (e.g. update stock and price per variant).
pipit_catalog_get_variants($slug);
For JS implementations, this can be used with Runway’s headless mode:
$Headless = $API->get('HeadlessAPI');
$Response = $Headless->new_response();
$ProductsSet = $Headless->new_set('products');
$OptionsSet = $Headless->new_set('options');
$out = pipit_catalog_get_variants(perch_post('s'));
$ProductsSet->add_items($out['products']);
$OptionsSet->add_items($out['options']);
$Response->add_set($ProductsSet);
$Response->add_set($OptionsSet);
$Response->respond();
let data = {};
let xhr = new XMLHttpRequest();
let formData = new FormData();
formData.append("s", "product-slug");
xhr.open("POST", "/api/products/variants", true);
xhr.send(formData);
xhr.onload = function () {
if (xhr.status == 200) {
data = JSON.parse(this.responseText).sets;
// now you have data.products and data.options
console.log(data);
}
};