vendor/shopware/core/Checkout/Cart/Price/QuantityPriceCalculator.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart\Price;
  3. use Shopware\Core\Checkout\Cart\Price\Struct\CalculatedPrice;
  4. use Shopware\Core\Checkout\Cart\Price\Struct\QuantityPriceDefinition;
  5. use Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection;
  6. use Shopware\Core\Checkout\Cart\Tax\Struct\TaxRuleCollection;
  7. use Shopware\Core\Checkout\Cart\Tax\TaxDetector;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. class QuantityPriceCalculator
  10. {
  11.     /**
  12.      * @var GrossPriceCalculator
  13.      */
  14.     private $grossPriceCalculator;
  15.     /**
  16.      * @var NetPriceCalculator
  17.      */
  18.     private $netPriceCalculator;
  19.     /**
  20.      * @var TaxDetector
  21.      */
  22.     private $taxDetector;
  23.     /**
  24.      * @var ReferencePriceCalculator
  25.      */
  26.     private $referencePriceCalculator;
  27.     public function __construct(
  28.         GrossPriceCalculator $grossPriceCalculator,
  29.         NetPriceCalculator $netPriceCalculator,
  30.         TaxDetector $taxDetector,
  31.         ReferencePriceCalculator $referencePriceCalculator
  32.     ) {
  33.         $this->grossPriceCalculator $grossPriceCalculator;
  34.         $this->netPriceCalculator $netPriceCalculator;
  35.         $this->taxDetector $taxDetector;
  36.         $this->referencePriceCalculator $referencePriceCalculator;
  37.     }
  38.     public function calculate(QuantityPriceDefinition $definitionSalesChannelContext $context): CalculatedPrice
  39.     {
  40.         if ($this->taxDetector->useGross($context)) {
  41.             $price $this->grossPriceCalculator->calculate($definition);
  42.         } else {
  43.             $price $this->netPriceCalculator->calculate($definition);
  44.         }
  45.         $taxRules $price->getTaxRules();
  46.         $calculatedTaxes $price->getCalculatedTaxes();
  47.         if ($this->taxDetector->isNetDelivery($context)) {
  48.             $taxRules = new TaxRuleCollection();
  49.             $calculatedTaxes = new CalculatedTaxCollection();
  50.         }
  51.         return new CalculatedPrice(
  52.             $price->getUnitPrice(),
  53.             $price->getTotalPrice(),
  54.             $calculatedTaxes,
  55.             $taxRules,
  56.             $price->getQuantity(),
  57.             $this->referencePriceCalculator->calculate($price->getUnitPrice(), $definition),
  58.             $price->getListPrice()
  59.         );
  60.     }
  61. }