/** * @dataProvider addressTypesUpdateDataProvider * * @param string $priority * @param ArrayCollection $remoteTypes * @param ArrayCollection $localTypes * @param ArrayCollection $contactTypes * @param array $expectedTypeNames */ public function testAddressTypesUpdate($priority, ArrayCollection $remoteTypes, ArrayCollection $localTypes, ArrayCollection $contactTypes, array $expectedTypeNames) { $channel = new Channel(); $channel->getSynchronizationSettingsReference()->offsetSet('syncPriority', $priority); $testCountry = new Country('US'); $contact = new Contact(); $contactAddress = new ContactAddress(); $contactAddress->setId(self::TEST_CONTACT_ADDRESS_ID); $contactAddress->setTypes($contactTypes); $contactAddress->setCountry($testCountry); $contact->addAddress($contactAddress); $phone = new ContactPhone(); $phone->setPhone('123-123-123'); $phone->setOwner($contact); $contact->addPhone($phone); $localCustomer = new Customer(); $localAddress = new Address(); $localAddress->setContactAddress($contactAddress); $localAddress->setTypes($localTypes); $localAddress->setCountry($testCountry); $localAddress->setPhone('123-123-123'); $localAddress->setContactPhone($phone); $localCustomer->addAddress($localAddress); $remoteCustomer = new Customer(); $remoteAddress = new Address(); $remoteAddress->setContactAddress($contactAddress); $remoteAddress->setTypes($remoteTypes); $remoteAddress->setCountry($testCountry); $remoteAddress->setContactPhone($phone); $remoteCustomer->addAddress($remoteAddress); $helper = $this->getHelper($channel); $helper->merge($remoteCustomer, $localCustomer, $contact); $this->assertCount(1, $contact->getAddresses()); $this->assertEquals($expectedTypeNames, $contactAddress->getTypeNames()); }
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)); }
public function testGetPhoneNumbers() { $entity = new Customer(); $contact = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock(); $entity->setContact($contact); $this->rootProvider->expects($this->once())->method('getPhoneNumbers')->with($this->identicalTo($contact))->will($this->returnValue([['123-123', $contact], ['456-456', $contact]])); $this->assertEquals([['123-123', $contact], ['456-456', $contact]], $this->provider->getPhoneNumbers($entity)); }
/** * Gets a list of all phone numbers available for the given Customer object * * @param Customer $object * * @return array of [phone number, phone owner] */ public function getPhoneNumbers($object) { $contact = $object->getContact(); if (!$contact) { return []; } return $this->rootProvider->getPhoneNumbers($contact); }
public function getGetStoreName() { $this->assertNull($this->entity->getStoreName()); $expectedValue = 'test'; $website = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Entity\\Store'); $website->expects($this->once())->method('getName')->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $website->getStoreName()); }
/** * @param Customer $customer * * @return NewsletterSubscriber */ public function getOrCreateFromCustomer(Customer $customer) { $newsletterSubscriber = $customer->getNewsletterSubscriber(); if (null === $newsletterSubscriber) { $newsletterSubscriber = new NewsletterSubscriber(); $newsletterSubscriber->setCustomer($customer)->setEmail($customer->getEmail())->setChannel($customer->getChannel())->setStore($customer->getStore())->setOrganization($customer->getOrganization())->setOwner($customer->getOwner())->setStatus($this->getStatus(NewsletterSubscriber::STATUS_UNSUBSCRIBED))->setDataChannel($customer->getDataChannel()); } return $newsletterSubscriber; }
/** * 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; }
/** * @param Customer $value * @return array */ protected function getRemoteCustomers($value) { $this->transport->init($value->getChannel()->getTransport()); $filter = new BatchFilterBag(); $filter->addComplexFilter('email', ['key' => 'email', 'value' => ['key' => 'eq', 'value' => $value->getEmail()]]); $filter->addComplexFilter('store_id', ['key' => 'store_id', 'value' => ['key' => 'eq', 'value' => $value->getStore()->getOriginId()]]); $filters = $filter->getAppliedFilters(); $customers = $this->transport->call(SoapTransport::ACTION_CUSTOMER_LIST, $filters); return (array) $customers; }
/** * @param Customer $customer * * @return NewsletterSubscriber[]|Collection */ public function getOrCreateFromCustomer(Customer $customer) { $newsletterSubscribers = $customer->getNewsletterSubscribers(); if (count($newsletterSubscribers) === 0) { $newsletterSubscriber = new NewsletterSubscriber(); $newsletterSubscriber->setCustomer($customer)->setEmail($customer->getEmail())->setChannel($customer->getChannel())->setStore($customer->getStore())->setOrganization($customer->getOrganization())->setOwner($customer->getOwner())->setStatus($this->getStatus(NewsletterSubscriber::STATUS_UNSUBSCRIBED))->setDataChannel($customer->getDataChannel()); $newsletterSubscribers = new ArrayCollection([$newsletterSubscriber]); } return $newsletterSubscribers; }
/** * @param EntityManager $entityManager * @param Customer $customer */ protected function recalculateCustomerLifetime(EntityManager $entityManager, Customer $customer) { $oldLifetime = $customer->getLifetime(); /** @var OrderRepository $orderRepository */ $orderRepository = $entityManager->getRepository('OroCRMMagentoBundle:Order'); $newLifetime = $orderRepository->getCustomerOrdersSubtotalAmount($customer); if ($newLifetime != $oldLifetime) { $entityManager->getUnitOfWork()->scheduleExtraUpdate($customer, array('lifetime' => array($oldLifetime, $newLifetime))); } }
/** * {@inheritdoc} */ protected function getPermissionForAttribute($class, $identifier, $attribute) { if (is_a($this->object, $this->className, true) && ($attribute === self::ATTRIBUTE_EDIT && (!$this->object->getOriginId() && !$this->object->isGuest()))) { return self::ACCESS_DENIED; } if (is_a($this->object, $this->className, true) && $this->object->getChannel() && !$this->settingsProvider->isChannelApplicable($this->object->getChannel()->getId(), false)) { return self::ACCESS_DENIED; } if (!$this->settingsProvider->hasApplicableChannels(false)) { return self::ACCESS_DENIED; } return self::ACCESS_ABSTAIN; }
public function testProcessLoadCustomer() { /** @var NewsletterSubscriber $newsletterSubscriber */ $newsletterSubscriber = $this->getReference('newsletter_subscriber2'); $customer = new Customer(); $originId = time(); $customer->setOriginId($originId); $newsletterSubscriber->setCustomer($customer); $this->strategy->setEntityName(get_class($newsletterSubscriber)); $this->assertEquals(null, $this->strategy->process($newsletterSubscriber)); $this->assertNotEmpty($this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessSubscribers')); $this->assertEquals([$originId], $this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessCustomerIds')); }
/** * "Success" form handler * * @param Customer $entity */ protected function onSuccess(Customer $entity) { if (null === $entity->getOrganization()) { $entity->setOrganization($this->organization); } $addresses = $entity->getAddresses(); foreach ($addresses as $address) { if (null === $address->getOrganization()) { $address->setOrganization($this->organization); } } $this->manager->persist($entity); $this->manager->flush(); }
/** * @param array $item * @param Customer $entity */ protected function writeNewItem(array $item, Customer $entity) { try { $customerId = $this->transport->createCustomer($item); $entity->setOriginId($customerId); $this->stateHandler->markCustomerSynced($entity); $this->stateHandler->markAddressesForSync($entity); $this->logger->info(sprintf('Customer with id %s successfully created with data %s', $customerId, json_encode($item))); $entity->setCreatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); $entity->setUpdatedAt($entity->getCreatedAt()); } catch (\Exception $e) { $this->logger->error($e->getMessage()); $this->stepExecution->addFailureException($e); } }
/** * @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); } }
/** * @param Customer $entity */ protected function processAddresses(Customer $entity) { if (!$entity->getAddresses()->isEmpty()) { /** @var Address $address */ foreach ($entity->getAddresses() as $address) { $address->setOwner($entity); $originId = $address->getOriginId(); if (array_key_exists($originId, $this->importingAddresses)) { $remoteAddress = $this->importingAddresses[$originId]; $this->addressHelper->mergeAddressTypes($address, $remoteAddress); if (!empty($this->addressRegions[$originId]) && $address->getCountry()) { $this->addressHelper->updateRegionByMagentoRegionId($address, $address->getCountry()->getIso2Code(), $this->addressRegions[$originId]); } } } } }
public function testCreateFromCustomer() { /** @var Channel $integration */ $integration = $this->getReference('integration'); /** @var Customer $customer */ $customer = new Customer(); $customer->setChannel($integration); $this->assertEmpty($customer->getNewsletterSubscriber()); $newsletterSubscriber = $this->getContainer()->get('orocrm_magento.model.newsletter_subscriber_manager')->getOrCreateFromCustomer($customer); $this->assertEquals($customer->getEmail(), $newsletterSubscriber->getEmail()); $this->assertEquals($customer, $newsletterSubscriber->getCustomer()); $this->assertEquals($customer->getChannel(), $newsletterSubscriber->getChannel()); $this->assertEquals($customer->getStore(), $newsletterSubscriber->getStore()); $this->assertEquals($customer->getOrganization(), $newsletterSubscriber->getOrganization()); $this->assertEquals($customer->getOwner(), $newsletterSubscriber->getOwner()); $this->assertEquals($customer->getDataChannel(), $newsletterSubscriber->getDataChannel()); $this->assertEquals(NewsletterSubscriber::STATUS_UNSUBSCRIBED, $newsletterSubscriber->getStatus()->getId()); }
/** * @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)); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { foreach ($this->data as $data) { /** @var Channel $channel */ $channel = $this->getReference($data['channel']); $now = new \DateTime(); $entity = new Customer(); $entity->setCreatedAt($now)->setUpdatedAt($now)->setDataChannel($channel); $excludeProperties = ['reference', 'channel']; $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($data as $property => $value) { if (in_array($property, $excludeProperties)) { continue; } $propertyAccessor->setValue($entity, $property, $value); } $this->setReference($data['reference'], $entity); $manager->persist($entity); } $manager->flush(); }
/** * @param array $data * * @dataProvider dataProvider */ public function testRead(array $data) { $this->executionContext->expects($this->once())->method('get')->will($this->returnCallback(function ($key) use($data) { if (empty($data[$key])) { return null; } return $data[$key]; })); $originId = 123; $expectedData = new Customer(); $expectedData->setOriginId($originId); $this->context->expects($this->any())->method('getConfiguration')->will($this->returnValue(['data' => $expectedData])); $this->transport->expects($this->once())->method('getCustomerInfo')->will($this->returnCallback(function ($customerId) { return ['origin_id' => $customerId, 'group_id' => 0, 'store_id' => 0, 'website_id' => 0]; })); $address = ['zip' => uniqid()]; $this->transport->expects($this->once())->method('getCustomerAddresses')->will($this->returnValue([$address])); $reader = $this->getReader(); $reader->setStepExecution($this->stepExecutionMock); $this->assertEquals(['origin_id' => $originId, 'group_id' => 0, 'store_id' => 0, 'website_id' => 0, 'addresses' => [['zip' => $address['zip']]]], $reader->read()); $this->assertNull($reader->read()); }
/** * @param Customer $entity */ protected function setDefaultGroup(Customer $entity) { if (!$entity->getGroup() && $entity->getWebsite()->getDefaultGroupId()) { $em = $this->strategyHelper->getEntityManager('OroCRMMagentoBundle:CustomerGroup'); $group = $em->getRepository('OroCRMMagentoBundle:CustomerGroup')->findOneBy(['originId' => $entity->getWebsite()->getDefaultGroupId(), 'channel' => $entity->getChannel()]); $entity->setGroup($group); } }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $addressTypeRepo = $manager->getRepository('OroAddressBundle:AddressType'); foreach (self::$data as $item) { $customer = new Customer(); $customer->setEmail($item['email']); $customer->setFirstName($item['firstName']); $customer->setLastName($item['lastName']); $customer->setCreatedAt(new \DateTime()); $customer->setUpdatedAt($customer->getCreatedAt()); foreach ($item['addresses'] as $addressData) { $address = new Address(); $address->setPostalCode($addressData['postalCode']); $address->addType($addressTypeRepo->findOneBy(['name' => $addressData['type']])); $customer->addAddress($address); $manager->persist($address); } $manager->persist($customer); $manager->flush(); $this->setReference($item['reference'], $customer); } }
/** * @Route( * "/customer_sync/{id}", * name="orocrm_magento_orderplace_new_customer_order_sync", requirements={"id"="\d+"}) * ) * @AclAncestor("oro_workflow") */ public function customerSyncAction(Customer $customer) { $em = $this->get('doctrine.orm.entity_manager'); try { $orderConnector = $this->get('orocrm_magento.mage.order_connector'); $processor = $this->get('oro_integration.sync.processor'); $processor->process($customer->getChannel(), $orderConnector->getType(), ['filters' => ['customer_id' => $customer->getOriginId()]]); $order = $em->getRepository('OroCRMMagentoBundle:Order')->getLastPlacedOrderBy($customer, 'customer'); 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) { $redirectUrl = $this->generateUrl('orocrm_magento_customer_view', ['id' => $customer->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]); }
/** * @param Customer $customer * * @return array */ protected function getModifiedCustomerOrder(Customer $customer) { return ['increment_id' => '100000307', 'store_id' => $customer->getStore()->getOriginId(), 'created_at' => '2014-05-29 16:41:43', 'updated_at' => '2014-05-29 16:41:43', 'customer_id' => $customer->getOriginId(), 'tax_amount' => '0.0000', 'shipping_amount' => '5.0000', 'discount_amount' => '0.0000', 'subtotal' => '750.0000', 'grand_total' => '755.0000', 'total_qty_ordered' => '1.0000', 'base_tax_amount' => '0.0000', 'base_shipping_amount' => '5.0000', 'base_discount_amount' => '0.0000', 'base_subtotal' => '750.0000', 'base_grand_total' => '755.0000', 'billing_address_id' => '603', 'billing_firstname' => 'asdf', 'billing_lastname' => 'asdf', 'shipping_address_id' => '604', 'shipping_firstname' => 'asdf', 'shipping_lastname' => 'asdf', 'billing_name' => 'asdf asdf', 'shipping_name' => 'asdf asdf', 'store_to_base_rate' => '1.0000', 'store_to_order_rate' => '1.0000', 'base_to_global_rate' => '1.0000', 'base_to_order_rate' => '1.0000', 'weight' => '0.3000', 'store_name' => $customer->getStore()->getName(), 'status' => 'pending', 'state' => 'new', 'global_currency_code' => 'USD', 'base_currency_code' => 'USD', 'store_currency_code' => 'USD', 'order_currency_code' => 'USD', 'shipping_method' => 'flatrate_flatrate', 'shipping_description' => 'Flat Rate - Fixed', 'customer_email' => '*****@*****.**', 'customer_firstname' => 'asdf', 'customer_lastname' => 'asdf', 'quote_id' => '368', 'is_virtual' => '0', 'customer_group_id' => '1', 'customer_note_notify' => '0', 'customer_is_guest' => '0', 'email_sent' => '1', 'order_id' => '302', 'shipping_address' => [], 'billing_address' => [], 'items' => [], 'payment' => '', 'status_history' => [], 'store_code' => $customer->getStore()->getCode(), 'store_storename' => $customer->getStore()->getName(), 'store_website_id' => $customer->getStore()->getWebsite()->getOriginId(), 'store_website_code' => $customer->getStore()->getWebsite()->getCode(), 'store_website_name' => $customer->getStore()->getWebsite()->getName()]; }
/** * @param $oid * @param Account $account * @param MagentoAddress $address * * @return Customer */ protected function createCustomer($oid, Account $account, MagentoAddress $address) { $customer = new Customer(); $customer->setChannel($this->integration); $customer->setDataChannel($this->channel); $customer->setFirstName('John'); $customer->setLastName('Doe'); $customer->setEmail('*****@*****.**'); $customer->setOriginId($oid); $customer->setIsActive(true); $customer->setWebsite($this->website); $customer->setStore($this->store); $customer->setAccount($account); $customer->setGender(Gender::MALE); $customer->setGroup($this->customerGroup); $customer->setCreatedAt(new \DateTime('now')); $customer->setUpdatedAt(new \DateTime('now')); $customer->addAddress($address); $customer->setOwner($this->getUser()); $customer->setOrganization($this->organization); $this->em->persist($customer); return $customer; }
/** * Find remote addresses that do not have correspondent one in database * * @param Customer $remoteCustomer * @param Customer $localCustomer * * @return ArrayCollection */ protected function getOrphanRemoteAddresses(Customer $remoteCustomer, Customer $localCustomer) { $self = $this; $filtered = $remoteCustomer->getAddresses()->filter(function (Address $address) use($self, $localCustomer) { return !$self->getCorrespondentLocalAddress($localCustomer, $address); }); return $filtered; }
/** * {@inheritdoc} */ public function getCustomerAddresses(Customer $customer) { $customerId = $customer->getOriginId(); $addresses = $this->call(SoapTransport::ACTION_CUSTOMER_ADDRESS_LIST, ['customerId' => $customerId]); $addresses = WSIUtils::processCollectionResponse($addresses); return $addresses; }
/** * @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); } }
/** * @param $oid * @param Account $account * @param MagentoAddress $address * * @return Customer */ protected function createCustomer($oid, Account $account, MagentoAddress $address) { $customer = new Customer(); $customer->setChannel($this->integration); $customer->setDataChannel($this->channel); $customer->setFirstName('John'); $customer->setLastName('Doe'); $customer->setEmail('*****@*****.**'); $customer->setOriginId($oid); $customer->setIsActive(true); $customer->setWebsite($this->website); $customer->setStore($this->store); $customer->setAccount($account); $customer->setGender(Gender::MALE); $customer->setGroup($this->customerGroup); // TODO: DateTimeZones should be removed in BAP-8710. Tests should be passed for: // - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\CustomerControllerTest // - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\MagentoCustomerControllerTest $customer->setCreatedAt(new \DateTime('now', new \DateTimezone('UTC'))); $customer->setUpdatedAt(new \DateTime('now', new \DateTimezone('UTC'))); $customer->addAddress($address); $customer->setOwner($this->getUser()); $customer->setOrganization($this->organization); $this->em->persist($customer); return $customer; }