/** * @Route("/sync/{id}", name="orocrm_magento_orderplace_new_cart_order_sync", requirements={"id"="\d+"})) * @AclAncestor("oro_workflow") * @param Cart $cart * @return JsonResponse */ public function syncAction(Cart $cart) { /** @var EntityManager $em */ $em = $this->get('doctrine.orm.entity_manager'); try { $isOrderLoaded = $this->loadOrderInformation($cart->getChannel(), ['filters' => ['quote_id' => $cart->getOriginId()], ProcessorRegistry::TYPE_IMPORT => [EntityWriter::SKIP_CLEAR => true]]); $isCartLoaded = $this->loadCartInformation($cart->getChannel(), ['filters' => ['entity_id' => $cart->getOriginId()], ProcessorRegistry::TYPE_IMPORT => [EntityWriter::SKIP_CLEAR => true]]); if (!$isOrderLoaded || !$isCartLoaded) { throw new \LogicException('Unable to load information.'); } $order = $em->getRepository('OroCRMMagentoBundle:Order')->getLastPlacedOrderBy($cart, 'cart'); if (null === $order) { throw new \LogicException('Unable to load order.'); } $redirectUrl = $this->generateUrl('orocrm_magento_order_view', ['id' => $order->getId()]); $message = $this->get('translator')->trans('orocrm.magento.controller.synchronization_success'); $status = self::SYNC_SUCCESS; } catch (\Exception $e) { $cart->setStatusMessage('orocrm.magento.controller.synchronization_failed_status'); $em->flush($cart); $redirectUrl = $this->generateUrl('orocrm_magento_cart_view', ['id' => $cart->getId()]); $message = $this->get('translator')->trans('orocrm.magento.controller.sync_error_with_magento'); $status = self::SYNC_ERROR; } return new JsonResponse(['statusType' => $status, 'message' => $message, 'url' => $redirectUrl]); }
/** * @Route("/sync/{id}", name="orocrm_magento_orderplace_new_cart_order_sync", requirements={"id"="\d+"})) * @AclAncestor("oro_workflow") */ public function syncAction(Cart $cart) { /** @var EntityManager $em */ $em = $this->get('doctrine.orm.entity_manager'); try { $cartConnector = $this->get('orocrm_magento.mage.cart_connector'); $orderConnector = $this->get('orocrm_magento.mage.order_connector'); $processor = $this->get('oro_integration.sync.processor'); $processor->process($cart->getChannel(), $cartConnector->getType(), ['filters' => ['entity_id' => $cart->getOriginId()]]); $processor->process($cart->getChannel(), $orderConnector->getType(), ['filters' => ['quote_id' => $cart->getOriginId()]]); $order = $em->getRepository('OroCRMMagentoBundle:Order')->getLastPlacedOrderBy($cart, 'cart'); if (null === $order) { throw new \LogicException('Unable to load order.'); } $redirectUrl = $this->generateUrl('orocrm_magento_order_view', ['id' => $order->getId()]); $message = $this->get('translator')->trans('orocrm.magento.controller.synchronization_success'); $status = self::SYNC_SUCCESS; } catch (\Exception $e) { $cart->setStatusMessage('orocrm.magento.controller.synchronization_failed_status'); // in import process we have EntityManager#clear() $cart = $em->merge($cart); $em->flush(); $redirectUrl = $this->generateUrl('orocrm_magento_cart_view', ['id' => $cart->getId()]); $message = $this->get('translator')->trans('orocrm.magento.controller.sync_error_with_magento'); $status = self::SYNC_ERROR; } return new JsonResponse(['statusType' => $status, 'message' => $message, 'url' => $redirectUrl]); }
/** * @Route("/actualize/{id}", name="orocrm_magento_cart_actualize", requirements={"id"="\d+"})) * @AclAncestor("orocrm_magento_cart_view") */ public function actualizeAction(Cart $cart) { $connector = $this->get('orocrm_magento.mage.cart_connector'); try { $processor = $this->get('oro_integration.sync.processor'); $processor->process($cart->getChannel(), $connector->getType(), ['filters' => ['entity_id' => $cart->getOriginId()]]); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('orocrm.magento.controller.synchronization_success')); } catch (\LogicException $e) { $this->get('logger')->addCritical($e->getMessage(), ['exception' => $e]); $this->get('session')->getFlashBag()->add('error', $this->get('translator')->trans('orocrm.magento.controller.synchronization_error')); } return $this->redirect($this->generateUrl('orocrm_magento_cart_view', ['id' => $cart->getId()])); }