vendor/shopware/core/Checkout/Cart/Price/Struct/CalculatedPrice.php line 10

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart\Price\Struct;
  3. use Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection;
  4. use Shopware\Core\Checkout\Cart\Tax\Struct\TaxRuleCollection;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Shopware\Core\Framework\Struct\Struct;
  7. use Shopware\Core\Framework\Util\FloatComparator;
  8. #[Package('checkout')]
  9. class CalculatedPrice extends Struct
  10. {
  11.     /**
  12.      * @var float
  13.      */
  14.     protected $unitPrice;
  15.     /**
  16.      * @var int
  17.      */
  18.     protected $quantity;
  19.     /**
  20.      * @var float
  21.      */
  22.     protected $totalPrice;
  23.     /**
  24.      * @var CalculatedTaxCollection
  25.      */
  26.     protected $calculatedTaxes;
  27.     /**
  28.      * @var TaxRuleCollection
  29.      */
  30.     protected $taxRules;
  31.     /**
  32.      * @var ReferencePrice|null
  33.      */
  34.     protected $referencePrice;
  35.     /**
  36.      * @var ListPrice|null
  37.      */
  38.     protected $listPrice;
  39.     /**
  40.      * @var RegulationPrice|null
  41.      */
  42.     protected $regulationPrice;
  43.     public function __construct(
  44.         float $unitPrice,
  45.         float $totalPrice,
  46.         CalculatedTaxCollection $calculatedTaxes,
  47.         TaxRuleCollection $taxRules,
  48.         int $quantity 1,
  49.         ?ReferencePrice $referencePrice null,
  50.         ?ListPrice $listPrice null,
  51.         ?RegulationPrice $regulationPrice null
  52.     ) {
  53.         $this->unitPrice FloatComparator::cast($unitPrice);
  54.         $this->totalPrice FloatComparator::cast($totalPrice);
  55.         $this->calculatedTaxes $calculatedTaxes;
  56.         $this->taxRules $taxRules;
  57.         $this->quantity $quantity;
  58.         $this->referencePrice $referencePrice;
  59.         $this->listPrice $listPrice;
  60.         $this->regulationPrice $regulationPrice;
  61.     }
  62.     public function getTotalPrice(): float
  63.     {
  64.         return FloatComparator::cast($this->totalPrice);
  65.     }
  66.     public function getCalculatedTaxes(): CalculatedTaxCollection
  67.     {
  68.         return $this->calculatedTaxes;
  69.     }
  70.     public function setCalculatedTaxes(CalculatedTaxCollection $calculatedTaxes): void
  71.     {
  72.         $this->calculatedTaxes $calculatedTaxes;
  73.     }
  74.     public function getTaxRules(): TaxRuleCollection
  75.     {
  76.         return $this->taxRules;
  77.     }
  78.     public function getUnitPrice(): float
  79.     {
  80.         return $this->unitPrice;
  81.     }
  82.     public function getQuantity(): int
  83.     {
  84.         return $this->quantity;
  85.     }
  86.     public function getReferencePrice(): ?ReferencePrice
  87.     {
  88.         return $this->referencePrice;
  89.     }
  90.     public function getListPrice(): ?ListPrice
  91.     {
  92.         return $this->listPrice;
  93.     }
  94.     public function getRegulationPrice(): ?RegulationPrice
  95.     {
  96.         return $this->regulationPrice;
  97.     }
  98.     public function getApiAlias(): string
  99.     {
  100.         return 'calculated_price';
  101.     }
  102.     /**
  103.      * Changing a price should always be a full change, otherwise you have
  104.      * mismatching information regarding the unit, total and tax values.
  105.      */
  106.     public function overwrite(float $unitPricefloat $totalPriceCalculatedTaxCollection $taxes): void
  107.     {
  108.         $this->unitPrice $unitPrice;
  109.         $this->totalPrice $totalPrice;
  110.         $this->calculatedTaxes $taxes;
  111.     }
  112. }