CheapestPrice example


    /** * Regression test where the cheapest price and cheapest price container were exposed because the StructEncoder did not consider sales channel definitions */
    public function testCheapestPricesAreNotExposed(): void
    {
        $product = new SalesChannelProductEntity();
        $product->internalSetEntityData('product', new FieldVisibility([]));

        $product->setName('test');
        $product->setCheapestPrice(
            (new CheapestPrice())->assign([
                'hasRange' => false,
                'variantId' => Uuid::randomHex(),
                'parentId' => Uuid::randomHex(),
                'ruleId' => Uuid::randomHex(),
                'purchase' => 1.0,
                'reference' => 1.0,
                'price' => new PriceCollection(),
            ])
        );

        $registry = new StaticDefinitionInstanceRegistry(
            [

            ]),
            new PriceAssertion(2.0, 3.0, null, 4.0),
        ];

        yield 'Cheapest price calculation uses the cheapest price container' => [
            (new PartialEntity())->assign([
                'taxId' => Uuid::randomHex(),
                'price' => new PriceCollection([
                    new Price(Defaults::CURRENCY, 2, 2, false, new Price(Defaults::CURRENCY, 3, 3, false), null, new Price(Defaults::CURRENCY, 4, 4, false)),
                ]),
                'cheapestPrice' => (new CheapestPrice())->assign([
                    'price' => new PriceCollection([
                        new Price(Defaults::CURRENCY, 20, 20, false, new Price(Defaults::CURRENCY, 30, 30, false), null, new Price(Defaults::CURRENCY, 40, 40, false)),
                    ]),
                    'variantId' => Uuid::randomHex(),
                    'hasRange' => true,
                ]),
            ]),
            new PriceAssertion(20.0, 30.0, null, 40.0),
        ];
    }
}

if ($current !== $reference || $price['is_ranged']) {
                $hasRange = true;
            }

            if ($current < $reference) {
                $reference = $current;
                $cheapest = $price;
            }
        }
        // @codeCoverageIgnoreEnd
        $object = new CheapestPrice();
        $object->setRuleId($cheapest['rule_id']);
        $object->setVariantId($cheapest['variant_id']);
        $object->setParentId($cheapest['parent_id']);
        $object->setHasRange($hasRange);
        $object->setPurchase($cheapest['purchase_unit'] ? (float) $cheapest['purchase_unit'] : null);
        $object->setReference($cheapest['reference_unit'] ? (float) $cheapest['reference_unit'] : null);
        $object->setUnitId($cheapest['unit_id'] ?? null);

        $prices = [];

        $blueprint = new Price('', 1, 1, true);

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