Browse Source

MerchantResolver : ajout méthode isOutOfMerchant()

packProduct
Guillaume 3 years ago
parent
commit
3690294c2b
1 changed files with 25 additions and 16 deletions
  1. +25
    -16
      Resolver/MerchantResolver.php

+ 25
- 16
Resolver/MerchantResolver.php View File

@@ -61,13 +61,34 @@ class MerchantResolver
$this->settingSolver = $settingSolver;
}

public function isOutOfMerchant()
{
return !$this->getCurrentProtected();
}

public function getCurrent(): MerchantInterface
{
if (isset($this->currentMerchant) && $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();
$merchants = $this->merchantRepository->findAll();
$isCli = php_sapi_name() === 'cli';
@@ -76,7 +97,7 @@ class MerchantResolver
if ($isCli || $this->urlResolver->isServerLocalhost()) {
foreach ($merchants as $merchant) {
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) {
$this->currentMerchant = $merchant;
$currentMerchant = $merchant;
}
}
} // distant
@@ -84,25 +105,13 @@ class MerchantResolver
foreach ($merchants as $merchant) {
$url = $this->settingSolver->getSettingValue($merchant, MerchantSettingDefinition::SETTING_URL);
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;
}
}
}*/
}
}

if ($this->currentMerchant instanceof MerchantInterface) {
return $this->currentMerchant;
} else {
throw new \ErrorException('Aucun merchant courant');
}
return $currentMerchant;
}

public function getUserMerchant(

Loading…
Cancel
Save