ItemsFacade example

private SalesChannelContext $context
    ) {
    }

    /** * The `items()` method returns all line-items of the current cart for further manipulation. * * @return ItemsFacade A `ItemsFacade` containing all line-items in the current cart as a collection. */
    public function items(): ItemsFacade
    {
        return new ItemsFacade($this->cart->getLineItems()$this->priceStubs, $this->helper, $this->context);
    }

    /** * The `product()` method returns all products of the current cart for further manipulation. * Similar to the `items()` method, but the line-items are filtered, to only contain product line items. * * @return ProductsFacade A `ProductsFacade` containing all product line-items in the current cart as a collection. */
    public function products(): ProductsFacade
    {
        return new ProductsFacade($this->cart->getLineItems()$this->priceStubs, $this->helper, $this->context);
    }

class ItemsFacadeTest extends TestCase
{
    public function testPublicApiAvailable(): void
    {
        $items = new LineItemCollection();

        $stubs = $this->createMock(ScriptPriceStubs::class);
        $helper = $this->createMock(CartFacadeHelper::class);
        $context = $this->createMock(SalesChannelContext::class);

        $facade = new ItemsFacade($items$stubs$helper$context);

        $facade->add(
            $this->item(new LineItem('item-1', 'item', 'reference'))
        );

        static::assertCount(1, $facade);
        static::assertTrue($facade->has('item-1'));
        static::assertInstanceOf(ItemFacade::class$facade->get('item-1'));

        $facade->remove('item-1');

        

        );
    }

    /** * `getChildren()` returns the child line-items of this line-item. * * @return ItemsFacade Returns the children as a `ItemsFacade`, that may be empty if no children exist. */
    public function getChildren(): ItemsFacade
    {
        return new ItemsFacade($this->item->getChildren()$this->priceStubs, $this->helper, $this->context);
    }

    /** * `getType()` returns the type of this line-item. * Possible types include `product`, `discount`, `container`, etc. * * @return string The type of the line-item. */
    public function getType(): string
    {
        return $this->item->getType();
    }
Home | Imprint | This part of the site doesn't use cookies.