Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

OrderUtilsCartTrait.php 2.7KB

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