Browse Source

Frontend : création du panier au moment de l'ajout d'un produit + set user

feature/export_comptable
Guillaume 4 years ago
parent
commit
45dd21f799
1 changed files with 30 additions and 18 deletions
  1. +30
    -18
      ShopBundle/Services/OrderUtils.php

+ 30
- 18
ShopBundle/Services/OrderUtils.php View File

} }


if ($orderShopUser || $orderShopVisitor) { 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); $orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client."); $this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
} else {
}
else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor; $orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
} }
// set user
if($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user) ;
$this->em->persist($orderShop) ;
$this->em->flush() ;
}
} }


if (!$user && !$visitor) { 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()
]);
}
$this->session->getFlashBag()->add('error', 'Vous devez accepter les cookies ou vous connecter pour avoir un panier sur le site.');
} }


return $orderShop; return $orderShop;


public function addOrderProduct($orderShop, $orderProductAdd, $persist = true) public function addOrderProduct($orderShop, $orderProductAdd, $persist = true)
{ {
if(!$orderShop) {
$orderShop = $this->createOrderShop([
'user' => $this->security->getUser(),
'visitor' => $this->userUtils->getVisitorCurrent(),
'merchant' => $this->merchantUtils->getMerchantCurrent()
]);
}

if ($orderProductAdd->getQuantityOrder() > 0) { if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false; $updated = false;


public function getOrderProductsByParentCategory($orderShop = null) public function getOrderProductsByParentCategory($orderShop = null)
{ {
$categoriesArray = []; $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; return $categoriesArray;

Loading…
Cancel
Save