How to add a custom cart promotion action? ========================================== Let's assume that you would like to have a cart promotion that gives **100% discount on the cheapest item in the cart**. See what steps need to be taken to achieve that: Create a new cart promotion action ---------------------------------- You will need a new class ``CheapestProductDiscountPromotionActionCommand``. It will give a discount equal to the unit price of the cheapest item. That's why it needs to have the Proportional Distributor and the Adjustments Applicator. The ``execute`` method applies the discount and distributes it properly on the totals. This class needs also a ``isConfigurationValid()`` method which was omitted in the snippet below. .. code-block:: php proportionalDistributor = $proportionalIntegerDistributor; $this->unitsPromotionAdjustmentsApplicator = $unitsPromotionAdjustmentsApplicator; } /** * {@inheritdoc} */ public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion) { if (!$subject instanceof OrderInterface) { throw new UnexpectedTypeException($subject, OrderInterface::class); } $items = $subject->getItems(); $cheapestItem = $items->first(); $itemsTotals = []; foreach ($items as $item) { $itemsTotals[] = $item->getTotal(); $cheapestItem = ($item->getVariant()->getPrice() < $cheapestItem->getVariant()->getPrice()) ? $item : $cheapestItem; } $splitPromotion = $this->proportionalDistributor->distribute($itemsTotals, -1 * $cheapestItem->getVariant()->getPrice()); $this->unitsPromotionAdjustmentsApplicator->apply($subject, $promotion, $splitPromotion); } /** * {@inheritdoc} */ public function getConfigurationFormType() { return CheapestProductDiscountConfigurationType::class; } } Prepare a configuration form type for the admin panel ----------------------------------------------------- The new action needs a form type to be available in the admin panel, while creating a new cart promotion. .. code-block:: php ` * :doc:`Cart Promotions Concept Documentation `