Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function processEntity($entity, $isFullData = false, $isPersistNew = false, $itemData = null, array $searchContext = [])
 {
     $excluded = [];
     if (!$entity->getName()) {
         // do not update name if it's empty, due to bug in magento API
         $excluded = ['name'];
     }
     return $this->doctrineHelper->findAndReplaceEntity($entity, MagentoConnectorInterface::REGION_TYPE, 'combinedCode', $excluded);
 }
Ejemplo n.º 2
0
 /**
  * @param AbstractAddress $address
  * @param string $countryCode
  * @param int|string|null $mageRegionId
  * @throws InvalidItemException
  */
 public function updateRegionByMagentoRegionId(AbstractAddress $address, $countryCode, $mageRegionId = null)
 {
     if (!empty($mageRegionId) && empty($this->mageRegionsCache[$mageRegionId]) && is_numeric($mageRegionId)) {
         $this->mageRegionsCache[$mageRegionId] = $this->findRegionByRegionId($mageRegionId);
     }
     if (!empty($this->mageRegionsCache[$mageRegionId])) {
         /** @var Region $mageRegion */
         $mageRegion = $this->mageRegionsCache[$mageRegionId];
         $combinedCode = $mageRegion->getCombinedCode();
         $regionCode = $mageRegion->getCode();
         if (!array_key_exists($combinedCode, $this->regionsCache)) {
             $this->regionsCache[$combinedCode] = $this->loadRegionByCode($combinedCode, $countryCode, $regionCode);
         }
         /**
          * no region found in system db for corresponding magento region, use region text
          */
         if (empty($this->regionsCache[$combinedCode])) {
             $address->setRegion(null);
             $address->setRegionText($mageRegion->getName());
         } else {
             $this->regionsCache[$combinedCode] = $this->doctrineHelper->merge($this->regionsCache[$combinedCode]);
             $address->setRegion($this->regionsCache[$combinedCode]);
             $address->setRegionText(null);
         }
     } elseif ($address->getRegionText() || $address->getCountry()) {
         $address->setRegion(null);
         // unable to find corresponding region and region text is empty,
         // it's correct case for UK addresses, if country present
     } else {
         throw new InvalidItemException('Unable to handle region for address', [$address]);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $combinedCode
  * @param string $countryCode
  * @param string $code
  *
  * @return BAPRegion
  */
 public function loadRegionByCode($combinedCode, $countryCode, $code)
 {
     $regionClass = 'Oro\\Bundle\\AddressBundle\\Entity\\Region';
     $countryClass = 'Oro\\Bundle\\AddressBundle\\Entity\\Country';
     // Simply search region by combinedCode
     $region = $this->doctrineHelper->getEntityByCriteria(array('combinedCode' => $combinedCode), $regionClass);
     if (!$region) {
         // Some region codes in magento are filled by region names
         $em = $this->doctrineHelper->getEntityManager($countryClass);
         $country = $em->getReference($countryClass, $countryCode);
         $region = $this->doctrineHelper->getEntityByCriteria(array('country' => $country, 'name' => $combinedCode), $regionClass);
     }
     if (!$region) {
         // Some numeric regions codes may be padded by 0 in ISO format and not padded in magento
         // As example FR-1 in magento and FR-01 in ISO
         $region = $this->doctrineHelper->getEntityByCriteria(array('combinedCode' => BAPRegion::getRegionCombinedCode($countryCode, str_pad($code, 2, '0', STR_PAD_LEFT))), $regionClass);
     }
     return $region;
 }
Ejemplo n.º 4
0
 /**
  * @param $entity
  *
  * @return object
  */
 protected function merge($entity)
 {
     return $this->doctrineHelper->merge($entity);
 }