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.     public function __construct(
  37.         float $netPrice,
  38.         float $totalPrice,
  39.         float $positionPrice,
  40.         CalculatedTaxCollection $calculatedTaxes,
  41.         TaxRuleCollection $taxRules,
  42.         string $taxStatus
  43.     ) {
  44.         $this->netPrice FloatComparator::cast($netPrice);
  45.         $this->totalPrice FloatComparator::cast($totalPrice);
  46.         $this->calculatedTaxes $calculatedTaxes;
  47.         $this->taxRules $taxRules;
  48.         $this->positionPrice $positionPrice;
  49.         $this->taxStatus $taxStatus;
  50.     }
  51.     public function getNetPrice(): float
  52.     {
  53.         return FloatComparator::cast($this->netPrice);
  54.     }
  55.     public function getTotalPrice(): float
  56.     {
  57.         return FloatComparator::cast($this->totalPrice);
  58.     }
  59.     public function getCalculatedTaxes(): CalculatedTaxCollection
  60.     {
  61.         return $this->calculatedTaxes;
  62.     }
  63.     public function getTaxRules(): TaxRuleCollection
  64.     {
  65.         return $this->taxRules;
  66.     }
  67.     public function getPositionPrice(): float
  68.     {
  69.         return $this->positionPrice;
  70.     }
  71.     public function getTaxStatus(): string
  72.     {
  73.         return $this->taxStatus;
  74.     }
  75.     public function hasNetPrices(): bool
  76.     {
  77.         return \in_array($this->taxStatus, [self::TAX_STATE_NETself::TAX_STATE_FREE], true);
  78.     }
  79.     public function isTaxFree(): bool
  80.     {
  81.         return $this->taxStatus === self::TAX_STATE_FREE;
  82.     }
  83.     public static function createEmpty(string $taxState self::TAX_STATE_GROSS): CartPrice
  84.     {
  85.         return new self(000, new CalculatedTaxCollection(), new TaxRuleCollection(), $taxState);
  86.     }
  87.     public function getApiAlias(): string
  88.     {
  89.         return 'cart_price';
  90.     }
  91. }