public function testProcess()
 {
     $customer = new Customer();
     $customer->setOriginId(1);
     $transport = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\MagentoSoapTransport')->disableOriginalConstructor()->getMock();
     $transport->expects($this->once())->method('getIsExtensionInstalled')->will($this->returnValue(true));
     $channel = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel')->disableOriginalConstructor()->getMock();
     $channel->expects($this->once())->method('getTransport')->will($this->returnValue($transport));
     $order = new Order();
     $cart = new Cart();
     $cart->setOriginId(1);
     $order->setCustomer($customer);
     $order->setChannel($channel);
     $order->setCart($cart);
     $this->databaseHelper->expects($this->once())->method('findOneByIdentity')->with($channel)->will($this->returnValue($channel));
     $strategy = $this->getStrategy();
     $execution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext');
     $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($execution));
     $strategy->setStepExecution($this->stepExecution);
     $orderItemDate = ['customerId' => uniqid()];
     /** @var \PHPUnit_Framework_MockObject_MockObject|ContextInterface $context */
     $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $context->expects($this->once())->method('getValue')->will($this->returnValue($orderItemDate));
     $strategy->setImportExportContext($context);
     $execution->expects($this->exactly(3))->method('get')->with($this->isType('string'));
     $execution->expects($this->exactly(3))->method('put')->with($this->isType('string'), $this->isType('array'));
     $this->assertNull($strategy->process($order));
 }
 /**
  * @param Cart $cart
  * @return bool
  */
 protected function isProcessingAllowed(Cart $cart)
 {
     $customer = $this->findExistingEntity($cart->getCustomer());
     $isProcessingAllowed = true;
     $customerOriginId = $cart->getCustomer()->getOriginId();
     if (!$customer && $customerOriginId) {
         $this->appendDataToContext(ContextCustomerReader::CONTEXT_POST_PROCESS_CUSTOMERS, $customerOriginId);
         $isProcessingAllowed = false;
     }
     return $isProcessingAllowed;
 }
Example #3
0
 /**
  * @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]]];
 }
 public function testProcess()
 {
     $customer = new Customer();
     $customer->setOriginId(1);
     $channel = new Channel();
     $cart = new Cart();
     $cart->setCustomer($customer)->setChannel($channel)->setItemsCount(2)->setEmail('*****@*****.**');
     $strategy = $this->getStrategy();
     $execution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext');
     $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($execution));
     $strategy->setStepExecution($this->stepExecution);
     $cartItem = ['customerId' => uniqid()];
     /** @var \PHPUnit_Framework_MockObject_MockObject|ContextInterface $context */
     $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $context->expects($this->once())->method('getValue')->will($this->returnValue($cartItem));
     $strategy->setImportExportContext($context);
     $execution->expects($this->exactly(2))->method('get')->with($this->isType('string'));
     $execution->expects($this->exactly(2))->method('put')->with($this->isType('string'), $this->isType('array'));
     $this->assertNull($strategy->process($cart));
 }
Example #5
0
 /**
  * "Success" form handler
  *
  * @param Cart $entity
  */
 protected function onSuccess(Cart $entity)
 {
     $count = 0;
     /** @var CartItem $item */
     foreach ($entity->getCartItems() as $item) {
         $item->setCart($entity);
         ++$count;
     }
     $entity->setItemsCount($count);
     if (null === $entity->getOrganization()) {
         $entity->setOrganization($this->organization);
     }
     if ($entity->getShippingAddress() instanceof AbstractAddress && null === $entity->getShippingAddress()->getOrganization()) {
         $entity->getShippingAddress()->setOrganization($this->organization);
     }
     if ($entity->getBillingAddress() instanceof AbstractAddress && null === $entity->getBillingAddress()->getOrganization()) {
         $entity->getBillingAddress()->setOrganization($this->organization);
     }
     $this->manager->persist($entity);
     $this->manager->flush();
 }
Example #6
0
 /**
  * @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]);
 }
Example #7
0
 /**
  * @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]);
 }
Example #8
0
 /**
  * Update cart status
  *
  * @param Cart $cart
  *
  * @return CartStrategy
  */
 protected function updateCartStatus(Cart $cart)
 {
     // allow to modify status only for "open" carts
     // because magento can only expire cart, so for different statuses this useless
     if ($this->existingEntity->getStatus()->getName() !== CartStatus::STATUS_OPEN) {
         $status = $this->existingEntity->getStatus();
     } else {
         $status = $cart->getStatus();
     }
     $cart->setStatus($status);
     return $this;
 }
Example #9
0
 /**
  * @param                 $billing
  * @param                 $shipping
  * @param Customer        $customer
  * @param ArrayCollection $item
  * @param CartStatus      $status
  *
  * @return Cart
  */
 protected function createCart($billing, $shipping, Customer $customer, ArrayCollection $item, $status)
 {
     $cart = new Cart();
     $cart->setChannel($this->integration);
     $cart->setDataChannel($this->channel);
     $cart->setBillingAddress($billing);
     $cart->setShippingAddress($shipping);
     $cart->setCustomer($customer);
     $cart->setEmail('*****@*****.**');
     $cart->setCreatedAt(new \DateTime('now'));
     $cart->setUpdatedAt(new \DateTime('now'));
     $cart->setCartItems($item);
     $cart->setStatus($status);
     $cart->setItemsQty(0);
     $cart->setItemsCount(1);
     $cart->setBaseCurrencyCode('code');
     $cart->setStoreCurrencyCode('code');
     $cart->setQuoteCurrencyCode('usd');
     $cart->setStoreToBaseRate(12);
     $cart->setGrandTotal(2.54);
     $cart->setIsGuest(0);
     $cart->setStore($this->store);
     $cart->setOwner($this->getUser());
     $cart->setOrganization($this->organization);
     $this->em->persist($cart);
     return $cart;
 }
Example #10
0
 /**
  * @param Cart $existingEntity
  *
  * @return $this
  */
 protected function removeErrorMessage(Cart $existingEntity)
 {
     $existingEntity->setStatusMessage(null);
     return $this;
 }
Example #11
0
 /**
  * @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()]));
 }
Example #12
0
 /**
  * @return int
  */
 protected function getMainEntityId()
 {
     $this->assertNotEmpty(self::$cart);
     return self::$cart->getId();
 }
Example #13
0
 /**
  * @param ObjectManager $om
  * @param Store         $store
  * @param Integration   $integration
  * @param Customer      $customer
  * @param CartStatus    $status
  * @param int           $origin
  * @param string        $currency
  * @param int           $rate
  *
  * @return Cart
  */
 protected function generateShoppingCart(ObjectManager $om, Store $store, Integration $integration, Customer $customer, CartStatus $status, $origin, $currency = 'USD', $rate = 1)
 {
     $cart = new Cart();
     $cart->setOrganization($this->organization);
     $cart->setChannel($integration);
     $cart->setCustomer($customer);
     $cart->setOwner($customer->getOwner());
     $cart->setStatus($status);
     $cart->setStore($store);
     $cart->setBaseCurrencyCode($currency);
     $cart->setStoreCurrencyCode($currency);
     $cart->setQuoteCurrencyCode($currency);
     $cart->setStoreToBaseRate($rate);
     $cart->setStoreToQuoteRate($rate);
     $cart->setIsGuest(0);
     $cart->setEmail($customer->getEmail());
     $cart->setCreatedAt(new \DateTime('now'));
     $cart->setUpdatedAt(new \DateTime('now'));
     $cart->setOriginId($origin);
     $cart->setDataChannel($this->dataChannel);
     $om->persist($cart);
     return $cart;
 }
Example #14
0
 protected function getMainEntityId()
 {
     return self::$cart->getid();
 }
Example #15
0
 public function testConstruct()
 {
     $this->assertNotEmpty($this->entity->getStatus());
     $this->assertEquals('open', $this->entity->getStatus()->getName());
 }
Example #16
0
 /**
  * @param Cart  $cart
  * @param array $data
  */
 protected function updateStatus(Cart $cart, array $data)
 {
     $statusClass = MagentoConnectorInterface::CART_STATUS_TYPE;
     $isActive = isset($data['is_active']) ? (bool) $data['is_active'] : true;
     $cart->setStatus(new $statusClass($isActive ? 'open' : 'expired'));
 }
Example #17
0
 /**
  * @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'];
 }
Example #18
0
 /**
  * @param array $properties
  *
  * @return Cart
  */
 protected function getEntity(array $properties = [])
 {
     $cart = new Cart();
     $channel = new Channel();
     $cart->setChannel($channel);
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     foreach ($properties as $property => $value) {
         if ($value instanceof ArrayCollection) {
             foreach ($value as $item) {
                 try {
                     $propertyAccessor->setValue($item, 'cart', $cart);
                 } catch (NoSuchPropertyException $e) {
                 }
             }
         } elseif (is_object($value)) {
             try {
                 $propertyAccessor->setValue($value, 'cart', $cart);
             } catch (NoSuchPropertyException $e) {
             }
         }
         $propertyAccessor->setValue($cart, $property, $value);
     }
     return $cart;
 }