Example #1
0
 /**
  * Test getAllAttributeMetadata
  */
 public function testGetAllAttributeMetadata()
 {
     $data = ['attribute_id' => 1, 'attribute_code' => 'description', 'frontend_label' => 'English', 'store_labels' => array(1 => 'France'), 'frontend_input' => 'textarea'];
     $attributeMock = $this->getMock('Magento\\Framework\\Object', array('usesSource', 'getSource', 'isScopeGlobal', 'getId'), array('data' => $data));
     $attributeMock->expects($this->once())->method('getId')->will($this->returnValue($data['attribute_id']));
     $attributeMock->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(true));
     $attributeMock->expects($this->any())->method('usesSource')->will($this->returnValue(true));
     $attributeMock->expects($this->any())->method('getSource')->will($this->returnValue(new \Magento\Framework\Object()));
     $this->eavConfigMock->expects($this->any())->method('getAttribute')->will($this->returnValue($attributeMock));
     $this->attributeCollectionFactory->expects($this->once())->method('create')->will($this->returnValue($this->attributeCollection));
     $searchCriteria = $this->getMockBuilder('\\Magento\\Framework\\Service\\V1\\Data\\SearchCriteria')->disableOriginalConstructor()->setMethods(['getFilterGroups'])->getMock();
     $searchCriteria->expects($this->once())->method('getFilterGroups')->will($this->returnValue(array()));
     $this->attributeCollection->expects($this->once())->method('getSize')->will($this->returnValue(1));
     $this->attributeCollection->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator(array($attributeMock))));
     /** @var \Magento\Catalog\Service\V1\Data\Product\Attribute\SearchResults $searchResult */
     $searchResult = $this->service->getAllAttributeMetadata('entity_type', $searchCriteria);
     $dto = $searchResult->getItems()[0];
     $this->assertInstanceOf('Magento\\Framework\\Service\\Data\\AbstractExtensibleObject', $dto);
     $this->assertEquals($attributeMock->getFrontendInput(), $dto->getFrontendInput());
     $this->assertEquals(0, $dto->getFrontendLabel()[0]->getStoreId());
     $this->assertEquals(1, $dto->getFrontendLabel()[1]->getStoreId());
     $this->assertEquals('English', $dto->getFrontendLabel()[0]->getLabel());
     $this->assertEquals('France', $dto->getFrontendLabel()[1]->getLabel());
 }
Example #2
0
 /**
  * Retrieve EAV attribute metadata of product
  *
  * @param int $attributeSetId
  * @return AttributeMetadata[]
  */
 public function getProductAttributesMetadata($attributeSetId = self::DEFAULT_ATTRIBUTE_SET_ID)
 {
     /** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchCriteria */
     $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($attributeSetId)->create()]);
     return $this->metadataService->getAllAttributeMetadata(MetadataServiceInterface::ENTITY_TYPE, $this->searchCriteriaBuilder->create())->getItems();
 }
 /**
  * Retrieve EAV attribute metadata of category
  *
  * @param int $attributeSetId
  * @return AttributeMetadata[]
  */
 public function getCategoryAttributesMetadata($attributeSetId = MetadataServiceInterface::DEFAULT_ATTRIBUTE_SET_ID)
 {
     $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($attributeSetId)->create()]);
     return $this->metadataService->getAllAttributeMetadata(MetadataServiceInterface::ENTITY_TYPE, $this->searchCriteriaBuilder->create())->getItems();
 }