Category Navigation
3 min
When Category Navigation Ordering & Rendering is set the Klevu Theme is enabled for all Categories.
This behaviour can be amended by injecting custom isEnabledConditions into the isEnabledDeterminer.
The default behaviour of the determiner for category navigation checks:
- If the store is integrated with Klevu
- If category navigation is enabled
- If the route is a category
- If the category is displaying products
<type name="Klevu\FrontendCategoryNavigation\Service\Action\UpdateCategoryPageLayoutAction">
<arguments>
<argument name="isEnabledConditions" xsi:type="array">
<item name="klevu_integrated"
xsi:type="object">Klevu\Frontend\Service\IsEnabledCondition\IsStoreIntegratedCondition</item>
<item name="klevu_catnav_enabled"
xsi:type="object">Klevu\FrontendCategoryNavigation\Service\IsEnabledCondition\IsCatNavEnabledCondition</item>
<item name="klevu_category_route"
xsi:type="object">Klevu\FrontendCategoryNavigation\Service\IsEnabledCondition\IsCategoryRouteCondition</item>
<item name="klevu_category_display_products"
xsi:type="object">Klevu\FrontendCategoryNavigation\Service\IsEnabledCondition\IsCategoryDisplayingProductsCondition</item>
</argument>
</arguments>
</type>If all these return true, the category navigation layout handle will be added to the page.
Enable for a subset of categories
Say we only wanted to enable Klevu's Category Navigation if the category ID was odd.
Inject your own isEnableCondition
<type name="Klevu\FrontendCategoryNavigation\Service\Action\UpdateCategoryPageLayoutAction">
<arguments>
<argument name="isEnabledConditions" xsi:type="array">
<item name="is_odd_category"
xsi:type="object">Vendor\Model\Service\IsEnabledCondition\IsCategoryOddCondition</item>
</argument>
</arguments>
</type>Create the Condition
<?php
declare(strict_types=1);
namespace Vendor\Module\Service\IsEnabledCondition;
use Klevu\FrontendCategoryNavigation\Service\IsEnabledCondition;
use Klevu\Registry\Api\CategoryRegistryInterface;
class IsCategoryOddCondition implements IsEnabledConditionInterface
{
public function __construct(CategoryRegistryInterface $categoryRegistry)
{
$this->categoryRegistry = $categoryRegistry;
}
public function execute(): bool
{
$category = $this->categoryRegistry->getCurrentCategory();
return $category->getId() & 1;
}
}
See module-m2-frontend-categorynavigation/Service/IsEnabledCondition for more examples of isEnabledDeterminer classes.