Category Management + Promotions and Discounts feature integration
Edit on GitHubThis document describes how to add the category
parameter to calculation and conditions queries in the Promotions & Discounts feature.
Install feature core
Follow the steps below to install the feature core.
Prerequisites
Install the required features:
NAME | VERSION | INSTALLATION GUIDE |
---|---|---|
Promotions & Discounts | 202311.0 | Install the Promotions & Discounts feature |
Category Management | 202311.0 | Install the Category Management feature |
Spryker Core | 202311.0 | Install the Spryker Core feature |
1) Set up behavior
Set up the following behaviors:
PLUGIN | SPECIFICATION | PREREQUISITES | NAMESPACE |
---|---|---|---|
CategoryDecisionRulePlugin | Checks if the category matches the clause. | None | Spryker\Zed\CategoryDiscountConnector\Communication\Plugin\Discount |
CategoryDiscountableItemCollectorPlugin | Collects discountable items from the given quote by item categories. | None | Spryker\Zed\CategoryDiscountConnector\Communication\Plugin\Discount |
src/Pyz/Zed/Discount/DiscountDependencyProvider.php
<?php
namespace Pyz\Zed\Discount;
use Spryker\Zed\CategoryDiscountConnector\Communication\Plugin\Discount\CategoryDecisionRulePlugin;
use Spryker\Zed\CategoryDiscountConnector\Communication\Plugin\Discount\CategoryDiscountableItemCollectorPlugin;
use Spryker\Zed\Discount\DiscountDependencyProvider as SprykerDiscountDependencyProvider;
class DiscountDependencyProvider extends SprykerDiscountDependencyProvider
{
/**
* @return array<\Spryker\Zed\DiscountExtension\Dependency\Plugin\DecisionRulePluginInterface>
*/
protected function getDecisionRulePlugins(): array
{
return array_merge(parent::getDecisionRulePlugins(), [
new CategoryDecisionRulePlugin(),
]);
}
/**
* @return array<\Spryker\Zed\DiscountExtension\Dependency\Plugin\DiscountableItemCollectorPluginInterface>
*/
protected function getCollectorPlugins(): array
{
return array_merge(parent::getCollectorPlugins(), [
new CategoryDiscountableItemCollectorPlugin(),
]);
}
}
Verification
Ensure that the plugins work correctly:
- Create a discount and define its condition as a query string with a category field.
- Add a product assigned to the defined category to the cart.
- The discount should be applied to the cart.
2) Build Zed UI frontend
Enable Javascript and CSS changes for Zed:
console frontend:zed:build
Thank you!
For submitting the form