PromotionNotEligibleError example

continue;
            }

            // if promotion is on exclusions stack it is ignored             if (!$discountItem->hasPayloadValue('promotionId')) {
                continue;
            }

            $promotionId = $discountItem->getPayloadValue('promotionId');

            if (\array_key_exists($promotionId$exclusions)) {
                $toCalculate->addErrors(new PromotionNotEligibleError($discountItem->getDescription() ?? $discountItem->getId()));

                continue;
            }

            $deliveryItemAdded = $this->calculateDeliveryPromotion($toCalculate$discountItem$context$notDiscountedDeliveriesValue);

            if ($deliveryItemAdded) {
                // ensure that a lineItem will be added to cart if a discount has been added                 $this->addFakeLineitem($toCalculate$discountItem$context);
                $this->addPromotionAddedNotice($original$toCalculate$discountItem);
            } else {
                
private function addPromotionNotFoundError(string $code, Cart $cart): void
    {
        $cart->addErrors(new PromotionNotFoundError($code));
    }

    /** * Adds a new error to the cart if the promotion has been found * but somehow is not eligible for the current cart. */
    private function addPromotionNotEligibleError(string $name, Cart $cart): void
    {
        $cart->addErrors(new PromotionNotEligibleError($name));
    }

    /** * function checks if the Original Cart contains the lineItem. * if not, an PromotionCartAddedInformationError is set in the calculated cart */
    private function addPromotionAddedNotice(Cart $original, Cart $calculated, LineItem $discountLineItem): void
    {
        if ($original->has($discountLineItem->getId())) {
            return;
        }
        
Home | Imprint | This part of the site doesn't use cookies.