Esempio n. 1
0
 /**
  * Update $entity with new data from imported $store, $website, $group
  *
  * @param Customer      $entity
  * @param Store         $store
  * @param Website       $website
  * @param CustomerGroup $group
  *
  * @return $this
  */
 protected function updateStoresAndGroup(Customer $entity, Store $store, Website $website, CustomerGroup $group)
 {
     // do not allow to change code/website name by imported entity
     $doNotUpdateFields = ['id', 'code', 'name'];
     if (!isset($this->websiteEntityCache[$website->getCode()])) {
         $this->websiteEntityCache[$website->getCode()] = $this->findAndReplaceEntity($website, MagentoConnectorInterface::WEBSITE_TYPE, ['code' => $website->getCode(), 'channel' => $website->getChannel(), 'originId' => $website->getOriginId()], $doNotUpdateFields);
     }
     $this->websiteEntityCache[$website->getCode()] = $this->merge($this->websiteEntityCache[$website->getCode()]);
     if (!isset($this->storeEntityCache[$store->getCode()])) {
         $this->storeEntityCache[$store->getCode()] = $this->findAndReplaceEntity($store, MagentoConnectorInterface::STORE_TYPE, ['code' => $store->getCode(), 'channel' => $store->getChannel(), 'originId' => $store->getOriginId()], $doNotUpdateFields);
     }
     $this->storeEntityCache[$store->getCode()] = $this->merge($this->storeEntityCache[$store->getCode()]);
     if (!isset($this->groupEntityCache[$group->getName()])) {
         $this->groupEntityCache[$group->getName()] = $this->findAndReplaceEntity($group, MagentoConnectorInterface::CUSTOMER_GROUPS_TYPE, ['name' => $group->getName(), 'channel' => $group->getChannel(), 'originId' => $group->getOriginId()], $doNotUpdateFields);
     }
     $this->groupEntityCache[$group->getName()] = $this->merge($this->groupEntityCache[$group->getName()]);
     $entity->setWebsite($this->websiteEntityCache[$website->getCode()])->setStore($this->storeEntityCache[$store->getCode()])->setGroup($this->groupEntityCache[$group->getName()]);
     $entity->getStore()->setWebsite($entity->getWebsite());
 }
Esempio n. 2
0
 /**
  * @param string        $storage
  * @param Website|Store $entity
  * @param array         $notImportedAttrs
  *
  * @return mixed
  */
 protected function getEntityFromCache($storage, $entity, $notImportedAttrs = [])
 {
     $code = $entity->getCode();
     $criteria = ['code' => $code, 'channel' => $entity->getChannel()];
     if (empty($this->{$storage}[$code])) {
         $this->{$storage}[$code] = $this->getEntityByCriteria($criteria, $entity);
         // if loaded from db just update
         if (null !== $this->{$storage}[$code]) {
             $this->strategyHelper->importEntity($this->{$storage}[$code], $entity, $notImportedAttrs);
         } else {
             $this->{$storage}[$code] = $entity->setId(null);
         }
         if ($entity instanceof Store) {
             $notImportedAttrs = ['id', 'code'];
             $website = $this->{$storage}[$code]->getWebsite();
             $website = $this->getEntityFromCache('websiteEntityCache', $website, $notImportedAttrs);
             $this->{$storage}[$code]->setWebsite($website);
         }
     }
     $this->{$storage}[$code] = $this->merge($this->{$storage}[$code]);
     return $this->{$storage}[$code];
 }