60 lines
2.2KB

  1. <?php
  2. namespace Lc\ShopBundle\Services\Order;
  3. use Lc\ShopBundle\Model\OrderStatus;
  4. trait OrderUtilsCartTrait
  5. {
  6. public function getCartCurrent()
  7. {
  8. $paramsSearchOrderShop = [];
  9. $user = $this->security->getUser();
  10. $visitor = $this->userUtils->getVisitorCurrent();
  11. $orderShop = null;
  12. $orderShopUser = null;
  13. $orderShopVisitor = null;
  14. if ($user) {
  15. $orderShopUser = $this->orderShopRepo->findCartCurrent([
  16. 'user' => $user
  17. ]);
  18. }
  19. if ($visitor) {
  20. $orderShopVisitor = $this->orderShopRepo->findCartCurrent([
  21. 'visitor' => $visitor
  22. ]);
  23. }
  24. if ($orderShopUser || $orderShopVisitor) {
  25. // merge
  26. if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
  27. && $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
  28. && $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
  29. $orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
  30. $this->utils->addFlash('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
  31. } else {
  32. $orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
  33. }
  34. // set user
  35. if ($orderShop && $user && !$orderShop->getUser()) {
  36. $orderShop->setUser($user);
  37. $orderShop->setVisitor(null) ;
  38. $this->em->persist($orderShop);
  39. $this->em->flush();
  40. }
  41. }
  42. return $orderShop;
  43. }
  44. public function isCartAllowToBeOrder($order){
  45. return true;
  46. }
  47. }