|
|
@@ -33,10 +33,11 @@ class OrderUtils |
|
|
|
protected $priceUtils; |
|
|
|
protected $productFamilyUtils; |
|
|
|
protected $documentUtils ; |
|
|
|
protected $session ; |
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils, |
|
|
|
MerchantUtilsInterface $merchantUtils, PriceUtils $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils, |
|
|
|
DocumentUtils $documentUtils) |
|
|
|
DocumentUtils $documentUtils, SessionInterface $session) |
|
|
|
{ |
|
|
|
$this->em = $em; |
|
|
|
$this->security = $security; |
|
|
@@ -46,6 +47,7 @@ class OrderUtils |
|
|
|
$this->priceUtils = $priceUtils; |
|
|
|
$this->productFamilyUtils = $productFamilyUtils; |
|
|
|
$this->documentUtils = $documentUtils ; |
|
|
|
$this->session = $session ; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@@ -73,23 +75,21 @@ class OrderUtils |
|
|
|
} |
|
|
|
|
|
|
|
if ($orderShopUser || $orderShopVisitor) { |
|
|
|
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor && $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) { |
|
|
|
// merge |
|
|
|
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor |
|
|
|
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) { |
|
|
|
|
|
|
|
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor); |
|
|
|
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client."); |
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!$user && !$visitor) { |
|
|
|
$this->session->getFlashBag()->add('error', 'Vous devez accepter les cookies ou vous connecter pour créer un panier.'); |
|
|
|
} else { |
|
|
|
if (!$orderShop) { |
|
|
|
$orderShop = $this->createOrderShop([ |
|
|
|
'user' => $user, |
|
|
|
'visitor' => $visitor, |
|
|
|
'merchant' => $this->merchantUtils->getMerchantCurrent() |
|
|
|
]); |
|
|
|
// set user |
|
|
|
if($orderShop && $user && !$orderShop->getUser()) { |
|
|
|
$orderShop->setUser($user) ; |
|
|
|
$this->em->persist($orderShop) ; |
|
|
|
$this->em->flush() ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -120,13 +120,26 @@ class OrderUtils |
|
|
|
throw new \ErrorException('La commande doit être liée à un merchant.'); |
|
|
|
} |
|
|
|
|
|
|
|
$orderShop = $this->setOrderStatus('cart', $orderShop); |
|
|
|
$orderShop = $this->changeOrderStatus('cart', $orderShop); |
|
|
|
|
|
|
|
return $orderShop; |
|
|
|
} |
|
|
|
|
|
|
|
public function addOrderProduct($orderShop, $orderProductAdd, $persist = true) |
|
|
|
{ |
|
|
|
$return = false ; |
|
|
|
|
|
|
|
$user = $this->security->getUser() ; |
|
|
|
$visitor = $this->userUtils->getVisitorCurrent() ; |
|
|
|
|
|
|
|
if(!$orderShop) { |
|
|
|
$orderShop = $this->createOrderShop([ |
|
|
|
'user' => $user, |
|
|
|
'visitor' => $visitor, |
|
|
|
'merchant' => $this->merchantUtils->getMerchantCurrent() |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
if ($orderProductAdd->getQuantityOrder() > 0) { |
|
|
|
$updated = false; |
|
|
|
|
|
|
@@ -160,6 +173,7 @@ class OrderUtils |
|
|
|
} |
|
|
|
|
|
|
|
$updated = true; |
|
|
|
$return = true ; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
@@ -184,9 +198,12 @@ class OrderUtils |
|
|
|
if ($persist) { |
|
|
|
$this->em->flush(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$return = true ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $return ; |
|
|
|
} |
|
|
|
|
|
|
|
public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2) |
|
|
@@ -218,14 +235,16 @@ class OrderUtils |
|
|
|
public function getOrderProductsByParentCategory($orderShop = null) |
|
|
|
{ |
|
|
|
$categoriesArray = []; |
|
|
|
foreach ($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
$productCategories = $orderProduct->getProduct()->getProductFamily()->getProductCategories(); |
|
|
|
$category = $productCategories[0]->getParentCategory(); |
|
|
|
$labelCategory = $category->getTitle(); |
|
|
|
if (!isset($categoriesArray[$labelCategory])) { |
|
|
|
$categoriesArray[$labelCategory] = []; |
|
|
|
if($orderShop) { |
|
|
|
foreach ($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
$productCategories = $orderProduct->getProduct()->getProductFamily()->getProductCategories(); |
|
|
|
$category = $productCategories[0]->getParentCategory(); |
|
|
|
$labelCategory = $category->getTitle(); |
|
|
|
if (!isset($categoriesArray[$labelCategory])) { |
|
|
|
$categoriesArray[$labelCategory] = []; |
|
|
|
} |
|
|
|
$categoriesArray[$labelCategory][] = $orderProduct; |
|
|
|
} |
|
|
|
$categoriesArray[$labelCategory][] = $orderProduct; |
|
|
|
} |
|
|
|
|
|
|
|
return $categoriesArray; |