瀏覽代碼

Frontend : amélioration fusion panier

feature/export_comptable
Guillaume 4 年之前
父節點
當前提交
9fdc4de273
共有 2 個檔案被更改,包括 28 行新增4 行删除
  1. +23
    -3
      ShopBundle/Services/Order/OrderUtils.php
  2. +5
    -1
      ShopBundle/Services/Order/OrderUtilsCartTrait.php

+ 23
- 3
ShopBundle/Services/Order/OrderUtils.php 查看文件

@@ -69,7 +69,6 @@ class OrderUtils

public function createOrderShop($params)
{

//TODO vérifier que l'utilisateur n'a pas déjà une commande en cours
$orderShop = new OrderShop();

@@ -78,7 +77,7 @@ class OrderUtils
$orderShopBelongTo = true;
$orderShop->setUser($params['user']);
}
if (isset($params['visitor']) && $params['visitor']) {
if (isset($params['visitor']) && $params['visitor'] && !$orderShop->getUser()) {
$orderShopBelongTo = true;
$orderShop->setVisitor($params['visitor']);
}
@@ -296,7 +295,17 @@ class OrderUtils
if ($orderShop1 && $orderShop2) {

foreach ($orderShop2->getOrderProducts() as $orderProduct) {
$this->addOrderProduct($orderShop1, $orderProduct);

$orderProductAlreadyInCart = $this->hasOrderProductAlreadyInCart($orderShop1, $orderProduct) ;
if($orderProductAlreadyInCart) {
if($orderProduct->getQuantityOrder() > $orderProductAlreadyInCart->getQuantityOrder()) {
$orderShop1->removeOrderProduct($orderProductAlreadyInCart) ;
$this->addOrderProduct($orderShop1, $orderProduct);
}
}
else {
$this->addOrderProduct($orderShop1, $orderProduct);
}

if($persist) {
$this->em->remove($orderProduct);
@@ -314,6 +323,17 @@ class OrderUtils
}


public function hasOrderProductAlreadyInCart($orderShop, $orderProductTest)
{
foreach($orderShop->getOrderProducts() as $orderProduct) {
if($orderProduct->getProduct() == $orderProductTest->getProduct()) {
return $orderProduct ;
}
}

return false ;
}

public function groupOrderProductsByProductFamily($orderProducts)
{
$orderProductsByProductFamily = [];

+ 5
- 1
ShopBundle/Services/Order/OrderUtilsCartTrait.php 查看文件

@@ -3,6 +3,8 @@
namespace Lc\ShopBundle\Services\Order;


use Lc\ShopBundle\Model\OrderStatus;

trait OrderUtilsCartTrait
{
public function getCartCurrent()
@@ -31,7 +33,8 @@ trait OrderUtilsCartTrait
if ($orderShopUser || $orderShopVisitor) {
// merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) {
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->utils->addFlash('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
} else {
@@ -40,6 +43,7 @@ trait OrderUtilsCartTrait
// set user
if ($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user);
$orderShop->setVisitor(null) ;
$this->em->persist($orderShop);
$this->em->flush();
}

Loading…
取消
儲存