/**
  * Test getType method
  *
  * @param string $attributeCode
  * @param string $serviceClass
  * @param array $attributeRepositoryResponse
  * @param \Magento\Framework\Stdlib\String $stringUtility,
  * @param array $serviceEntityTypeMapData
  * @param array $serviceBackendModelDataInterfaceMapData
  * @param string $expected
  * @dataProvider getTypeDataProvider
  */
 public function testGetType($attributeCode, $serviceClass, $attributeRepositoryResponse, $stringUtility, $serviceEntityTypeMapData, $serviceBackendModelDataInterfaceMapData, $expected)
 {
     $this->attributeRepository->expects($this->any())->method('get')->willReturn($attributeRepositoryResponse);
     $this->eavCustomAttributeTypeLocator = new EavCustomAttributeTypeLocator($this->attributeRepository, $stringUtility, $serviceEntityTypeMapData, $serviceBackendModelDataInterfaceMapData);
     $type = $this->eavCustomAttributeTypeLocator->getType($attributeCode, $serviceClass);
     $this->assertEquals($expected, $type, 'Expected: ' . $expected . 'but got: ' . $type);
 }
 /**
  * Returns array of fields
  *
  * @param string $entityType
  * @return array
  * @throws \Exception
  */
 public function getAttributes($entityType)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->create());
     $attributes = [];
     foreach ($searchResult->getItems() as $attribute) {
         $attributes[] = $attribute->getAttributeCode();
     }
     return $attributes;
 }
Example #3
0
 /**
  * @param string $entityType
  * @return \Magento\Eav\Api\Data\AttributeInterface[]
  * @throws \Exception
  */
 protected function getAttributes($entityType)
 {
     $attributes = $this->attributeCache->getAttributes($entityType);
     if ($attributes) {
         return $attributes;
     }
     $metadata = $this->metadataPool->getMetadata($entityType);
     $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->create());
     $attributes = $searchResult->getItems();
     $this->attributeCache->saveAttributes($entityType, $attributes);
     return $attributes;
 }
 /**
  * {@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;
 }
 /**
  * Get custom attributes
  *
  * @param string $entityType
  * @return \Magento\Eav\Api\Data\AttributeInterface[]
  * @throws \Exception
  */
 private function getNonStaticAttributes($entityType)
 {
     if (!isset($this->attributes[$entityType])) {
         $metadata = $this->metadataPool->getMetadata($entityType);
         $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->addFilter('attribute_set_id', null, 'neq')->create());
         $attributes = [];
         foreach ($searchResult->getItems() as $attribute) {
             if (!$attribute->isStatic()) {
                 $attributes[] = $attribute;
             }
         }
         $this->attributes[$entityType] = $attributes;
     }
     return $this->attributes[$entityType];
 }
Example #8
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);
         }
     }
 }
 public function testGetTypeIfAttributeDoesNotExist()
 {
     $this->attributeRepository->expects($this->any())->method('get')->willReturn(new \Magento\Framework\Exception\NoSuchEntityException());
     $this->eavCustomAttributeTypeLocator = new EavCustomAttributeTypeLocator($this->attributeRepository, new \Magento\Framework\Stdlib\StringUtils(), [], []);
     $this->assertNull($this->eavCustomAttributeTypeLocator->getType('media_galley', 'Magento\\Catalog\\Api\\Data\\ProductInterface'));
 }
 /**
  * @param string $entityType
  * @return \Magento\Eav\Api\Data\AttributeInterface[]
  */
 private function getAttributes($entityType)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->addFilters([$this->filterBuilder->setField('is_global')->setConditionType('in')->setValue([ScopedAttributeInterface::SCOPE_STORE, ScopedAttributeInterface::SCOPE_WEBSITE])->create()])->create());
     return $searchResult->getItems();
 }
Example #11
0
 /**
  * @param string $entityType
  * @return \Magento\Eav\Api\Data\AttributeInterface[]
  * @throws \Exception
  */
 protected function getAttributes($entityType)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->addFilter('attribute_set_id', null, 'neq')->create());
     return $searchResult->getItems();
 }
 /**
  * {@inheritdoc}
  */
 public function get($attributeCode)
 {
     return $this->eavAttributeRepository->get(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE, $attributeCode);
 }