ItemFacade example


        }
        static::assertEquals(2, $asserted);
    }

    private function item(LineItem $item): ItemFacade
    {
        $stubs = $this->createMock(ScriptPriceStubs::class);
        $helper = $this->createMock(CartFacadeHelper::class);
        $context = $this->createMock(SalesChannelContext::class);

        return new ItemFacade($item$stubs$helper$context);
    }
}
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;
    }
}
'foo' => 'bar',
            'nested' => ['foo' => 'nested'],
        ]);

        $price = new CalculatedPrice(10, 10, new CalculatedTaxCollection()new TaxRuleCollection());
        $item->setPrice($price);

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

        $facade = new ItemFacade($item$stubs$helper$context);

        static::assertEquals('foo', $facade->getId());
        static::assertEquals('type', $facade->getType());
        static::assertEquals('reference', $facade->getReferencedId());
        static::assertEquals('label', $facade->getLabel());
        static::assertEquals(2, $facade->getQuantity());

        static::assertInstanceOf(PriceFacade::class$facade->getPrice());
        static::assertEquals(10, $facade->getPrice()->getUnit());
        static::assertEquals(10, $facade->getPrice()->getTotal());

        
return null;
        }

        $new = clone $this->item;
        $new->setId($key ?? Uuid::randomHex());
        $new->setQuantity($quantity);

        $this->item->setQuantity(
            $this->item->getQuantity() - $quantity
        );

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

    /** * `getId()` returns the id of the line-item. * * @return string Returns the id. */
    public function getId(): string
    {
        return $this->item->getId();
    }

    

    public function create(string $productId, int $quantity = 1): ItemFacade
    {
        $product = $this->helper->product($productId$quantity$this->context);

        return new ItemFacade($product$this->priceStubs, $this->helper, $this->context);
    }

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