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

Open in your IDE?
  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\Struct\Struct;
  6. use Shopware\Core\Framework\Util\FloatComparator;
  7. class CartPrice extends Struct
  8. {
  9.     public const TAX_STATE_GROSS 'gross';
  10.     public const TAX_STATE_NET 'net';
  11.     public const TAX_STATE_FREE 'tax-free';
  12.     /**
  13.      * @var float
  14.      */
  15.     protected $netPrice;
  16.     /**
  17.      * @var float
  18.      */
  19.     protected $totalPrice;
  20.     /**
  21.      * @var CalculatedTaxCollection
  22.      */
  23.     protected $calculatedTaxes;
  24.     /**
  25.      * @var TaxRuleCollection
  26.      */
  27.     protected $taxRules;
  28.     /**
  29.      * @var float
  30.      */
  31.     protected $positionPrice;
  32.     /**
  33.      * @var string
  34.      */
  35.     protected $taxStatus;
  36.     /**
  37.      * @var float
  38.      */
  39.     protected $rawTotal;
  40.     public function __construct(
  41.         float $netPrice,
  42.         float $totalPrice,
  43.         float $positionPrice,
  44.         CalculatedTaxCollection $calculatedTaxes,
  45.         TaxRuleCollection $taxRules,
  46.         string $taxStatus,
  47.         ?float $rawTotal null
  48.     ) {
  49.         $this->netPrice FloatComparator::cast($netPrice);
  50.         $this->totalPrice FloatComparator::cast($totalPrice);
  51.         $this->calculatedTaxes $calculatedTaxes;
  52.         $this->taxRules $taxRules;
  53.         $this->positionPrice FloatComparator::cast($positionPrice);
  54.         $this->taxStatus $taxStatus;
  55.         $rawTotal $rawTotal ?? $totalPrice;
  56.         $this->rawTotal FloatComparator::cast($rawTotal);
  57.     }
  58.     public function getNetPrice(): float
  59.     {
  60.         return $this->netPrice;
  61.     }
  62.     public function getTotalPrice(): float
  63.     {
  64.         return $this->totalPrice;
  65.     }
  66.     public function getCalculatedTaxes(): CalculatedTaxCollection
  67.     {
  68.         return $this->calculatedTaxes;
  69.     }
  70.     public function getTaxRules(): TaxRuleCollection
  71.     {
  72.         return $this->taxRules;
  73.     }
  74.     public function getPositionPrice(): float
  75.     {
  76.         return $this->positionPrice;
  77.     }
  78.     public function getTaxStatus(): string
  79.     {
  80.         return $this->taxStatus;
  81.     }
  82.     public function hasNetPrices(): bool
  83.     {
  84.         return \in_array($this->taxStatus, [self::TAX_STATE_NETself::TAX_STATE_FREE], true);
  85.     }
  86.     public function isTaxFree(): bool
  87.     {
  88.         return $this->taxStatus === self::TAX_STATE_FREE;
  89.     }
  90.     public static function createEmpty(string $taxState self::TAX_STATE_GROSS): CartPrice
  91.     {
  92.         return new self(000, new CalculatedTaxCollection(), new TaxRuleCollection(), $taxState);
  93.     }
  94.     public function getApiAlias(): string
  95.     {
  96.         return 'cart_price';
  97.     }
  98.     public function getRawTotal(): float
  99.     {
  100.         return $this->rawTotal;
  101.     }
  102. }