/**
  * @param Order $order
  * @return bool
  */
 protected function isProcessingAllowed(Order $order)
 {
     $isProcessingAllowed = true;
     $customer = $this->findExistingEntity($order->getCustomer());
     $customerOriginId = $order->getCustomer()->getOriginId();
     if (!$customer && $customerOriginId) {
         $this->appendDataToContext(ContextCustomerReader::CONTEXT_POST_PROCESS_CUSTOMERS, $customerOriginId);
         $isProcessingAllowed = false;
     }
     // Do not try to load cart if bridge does not installed
     /** @var MagentoSoapTransport $transport */
     $channel = $this->databaseHelper->findOneByIdentity($order->getChannel());
     $transport = $channel->getTransport();
     if ($transport->getIsExtensionInstalled()) {
         $cart = $this->findExistingEntity($order->getCart());
         $cartOriginId = $order->getCart()->getOriginId();
         if (!$cart && $cartOriginId) {
             $this->appendDataToContext(ContextCartReader::CONTEXT_POST_PROCESS_CARTS, $cartOriginId);
             $isProcessingAllowed = false;
         }
     }
     if (!$customer && $order->getIsGuest() && $transport->getGuestCustomerSync()) {
         $this->appendDataToContext('postProcessGuestCustomers', $this->context->getValue('itemData'));
         $isProcessingAllowed = false;
     }
     return $isProcessingAllowed;
 }
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|object $order
  * @return bool
  */
 protected function isOrderValid($order)
 {
     if (!$order instanceof Order) {
         return false;
     }
     $customer = $order->getCustomer();
     if (!$customer || !$customer instanceof Customer) {
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * @param Order|object $order
  * @param float|null $newLifetime
  * @param array $changeSet
  * @dataProvider updateDataProvider
  */
 public function testUpdate($order, $newLifetime = null, array $changeSet = array())
 {
     $isUpdateRequired = array_intersect(array('subtotalAmount', 'status'), array_keys($changeSet));
     if ($isUpdateRequired && $newLifetime) {
         $entityManager = $this->createEntityManagerMock($order->getCustomer(), $newLifetime);
     } else {
         $entityManager = $this->createEntityManagerMock();
     }
     $listener = new OrderListener();
     $listener->preUpdate(new PreUpdateEventArgs($order, $entityManager, $changeSet));
     if ($isUpdateRequired) {
         $this->assertAttributeEquals(array($order->getId() => true), 'ordersForUpdate', $listener);
     } else {
         $this->assertAttributeEmpty('ordersForUpdate', $listener);
     }
     $listener->postUpdate(new LifecycleEventArgs($order, $entityManager));
     $this->assertAttributeEmpty('ordersForUpdate', $listener);
 }
Example #5
0
 /**
  * @param EntityManager $entityManager
  * @param Order         $order
  */
 protected function updateCustomerLifetime(EntityManager $entityManager, Order $order)
 {
     /** @var CustomerRepository $customerRepository */
     $customerRepository = $entityManager->getRepository('OroCRMMagentoBundle:Customer');
     $subtotalAmount = $order->getSubtotalAmount();
     if ($subtotalAmount) {
         $discountAmount = $order->getDiscountAmount();
         $lifetimeValue = $discountAmount ? $subtotalAmount - abs($discountAmount) : $subtotalAmount;
         // if order status changed to canceled we should remove order lifetime value from customer lifetime
         if ($order->isCanceled()) {
             $lifetimeValue *= -1;
         }
         $customer = $order->getCustomer();
         $customerRepository->updateCustomerLifetimeValue($customer, $lifetimeValue);
         // schedule lifetime history update
         if ($customer->getAccount()) {
             $this->channelDoctrineListener->scheduleEntityUpdate($customer, $customer->getAccount(), $customer->getDataChannel());
         }
     }
 }