Пример #1
0
 public function testCustomerSyncAction()
 {
     $newCustomerOrder = $this->getModifiedCustomerOrder($this->customer);
     $orderIterator = new StubIterator([$newCustomerOrder]);
     $this->soapTransport->expects($this->any())->method('call');
     /*$this->soapTransport->expects($this->once())->method('getCustomer')->will(
           $this->returnValue($customerIterator)
       );*/
     $this->soapTransport->expects($this->once())->method('getOrders')->will($this->returnValue($orderIterator));
     $this->client->request('GET', $this->getUrl('orocrm_magento_orderplace_new_customer_order_sync', ['id' => $this->customer->getId()]), [], [], ['HTTP_X-Requested-With' => 'XMLHttpRequest']);
     $result = $this->client->getResponse();
     $this->assertJsonResponseStatusCodeEquals($result, 200);
     $arrayJson = json_decode($result->getContent(), 1);
     $this->assertEquals($arrayJson['statusType'], 'success');
     $this->assertEquals($arrayJson['message'], 'Data successfully synchronized.');
     $this->assertEquals($arrayJson['url'], $this->getUrl('orocrm_magento_order_view', ['id' => $this->order->getId()]));
     $this->client->request('GET', $this->getUrl('orocrm_magento_customer_view', ['id' => $this->customer->getId()]));
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $this->assertContains('General Information', $result->getContent());
     $this->assertContains('100000307', $result->getContent());
     $this->assertContains('$750', $result->getContent());
     $this->assertContains('pending', $result->getContent());
     $this->assertContains('$755', $result->getContent());
     $this->assertContains('$755', $result->getContent());
 }
Пример #2
0
 /**
  * Allow to set password only for new customer.
  * Allow to set password for existing customer if Oro Bridge extension is installed.
  *
  * @param Customer|null $data
  * @return bool
  */
 protected function isPasswordSetAllowed($data)
 {
     if ($data && $data instanceof Customer && $data->getChannel() && $data->getChannel()->getTransport()) {
         /** @var MagentoSoapTransport $transport */
         $transport = $data->getChannel()->getTransport();
         return !$data->getId() || $transport->isSupportedExtensionVersion();
     }
     return true;
 }
Пример #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);
     }
 }
Пример #4
0
 /**
  * @Route("/customer/{id}", name="orocrm_magento_widget_customer_orderplace", requirements={"id"="\d+"}))
  * @AclAncestor("oro_workflow")
  * @Template("OroCRMMagentoBundle:OrderPlace:widget/place.html.twig")
  * @param Customer $customer
  * @return array
  */
 public function customerAction(Customer $customer)
 {
     $urlGenerator = $this->get('orocrm_magento.service.magento_url_generator')->setChannel($customer->getChannel())->setFlowName('oro_sales_new_order')->setOrigin('customer')->generate($customer->getOriginId(), 'orocrm_magento_orderplace_success', 'orocrm_magento_orderplace_error');
     $translator = $this->get('translator');
     return ['error' => $urlGenerator->isError() ? $translator->trans($urlGenerator->getError()) : false, 'sourceUrl' => $urlGenerator->getSourceUrl(), 'customerId' => $customer->getId()];
 }
Пример #5
0
 /**
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @param Customer             $entity
  * @param Collection|Address[] $addresses
  *
  * @return $this
  */
 protected function updateAddresses(Customer $entity, Collection $addresses)
 {
     // force option enforce re-import of all addresses
     if ($this->context->getOption('force') && $entity->getId()) {
         $entity->getAddresses()->clear();
     }
     $processedRemote = [];
     /** $address - imported address */
     foreach ($addresses as $address) {
         // at this point imported address region have code equal to region_id in magento db field
         $mageRegionId = $address->getRegion() ? $address->getRegion()->getCode() : null;
         $originAddressId = $address->getOriginId();
         if ($originAddressId && !$this->context->getOption('force')) {
             $existingAddress = $entity->getAddressByOriginId($originAddressId);
             if ($existingAddress) {
                 $this->strategyHelper->importEntity($existingAddress, $address, ['id', 'region', 'country', 'contactAddress', 'created', 'updated', 'contactPhone']);
                 // set remote data for further processing
                 $existingAddress->setRegion($address->getRegion());
                 $existingAddress->setCountry($address->getCountry());
                 $address = $existingAddress;
             }
         }
         $this->updateAddressCountryRegion($address, $mageRegionId);
         if ($address->getCountry()) {
             $this->updateAddressTypes($address);
             $address->setOwner($entity);
             $entity->addAddress($address);
             $processedRemote[] = $address;
         }
         $contact = $entity->getContact();
         if ($contact) {
             $contactAddress = $address->getContactAddress();
             $contactPhone = $address->getContactPhone();
             if ($contactAddress) {
                 $contactAddress->setOwner($contact);
             }
             if ($contactPhone) {
                 $contactPhone->setOwner($contact);
             }
         } else {
             $address->setContactAddress(null);
             $address->setContactPhone(null);
         }
     }
     // remove not processed addresses
     $toRemove = $entity->getAddresses()->filter(function (Address $address) use($processedRemote) {
         return !in_array($address, $processedRemote, true);
     });
     foreach ($toRemove as $address) {
         $entity->removeAddress($address);
     }
 }
Пример #6
0
 /**
  * @param Customer $customer
  * @param string   $value
  */
 public function updateCustomerLifetimeValue(Customer $customer, $value)
 {
     $qb = $this->createQueryBuilder('c')->update('OroCRMMagentoBundle:Customer', 'c')->set('c.lifetime', 'c.lifetime + :value')->setParameter('value', $value)->where('c.id = :id')->setParameter('id', $customer->getId());
     $qb->getQuery()->execute();
 }