Integrate the Category Management + Promotions & Discounts feature

Edit on GitHub

This 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

To start feature integration, integrate the required features:

NAME VERSION INTEGRATION GUIDE
Promotions & Discounts 202204.0 Promotions & Discounts feature integration
Category Management 202204.0 Category Management feature integration
Spryker Core 202204.0 Spryker Core feature integration

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:

  1. Create a discount and define its condition as a query string with a category field.
  2. Add a product assigned to the defined category to the cart.
  3. The discount should be applied to the cart.

2) Build Zed UI frontend

Enable Javascript and CSS changes for Zed:

console frontend:zed:build