|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
-
- namespace Lc\ShopBundle\Services\Order;
-
-
- use Lc\ShopBundle\Context\OrderShopInterface;
- use Lc\ShopBundle\Model\OrderStatus;
-
- trait OrderUtilsCartTrait
- {
- public function getCartByUserOrCreateIt($user){
- $newOrderShop= $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
- if ($newOrderShop === null) {
- $newOrderShop = $this->createOrderShop(array(
- 'user' => $user,
- 'merchant' => $this->merchantUtils->getMerchantUser()
- ));
- }
-
- return $newOrderShop;
- }
-
-
- public function getCartCurrent($createIfNotExist = false)
- {
- $paramsSearchOrderShop = [];
-
- $user = $this->security->getUser();
- $visitor = $this->userUtils->getVisitorCurrent();
-
- $orderShop = null;
- $orderShopUser = null;
- $orderShopVisitor = null;
-
- if ($user) {
- $orderShopUser = $this->orderShopRepo->findCartCurrent([
- 'user' => $user
- ]);
- }
-
- if ($visitor) {
- $orderShopVisitor = $this->orderShopRepo->findCartCurrent([
- 'visitor' => $visitor
- ]);
- }
-
- if ($orderShopUser || $orderShopVisitor) {
-
- if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
- && $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 {
- $orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
- }
-
- if ($orderShop && $user && !$orderShop->getUser()) {
- $orderShop->setUser($user);
- $orderShop->setVisitor(null) ;
- $this->em->persist($orderShop);
- $this->em->flush();
- }
- }
-
- if($createIfNotExist && !$orderShop) {
- $orderShop = $this->createOrderShop([
- 'user' => $user,
- 'visitor' => $visitor,
- 'merchant' => $this->merchantUtils->getMerchantCurrent()
- ]);
- }
-
- return $orderShop;
- }
-
-
- public function isCartAllowToBeOrder($order){
- return true;
- }
- }
|