60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\ZNZBundle\Context;
|
|
|
|
use External\ZNZBundle\Util\ZNZConfiguration;
|
|
use KupShop\KupShopBundle\Util\Compat\SymfonyBridge;
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
|
class CurrencyContext extends \KupShop\I18nBundle\Context\CurrencyContext
|
|
{
|
|
#[Required]
|
|
public RequestStack $requestStack;
|
|
|
|
#[Required]
|
|
public ZNZConfiguration $configuration;
|
|
|
|
protected array $domains = [];
|
|
|
|
#[Required]
|
|
public function setDomains(#[Autowire(param: 'shop.domains')] array $domains): CurrencyContext
|
|
{
|
|
$this->domains = $domains;
|
|
|
|
return $this;
|
|
}
|
|
|
|
protected function loadActive()
|
|
{
|
|
if ($this->configuration->isB2BShop()) {
|
|
return $this->loadActiveInB2BMode();
|
|
}
|
|
|
|
return $this->getCurrencyByConfig();
|
|
}
|
|
|
|
private function loadActiveInB2BMode(): string
|
|
{
|
|
$currency = $this->session->get('currency', $this->getCurrencyByConfig());
|
|
|
|
if (!$this->validate($currency)) {
|
|
$currency = $this->getCurrencyByConfig();
|
|
}
|
|
|
|
return $currency;
|
|
}
|
|
|
|
private function getCurrencyByConfig(): string
|
|
{
|
|
if (!($request = $this->requestStack->getMainRequest())) {
|
|
$request = SymfonyBridge::getCurrentRequest();
|
|
}
|
|
|
|
return $this->domains[$request->getHost()]['currency'] ?? 'CZK';
|
|
}
|
|
}
|