public function isOutOfSection() | public function isOutOfSection() | ||||
{ | { | ||||
return is_null($this->getSectionCurrent()); | |||||
return $this->get(SectionResolver::class)->isOutOfSection(); | |||||
} | } | ||||
public function getSectionCurrentSlug(): string | public function getSectionCurrentSlug(): string |
*/ | */ | ||||
protected $section; | protected $section; | ||||
public function getSection(): ?SectionInterface | |||||
public function getSection(): SectionInterface | |||||
{ | { | ||||
return $this->section; | return $this->section; | ||||
} | } |
protected ?SectionInterface $section = null; | protected ?SectionInterface $section = null; | ||||
protected EntityManagerInterface $entityManager; | protected EntityManagerInterface $entityManager; | ||||
protected Security $security; | |||||
protected MerchantResolver $merchantResolver; | protected MerchantResolver $merchantResolver; | ||||
protected SectionStore $sectionStore; | protected SectionStore $sectionStore; | ||||
protected RequestStack $requestStack; | protected RequestStack $requestStack; | ||||
protected UrlResolver $urlResolver; | protected UrlResolver $urlResolver; | ||||
public function __construct( | 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->entityManager = $entityManager; | ||||
$this->security = $security; | |||||
$this->merchantResolver = $merchantResolver; | $this->merchantResolver = $merchantResolver; | ||||
$this->sectionStore = $sectionStore; | $this->sectionStore = $sectionStore; | ||||
$this->requestStack = $requestStack; | $this->requestStack = $requestStack; | ||||
$this->urlResolver = $urlResolver; | $this->urlResolver = $urlResolver; | ||||
} | } | ||||
public function getCurrent() | |||||
public function getCurrent($returnDefaultIfOutOfSections = false, $returnVisitedIfOutOfSection = false) | |||||
{ | { | ||||
$requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all(); | $requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all(); | ||||
// admin | // admin | ||||
if (isset($requestAttributesArray['_firewall_context']) && $requestAttributesArray['_firewall_context'] == 'security.firewall.map.context.admin') { | if (isset($requestAttributesArray['_firewall_context']) && $requestAttributesArray['_firewall_context'] == 'security.firewall.map.context.admin') { | ||||
//dump($requestAttributesArray); | |||||
if (!$this->isCachedSection) { | if (!$this->isCachedSection) { | ||||
$currentAdminSection = null; | $currentAdminSection = null; | ||||
$userMerchant = $this->merchantResolver->getUserMerchant(); | $userMerchant = $this->merchantResolver->getUserMerchant(); | ||||
$currentAdminSection = $userMerchant->getCurrentAdminSection(); | $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->isCachedSection = true; | ||||
$this->section = $currentAdminSection; | $this->section = $currentAdminSection; | ||||
return $currentAdminSection; | return $currentAdminSection; | ||||
}else{ | |||||
} else { | |||||
return $this->section; | return $this->section; | ||||
} | } | ||||
} // front | } // front | ||||
else { | 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; | |||||
} | } | ||||
} | } | ||||
$byWeight = true; | $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 | public function hasMakeAChoiceAboutComplementaryOrder(OrderShop $orderShop): bool |
new TwigFunction('product_categories', [$this, 'getProductCategories']), | new TwigFunction('product_categories', [$this, 'getProductCategories']), | ||||
new TwigFunction('cart_current', [$this, 'getCartCurrent']), | new TwigFunction('cart_current', [$this, 'getCartCurrent']), | ||||
new TwigFunction('cart_current_visited', [$this, 'getCartCurrentVisited']), | |||||
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_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_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', [$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']), | ||||
new TwigFunction('section_setting_current', [$this, 'getSectionSettingCurrent']), | new TwigFunction('section_setting_current', [$this, 'getSectionSettingCurrent']), | ||||
new TwigFunction('visitor_current', [$this, 'getVisitorCurrent']), | 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() | public function getSections() | ||||
{ | { | ||||
return $this->sectionStore | return $this->sectionStore | ||||
return $this->sectionResolver->getCurrent(); | 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 | public function getSectionCurrentSlug(): string | ||||
{ | { | ||||
return $this->sectionResolver->getCurrent()->getSlug(); | 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 | public function getCartCurrent(): OrderShopInterface | ||||
{ | { | ||||
return $this->orderShopBuilder->createIfNotExist( | return $this->orderShopBuilder->createIfNotExist( | ||||
); | ); | ||||
} | } | ||||
public function getCartCurrentVisited(): OrderShopInterface | |||||
{ | |||||
return $this->orderShopBuilder->createIfNotExist( | |||||
$this->sectionResolver->getCurrent(true, true), | |||||
$this->security->getUser(), | |||||
$this->visitorResolver->getCurrent(), | |||||
true | |||||
); | |||||
} | |||||
public function getMerchantCurrent(): MerchantInterface | public function getMerchantCurrent(): MerchantInterface | ||||
{ | { | ||||
return $this->merchantResolver->getCurrent(); | return $this->merchantResolver->getCurrent(); |