buildDiscountLineItem example

$discount->setId('D5');
        $discount->setType(PromotionDiscountEntity::TYPE_ABSOLUTE);
        $discount->setValue(50);
        $discount->setConsiderAdvancedRules(true);
        $discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $currencyFactor = 0.3;

        $ruleCollection = new RuleCollection();
        $discount->setDiscountRules($ruleCollection);

        $item = $builder->buildDiscountLineItem('my-Code-123', $this->promotion, $discount, 'C1', $currencyFactor);

        $expected = [
            'promotionId' => 'PR-1',
            'discountId' => 'D5',
            'code' => 'my-Code-123',
            'discountType' => 'absolute',
            'value' => '50',
            'maxValue' => '',
            'discountScope' => 'cart',
            'setGroups' => [],
            'groupId' => '',
            
// add a new discount line item for this discount             // if we have at least one valid item that will be discounted.             if (\count($itemIds) <= 0) {
                continue;
            }

            $factor = 1.0;
            if (!$context->getCurrency()->getIsSystemDefault()) {
                $factor = $context->getCurrency()->getFactor();
            }

            $discountItem = $this->itemBuilder->buildDiscountLineItem(
                $code,
                $promotion,
                $discount,
                $context->getCurrency()->getId(),
                $factor
            );

            $originalCodeItem = $cart->getLineItems()->filter(function DLineItem $item) use ($code) {
                if ($item->getReferencedId() === $code) {
                    return $item;
                }

                

        $currencyFactor = random_int(0, mt_getrandmax()) / mt_getrandmax();

        $builder = new PromotionItemBuilder();

        $discount = new PromotionDiscountEntity();
        $discount->setId('D5');
        $discount->setType(PromotionDiscountEntity::TYPE_PERCENTAGE);
        $discount->setValue(50);
        $discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $item = $builder->buildDiscountLineItem('', $this->promotion, $discount, 'C1', $currencyFactor);

        static::assertEquals(PromotionProcessor::LINE_ITEM_TYPE, $item->getType());
    }

    /** * This test verifies that we always use the id of the * discount and not from the promotion for the item key. * If we have multiple discounts in a single promotion and use the promotion * id for the key, then we get duplicate key entries which leads to * errors like "line item not stackable". * * @group promotions * * @throws CartException * @throws UnknownPromotionDiscountTypeException */
Home | Imprint | This part of the site doesn't use cookies.