setReferencePriceDefinition example


class NetPriceCalculatorTest extends TestCase
{
    /** * @dataProvider referencePriceCalculationProvider */
    public function testReferencePriceCalculation(?ReferencePriceDefinition $reference, ?ReferencePrice $expected): void
    {
        $definition = new QuantityPriceDefinition(100, new TaxRuleCollection(), 1);
        $definition->setReferencePriceDefinition($reference);

        $calculator = new NetPriceCalculator(new TaxCalculator()new CashRounding());
        $price = $calculator->calculate($definitionnew CashRoundingConfig(2, 0.01, true));

        static::assertEquals($expected$price->getReferencePrice());
    }

    public static function referencePriceCalculationProvider(): \Generator
    {
        yield 'test calculation without reference price' => [
            null,
            

class GrossPriceCalculatorTest extends TestCase
{
    /** * @dataProvider referencePriceCalculationProvider */
    public function testReferencePriceCalculation(?ReferencePriceDefinition $reference, float $price, ?ReferencePrice $expected): void
    {
        $definition = new QuantityPriceDefinition($pricenew TaxRuleCollection(), 1);
        $definition->setReferencePriceDefinition($reference);

        $calculator = new GrossPriceCalculator(new TaxCalculator()new CashRounding());
        $result = $calculator->calculate($definitionnew CashRoundingConfig(2, 0.01, true));

        static::assertEquals($expected$result->getReferencePrice());
    }

    public static function referencePriceCalculationProvider(): \Generator
    {
        yield 'test calculation without reference price' => [
            null,
            
Entity $product,
        PriceCollection $prices,
        SalesChannelContext $context,
        UnitCollection $units,
        ReferencePriceDto $reference,
        int $quantity = 1
    ): QuantityPriceDefinition {
        $price = $this->getPriceValue($prices$context);

        $taxId = $product->get('taxId');
        $definition = new QuantityPriceDefinition($price$context->buildTaxRules($taxId)$quantity);
        $definition->setReferencePriceDefinition(
            $this->buildReferencePriceDefinition($reference$units)
        );
        $definition->setListPrice(
            $this->getListPrice($prices$context)
        );
        $definition->setRegulationPrice(
            $this->getRegulationPrice($prices$context)
        );

        return $definition;
    }

    
return $this->buildPriceDefinition($price$quantity);
    }

    private function buildPriceDefinition(CalculatedPrice $price, int $quantity): QuantityPriceDefinition
    {
        $definition = new QuantityPriceDefinition($price->getUnitPrice()$price->getTaxRules()$quantity);
        if ($price->getListPrice() !== null) {
            $definition->setListPrice($price->getListPrice()->getPrice());
        }

        if ($price->getReferencePrice() !== null) {
            $definition->setReferencePriceDefinition(
                new ReferencePriceDefinition(
                    $price->getReferencePrice()->getPurchaseUnit(),
                    $price->getReferencePrice()->getReferenceUnit(),
                    $price->getReferencePrice()->getUnitName()
                )
            );
        }

        return $definition;
    }

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