Sfoglia il codice sorgente

Modification SectionResolver et MerchantResolver

packProduct
Guillaume 3 anni fa
parent
commit
bc057c04e3
3 ha cambiato i file con 15 aggiunte e 22 eliminazioni
  1. +4
    -3
      Resolver/MerchantResolver.php
  2. +5
    -19
      Resolver/SectionResolver.php
  3. +6
    -0
      Twig/StoreTwigExtension.php

+ 4
- 3
Resolver/MerchantResolver.php Vedi File

@@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
@@ -119,12 +120,12 @@ class MerchantResolver
);
}

public function getUrl($merchant)
public function getUrl(SectionInterface $section)
{
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 {
return $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL);
return $section->getMerchant()->getSettingValue(MerchantSettingDefinition::SETTING_URL);
}
}


+ 5
- 19
Resolver/SectionResolver.php Vedi File

@@ -61,29 +61,15 @@ class SectionResolver
return $currentAdminSection;
} // front
else {
$sectionStore = $this->sectionStore->setMerchant($this->merchantResolver->getCurrent());
$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 Vedi File

@@ -85,6 +85,7 @@ class StoreTwigExtension extends AbstractExtension
new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']),
new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']),
new TwigFunction('section_current', [$this, 'getSectionCurrent']),
new TwigFunction('section_slug_current', [$this, 'getSectionSlugCurrent']),
new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']),
new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']),
new TwigFunction('section_setting', [$this, 'getSectionSetting']),
@@ -109,6 +110,11 @@ class StoreTwigExtension extends AbstractExtension
return $this->sectionResolver->getCurrent();
}

public function getSectionSlugCurrent(): string
{
return $this->sectionResolver->getCurrent()->getSlug();
}

public function getCartCurrent(): OrderShopInterface
{
return $this->orderShopBuilder->createIfNotExist(

Loading…
Annulla
Salva