<?php
declare(strict_types=1);
namespace Madco\Mykey\Core\System\SalesChannel\Context;
use Doctrine\DBAL\Connection;
use Madco\Mykey\Constants;
use Madco\Mykey\Struct\MykeyDataStruct;
use Shopware\Core\Checkout\Cart\Tax\TaxDetector;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\System\SalesChannel\Context\AbstractBaseContextFactory;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory as OriginalSalesChannelContextFactory;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\Tax\TaxRuleType\TaxRuleTypeFilterInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class SalesChannelContextFactory extends OriginalSalesChannelContextFactory
{
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $salesChannelRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $currencyRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $customerRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $customerGroupRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $countryRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $taxRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $addressRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $paymentMethodRepository;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $shippingMethodRepository;
/**
* @var Connection
*/
private Connection $connection;
/**
* @var EntityRepositoryInterface
*/
private EntityRepositoryInterface $countryStateRepository;
/**
* @var TaxDetector
*/
private TaxDetector $taxDetector;
/**
* @var iterable|TaxRuleTypeFilterInterface[]
*/
private iterable $taxRuleTypeFilter;
/**
* @var EventDispatcherInterface
*/
private EventDispatcherInterface $eventDispatcher;
private SessionInterface $session;
public function __construct(
EntityRepositoryInterface $salesChannelRepository,
EntityRepositoryInterface $currencyRepository,
EntityRepositoryInterface $customerRepository,
EntityRepositoryInterface $customerGroupRepository,
EntityRepositoryInterface $countryRepository,
EntityRepositoryInterface $taxRepository,
EntityRepositoryInterface $addressRepository,
EntityRepositoryInterface $paymentMethodRepository,
EntityRepositoryInterface $shippingMethodRepository,
Connection $connection,
EntityRepositoryInterface $countryStateRepository,
TaxDetector $taxDetector,
iterable $taxRuleTypeFilter,
EventDispatcherInterface $eventDispatcher,
SessionInterface $session,
EntityRepositoryInterface $currencyCountryRepository,
AbstractBaseContextFactory $abstractBaseContextFactory
) {
$this->salesChannelRepository = $salesChannelRepository;
$this->currencyRepository = $currencyRepository;
$this->customerRepository = $customerRepository;
$this->customerGroupRepository = $customerGroupRepository;
$this->countryRepository = $countryRepository;
$this->taxRepository = $taxRepository;
$this->addressRepository = $addressRepository;
$this->paymentMethodRepository = $paymentMethodRepository;
$this->shippingMethodRepository = $shippingMethodRepository;
$this->connection = $connection;
$this->countryStateRepository = $countryStateRepository;
$this->taxDetector = $taxDetector;
$this->taxRuleTypeFilter = $taxRuleTypeFilter;
$this->eventDispatcher = $eventDispatcher;
$this->session = $session;
parent::__construct(
$customerRepository,
$customerGroupRepository,
$addressRepository,
$paymentMethodRepository,
$taxDetector,
$taxRuleTypeFilter,
$eventDispatcher,
$currencyCountryRepository,
$abstractBaseContextFactory
);
}
public function create(string $token, string $salesChannelId, array $options = []): SalesChannelContext
{
$salesChannelContext = parent::create($token, $salesChannelId, $options); // TODO: Change the autogenerated stub
//$request = $this->requestStack->getCurrentRequest();
$affiliateRequestAttribute = $this->session->get(Constants::MYKEY_AFFILIATE_SESSION_ATTRIBUTE, null);
$mykeyPartnerRequestAttribute = $this->session->get(Constants::MYKEY_PARTNER_SESSION_ATTRIBUTE, null);
if ($affiliateRequestAttribute instanceof MykeyDataStruct) {
$salesChannelContext->addExtension(Constants::MYKEY_AFFILIATE_SESSION_ATTRIBUTE, $affiliateRequestAttribute);
$salesChannelContext->getContext()->addExtension(Constants::MYKEY_AFFILIATE_SESSION_ATTRIBUTE, $affiliateRequestAttribute);
}
if ($mykeyPartnerRequestAttribute instanceof MykeyDataStruct) {
$salesChannelContext->addExtension(Constants::MYKEY_PARTNER_SESSION_ATTRIBUTE, $mykeyPartnerRequestAttribute);
$salesChannelContext->getContext()->addExtension(Constants::MYKEY_PARTNER_SESSION_ATTRIBUTE, $mykeyPartnerRequestAttribute);
}
return $salesChannelContext;
}
}