PromotionDiscountEntity example

static::assertFalse($promotion->hasDiscount());
    }

    /** * This test verifies that we get the correct * FALSE result for hasDiscount, if discounts have been set. * * @group promotions */
    public function testPromotionHasDiscountYes(): void
    {
        $discount = new PromotionDiscountEntity();
        $discount->setId('D1');

        $promotion = new PromotionEntity();
        $promotion->setDiscounts(new PromotionDiscountCollection([$discount]));

        static::assertTrue($promotion->hasDiscount());
    }
}

    public function testLineItemType(): void
    {
        $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 */

    public function testPayloadStructureBasic(): void
    {
        $builder = new PromotionItemBuilder();

        $discount = new PromotionDiscountEntity();
        $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);

        
Home | Imprint | This part of the site doesn't use cookies.