Example #1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $om)
 {
     $this->organization = $this->getReference('default_organization');
     $this->users = $om->getRepository('OroUserBundle:User')->findAll();
     $website = new Website();
     $website->setCode('admin')->setName('Admin');
     $om->persist($website);
     $store = new Store();
     $store->setCode('admin')->setName('Admin')->setWebsite($website);
     $om->persist($store);
     $transport = new MagentoSoapTransport();
     $transport->setApiUser('api_user');
     $transport->setApiKey('api_key');
     $transport->setExtensionVersion(SoapTransport::REQUIRED_EXTENSION_VERSION);
     $transport->setIsExtensionInstalled(true);
     $transport->setMagentoVersion('1.9.1.0');
     $transport->setWsdlUrl('http://magento.domain');
     $om->persist($transport);
     $integration = new Integration();
     $integration->setType('magento');
     $integration->setConnectors(['customer', 'cart', 'order', 'newsletter_subscriber']);
     $integration->setName(self::INTEGRATION_NAME);
     $integration->setTransport($transport);
     $integration->setOrganization($this->organization);
     $om->persist($integration);
     $builder = $this->factory->createBuilderForIntegration($integration);
     $builder->setOwner($integration->getOrganization());
     $builder->setDataSource($integration);
     $builder->setStatus($integration->isEnabled() ? Channel::STATUS_ACTIVE : Channel::STATUS_INACTIVE);
     $this->dataChannel = $builder->getChannel();
     $om->persist($this->dataChannel);
     $group = new CustomerGroup();
     $group->setName('General');
     $group->setOriginId(15000);
     $group->setChannel($integration);
     $om->persist($group);
     $om->flush();
     $this->persistDemoCustomers($om, $website, $store, $group, $integration);
     $om->flush();
     $this->persistDemoCarts($om, $store, $integration);
     $om->flush();
     $this->persistDemoOrders($om, $store, $integration);
     $om->flush();
     $this->persistDemoRFM($om);
     $om->flush();
 }
Example #2
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());
 }
Example #3
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];
 }
Example #4
0
 /**
  * @return string
  */
 public function getWebsiteName()
 {
     return $this->website ? $this->website->getName() : null;
 }
Example #5
0
 /**
  * @return $this
  */
 protected function createWebSite()
 {
     $website = new Website();
     $website->setName('web site');
     $website->setOriginId(1);
     $website->setCode('web site code');
     $website->setChannel($this->integration);
     $this->em->persist($website);
     $this->website = $website;
     return $this;
 }