|
|
|
|
|
|
|
|
$this->settingSolver = $settingSolver; |
|
|
$this->settingSolver = $settingSolver; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function isOutOfMerchant() |
|
|
|
|
|
{ |
|
|
|
|
|
return !$this->getCurrentProtected(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function getCurrent(): MerchantInterface |
|
|
public function getCurrent(): MerchantInterface |
|
|
{ |
|
|
{ |
|
|
if (isset($this->currentMerchant) && $this->currentMerchant) { |
|
|
if (isset($this->currentMerchant) && $this->currentMerchant) { |
|
|
return $this->currentMerchant; |
|
|
return $this->currentMerchant; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->currentMerchant = null; |
|
|
|
|
|
|
|
|
$merchant = $this->getCurrentProtected(); |
|
|
|
|
|
|
|
|
|
|
|
if($merchant) { |
|
|
|
|
|
$this->currentMerchant = $merchant; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($this->currentMerchant instanceof MerchantInterface) { |
|
|
|
|
|
return $this->currentMerchant; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw new \ErrorException('Aucun merchant courant'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function getCurrentProtected(): ?MerchantInterface |
|
|
|
|
|
{ |
|
|
|
|
|
$currentMerchant = null; |
|
|
$request = $this->requestStack->getCurrentRequest(); |
|
|
$request = $this->requestStack->getCurrentRequest(); |
|
|
$merchants = $this->merchantRepository->findAll(); |
|
|
$merchants = $this->merchantRepository->findAll(); |
|
|
$isCli = php_sapi_name() === 'cli'; |
|
|
$isCli = php_sapi_name() === 'cli'; |
|
|
|
|
|
|
|
|
if ($isCli || $this->urlResolver->isServerLocalhost()) { |
|
|
if ($isCli || $this->urlResolver->isServerLocalhost()) { |
|
|
foreach ($merchants as $merchant) { |
|
|
foreach ($merchants as $merchant) { |
|
|
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) { |
|
|
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) { |
|
|
$this->currentMerchant = $merchant; |
|
|
|
|
|
|
|
|
$currentMerchant = $merchant; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} // distant |
|
|
} // distant |
|
|
|
|
|
|
|
|
foreach ($merchants as $merchant) { |
|
|
foreach ($merchants as $merchant) { |
|
|
$url = $this->settingSolver->getSettingValue($merchant, MerchantSettingDefinition::SETTING_URL); |
|
|
$url = $this->settingSolver->getSettingValue($merchant, MerchantSettingDefinition::SETTING_URL); |
|
|
if ($url && strlen($url) && strpos($url, $_SERVER['HTTP_HOST']) !== false) { |
|
|
if ($url && strlen($url) && strpos($url, $_SERVER['HTTP_HOST']) !== false) { |
|
|
$this->currentMerchant = $merchant; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
/*if ($_ENV['CURRENT_MERCHANT_COMMAND']) { |
|
|
|
|
|
foreach ($merchants as $merchant) { |
|
|
|
|
|
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_COMMAND']) { |
|
|
|
|
|
$currentMerchant = $merchant; |
|
|
$currentMerchant = $merchant; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}*/ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($this->currentMerchant instanceof MerchantInterface) { |
|
|
|
|
|
return $this->currentMerchant; |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new \ErrorException('Aucun merchant courant'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $currentMerchant; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUserMerchant( |
|
|
public function getUserMerchant( |