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

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