products example

$facade = $this->rampUpFacade();

        static::assertEquals('container', $facade->getType());
        static::assertEquals('container', $facade->getId());
        static::assertEquals('container', $facade->getReferencedId());

        static::assertEquals(1, $facade->getQuantity());
        static::assertTrue($facade->has('foo'));

        $facade->remove('foo');
        static::assertFalse($facade->has('foo'));
        static::assertCount(0, $facade->products());
    }

    public function testAbsoluteDiscount(): void
    {
        $facade = $this->rampUpFacade();

        static::assertEquals(1, $facade->getQuantity());
        static::assertTrue($facade->has('foo'));

        $absolute = new PriceCollection([new Price(Defaults::CURRENCY, 5, 5, false)]);
        $facade->discount('absolute', 'absolute', $absolute, 'my-discount');

        

    public function testAddProduct(string $input, ?string $expected): void
    {
        $context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL, []);

        $hook = new CartHook($this->createCart()$context);

        $service = $this->getContainer()->get(CartFacadeHookFactory::class)
            ->factory($hook$this->script);

        $service->products()->add($this->ids->get($input));
        $service->calculate();

        $item = $service->products()->get($this->ids->get($input));

        if ($expected === null) {
            static::assertNull($item);

            return;
        }

        static::assertInstanceOf(ItemFacade::class$item);
        
$facade = new CartFacade(
            $this->createMock(CartFacadeHelper::class),
            $this->createMock(ScriptPriceStubs::class),
            $cart,
            $this->createMock(SalesChannelContext::class)
        );

        $items = $facade->items();
        static::assertCount(3, $items);
        static::assertTrue($items->has('item'));

        $items = $facade->products();
        static::assertCount(3, $items);

        $price = $facade->price();
        static::assertEquals(100, $price->getTotal());

        $errors = $facade->errors();
        static::assertCount(1, $errors);

        static::assertSame('my-container', $facade->container('my-container')->getId());
        static::assertEquals(3, $facade->count());
        static::assertTrue($cart->has('item'));
        
Home | Imprint | This part of the site doesn't use cookies.