Quellcode durchsuchen

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

feature/export_comptable
Guillaume vor 4 Jahren
Ursprung
Commit
45dd21f799
1 geänderte Dateien mit 30 neuen und 18 gelöschten Zeilen
  1. +30
    -18
      ShopBundle/Services/OrderUtils.php

+ 30
- 18
ShopBundle/Services/OrderUtils.php Datei anzeigen

@@ -73,24 +73,26 @@ 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;
}
// set user
if($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user) ;
$this->em->persist($orderShop) ;
$this->em->flush() ;
}
}

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;
@@ -127,6 +129,14 @@ class OrderUtils

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) {
$updated = false;

@@ -218,14 +228,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;

Laden…
Abbrechen
Speichern