getPromotionId example

if (!$lineItems || !$customer) {
            return;
        }

        $promotionIds = [];
        /** @var OrderLineItemEntity $lineItem */
        foreach ($lineItems as $lineItem) {
            if ($lineItem->getType() !== PromotionProcessor::LINE_ITEM_TYPE) {
                continue;
            }

            $promotionId = $lineItem->getPromotionId();
            if ($promotionId === null) {
                continue;
            }

            $promotionIds[] = $promotionId;
        }

        if (!$promotionIds) {
            return;
        }

        
$discountItem->setPayloadValue('exclusions', []);
        $discountItems = new LineItemCollection([$discountItem]);
        $original = new Cart(Uuid::randomHex());
        $toCalculate = new Cart(Uuid::randomHex());

        $this->promotionCalculator->calculate($discountItems$original$toCalculate$this->salesChannelContext, new CartBehavior());
        static::assertEmpty($toCalculate->getLineItems());
    }

    public function testCalculateAddsValidPromotionToCalculatedCart(): void
    {
        $promotionId = $this->getPromotionId();
        $discountItem = $this->getDiscountItem($promotionId);

        $discountItems = new LineItemCollection([$discountItem]);
        $original = new Cart(Uuid::randomHex());

        $productLineItem = new LineItem(Uuid::randomHex(), LineItem::PRODUCT_LINE_ITEM_TYPE);
        $productLineItem->setPrice(new CalculatedPrice(100.0, 100.0, new CalculatedTaxCollection()new TaxRuleCollection()));
        $productLineItem->setStackable(true);

        $toCalculate = new Cart(Uuid::randomHex());
        $toCalculate->add($productLineItem);
        
$context = Context::createDefaultContext();

        $this->buildPromotionLineItem($context$promotionExists);

        /** @var EntityRepository<OrderLineItemCollection> $orderLineItemRepository */
        $orderLineItemRepository = $this->getContainer()->get('order_line_item.repository');

        /** @var OrderLineItemEntity|null $lineItem */
        $lineItem = $orderLineItemRepository->search(new Criteria([$this->ids->get('line-item')])$context)->first();

        static::assertNotNull($lineItem);
        static::assertNull($lineItem->getPromotionId());

        $this->removeColumn();
        $migration = new Migration1648031611AddOrderLineItemPromotionId();
        $migration->update($this->connection);

        /** @var OrderLineItemEntity|null $lineItem */
        $lineItem = $orderLineItemRepository->search(new Criteria([$this->ids->get('line-item')])$context)->first();
        static::assertNotNull($lineItem);

        if ($promotionExists) {
            static::assertSame($this->ids->get('promotion')$lineItem->getPromotionId());
        }
Home | Imprint | This part of the site doesn't use cookies.