Esempio n. 1
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) {
                 }
             }
         }
     }
 }