/**
  * {@inheritdoc}
  */
 public function getType($attributeCode, $serviceClass)
 {
     if (!$serviceClass || !$attributeCode || !isset($this->serviceEntityTypeMap[$serviceClass]) || !isset($this->serviceBackendModelDataInterfaceMap[$serviceClass])) {
         return TypeProcessor::ANY_TYPE;
     }
     try {
         $attribute = $this->attributeRepository->get($this->serviceEntityTypeMap[$serviceClass], $attributeCode);
     } catch (NoSuchEntityException $e) {
         return TypeProcessor::ANY_TYPE;
     }
     $dataInterface = $this->getComplexTypeLocator()->getType($attribute, $serviceClass, $this->serviceBackendModelDataInterfaceMap);
     return $dataInterface ?: $this->getSimpleTypeLocator()->getType($attribute);
 }
 /**
  * {@inheritdoc}
  */
 public function getType($attributeCode, $serviceClass)
 {
     if (!$serviceClass || !$attributeCode || !isset($this->serviceEntityTypeMap[$serviceClass]) || !isset($this->serviceBackendModelDataInterfaceMap[$serviceClass])) {
         return null;
     }
     try {
         $backendModel = $this->attributeRepository->get($this->serviceEntityTypeMap[$serviceClass], $attributeCode)->getBackendModel();
     } catch (NoSuchEntityException $e) {
         return null;
     }
     $dataInterface = isset($this->serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel]) ? $this->serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel] : null;
     return $dataInterface;
 }
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getType($attributeCode, $serviceClass)
 {
     if (!$serviceClass || !$attributeCode || !isset($this->serviceEntityTypeMap[$serviceClass]) || !isset($this->serviceBackendModelDataInterfaceMap[$serviceClass])) {
         return null;
     }
     try {
         $attribute = $this->attributeRepository->get($this->serviceEntityTypeMap[$serviceClass], $attributeCode);
         $backendModel = $attribute->getBackendModel();
     } catch (NoSuchEntityException $e) {
         return null;
     }
     //If empty backend model, check if it can be derived
     if (empty($backendModel)) {
         $backendModelClass = sprintf('Magento\\Eav\\Model\\Attribute\\Data\\%s', $this->stringUtility->upperCaseWords($attribute->getFrontendInput()));
         $backendModel = class_exists($backendModelClass) ? $backendModelClass : null;
     }
     $dataInterface = isset($this->serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel]) ? $this->serviceBackendModelDataInterfaceMap[$serviceClass][$backendModel] : null;
     return $dataInterface;
 }
Example #4
0
 /**
  * @param string $entityType
  * @param array $context
  * @return void
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function processUpdates($entityType, $context)
 {
     if (!isset($this->update[$entityType]) || !is_array($this->update[$entityType])) {
         return;
     }
     $metadata = $this->metadataPool->getMetadata($entityType);
     foreach ($this->update[$entityType] as $link => $data) {
         foreach ($data as $attributeCode => $attributeValue) {
             /** @var AbstractAttribute $attribute */
             $attribute = $this->attributeRepository->get($metadata->getEavEntityType(), $attributeCode);
             $conditions = [$metadata->getLinkField() . ' = ?' => $link, 'attribute_id = ?' => $attribute->getAttributeId()];
             foreach ($context as $field => $value) {
                 $conditions[$metadata->getEntityConnection()->quoteIdentifier($field) . ' = ?'] = $value;
             }
             $metadata->getEntityConnection()->update($attribute->getBackend()->getTable(), ['value' => $this->prepareValue($entityType, $attributeValue, $attribute)], $conditions);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function get($attributeCode)
 {
     return $this->eavAttributeRepository->get(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE, $attributeCode);
 }