isRemovable example

$this->addTaxDataToSalesChannel($context$product['tax']);

        $lineItem = (new ProductLineItemFactory(new PriceDefinitionFactory()))->create(['id' => $productId, 'referencedId' => $productId]$context);
        $cart = $cartService->getCart($context->getToken()$context);
        $cart = $cartService->add($cart$lineItem$context);

        $lineItem = $cart->getLineItems()->get($productId);

        static::assertInstanceOf(LineItem::class$lineItem);
        static::assertEquals(1, $lineItem->getQuantity());
        static::assertTrue($lineItem->isStackable());
        static::assertTrue($lineItem->isRemovable());

        $cart = $cartService->update($cart['foo' => [
            'id' => $productId,
            'quantity' => 20,
            'payload' => ['foo' => 'bar'],
            'stackable' => false,
            'removable' => false,
        ]]$context);

        static::assertEquals(20, $lineItem->getQuantity());
        static::assertTrue($lineItem->isStackable());
        
$data = [
            'id' => $id,
            'identifier' => $lineItem->getId(),
            'productId' => $productId,
            'promotionId' => $promotionId,
            'referencedId' => $lineItem->getReferencedId(),
            'quantity' => $lineItem->getQuantity(),
            'type' => $lineItem->getType(),
            'label' => $lineItem->getLabel(),
            'description' => $lineItem->getDescription(),
            'good' => $lineItem->isGood(),
            'removable' => $lineItem->isRemovable(),
            'stackable' => $lineItem->isStackable(),
            'position' => $position,
            'price' => $lineItem->getPrice(),
            'priceDefinition' => $definition,
            'parentId' => $parentId,
            'coverId' => $lineItem->getCover() ? $lineItem->getCover()->getId() : null,
            'payload' => $lineItem->getPayload(),
            'states' => $lineItem->getStates(),
        ];

        $downloads = $lineItem->getExtensionOfType(OrderConverter::ORIGINAL_DOWNLOADS, OrderLineItemDownloadCollection::class);
        
/** * @throws CartException */
    public function remove(string $key): void
    {
        $item = $this->get($key);

        if (!$item) {
            throw CartException::lineItemNotFound($key);
        }

        if (!$item->isRemovable()) {
            throw CartException::lineItemNotRemovable($key);
        }

        $this->lineItems->remove($key);
    }

    public function getTransactions(): TransactionCollection
    {
        return $this->transactions;
    }

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