getDiscount example


    public function toArray()
    {
        return [
            'id' => $this->getId(),
            'key' => $this->getKey(),
            'tax' => $this->getTax(),
            'mode' => $this->getMode(),
            'minimumorder' => $this->getMinimumOrder(),
            'minimumordersurcharge' => $this->getMinimumOrderSurcharge(),
            'basketdiscount' => $this->getDiscount(),
        ];
    }
}
static::assertInstanceOf(SalesChannelProductEntity::class$product);

            $price = $product->getCalculatedPrice();

            static::assertInstanceOf(ListPrice::class$price->getListPrice());

            static::assertEquals($case->expectedPrice, $price->getUnitPrice());
            static::assertEquals($case->expectedWas, $price->getListPrice()->getPrice());

            static::assertEquals($case->percentage, $price->getListPrice()->getPercentage());
            static::assertEquals($case->discount, $price->getListPrice()->getDiscount());

            $partialCriteria = new Criteria([$id]);
            $partialCriteria->addFields(['price', 'taxId']);
            $product = $this->getContainer()->get('sales_channel.product.repository')
                ->search($partialCriteria$context)
                ->get($id);

            static::assertInstanceOf(PartialEntity::class$product);

            $price = $product->get('calculatedPrice');

            
/** @var ArrayEntity $entity */
        static::assertInstanceOf(ArrayEntity::class$entity);

        $price = $entity->get('price');

        /** @var CalculatedPrice $price */
        static::assertInstanceOf(CalculatedPrice::class$price);

        static::assertInstanceOf(ListPrice::class$price->getListPrice());
        static::assertEquals(200, $price->getListPrice()->getPrice());
        static::assertEquals(-100, $price->getListPrice()->getDiscount());
        static::assertEquals(50, $price->getListPrice()->getPercentage());
    }
}
$taxCalculator = new TaxCalculator();

        $calculator = new AbsolutePriceCalculator(
            new QuantityPriceCalculator(
                new GrossPriceCalculator($taxCalculator$rounding),
                new NetPriceCalculator($taxCalculator$rounding),
            ),
            new PercentageTaxRuleBuilder()
        );

        $calculatedPrice = $calculator->calculate(
            $calculation->getDiscount(),
            $calculation->getPrices(),
            Generator::createSalesChannelContext()
        );

        static::assertEquals($calculation->getExpected()->getCalculatedTaxes()$calculatedPrice->getCalculatedTaxes());
        static::assertEquals($calculation->getExpected()->getTaxRules()$calculatedPrice->getTaxRules());
        static::assertEquals($calculation->getExpected()->getTotalPrice()$calculatedPrice->getTotalPrice());
        static::assertEquals($calculation->getExpected()->getUnitPrice()$calculatedPrice->getUnitPrice());
        static::assertEquals($calculation->getExpected()->getQuantity()$calculatedPrice->getQuantity());
    }

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