/** * @param Customer $entity */ protected function setDefaultGroup(Customer $entity) { if (!$entity->getGroup() && $entity->getWebsite()->getDefaultGroupId()) { $em = $this->strategyHelper->getEntityManager('OroCRMMagentoBundle:CustomerGroup'); $group = $em->getRepository('OroCRMMagentoBundle:CustomerGroup')->findOneBy(['originId' => $entity->getWebsite()->getDefaultGroupId(), 'channel' => $entity->getChannel()]); $entity->setGroup($group); } }
/** * 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()); }
protected function setStore(Customer $object, array $data, $format = null, array $context = array()) { /** @var Store $store */ $store = $this->denormalizeObject($data, 'store', MagentoConnectorInterface::STORE_TYPE, $format, $context); if ($store) { $store->setWebsite($object->getWebsite()); $store->setChannel($object->getChannel()); $object->setStore($store); } }