use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; | use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; | ||||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; | use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | ||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | ||||
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; | use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; | ||||
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; | use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; | ||||
); | ); | ||||
} | } | ||||
public function getUrl($merchant) | |||||
public function getUrl(SectionInterface $section) | |||||
{ | { | ||||
if ($this->urlResolver->isServerLocalhost()) { | if ($this->urlResolver->isServerLocalhost()) { | ||||
return $this->router->generate('frontend_home', [], UrlGeneratorInterface::ABSOLUTE_URL); | |||||
return $this->router->generate('frontend_home', ['section' => $section->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL); | |||||
} else { | } else { | ||||
return $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL); | |||||
return $section->getMerchant()->getSettingValue(MerchantSettingDefinition::SETTING_URL); | |||||
} | } | ||||
} | } | ||||
return $currentAdminSection; | return $currentAdminSection; | ||||
} // front | } // front | ||||
else { | else { | ||||
$sectionStore = $this->sectionStore->setMerchant($this->merchantResolver->getCurrent()); | |||||
$sectionCurrent = null; | $sectionCurrent = null; | ||||
$isCli = php_sapi_name() === 'cli'; | |||||
$sectionDefault = $sectionStore->getOneDefault(); | |||||
// local | |||||
if ($isCli || $this->urlResolver->isServerLocalhost()) { | |||||
$sectionArray = $this->sectionStore | |||||
->setMerchant($this->merchantResolver->getCurrent()) | |||||
->getOnline(); | |||||
foreach ($sectionArray as $section) { | |||||
if ($section->getDevAlias() == $_ENV['CURRENT_SECTION_LOCAL']) { | |||||
$sectionCurrent = $section; | |||||
} | |||||
} | |||||
} | |||||
// distant | |||||
else { | |||||
$sectionCurrent = $this->sectionStore | |||||
->setMerchant($this->merchantResolver->getCurrent()) | |||||
->getOneDefault(); | |||||
if(isset($requestAttributesArray['section'])) { | |||||
$sectionCurrent = $sectionStore->getOneBySlug($requestAttributesArray['section']); | |||||
} | } | ||||
return $sectionCurrent; | |||||
return $sectionCurrent ?: $sectionDefault; | |||||
} | } | ||||
} | } | ||||
new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']), | new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']), | ||||
new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']), | new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']), | ||||
new TwigFunction('section_current', [$this, 'getSectionCurrent']), | new TwigFunction('section_current', [$this, 'getSectionCurrent']), | ||||
new TwigFunction('section_slug_current', [$this, 'getSectionSlugCurrent']), | |||||
new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']), | new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']), | ||||
new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']), | new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']), | ||||
new TwigFunction('section_setting', [$this, 'getSectionSetting']), | new TwigFunction('section_setting', [$this, 'getSectionSetting']), | ||||
return $this->sectionResolver->getCurrent(); | return $this->sectionResolver->getCurrent(); | ||||
} | } | ||||
public function getSectionSlugCurrent(): string | |||||
{ | |||||
return $this->sectionResolver->getCurrent()->getSlug(); | |||||
} | |||||
public function getCartCurrent(): OrderShopInterface | public function getCartCurrent(): OrderShopInterface | ||||
{ | { | ||||
return $this->orderShopBuilder->createIfNotExist( | return $this->orderShopBuilder->createIfNotExist( |