Browse Source

Modification SectionResolver et MerchantResolver

packProduct
Guillaume 3 years ago
parent
commit
bc057c04e3
3 changed files with 15 additions and 22 deletions
  1. +4
    -3
      Resolver/MerchantResolver.php
  2. +5
    -19
      Resolver/SectionResolver.php
  3. +6
    -0
      Twig/StoreTwigExtension.php

+ 4
- 3
Resolver/MerchantResolver.php View File

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);
} }
} }



+ 5
- 19
Resolver/SectionResolver.php View File

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;
} }
} }



+ 6
- 0
Twig/StoreTwigExtension.php View File

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(

Loading…
Cancel
Save