custom/plugins/MadMykey/src/Core/System/SalesChannel/Context/SalesChannelContextFactory.php line 148

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Madco\Mykey\Core\System\SalesChannel\Context;
  4. use Doctrine\DBAL\Connection;
  5. use Madco\Mykey\Constants;
  6. use Madco\Mykey\Struct\MykeyDataStruct;
  7. use Shopware\Core\Checkout\Cart\Tax\TaxDetector;
  8. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  9. use Shopware\Core\System\SalesChannel\Context\AbstractBaseContextFactory;
  10. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory as OriginalSalesChannelContextFactory;
  11. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  12. use Shopware\Core\System\Tax\TaxRuleType\TaxRuleTypeFilterInterface;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  15. class SalesChannelContextFactory extends OriginalSalesChannelContextFactory
  16. {
  17.     /**
  18.      * @var EntityRepositoryInterface
  19.      */
  20.     private EntityRepositoryInterface $salesChannelRepository;
  21.     /**
  22.      * @var EntityRepositoryInterface
  23.      */
  24.     private EntityRepositoryInterface $currencyRepository;
  25.     /**
  26.      * @var EntityRepositoryInterface
  27.      */
  28.     private EntityRepositoryInterface $customerRepository;
  29.     /**
  30.      * @var EntityRepositoryInterface
  31.      */
  32.     private EntityRepositoryInterface $customerGroupRepository;
  33.     /**
  34.      * @var EntityRepositoryInterface
  35.      */
  36.     private EntityRepositoryInterface $countryRepository;
  37.     /**
  38.      * @var EntityRepositoryInterface
  39.      */
  40.     private EntityRepositoryInterface $taxRepository;
  41.     /**
  42.      * @var EntityRepositoryInterface
  43.      */
  44.     private EntityRepositoryInterface $addressRepository;
  45.     /**
  46.      * @var EntityRepositoryInterface
  47.      */
  48.     private EntityRepositoryInterface $paymentMethodRepository;
  49.     /**
  50.      * @var EntityRepositoryInterface
  51.      */
  52.     private EntityRepositoryInterface $shippingMethodRepository;
  53.     /**
  54.      * @var Connection
  55.      */
  56.     private Connection $connection;
  57.     /**
  58.      * @var EntityRepositoryInterface
  59.      */
  60.     private EntityRepositoryInterface $countryStateRepository;
  61.     /**
  62.      * @var TaxDetector
  63.      */
  64.     private TaxDetector $taxDetector;
  65.     /**
  66.      * @var iterable|TaxRuleTypeFilterInterface[]
  67.      */
  68.     private iterable $taxRuleTypeFilter;
  69.     /**
  70.      * @var EventDispatcherInterface
  71.      */
  72.     private EventDispatcherInterface $eventDispatcher;
  73.     private SessionInterface $session;
  74.     public function __construct(
  75.         EntityRepositoryInterface $salesChannelRepository,
  76.         EntityRepositoryInterface $currencyRepository,
  77.         EntityRepositoryInterface $customerRepository,
  78.         EntityRepositoryInterface $customerGroupRepository,
  79.         EntityRepositoryInterface $countryRepository,
  80.         EntityRepositoryInterface $taxRepository,
  81.         EntityRepositoryInterface $addressRepository,
  82.         EntityRepositoryInterface $paymentMethodRepository,
  83.         EntityRepositoryInterface $shippingMethodRepository,
  84.         Connection $connection,
  85.         EntityRepositoryInterface $countryStateRepository,
  86.         TaxDetector $taxDetector,
  87.         iterable $taxRuleTypeFilter,
  88.         EventDispatcherInterface $eventDispatcher,
  89.         SessionInterface $session,
  90.         EntityRepositoryInterface $currencyCountryRepository,
  91.         AbstractBaseContextFactory $abstractBaseContextFactory
  92.     ) {
  93.         $this->salesChannelRepository $salesChannelRepository;
  94.         $this->currencyRepository $currencyRepository;
  95.         $this->customerRepository $customerRepository;
  96.         $this->customerGroupRepository $customerGroupRepository;
  97.         $this->countryRepository $countryRepository;
  98.         $this->taxRepository $taxRepository;
  99.         $this->addressRepository $addressRepository;
  100.         $this->paymentMethodRepository $paymentMethodRepository;
  101.         $this->shippingMethodRepository $shippingMethodRepository;
  102.         $this->connection $connection;
  103.         $this->countryStateRepository $countryStateRepository;
  104.         $this->taxDetector $taxDetector;
  105.         $this->taxRuleTypeFilter $taxRuleTypeFilter;
  106.         $this->eventDispatcher $eventDispatcher;
  107.         $this->session $session;
  108.         parent::__construct(
  109.             $customerRepository,
  110.             $customerGroupRepository,
  111.             $addressRepository,
  112.             $paymentMethodRepository,
  113.             $taxDetector,
  114.             $taxRuleTypeFilter,
  115.             $eventDispatcher,
  116.             $currencyCountryRepository,
  117.             $abstractBaseContextFactory
  118.         );
  119.     }
  120.     public function create(string $tokenstring $salesChannelId, array $options = []): SalesChannelContext
  121.     {
  122.         $salesChannelContext parent::create($token$salesChannelId$options); // TODO: Change the autogenerated stub
  123.         //$request = $this->requestStack->getCurrentRequest();
  124.         $affiliateRequestAttribute $this->session->get(Constants::MYKEY_AFFILIATE_SESSION_ATTRIBUTEnull);
  125.         $mykeyPartnerRequestAttribute $this->session->get(Constants::MYKEY_PARTNER_SESSION_ATTRIBUTEnull);
  126.         if ($affiliateRequestAttribute instanceof MykeyDataStruct) {
  127.             $salesChannelContext->addExtension(Constants::MYKEY_AFFILIATE_SESSION_ATTRIBUTE$affiliateRequestAttribute);
  128.             $salesChannelContext->getContext()->addExtension(Constants::MYKEY_AFFILIATE_SESSION_ATTRIBUTE$affiliateRequestAttribute);
  129.         }
  130.         if ($mykeyPartnerRequestAttribute instanceof MykeyDataStruct) {
  131.             $salesChannelContext->addExtension(Constants::MYKEY_PARTNER_SESSION_ATTRIBUTE$mykeyPartnerRequestAttribute);
  132.             $salesChannelContext->getContext()->addExtension(Constants::MYKEY_PARTNER_SESSION_ATTRIBUTE$mykeyPartnerRequestAttribute);
  133.         }
  134.         return $salesChannelContext;
  135.     }
  136. }