|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function createOrderShop($params) |
|
|
public function createOrderShop($params) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
//TODO vérifier que l'utilisateur n'a pas déjà une commande en cours |
|
|
//TODO vérifier que l'utilisateur n'a pas déjà une commande en cours |
|
|
$orderShop = new OrderShop(); |
|
|
$orderShop = new OrderShop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$orderShopBelongTo = true; |
|
|
$orderShopBelongTo = true; |
|
|
$orderShop->setUser($params['user']); |
|
|
$orderShop->setUser($params['user']); |
|
|
} |
|
|
} |
|
|
if (isset($params['visitor']) && $params['visitor']) { |
|
|
|
|
|
|
|
|
if (isset($params['visitor']) && $params['visitor'] && !$orderShop->getUser()) { |
|
|
$orderShopBelongTo = true; |
|
|
$orderShopBelongTo = true; |
|
|
$orderShop->setVisitor($params['visitor']); |
|
|
$orderShop->setVisitor($params['visitor']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($orderShop1 && $orderShop2) { |
|
|
if ($orderShop1 && $orderShop2) { |
|
|
|
|
|
|
|
|
foreach ($orderShop2->getOrderProducts() as $orderProduct) { |
|
|
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) { |
|
|
if($persist) { |
|
|
$this->em->remove($orderProduct); |
|
|
$this->em->remove($orderProduct); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function hasOrderProductAlreadyInCart($orderShop, $orderProductTest) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach($orderShop->getOrderProducts() as $orderProduct) { |
|
|
|
|
|
if($orderProduct->getProduct() == $orderProductTest->getProduct()) { |
|
|
|
|
|
return $orderProduct ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function groupOrderProductsByProductFamily($orderProducts) |
|
|
public function groupOrderProductsByProductFamily($orderProducts) |
|
|
{ |
|
|
{ |
|
|
$orderProductsByProductFamily = []; |
|
|
$orderProductsByProductFamily = []; |