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));
 }
Example #2
0
 /**
  * If customer exists then add relation to it,
  * do nothing otherwise
  *
  * @param Order $entity
  */
 protected function processCustomer(Order $entity)
 {
     // customer could be array if comes new order or object if comes from DB
     $customerId = is_object($entity->getCustomer()) ? $entity->getCustomer()->getOriginId() : $entity->getCustomer()['originId'];
     $criteria = ['originId' => $customerId, 'channel' => $entity->getChannel()];
     /** @var Customer|null $customer */
     $customer = $this->getEntityByCriteria($criteria, MagentoConnectorInterface::CUSTOMER_TYPE);
     if ($customer instanceof Customer) {
         // now customer orders subtotal calculation support only one currency.
         // also we do not take into account order refunds due to magento does not bring subtotal data
         // customer currency needs on customer's grid to format lifetime value.
         $customer->setCurrency($entity->getCurrency());
     }
     $entity->setCustomer($customer);
 }
Example #3
0
 /**
  * @param Order $order
  * @param Customer $customer
  */
 protected function processCustomer(Order $order, Customer $customer = null)
 {
     if (!$customer || !$customer->getId()) {
         $customer = $this->databaseHelper->findOneBy('OroCRM\\Bundle\\MagentoBundle\\Entity\\Customer', ['email' => $order->getCustomerEmail(), 'channel' => $order->getChannel()]);
     }
     if ($customer instanceof Customer) {
         // now customer orders subtotal calculation support only one currency.
         // also we do not take into account order refunds due to magento does not bring subtotal data
         // customer currency needs on customer's grid to format lifetime value.
         $customer->setCurrency($order->getCurrency());
     }
     $order->setCustomer($customer);
     if ($order->getCart()) {
         $order->getCart()->setCustomer($customer);
     }
 }
Example #4
0
 /**
  * @param Cart     $cart
  * @param Customer $customer
  *
  * @return Order
  */
 protected function createOrder(Cart $cart, Customer $customer)
 {
     $order = new Order();
     $order->setChannel($this->integration);
     $order->setDataChannel($this->channel);
     $order->setStatus('open');
     $order->setIncrementId('one');
     $order->setCreatedAt(new \DateTime('now'));
     $order->setUpdatedAt(new \DateTime('now'));
     $order->setCart($cart);
     $order->setStore($this->store);
     $order->setCustomer($customer);
     $order->setCustomerEmail('*****@*****.**');
     $order->setDiscountAmount(34.4);
     $order->setTaxAmount(12.47);
     $order->setShippingAmount(5);
     $order->setTotalPaidAmount(17.85);
     $order->setTotalInvoicedAmount(11);
     $order->setTotalRefundedAmount(4);
     $order->setTotalCanceledAmount(0);
     $order->setShippingMethod('some unique shipping method');
     $order->setRemoteIp('unique ip');
     $order->setGiftMessage('some very unique gift message');
     $order->setOwner($this->getUser());
     $order->setOrganization($this->organization);
     $this->em->persist($order);
     return $order;
 }
Example #5
0
 /**
  * @param ObjectManager $om
  * @param Store         $store
  * @param Integration   $integration
  * @param Customer      $customer
  * @param string        $status
  * @param Cart          $cart
  * @param string        $paymentMethod
  * @param string        $paymentMethodDetails
  * @param mixed         $origin
  *
  * @return Order
  */
 protected function generateOrder(ObjectManager $om, Store $store, Integration $integration, Customer $customer, $status, Cart $cart, $paymentMethod, $paymentMethodDetails, $origin)
 {
     $order = new Order();
     $order->setOrganization($this->organization);
     $order->setChannel($integration);
     $order->setCustomer($customer);
     $order->setOwner($customer->getOwner());
     $order->setStatus($status);
     $order->setStore($store);
     $order->setStoreName($store->getName());
     $order->setIsGuest(0);
     $order->setIncrementId((string) $origin);
     $order->setCreatedAt(new \DateTime('now'));
     $order->setUpdatedAt(new \DateTime('now'));
     $order->setCart($cart);
     $order->setCurrency($cart->getBaseCurrencyCode());
     $order->setTotalAmount($cart->getGrandTotal());
     $order->setTotalInvoicedAmount($cart->getGrandTotal());
     $order->setDataChannel($this->dataChannel);
     if ($status == 'Completed') {
         $order->setTotalPaidAmount($cart->getGrandTotal());
     }
     $order->setSubtotalAmount($cart->getSubTotal());
     $order->setShippingAmount(rand(5, 10));
     $order->setPaymentMethod($paymentMethod);
     $order->setPaymentDetails($paymentMethodDetails);
     $order->setShippingMethod('flatrate_flatrate');
     $address = $this->getOrderAddress($om);
     $order->addAddress($address);
     $address->setOwner($order);
     $om->persist($order);
     return $order;
 }
Example #6
0
 public function testNotScheduleLifetimeValueHistoryWithoutAccount()
 {
     $expectedLifetime = 200;
     $order = new Order();
     $customer = new Customer();
     $order->setCustomer($customer)->setSubtotalAmount($expectedLifetime);
     $entityManager = $this->createEntityManagerMock();
     $this->customerRepository->expects($this->once())->method('updateCustomerLifetimeValue')->with($this->isInstanceOf('OroCRM\\Bundle\\MagentoBundle\\Entity\\Customer'), $expectedLifetime);
     $this->listener->expects($this->never())->method('scheduleEntityUpdate');
     $listener = new OrderListener($this->listener);
     $listener->prePersist(new LifecycleEventArgs($order, $entityManager));
 }
Example #7
0
 /**
  * @param Customer|object|null $customer
  * @param float $subtotal
  * @return Order
  */
 protected function createOrder($customer = null, $subtotal = 10.1)
 {
     $order = new Order();
     $order->setId(1);
     if ($customer) {
         $order->setCustomer($customer);
     }
     $order->setSubtotalAmount($subtotal);
     return $order;
 }