Beispiel #1
0
 /**
  * BC layer to find existing collection items by old identity filed values
  *
  * {@inheritdoc}
  */
 protected function findExistingEntity($entity, array $searchContext = [])
 {
     $existingEntity = parent::findExistingEntity($entity, $searchContext);
     if (!$existingEntity && $entity instanceof OrderAddress) {
         $propertyAccessor = PropertyAccess::createPropertyAccessor();
         /** @var OrderAddress $existingEntity */
         $existingEntity = $this->existingEntity->getAddresses()->filter(function (OrderAddress $address) use($entity, $propertyAccessor) {
             $isMatched = true;
             $fieldsToMatch = ['street', 'city', 'postalCode', 'country', 'region'];
             foreach ($fieldsToMatch as $fieldToMatch) {
                 $addressValue = $propertyAccessor->getValue($address, $fieldToMatch);
                 $entityValue = $propertyAccessor->getValue($entity, $fieldToMatch);
                 $isMatched = $isMatched && $addressValue === $entityValue;
             }
             return $isMatched;
         })->first();
         if ($existingEntity && $entity->getOriginId()) {
             $existingEntity->setOriginId($entity->getOriginId());
         }
     }
     return $existingEntity;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function findExistingEntity($entity, array $searchContext = [])
 {
     if ($entity instanceof Customer) {
         $website = $this->databaseHelper->findOneBy('OroCRM\\Bundle\\MagentoBundle\\Entity\\Website', ['originId' => $entity->getWebsite()->getOriginId(), 'channel' => $entity->getChannel()]);
         if ($website) {
             $searchContext['website'] = $website;
         }
         /** @var Customer $existingEntity */
         $existingEntity = parent::findExistingEntity($entity, $searchContext);
         if (!$existingEntity) {
             $existingEntity = $this->databaseHelper->findOneBy('OroCRM\\Bundle\\MagentoBundle\\Entity\\Customer', ['email' => $entity->getEmail(), 'channel' => $entity->getChannel(), 'website' => $website]);
             if ($existingEntity && $existingEntity->getId()) {
                 if ($existingEntity->isGuest()) {
                     $existingEntity->setGuest(false);
                     $existingEntity->setIsActive(true);
                 }
                 if ($entity->getOriginId()) {
                     $existingEntity->setOriginId($entity->getOriginId());
                 }
             }
         }
     } else {
         /** @var Customer $existingEntity */
         $existingEntity = parent::findExistingEntity($entity, $searchContext);
     }
     return $existingEntity;
 }
Beispiel #3
0
 /**
  * BC layer to find existing collection items by old identity filed values
  *
  * {@inheritdoc}
  */
 protected function findExistingEntity($entity, array $searchContext = [])
 {
     $existingEntity = parent::findExistingEntity($entity, $searchContext);
     if (!$existingEntity && $entity instanceof OrderAddress) {
         /** @var OrderAddress $existingEntity */
         $existingEntity = $this->existingEntity->getAddresses()->filter(function (OrderAddress $address) use($entity) {
             $isMatched = true;
             $fieldsToMatch = ['street', 'city', 'postalCode', 'country', 'region'];
             foreach ($fieldsToMatch as $fieldToMatch) {
                 $addressValue = $this->getPropertyAccessor()->getValue($address, $fieldToMatch);
                 $entityValue = $this->getPropertyAccessor()->getValue($entity, $fieldToMatch);
                 $isMatched = $isMatched && $addressValue === $entityValue;
             }
             return $isMatched;
         })->first();
         if ($existingEntity && $entity->getOriginId()) {
             $existingEntity->setOriginId($entity->getOriginId());
         }
     }
     if ($entity instanceof OrderItem && is_null($entity->getName())) {
         //name can't be null, so to avoid import job failing empty string is used
         $entity->setName('');
     }
     return $existingEntity;
 }