Esempio n. 1
0
 /**
  * @param ContactAddress $contactAddress
  */
 public function prepareAddress(ContactAddress $contactAddress)
 {
     // at this point imported address region have code equal to region_id in magento db field
     $mageRegionId = $contactAddress->getRegion() ? $contactAddress->getRegion()->getCode() : null;
     $contactAddress->setId(null);
     $this->addressImportHelper->updateAddressCountryRegion($contactAddress, $mageRegionId);
     $this->addressImportHelper->updateAddressTypes($contactAddress);
 }
Esempio n. 2
0
 /**
  * @param Address $entity
  * @param array   $changedData
  */
 protected function setRemoteDataChanges($entity, array $changedData)
 {
     foreach ($changedData as $fieldName => $value) {
         if ($fieldName !== 'addresses') {
             if ($fieldName === 'region') {
                 try {
                     $mageRegionId = $this->accessor->getValue($value, 'code');
                     $magentoRegion = $this->addressImportHelper->findRegionByRegionId($mageRegionId);
                     if ($magentoRegion instanceof Region) {
                         $this->accessor->setValue($entity, $fieldName, $this->getChangedRegion($entity, $magentoRegion));
                     }
                 } catch (\Exception $e) {
                     $this->accessor->setValue($entity, $fieldName, null);
                     $this->accessor->setValue($entity, 'contact_address.region', null);
                 }
             } elseif ($fieldName === 'country') {
                 if ($value instanceof BAPCountry) {
                     if (!$value->getIso3Code()) {
                         $country = $this->em->getRepository('OroAddressBundle:Country')->findOneBy(['iso2Code' => $value->getIso2Code()]);
                     } else {
                         $country = $value;
                     }
                     $this->accessor->setValue($entity, $fieldName, $this->getChangedCountry($entity, $country));
                 }
             } elseif ($fieldName === 'types') {
                 $this->addTypes($fieldName, $value, $entity);
             } elseif ($fieldName === 'remove_types') {
                 $this->removeTypes($value, $entity);
             } else {
                 try {
                     $this->accessor->setValue($entity, $fieldName, $value);
                 } catch (\Exception $e) {
                 }
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * @param AbstractAddress $address
  * @param string          $countryCode
  *
  * @return Country|null
  */
 protected function getAddressCountryByCode(AbstractAddress $address, $countryCode)
 {
     return $this->addressHelper->getAddressCountryByCode($address, $countryCode);
 }