/** * @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]); }
/** * @return array */ public function itemsProvider() { $order1 = new Order(); $order2 = new Order(); $order1->setIncrementId('1111'); $order2->setIncrementId('2222'); $order3 = clone $order1; $cart1 = new Cart(); $cart2 = new Cart(); $cart1->setOriginId(1111); $cart2->setOriginId(2222); $cart3 = clone $cart1; $customer1 = new Customer(); $customer1->setOriginId(111); $customer2 = clone $customer1; $someEntity = new \stdClass(); $someEntity2 = new \stdClass(); return ['should skip non-unique orders' => ['$items' => [$order1, $order2, $order3], '$expectedItems' => [$order3->getIncrementId() => $order3, $order2->getIncrementId() => $order2]], 'should skip non-unique carts' => ['$items' => [$cart1, $cart2, $cart3], '$expectedItems' => [$cart3->getOriginId() => $cart3, $cart2->getOriginId() => $cart2]], 'should skip non-unique customers' => ['$items' => [$customer1, $customer2], '$expectedItems' => [$customer2->getOriginId() => $customer2]], 'should not break logic with entities that not consist originId' => ['$items' => [$someEntity, $someEntity2], '$expectedItems' => [$someEntity, $someEntity2]]]; }
/** * @param Cart $cart * @param Customer $customer * * @return array */ protected function getModifiedCartData(Cart $cart, Customer $customer) { return ['entity_id' => $cart->getOriginId(), 'store_id' => $cart->getStore()->getOriginId(), 'created_at' => '2014-04-22 10:41:43', 'updated_at' => '2014-05-29 08:52:33', 'is_active' => false, 'is_virtual' => false, 'is_multi_shipping' => false, 'items_count' => '2', 'items_qty' => self::TEST_NEW_ITEMS_QTY, 'orig_order_id' => '0', 'store_to_base_rate' => '1.0000', 'store_to_quote_rate' => '1.0000', 'base_currency_code' => 'USD', 'store_currency_code' => 'USD', 'quote_currency_code' => 'USD', 'grand_total' => '855.0000', 'base_grand_total' => '855.0000', 'customer_id' => $customer->getOriginId(), 'customer_tax_class_id' => '3', 'customer_group_id' => '1', 'customer_email' => self::TEST_NEW_EMAIL, 'customer_firstname' => 'firstname', 'customer_lastname' => 'lastname', 'customer_note_notify' => '1', 'customer_is_guest' => '0', 'remote_ip' => '82.117.235.210', 'global_currency_code' => 'USD', 'base_to_global_rate' => '1.0000', 'base_to_quote_rate' => '1.0000', 'subtotal' => '855.0000', 'base_subtotal' => '855.0000', 'subtotal_with_discount' => '855.0000', 'base_subtotal_with_discount' => '855.0000', 'is_changed' => '1', 'trigger_recollect' => '0', 'is_persistent' => '0', 'shipping_address' => [], 'billing_address' => [], 'items' => [], 'payment' => '', 'store_code' => $cart->getStore()->getCode(), 'store_storename' => $cart->getStore()->getName(), 'store_website_id' => $cart->getStore()->getWebsite()->getOriginId(), 'store_website_code' => $cart->getStore()->getWebsite()->getCode(), 'store_website_name' => $cart->getStore()->getWebsite()->getName(), 'customer_group_code' => 'General', 'customer_group_name' => 'General']; }
/** * @param Cart $entity * @return null */ protected function hasContactInfo(Cart $entity) { $hasContactInfo = $entity->getBillingAddress() && $entity->getBillingAddress()->getPhone() || $entity->getEmail(); if (!$hasContactInfo) { $this->context->incrementErrorEntriesCount(); $this->logger->debug(sprintf('Cart ID: %d was skipped because lack of contact info', $entity->getOriginId())); return false; } return true; }
/** * @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()])); }