ContainerFacade example


    public function container(string $id, ?string $label = null): ContainerFacade
    {
        $item = new LineItem($id, LineItem::CONTAINER_LINE_ITEM, $id);
        $item->setLabel($label);
        $item->setRemovable(true);
        $item->setStackable(false);

        return new ContainerFacade($item$this->priceStubs, $this->helper, $this->context);
    }

    private function getItems(): LineItemCollection
    {
        return $this->items;
    }
}
$facade->surcharge('my-surcharge', 'foo', 10, 'my-surcharge');
    }

    private function rampUpFacade(): ContainerFacade
    {
        $container = new LineItem('container', 'container', 'container');

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

        $facade->add(
            new ItemFacade(new LineItem('foo', 'foo', 'foo')$stubs$helper$context)
        );

        return $facade;
    }
}
private SalesChannelContext $context;

    /** * @internal should not be used directly, loop over an ItemsFacade directly inside twig instead */
    public function getIterator(): \ArrayIterator
    {
        $items = [];
        foreach ($this->getItems() as $key => $item) {
            $items[$key] = match ($item->getType()) {
                LineItem::CONTAINER_LINE_ITEM => new ContainerFacade($item$this->priceStubs, $this->helper, $this->context),
                default => new ItemFacade($item$this->priceStubs, $this->helper, $this->context),
            };
        }

        return new \ArrayIterator($items);
    }

    private function getItems(): LineItemCollection
    {
        return $this->items;
    }
}

    public function get(string $id): ?ItemFacade
    {
        $item = $this->getItems()->get($id);

        if (!$item instanceof LineItem) {
            return null;
        }

        return match ($item->getType()) {
            LineItem::CONTAINER_LINE_ITEM => new ContainerFacade($item$this->priceStubs, $this->helper, $this->context),
            default => new ItemFacade($item$this->priceStubs, $this->helper, $this->context),
        };
    }

    private function getItems(): LineItemCollection
    {
        return $this->items;
    }
}
Home | Imprint | This part of the site doesn't use cookies.