Finder API: Products
Templates
Main Product
| Name | padloper-product |
|---|---|
| Description | The template used by Padloper product pages that are not variants. The pages may or may not have variants (child pages). |
Fields
Below are the frontend-relevant fields in the padloper-product template.
INFO
Some of the fields listed here may not be present in depending on the Padloper optional features that were selected during install.
Title
| Name | title |
|---|---|
| Description | ProcessWire PageTitle/PageTitleLanguage field that stores the title of the product. |
| Subfields | N/A |
| API | $product->title |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var string $product->title */
echo $product->title;
2
3
4
5
6
7
Description
| Name | padloper_description |
|---|---|
| Description | Texarea/TextareaLanguage rich-text field that contains the product description. |
| Subfields | N/A |
| API | $product->padloper_description |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var string $description */
$description = $product->padloper_description;
echo $description;
2
3
4
5
6
7
8
Stock
| Name | padloper_product_stock |
|---|---|
| Description | Custom Padloper field that holds stock information for a product, including sku, price, quantity and inventory control. |
| Subfields | sku, price, compare_price, quantity, allow_backorders, enabled. |
| API | $product->padloper_product_stock |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var WireData $stock */
$stock = $product->padloper_product_stock;
echo $stock->sku;
echo $stock->price;
echo $stock->comparePrice;
echo $stock->quantity;
echo $stock->allowBackorders;
echo $stock->enabled;
2
3
4
5
6
7
8
9
10
11
12
13
Images
| Name | padloper_images |
|---|---|
| Description | ProcessWire multi-images field that stores the product images. |
| Subfields | As per ProcessWire image fields. |
| API | $product->padloper_images |
INFO
The allowed image file extensions are determined by the shop's general settings.
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var Pageimages $images */
$images = $product->padloper_images;
// work with $images
2
3
4
5
6
7
8
Settings
| Name | padloper_product_settings |
|---|---|
| Description | Custom Padloper field that holds product settings information for the details product shipping type, whether the product is taxable, if it tracks inventory, main colour and whether it will have variants. |
| Subfields | shipping_type, taxable, track_inventory, use_variants, colour. |
| API | $product->padloper_product_settings |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var WireData $settings */
$settings = $product->padloper_product_settings;
// 'physical' | 'physical_no_shipping' | 'digital' | 'service'
echo $settings->shippingType;
echo $settings->taxable;
echo $settings->trackInventory;
echo $settings->useVariants;
echo $settings->colour;
2
3
4
5
6
7
8
9
10
11
12
13
Attributes
| Name | padloper_product_attributes |
|---|---|
| Description | ProcessWire multi-page reference field that stores the attributes selected for this product. E.g. colour, size, material. |
| Subfields | title |
| API | $product->padloper_product_attributes |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var PageArray $attributes */
$attributes = $product->padloper_product_attributes;
if($attributes->count()){
foreach ($attributes as $attribute) {
/** @var Page $attribute */
echo $attribute->title;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
Downloads
| Name | padloper_downloads |
|---|---|
| Description | ProcessWire multi-page reference field that stores the downloads selected for this product. |
| Subfields | title, padloper_description, padloper_file |
| API | $product->padloper_downloads |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var PageArray $downloads */
$downloads = $product->padloper_downloads;
if($downloads->count()){
foreach ($downloads as $download) {
/** @var Page $download */
echo $download->title;
echo $download->padloper_description;
/** @var Pagefile $downloadFile */
$downloadFile = $download->padloper_file;
echo $downloadFile->name;
// etc
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Type
| Name | padloper_type |
|---|---|
| Description | ProcessWire single-page reference field that stores the product type this product, e.g. belt, shirt, etc. |
| Subfields | title |
| API | $product->padloper_type |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var Page $type */
$type = $product->padloper_type;
if($type){
echo $type->title;
}
2
3
4
5
6
7
8
9
10
Brand
| Name | padloper_brand |
|---|---|
| Description | ProcessWire single-page reference field that stores the product brand/manufacturer. |
| Subfields | title, padloper_images |
| API | $product->padloper_brand |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var Page $brand */
$brand = $product->padloper_brand;
if($brand){
echo $brand->title;
if(!empty($brand->padloper_images->count())){
/** @var Pageimage $logo */
$logo = $brand->padloper_images->first();
// work with logo
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Categories
| Name | padloper_categories |
|---|---|
| Description | ProcessWire multi-page reference field that stores the product categories, e.g. kitchen, electronics, summer wear, etc. |
| Subfields | title, padloper_description |
| API | $product->padloper_categories |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var PageArray $categories */
$categories = $product->padloper_categories;
if($categories->count()){
foreach ($categories as $category) {
echo $category->title;
echo $category->padloper_description;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
Tags
| Name | padloper_tags |
|---|---|
| Description | ProcessWire multi-page reference field that stores the product tags, e.g. sale, hot, etc. |
| Subfields | title |
| API | $product->padloper_tags |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var PageArray $tags */
$tags = $product->padloper_tags;
if($tags->count()){
foreach ($tags as $tag) {
echo $tag->title;
}
}
2
3
4
5
6
7
8
9
10
11
12
Properties
| Name | padloper_product_properties |
|---|---|
| Description | Custom Padloper multi-field that holds product information for product properties, i.e. the propery type (e.g. length, weight, grade, etc) , the dimension/measurement of the property (e.g. kilograms, litres, etc) and the numeric value of the dimension. |
| Subfields | value, property_id, dimension_id |
| API | $product->padloper_product_properties |
// any valid ProcessWire selector
$selector = "";
/** @var Page $product */
$product = $padloper->get("template=product,{$selector}");
/** @var WireArray $productProperties */
$productProperties = $product->padloper_product_properties;
if($productProperties->count()){
foreach ($productProperties as $productProperty) {
// e.g. Weight
echo $productProperty->property;
echo $productProperty->propertyID;
// e.g. Kilograms
echo $productProperty->dimension;
echo $productProperty->dimensionID;
// e.g. 25
echo $productProperty->value;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Product Variant
Fields
Below are the frontend-relevant fields in the padloper-product-variant template.
INFO
Some of the fields listed here may not be present in depending on the Padloper optional features that were selected during install.
In the all the product variants examples, the variable $variants is populated using the method $padloper->getProductVariants()as follows:
// for selectors
// $productID = 1846;
// $productName = "t-shirt";
$productTitle = "T shirt";
// $product = $padloper->get("title={$productTitle}");
// selector can be product Page, ID, name or title
// $selector = $productID;
// $selector = $product;
// $selector = $productName;
$selector = $productTitle;
/** @var PageArray $variants */
$variants = $padloper->getProductVariants($selector, $isUseRaw = false);
// ... work with $variants
2
3
4
5
6
7
8
9
10
11
12
13
14
| Name | padloper-product-variant |
|---|---|
| Description | The template used by Padloper product pages that are variants. The pages cannot have child pages themselves. |
Title
| Name | title |
|---|---|
| Description | ProcessWire PageTitle/PageTitleLanguage field that stores the title of a product variant. |
| Subfields | N/A |
| API | $variant->title |
/** @var PageArray $variants */
if (!empty($variants)) {
foreach ($variants as $variant) {
echo $variant->title . '<br>';
}
}
2
3
4
5
6
Stock
| Name | padloper_product_stock |
|---|---|
| Description | Custom Padloper field that holds stock information for a product variant, including sku, price, quantity and inventory control. |
| Subfields | sku, price, compare_price, quantity, allow_backorders, enabled. |
| API | $variant->padloper_product_stock |
/** @var PageArray $variants */
if (!empty($variants)) {
foreach ($variants as $variant) {
/** @var WireData $stock */
$stock = $variant->padloper_product_stock;
echo $stock->sku . '<br>';
echo $stock->price . '<br>';
echo $stock->comparePrice . '<br>';
echo $stock->quantity . '<br>';
echo $stock->allowBackorders . '<br>';
echo $stock->enabled . '<br>';
}
}
2
3
4
5
6
7
8
9
10
11
12
13
Images
| Name | padloper_images |
|---|---|
| Description | ProcessWire multi-images field that stores the images for a product variant. |
| Subfields | As per ProcessWire image fields. |
| API | $variant->padloper_images |
INFO
The allowed image file extensions are determined by the shop's general settings.
/** @var PageArray $variants */
if (!empty($variants)) {
foreach ($variants as $variant) {
/** @var Pageimages $images */
$images = $variant->padloper_images;
// work with $images
}
}
2
3
4
5
6
7
8
Downloads
| Name | padloper_downloads |
|---|---|
| Description | ProcessWire multi-page reference field that stores the downloads selected for a product variant. |
| Subfields | title, padloper_description, padloper_file |
| API | $variant->padloper_downloads |
/** @var PageArray $variants */
if (!empty($variants)) {
foreach ($variants as $variant) {
echo $variant->title . " ({$padloper->renderCartPriceAndCurrency($variant->padloper_product_stock->price)}))</br>";
/** @var PageArray $downloads */
$downloads = $variant->padloper_downloads;
if ($downloads->count()) {
foreach ($downloads as $download) {
/** @var Page $download */
echo $download->title . '<br>';
echo $download->padloper_description . '<br>';
/** @var Pagefile $downloadFile */
$downloadFile = $download->padloper_file;
echo $downloadFile->name . '<br>';
// etc
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Examples
Find multiple products
$padloper->find()
// any valid ProcessWire selector
$selector = "";
/** @var PageArray $products */
$products = $padloper->find("template=product,{$selector}");
// work with $products
2
3
4
5
OR:groups
// find products whose stock is greater than 4 or whose category is 'kitchen'
$selector = "template=product,(stock.quantity>4),(categories=kitchen)";
/** @var Page $product */
$products = $padloper->find($selector);
2
3
4
$padloper->findRaw()
$selector = "template=product,sort=title";
$fieldsOptions = ['title', 'padloper_product_stock' => 'stock', 'padloper_images' => 'images'];
/** @var array $products */
$products = $padloper->findRaw($selector, $fieldsOptions);
$out = '';
if (!empty($products)) {
$out .= "<ul>";
foreach ($products as $id => $values) {
$title = $values['title'];
$stock = $values['stock'];
$price = $padloper->renderCartPriceAndCurrency($stock['price']);
$quantity = $stock['quantity'];
$out .= "<li>{$title} - {$price} ({$quantity} in stock)</li>";
}
}
echo $out;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Retrieve a single product
$padloper->get()
// get a single product
$out = "";
$selector = "template='product";
/** @var Page $product */
$product = $padloper->get($selector);
$out .= "<p>" . $product->title . "</p>";
if ($product->padloper_images->count()) {
$image = $product->padloper_images->first();
$imageThumb = $image->height(130);
$out .= "<img src={$image->url}>";
}
echo $out;
2
3
4
5
6
7
8
9
10
11
12
$padloper->getRaw()
Get a single product's title and image thumb
$selector = "template=product,sort=-title";
$fieldsOptions = ['title', 'padloper_images' => 'images'];
/** @var array $product */
$product = $padloper->getRaw($selector, $fieldsOptions);
// work with $product
2
3
4
5
Find a product's variants
$padloper->getProductVariants()
$padloper->getProductVariants(mixed $product, bool $isUseRaw = true, array|null $fields = null, array $options = [])
Arguments
| Name | Type(s) | Description |
|---|---|---|
$product | string, array, field | The product whose variants to retrieve. |
$isUseRaw | bool | Whether to use $pages->find() or $pages->findRaw() (default). |
$fields | string, array, Field | The field argument passed to $pages->findRaw(). |
$options | array | The options argument passed to $pages->findRaw(). |
$productTitle = "T shirt";
// for selectors
// $productID = 1846;
// $productName = "t-shirt";
$productTitle = "T shirt";
// $product = $padloper->get("title={$productTitle}");
// selector can be product Page, ID, name or title
// $selector = $productID;
// $selector = $product;
// $selector = $productName;
$selector = $productTitle;
/** @var PageArray $variants */
$variants = $padloper->getProductVariants($selector, $isUseRaw = false);
// ... work with $variants
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16