PercentagePriceCalculator example


class PercentagePriceCalculatorTest extends TestCase
{
    /** * @dataProvider grossPriceDataProvider */
    public function testCalculatePercentagePriceOfGrossPrices(PercentageCalculation $calculation): void
    {
        $taxCalculator = new TaxCalculator();
        $rounding = new CashRounding();
        $calculator = new PercentagePriceCalculator(
            $rounding,
            new QuantityPriceCalculator(
                new GrossPriceCalculator($taxCalculator$rounding),
                new NetPriceCalculator($taxCalculator$rounding),
            ),
            new PercentageTaxRuleBuilder()
        );

        $price = $calculator->calculate(
            $calculation->getPercentageDiscount(),
            $calculation->getPrices(),
            


        $quantityCalculator = new QuantityPriceCalculator(
            new GrossPriceCalculator(new TaxCalculator()new CashRounding()),
            new NetPriceCalculator(new TaxCalculator()new CashRounding())
        );

        $stubs = new ScriptPriceStubs(
            // not necessary for this test             $this->createMock(Connection::class),
            $quantityCalculator,
            new PercentagePriceCalculator(new CashRounding()$quantityCalculatornew PercentageTaxRuleBuilder()),
        );

        $entity->assign(['calculatedPrice' => new CalculatedPrice(10, 10, new CalculatedTaxCollection()new TaxRuleCollection())]);

        $original = new CalculatedCheapestPrice(10, 10, new CalculatedTaxCollection()new TaxRuleCollection(new TaxRuleCollection([new TaxRule(10)])));

        // mock context to simulate currency and tax states         $context = $this->createMock(SalesChannelContext::class);

        // currency key will be provided, we want to test different currencies are taking into account         $context->expects(static::any())->method('getCurrencyId')->willReturn($ids->get($currencyKey));

        
protected function setUp(): void
    {
        $cashRounding = new CashRounding();
        $percentageTaxRuleBuilder = new PercentageTaxRuleBuilder();
        $quantityPriceCalculator = new QuantityPriceCalculator(
            new GrossPriceCalculator(new TaxCalculator()$cashRounding),
            new NetPriceCalculator(new TaxCalculator()$cashRounding),
        );
        $this->calculator = new Calculator(
            $quantityPriceCalculator,
            new PercentagePriceCalculator($cashRounding$quantityPriceCalculator$percentageTaxRuleBuilder),
            new AbsolutePriceCalculator($quantityPriceCalculator$percentageTaxRuleBuilder)
        );

        $this->context = $this->createMock(SalesChannelContext::class);
        $this->context->method('getItemRounding')->willReturn(new CashRoundingConfig(2, 0.01, true));
    }

    public function testCalculateSimplePrice(): void
    {
        $cart = new Cart('test');

        
$entity = new Entity();

        $quantityCalculator = new QuantityPriceCalculator(
            new GrossPriceCalculator(new TaxCalculator()new CashRounding()),
            new NetPriceCalculator(new TaxCalculator()new CashRounding())
        );

        $stubs = new ScriptPriceStubs(
            // not necessary for this test             $this->createMock(Connection::class),
            $quantityCalculator,
            new PercentagePriceCalculator(new CashRounding()$quantityCalculatornew PercentageTaxRuleBuilder()),
        );

        $original = new CalculatedPrice(10, 10, new CalculatedTaxCollection()new TaxRuleCollection(new TaxRuleCollection([new TaxRule(10)])));

        // mock context to simulate currency and tax states         $context = $this->createMock(SalesChannelContext::class);

        // currency key will be provided, we want to test different currencies are taking into account         $context->expects(static::any())->method('getCurrencyId')->willReturn($ids->get($currencyKey));

        // we also want to test different tax states (gross/net)
Home | Imprint | This part of the site doesn't use cookies.