vendor/shopware/core/System/SalesChannel/BaseContext.php line 79

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\SalesChannel;
  3. use Shopware\Core\Checkout\Cart\Delivery\Struct\ShippingLocation;
  4. use Shopware\Core\Checkout\Customer\Aggregate\CustomerGroup\CustomerGroupEntity;
  5. use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
  6. use Shopware\Core\Checkout\Shipping\ShippingMethodEntity;
  7. use Shopware\Core\Framework\Context;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Pricing\CashRoundingConfig;
  9. use Shopware\Core\Framework\Feature;
  10. use Shopware\Core\System\Currency\CurrencyEntity;
  11. use Shopware\Core\System\Tax\TaxCollection;
  12. /**
  13.  * @internal Use SalesChannelContext for extensions
  14.  */
  15. class BaseContext
  16. {
  17.     protected CustomerGroupEntity $currentCustomerGroup;
  18.     protected CustomerGroupEntity $fallbackCustomerGroup;
  19.     protected CurrencyEntity $currency;
  20.     protected SalesChannelEntity $salesChannel;
  21.     protected TaxCollection $taxRules;
  22.     protected PaymentMethodEntity $paymentMethod;
  23.     protected ShippingMethodEntity $shippingMethod;
  24.     protected ShippingLocation $shippingLocation;
  25.     protected Context $context;
  26.     private CashRoundingConfig $itemRounding;
  27.     private CashRoundingConfig $totalRounding;
  28.     /**
  29.      * @deprecated tag:v6.5.0 - Parameter $fallbackCustomerGroup is deprecated and will be removed
  30.      */
  31.     public function __construct(
  32.         Context $baseContext,
  33.         SalesChannelEntity $salesChannel,
  34.         CurrencyEntity $currency,
  35.         CustomerGroupEntity $currentCustomerGroup,
  36.         CustomerGroupEntity $fallbackCustomerGroup,
  37.         TaxCollection $taxRules,
  38.         PaymentMethodEntity $paymentMethod,
  39.         ShippingMethodEntity $shippingMethod,
  40.         ShippingLocation $shippingLocation,
  41.         CashRoundingConfig $itemRounding,
  42.         CashRoundingConfig $totalRounding
  43.     ) {
  44.         $this->currentCustomerGroup $currentCustomerGroup;
  45.         $this->fallbackCustomerGroup $fallbackCustomerGroup;
  46.         $this->currency $currency;
  47.         $this->salesChannel $salesChannel;
  48.         $this->taxRules $taxRules;
  49.         $this->paymentMethod $paymentMethod;
  50.         $this->shippingMethod $shippingMethod;
  51.         $this->shippingLocation $shippingLocation;
  52.         $this->context $baseContext;
  53.         $this->itemRounding $itemRounding;
  54.         $this->totalRounding $totalRounding;
  55.     }
  56.     public function getCurrentCustomerGroup(): CustomerGroupEntity
  57.     {
  58.         return $this->currentCustomerGroup;
  59.     }
  60.     /**
  61.      * @deprecated tag:v6.5.0 - Fallback customer group is deprecated and will be removed, use getCurrentCustomerGroup instead
  62.      */
  63.     public function getFallbackCustomerGroup(): CustomerGroupEntity
  64.     {
  65.         Feature::triggerDeprecationOrThrow(
  66.             'v6.5.0.0',
  67.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0''getCurrentCustomerGroup')
  68.         );
  69.         return $this->fallbackCustomerGroup;
  70.     }
  71.     public function getCurrency(): CurrencyEntity
  72.     {
  73.         return $this->currency;
  74.     }
  75.     public function getSalesChannel(): SalesChannelEntity
  76.     {
  77.         return $this->salesChannel;
  78.     }
  79.     public function getTaxRules(): TaxCollection
  80.     {
  81.         return $this->taxRules;
  82.     }
  83.     public function getPaymentMethod(): PaymentMethodEntity
  84.     {
  85.         return $this->paymentMethod;
  86.     }
  87.     public function getShippingMethod(): ShippingMethodEntity
  88.     {
  89.         return $this->shippingMethod;
  90.     }
  91.     public function getShippingLocation(): ShippingLocation
  92.     {
  93.         return $this->shippingLocation;
  94.     }
  95.     public function getContext(): Context
  96.     {
  97.         return $this->context;
  98.     }
  99.     public function getTaxState(): string
  100.     {
  101.         return $this->context->getTaxState();
  102.     }
  103.     public function getApiAlias(): string
  104.     {
  105.         return 'base_channel_context';
  106.     }
  107.     /**
  108.      * @codeCoverageIgnore
  109.      */
  110.     public function getTotalRounding(): CashRoundingConfig
  111.     {
  112.         return $this->totalRounding;
  113.     }
  114.     /**
  115.      * @codeCoverageIgnore
  116.      */
  117.     public function getItemRounding(): CashRoundingConfig
  118.     {
  119.         return $this->itemRounding;
  120.     }
  121.     public function getCurrencyId(): string
  122.     {
  123.         return $this->getCurrency()->getId();
  124.     }
  125. }