Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

56 lines
2.0KB

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