public function testGettersSetters() { $this->entity->setFirstName(self::TEST_STRING . 'first'); $this->entity->setLastName(self::TEST_STRING . 'last'); $this->assertNull($this->entity->getOrganization()); $this->entity->addAddress($this->getMock('OroCRM\\Bundle\\MagentoBundle\\Entity\\Address')); $this->entity->setOrganization($this->getMock('Oro\\Bundle\\OrganizationBundle\\Entity\\Organization')); $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $this->entity->getAddresses()); $this->assertInstanceOf('Oro\\Bundle\\OrganizationBundle\\Entity\\Organization', $this->entity->getOrganization()); $this->assertFalse($this->entity->getAddressByOriginId(1)); }
/** * @param Customer $entity */ protected function processChangeAttributes(Customer $entity) { foreach ($entity->getAddresses() as $address) { $address->setOriginId(null); } $entity->setWebsite($entity->getStore()->getWebsite()); $this->setDefaultGroup($entity); }
/** * @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]); } } } } }
/** * "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(); }
/** * 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; }
/** * @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 Customer $customer */ public function markAddressesRemoved(Customer $customer) { if (!$customer->getAddresses()->isEmpty()) { /** @var Address $address */ foreach ($customer->getAddresses() as $address) { $this->markAddressRemoved($address); } } }