@@ -156,7 +156,7 @@ trait ControllerTrait | |||
public function isOutOfSection() | |||
{ | |||
return is_null($this->getSectionCurrent()); | |||
return $this->get(SectionResolver::class)->isOutOfSection(); | |||
} | |||
public function getSectionCurrentSlug(): string |
@@ -17,7 +17,7 @@ abstract class NewsletterModel extends SovNewsletterModel implements FilterSecti | |||
*/ | |||
protected $section; | |||
public function getSection(): ?SectionInterface | |||
public function getSection(): SectionInterface | |||
{ | |||
return $this->section; | |||
} |
@@ -19,33 +19,34 @@ class SectionResolver | |||
protected ?SectionInterface $section = null; | |||
protected EntityManagerInterface $entityManager; | |||
protected Security $security; | |||
protected MerchantResolver $merchantResolver; | |||
protected SectionStore $sectionStore; | |||
protected RequestStack $requestStack; | |||
protected UrlResolver $urlResolver; | |||
public function __construct( | |||
EntityManagerInterface $entityManager, | |||
MerchantResolver $merchantResolver, | |||
SectionStore $sectionStore, | |||
RequestStack $requestStack, | |||
UrlResolver $urlResolver | |||
) | |||
{ | |||
EntityManagerInterface $entityManager, | |||
Security $security, | |||
MerchantResolver $merchantResolver, | |||
SectionStore $sectionStore, | |||
RequestStack $requestStack, | |||
UrlResolver $urlResolver | |||
) { | |||
$this->entityManager = $entityManager; | |||
$this->security = $security; | |||
$this->merchantResolver = $merchantResolver; | |||
$this->sectionStore = $sectionStore; | |||
$this->requestStack = $requestStack; | |||
$this->urlResolver = $urlResolver; | |||
} | |||
public function getCurrent() | |||
public function getCurrent($returnDefaultIfOutOfSections = false, $returnVisitedIfOutOfSection = false) | |||
{ | |||
$requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all(); | |||
// admin | |||
if (isset($requestAttributesArray['_firewall_context']) && $requestAttributesArray['_firewall_context'] == 'security.firewall.map.context.admin') { | |||
//dump($requestAttributesArray); | |||
if (!$this->isCachedSection) { | |||
$currentAdminSection = null; | |||
$userMerchant = $this->merchantResolver->getUserMerchant(); | |||
@@ -54,42 +55,42 @@ class SectionResolver | |||
$currentAdminSection = $userMerchant->getCurrentAdminSection(); | |||
} | |||
/*if ($currentAdminSection === null) { | |||
$currentAdminSection = $this->sectionStore | |||
->setMerchant($userMerchant->getMerchant()) | |||
->getOneDefault(); | |||
if ($currentAdminSection === null) { | |||
throw new \ErrorException('Aucune section par défaut définie pour ce merchant'); | |||
} | |||
}*/ | |||
$this->isCachedSection = true; | |||
$this->section = $currentAdminSection; | |||
return $currentAdminSection; | |||
}else{ | |||
} else { | |||
return $this->section; | |||
} | |||
} // front | |||
else { | |||
$userCurrent = $this->security->getUser(); | |||
$merchantCurrent = $this->merchantResolver->getCurrent(); | |||
$sectionStore = $this->sectionStore->setMerchant($merchantCurrent); | |||
if($this->section === null) { | |||
$merchantCurrent = $this->merchantResolver->getCurrent(); | |||
$sectionStore = $this->sectionStore->setMerchant($merchantCurrent); | |||
$sectionCurrent = null; | |||
$sectionDefault = $sectionStore->getOneDefault(); | |||
$sectionCurrent = null; | |||
$sectionDefault = $sectionStore->getOneDefault(); | |||
if (isset($requestAttributesArray['section'])) { | |||
$sectionCurrent = $sectionStore | |||
->setMerchant($merchantCurrent) | |||
->getOneBySlug($requestAttributesArray['section']); | |||
} | |||
$currentVisitedSection = null; | |||
if ($userCurrent && $userCurrent->getCurrentVisitedSection()) { | |||
$currentVisitedSection = $userCurrent->getCurrentVisitedSection(); | |||
} | |||
if (isset($requestAttributesArray['section'])) { | |||
$sectionCurrent = $sectionStore | |||
->setMerchant($merchantCurrent) | |||
->getOneBySlug($requestAttributesArray['section']); | |||
} | |||
$this->section = $sectionCurrent ?: $sectionDefault; | |||
if ($sectionCurrent) { | |||
return $sectionCurrent; | |||
} elseif ($returnVisitedIfOutOfSection && $currentVisitedSection) { | |||
return $currentVisitedSection; | |||
} elseif ($returnDefaultIfOutOfSections && $sectionDefault) { | |||
return $sectionDefault; | |||
} | |||
return $this->section; | |||
return null; | |||
} | |||
} | |||
@@ -351,11 +351,11 @@ class OrderShopSolver | |||
$byWeight = true; | |||
} | |||
return $this->productSolver->getAvailableQuantityInherited($product) - $this->getQuantityOrderByProduct( | |||
$orderShop, | |||
$product, | |||
$byWeight | |||
); | |||
return max($this->productSolver->getAvailableQuantityInherited($product) - $this->getQuantityOrderByProduct( | |||
$orderShop, | |||
$product, | |||
$byWeight | |||
), 0); | |||
} | |||
public function hasMakeAChoiceAboutComplementaryOrder(OrderShop $orderShop): bool |
@@ -82,18 +82,36 @@ class StoreTwigExtension extends AbstractExtension | |||
new TwigFunction('product_categories', [$this, 'getProductCategories']), | |||
new TwigFunction('cart_current', [$this, 'getCartCurrent']), | |||
new TwigFunction('cart_current_visited', [$this, 'getCartCurrentVisited']), | |||
new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']), | |||
new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']), | |||
new TwigFunction('section_current', [$this, 'getSectionCurrent']), | |||
new TwigFunction('section_current_default', [$this, 'getSectionCurrentDefault']), | |||
new TwigFunction('section_current_visited', [$this, 'getSectionCurrentVisited']), | |||
new TwigFunction('is_out_of_sections', [$this, 'isOutOfSections']), | |||
new TwigFunction('is_inside_section', [$this, 'isInsideSection']), | |||
new TwigFunction('section_current_slug', [$this, 'getSectionCurrentSlug']), | |||
new TwigFunction('section_current_default_slug', [$this, 'getSectionCurrentDefaultSlug']), | |||
new TwigFunction('section_current_visited_slug', [$this, 'getSectionCurrentVisitedSlug']), | |||
new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']), | |||
new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']), | |||
new TwigFunction('section_setting', [$this, 'getSectionSetting']), | |||
new TwigFunction('section_setting_current', [$this, 'getSectionSettingCurrent']), | |||
new TwigFunction('visitor_current', [$this, 'getVisitorCurrent']), | |||
); | |||
} | |||
public function isInsideSection(): bool | |||
{ | |||
return (bool) $this->sectionResolver->getCurrent(); | |||
} | |||
public function isOutOfSections() | |||
{ | |||
return $this->sectionResolver->isOutOfSection(); | |||
} | |||
public function getSections() | |||
{ | |||
return $this->sectionStore | |||
@@ -111,11 +129,31 @@ class StoreTwigExtension extends AbstractExtension | |||
return $this->sectionResolver->getCurrent(); | |||
} | |||
public function getSectionCurrentDefault(): ?SectionInterface | |||
{ | |||
return $this->sectionResolver->getCurrent(true); | |||
} | |||
public function getSectionCurrentVisited(): ?SectionInterface | |||
{ | |||
return $this->sectionResolver->getCurrent(true, true); | |||
} | |||
public function getSectionCurrentSlug(): string | |||
{ | |||
return $this->sectionResolver->getCurrent()->getSlug(); | |||
} | |||
public function getSectionCurrentDefaultSlug(): string | |||
{ | |||
return $this->sectionResolver->getCurrent(true)->getSlug(); | |||
} | |||
public function getSectionCurrentVisitedSlug(): string | |||
{ | |||
return $this->sectionResolver->getCurrent(true, true)->getSlug(); | |||
} | |||
public function getCartCurrent(): OrderShopInterface | |||
{ | |||
return $this->orderShopBuilder->createIfNotExist( | |||
@@ -126,6 +164,16 @@ class StoreTwigExtension extends AbstractExtension | |||
); | |||
} | |||
public function getCartCurrentVisited(): OrderShopInterface | |||
{ | |||
return $this->orderShopBuilder->createIfNotExist( | |||
$this->sectionResolver->getCurrent(true, true), | |||
$this->security->getUser(), | |||
$this->visitorResolver->getCurrent(), | |||
true | |||
); | |||
} | |||
public function getMerchantCurrent(): MerchantInterface | |||
{ | |||
return $this->merchantResolver->getCurrent(); |