|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
-
- namespace Lc\ShopBundle\Services\Order;
-
-
- use Lc\ShopBundle\Model\OrderStatus;
-
- trait OrderUtilsCartTrait
- {
- public function getCartCurrent()
- {
- $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) {
- // merge
- 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;
- }
- // set user
- if ($orderShop && $user && !$orderShop->getUser()) {
- $orderShop->setUser($user);
- $orderShop->setVisitor(null) ;
- $this->em->persist($orderShop);
- $this->em->flush();
- }
- }
-
- return $orderShop;
- }
-
-
- public function isCartAllowToBeOrder($order){
- return true;
- }
- }
|