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)); }
/** * @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); } }