addCustomLineItem example

$lineItem->setRemovable($removeable);
        $lineItem->setStackable($stackable);
        $lineItem->setPayload($payload);

        $lineItem->setPriceDefinition(
            new AbsolutePriceDefinition(
                (float) $priceDefinition['price'],
                new LineItemOfTypeRule(Rule::OPERATOR_NEQ, $type)
            )
        );

        $this->recalculationService->addCustomLineItem($orderId$lineItem$context);

        return new Response(null, Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/order/{orderId}/lineItem', name: 'api.action.order.add-line-item', methods: ['POST'])]     public function addCustomLineItemToOrder(string $orderId, Request $request, Context $context): Response
    {
        $identifier = (string) $request->request->get('identifier');
        $type = $request->request->get('type', LineItem::CUSTOM_LINE_ITEM_TYPE);
        $quantity = $request->request->getInt('quantity', 1);

        
$entityRepository,
            $this->orderConverter,
            $this->createMock(CartService::class),
            $entityRepository,
            $entityRepository,
            $entityRepository,
            $this->createMock(Processor::class),
            $this->cartRuleLoader,
            $this->createMock(PromotionItemBuilder::class)
        );

        $recalculationService->addCustomLineItem($order->getId()$lineItem$this->context);
    }

    public function testAddPromotionLineItem(): void
    {
        $lineItem = new LineItem(Uuid::randomHex(), LineItem::CUSTOM_LINE_ITEM_TYPE);

        $order = $this->orderEntity();
        $cart = $this->getCart();
        $cart->add($lineItem);

        $entityRepository = $this->createMock(EntityRepository::class);
        
Home | Imprint | This part of the site doesn't use cookies.