take example

->factory($hook$this->script);

        $id = $this->ids->get('p1');

        $product = $service->products()->add($id, 10);

        $container = $service->container('my-container');

        static::assertInstanceOf(ItemFacade::class$product);
        static::assertInstanceOf(ContainerFacade::class$container);

        $split = $product->take(1);
        static::assertInstanceOf(ItemFacade::class$split);
        $container->add($split);

        $split = $product->take(1);
        static::assertInstanceOf(ItemFacade::class$split);
        $container->add($split);
        $container->discount('my-discount', 'percentage', -10, 'Fanzy discount');

        $surcharge = new PriceCollection([new Price(Defaults::CURRENCY, 2, 2, false)]);
        $container->surcharge('my-surcharge', 'absolute', $surcharge, 'unit test');

        

        $item = new LineItem('foo', 'type', 'reference', 5);
        $item->setLabel('label');
        $item->setStackable(true);

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

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

        $new = $facade->take(2);

        static::assertInstanceOf(ItemFacade::class$new);

        static::assertEquals(2, $new->getQuantity());
        static::assertEquals(3, $facade->getQuantity());
        static::assertNotEquals($facade->getId()$new->getId());
        static::assertEquals($facade->getType()$new->getType());
        static::assertEquals($facade->getReferencedId()$new->getReferencedId());
        static::assertEquals($facade->getLabel()$new->getLabel());

        static::assertNull($facade->take(100));
    }
Home | Imprint | This part of the site doesn't use cookies.