bool $cache = false | bool $cache = false | ||||
): OrderShopInterface { | ): OrderShopInterface { | ||||
$cart = null; | |||||
// cache | // cache | ||||
$cacheIdCartCurrent = 'cart_current_'.$section->getId(); | $cacheIdCartCurrent = 'cart_current_'.$section->getId(); | ||||
if($cache && isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent])) { | if($cache && isset($this->cacheCartCurrentBySection[$cacheIdCartCurrent])) { | ||||
if ($cartUser && $cartVisitor && $cartUser->getId() != $cartVisitor->getId()) { | if ($cartUser && $cartVisitor && $cartUser->getId() != $cartVisitor->getId()) { | ||||
$cart = $this->merge($cartUser, $cartVisitor); | $cart = $this->merge($cartUser, $cartVisitor); | ||||
} else { | } else { | ||||
$cart = $cartUser ?: $cartVisitor; | |||||
if($cartUser) { | |||||
$cart = $cartUser; | |||||
} | |||||
elseif($cartVisitor) { | |||||
if($user && $cartVisitor && !$cartVisitor->getUser()) { | |||||
$cartVisitor->setUser($user); | |||||
$this->entityManager->update($cartVisitor); | |||||
$this->entityManager->flush(); | |||||
} | |||||
$cart = $cartVisitor; | |||||
} | |||||
} | } | ||||
if (!$cart) { | if (!$cart) { | ||||
$cart = $this->create($section, $user, $visitor); | $cart = $this->create($section, $user, $visitor); | ||||
} | } | ||||
// @TODO : obligé de faire ça sinon le panier ne se met pas à jour quand on ajoute des produits. Pourquoi ? | |||||
$this->entityManager->refresh($cart); | |||||
// cache | // cache | ||||
$this->cacheCartCurrentBySection[$cacheIdCartCurrent] = $cart; | $this->cacheCartCurrentBySection[$cacheIdCartCurrent] = $cart; | ||||
return $cart; | return $cart; | ||||
// @TODO : obligé de faire ça sinon le panier ne se met pas à jour quand on ajoute des produits. Pourquoi ? | |||||
//$this->entityManager->refresh($cart); | |||||
} | } | ||||
public function setOrderStatus( | public function setOrderStatus( | ||||
&& $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery() | && $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery() | ||||
&& (string)$this->priceSolver->getPrice($orderProduct) | && (string)$this->priceSolver->getPrice($orderProduct) | ||||
== (string)$this->priceSolver->getPrice($orderProductAdd) | == (string)$this->priceSolver->getPrice($orderProductAdd) | ||||
&& $orderProduct->getOrderProductReductionCatalog() | |||||
&& $orderProductAdd->getOrderProductReductionCatalog() | |||||
&& $this->orderProductReductionCatalogSolver->compare( | && $this->orderProductReductionCatalogSolver->compare( | ||||
$orderProduct->getOrderProductReductionCatalog(), | $orderProduct->getOrderProductReductionCatalog(), | ||||
$orderProductAdd->getOrderProductReductionCatalog() | $orderProductAdd->getOrderProductReductionCatalog() |
$form->handleRequest($request); | $form->handleRequest($request); | ||||
if ($form->isSubmitted() && $form->isValid()) { | if ($form->isSubmitted() && $form->isValid()) { | ||||
$orderShop = $this->getOrderShopContainer()->getBuilder()->createIfNotExist( | $orderShop = $this->getOrderShopContainer()->getBuilder()->createIfNotExist( | ||||
$this->getSectionCurrent(), | $this->getSectionCurrent(), | ||||
$this->getUserCurrent(), | $this->getUserCurrent(), |
$idProductFamily = $options['data']['id_product_family']; | $idProductFamily = $options['data']['id_product_family']; | ||||
$productFamily = $this->productFamilyStore->getOneById($idProductFamily); | $productFamily = $this->productFamilyStore->getOneById($idProductFamily); | ||||
// @TODO : obligé sinon ne fonctionne pas. Problème avec le chargement des relations ? | |||||
$this->entityManager->refresh($productFamily); | |||||
$builder->add('id_product_family', HiddenType::class, [ | $builder->add('id_product_family', HiddenType::class, [ | ||||
'data' => $productFamily->getId() | 'data' => $productFamily->getId() | ||||
]); | ]); | ||||
if ($productFamily) { | if ($productFamily) { | ||||
if ($productFamily->getActiveProducts() | if ($productFamily->getActiveProducts() | ||||
&& $productFamily->getBehaviorAddToCart() == 'multiple') { | && $productFamily->getBehaviorAddToCart() == 'multiple') { | ||||
$cpt = 0; | |||||
foreach ($this->productFamilySolver->getProductsGroupByTitle($productFamily) as $key => $product) { | |||||
$cpt = 0; | |||||
foreach ($this->productFamilySolver->getProductsGroupByTitle($productFamily) as $product) { | |||||
$orderProduct = $this->orderProductFactory->create($product[0], 0); | $orderProduct = $this->orderProductFactory->create($product[0], 0); | ||||
$builder->add('order_product_' . $cpt, OrderProductType::class, [ | $builder->add('order_product_' . $cpt, OrderProductType::class, [ | ||||
'data' => $orderProduct | 'data' => $orderProduct | ||||
$product = null; | $product = null; | ||||
if ($productFamily->getActiveProducts()) { | if ($productFamily->getActiveProducts()) { | ||||
$products = $this->productFamilySolver->getProductsOnline($productFamily); | $products = $this->productFamilySolver->getProductsOnline($productFamily); | ||||
if ($products && count($products) > 0) { | if ($products && count($products) > 0) { | ||||
$product = $products[0]; | $product = $products[0]; | ||||
} | } |
// findCartCurrent | // findCartCurrent | ||||
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface | public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface | ||||
{ | { | ||||
if(is_null($user) && is_null($visitor)) { | |||||
return null; | |||||
} | |||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
if (!is_null($user)) { | if (!is_null($user)) { |
// compareOrderProductReductionCatalog | // compareOrderProductReductionCatalog | ||||
public function compare( | public function compare( | ||||
OrderProductReductionCatalogInterface $orderProductReductionCatalog, | |||||
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare | |||||
OrderProductReductionCatalogInterface $orderProductReductionCatalog = null, | |||||
OrderProductReductionCatalogInterface $orderProductReductionCatalogCompare = null | |||||
): bool { | ): bool { | ||||
if(is_null($orderProductReductionCatalog) && is_null($orderProductReductionCatalogCompare)) { | |||||
return true; | |||||
} | |||||
if(is_null($orderProductReductionCatalog) || is_null($orderProductReductionCatalogCompare)) { | |||||
return false; | |||||
} | |||||
return $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit() | return $orderProductReductionCatalog->getUnit() == $orderProductReductionCatalogCompare->getUnit() | ||||
&& (string)$orderProductReductionCatalog->getValue( | && (string)$orderProductReductionCatalog->getValue( | ||||
) == (string)$orderProductReductionCatalogCompare->getValue() | ) == (string)$orderProductReductionCatalogCompare->getValue() |
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) | || (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) | ||||
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { | && $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { | ||||
if ($byWeight) { | if ($byWeight) { | ||||
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getProduct()->getUnitInherited()->getCoefficient()); | |||||
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $this->productSolver->getUnitInherited($orderProduct->getProduct())->getCoefficient()); | |||||
} else { | } else { | ||||
$quantity += $orderProduct->getQuantityOrder(); | $quantity += $orderProduct->getQuantityOrder(); | ||||
} | } |
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']), | |||||
); | ); | ||||
} | } | ||||
//TODO mettre à jour une fois les repo fait | //TODO mettre à jour une fois les repo fait | ||||
return array(); | return array(); | ||||
} | } | ||||
public function getVisitorCurrent() | |||||
{ | |||||
return $this->visitorResolver->getCurrent(); | |||||
} | |||||
} | } |