prices example

->variant(
                    (new ProductBuilder($this->ids, 'v.4.2'))
                        ->price(70)
                        ->price(101, null, 'currency')
                        ->build()
                )
                ->build(),

            // no rule = 110€ || rule-a = 130€             (new ProductBuilder($this->ids, 'p.5'))
                ->price(110)
                ->prices('rule-a', 130)
                ->prices('rule-a', 120, 'default', null, 3)
                ->visibility(TestDefaults::SALES_CHANNEL)
                ->build(),

            // no rule = 120€ || rule-a = 130€             (new ProductBuilder($this->ids, 'p.6'))
                ->price(120)
                ->prices('rule-a', 150)
                ->prices('rule-a', 140, 'default', null, 3)
                ->prices('rule-a', 199, 'currency')
                ->prices('rule-a', 188, 'currency', null, 3)
                
->variant(
                        (new ProductBuilder($ids, 'v.4.2'))
                            ->price(70, null, 'default', 77)
                            ->price(101, null, 'currency')
                            ->build()
                    )
                    ->build(),

                // no rule = 110€ || rule-a = 130€                 (new ProductBuilder($ids, 'p.5'))
                    ->price(110)
                    ->prices('rule-a', 130, 'default')
                    ->prices('rule-a', 120, 'default', null, 3, false, 150)
                    ->visibility(TestDefaults::SALES_CHANNEL)
                    ->build(),

                // no rule = 120€ || rule-a = 130€                 (new ProductBuilder($ids, 'p.6'))
                    ->price(120)
                    ->prices('rule-a', 150)
                    ->prices('rule-a', 140, 'default', null, 3)
                    ->prices('rule-a', 199, 'currency')
                    ->prices('rule-a', 188, 'currency', null, 3)
                    
static::assertNotContains('v.2.2', $names);
    }

    private function prepareTestData(): void
    {
        $products = [
            (new ProductBuilder($this->ids, 'p.1'))
                ->price(900)
                ->property('rot', 'Farbe')
                ->property('grün', 'Farbe')
                ->visibility(TestDefaults::SALES_CHANNEL)
                ->prices('rule-a', 220, 'default', null, 3, true)
                ->variant(
                    (new ProductBuilder($this->ids, 'v.1.1'))
                        ->build()
                )
                ->variant(
                    (new ProductBuilder($this->ids, 'v.1.2'))
                        ->prices('rule-a', 210, 'default', null, 3, true)
                        ->prices('rule-b', 501, 'default', null, 3, true)
                        ->build()
                )
                ->build(),
            (

        $ids = new IdsCollection();

        $products = [
            (new ProductBuilder($ids, 'p1'))
                ->visibility()
                ->price(100)
                ->build(),
            (new ProductBuilder($ids, 'p2'))
                ->price(100)
                ->visibility()
                ->prices('rule-A', 50)
                ->prices('rule-A', 30, 'default', null, 10)
                ->prices('rule-A', 15, 'default', null, 20)
                ->build(),
            (new ProductBuilder($ids, 'p3'))
                ->price(100)
                ->visibility()
                ->variant((new ProductBuilder($ids, 'p3.1'))->price(50)->build())
                ->variant((new ProductBuilder($ids, 'p3.2'))->price(40)->build())
                ->build(),
        ];

        
$products = [
            (new ProductBuilder($ids, 'product-1', 10, 'tax'))
                ->price(15, 10)
                ->manufacturer('manufacturer-1')
                ->property('red', 'color')
                ->property('yellow', 'color')
                ->property('XL', 'size')
                ->property('L', 'size')
                ->category('category-1')
                ->category('category-2')
                ->prices('rule-1', 100)
                ->prices('rule-2', 150)
                ->build(),

            (new ProductBuilder($ids, 'product-1-variant', 10, 'tax'))
                ->parent('product-1')
                ->build(),

            (new ProductBuilder($ids, 'product-2', 3, 'tax'))
                ->price(15, 10)
                ->manufacturer('manufacturer-2')
                ->property('red', 'color')
                
$this->productRepository = $this->getContainer()->get('product.repository');
        $this->entityLoadedEventFactory = $this->getContainer()->get(EntityLoadedEventFactory::class);
        $this->ids = new IdsCollection();
    }

    public function testCreate(): void
    {
        $builder = (new ProductBuilder($this->ids, 'p1'))
            ->price(10)
            ->category('c1')
            ->manufacturer('m1')
            ->prices('r1', 5);

        $this->productRepository->create([$builder->build()], Context::createDefaultContext());

        $criteria = new Criteria();
        $criteria->addAssociations([
            'manufacturer',
            'prices',
            'categories',
        ]);

        /** @var ProductEntity $product */
        
static::assertIsString(ProductSubscriber::getSubscribedEvents()['sales_channel.product.loaded']);
    }

    public function testCheapestPriceOnSalesChannelProductEntity(): void
    {
        $ids = new IdsCollection();

        $this->getContainer()->get('product.repository')
            ->create([
                (new ProductBuilder($ids, 'p.1'))
                    ->price(130)
                    ->prices('rule-a', 150)
                    ->visibility()
                    ->build(),
            ], Context::createDefaultContext());

        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
        /** @var SalesChannelProductEntity $productEntity */
        $productEntity = $this->getContainer()
            ->get('sales_channel.product.repository')
            ->search(new Criteria([$ids->get('p.1')])$salesChannelContext)
            ->first();

        


    /** * @dataProvider advancedPricingProvider */
    public function testAdvancedPricing(bool $valid, float $price): void
    {
        $ids = new IdsCollection();

        $product = (new ProductBuilder($ids, 'test'))
            ->price(100)
            ->prices('rule-1', 200, 'default', null, 1, $valid)
            ->visibility()
            ->build();

        $this->getContainer()->get('product.repository')->create([$product], Context::createDefaultContext());

        $context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $result = $this->getContainer()->get(CartRuleLoader::class)
            ->loadByToken($context, Uuid::randomHex());

        
Home | Imprint | This part of the site doesn't use cookies.