Categories and Tags
Categories
<?php foreach (kart()->categories()->sortBy('count', 'desc') as $c) {
/** @var \Bnomei\Kart\Category $c */
?>
<a class="<?php e($c->isActive(), 'is-active') ?>"
href="<?= $c->urlWithParams() ?>"><?= $c ?></a>
<?php } ?>
$category->count()
$category->id()
$category->isActive()
$category->text()
$category->url()
$category->urlWithParams()
<?php
// productsWithCategory(string|array $categories, bool $any = true)
foreach (kart()->productsWithCategory($categories) as $product) {
/** @var ProductPage $product */
?>
<a href="<?= product->url() ?>"><?= product->title() ?></a>
<?php } ?>
Tags
<?php foreach (kart()->tags()->sortBy('count', 'desc') as $t) {
/** @var \Bnomei\Kart\Tag $t */
?>
<a class="<?php e($t->isActive(), 'is-active') ?>"
href="<?= $t->urlWithParams() ?>"><?= $t ?></a>
<?php } ?>
$tag->count()
$tag->id()
$tag->isActive()
$tag->text()
$tag->url()
$tag->urlWithParams()
<?php
// productsWithTag(string|array $tags, bool $any = true)
foreach (kart()-> productsWithTag($tags) as $product) {
/** @var ProductPage $product */
?>
<a href="<?= product->url() ?>"><?= product->title() ?></a>
<?php } ?>
Related products
<?php foreach (kart()->productsRelated($product)->not($product) as $related) {
/** @var ProductPage $related */ ?>
<a href="<?= $related->url() ?>"><?= $related->title() ?></a>
<?php } ?>
Products by URL params
http://localhost:8000/products/category:evil/tags:heavy,medium
<?php foreach (kart()->productsByParams() as $product) {
/** @var ProductPage $product */ ?>
<a href="<?= $product->url() ?>"><?= $product->title() ?></a>
<?php } ?>
Performance
The Kirby Kart plugin will store the matching products for each combination of categories and tags in caches to improve the lookup performance. These caches will be flushed when any product gets updated via the Panel.