protected function setUp() { $this->_objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_productMetadataService = $this->getMockBuilder('Magento\\Catalog\\Service\\V1\\Product\\MetadataService')->setMethods(array('getCustomAttributesMetadata'))->disableOriginalConstructor()->getMock(); $this->_productMetadataService->expects($this->any())->method('getCustomAttributesMetadata')->will($this->returnValue(array(new \Magento\Framework\Object(array('attribute_code' => 'attribute_code_1')), new \Magento\Framework\Object(array('attribute_code' => 'attribute_code_2'))))); $this->_valueBuilder = $this->_objectManager->getObject('Magento\\Framework\\Service\\Data\\AttributeValueBuilder'); $this->_productBuilder = $this->_objectManager->getObject('Magento\\Catalog\\Service\\V1\\Data\\ProductBuilder', ['valueBuilder' => $this->_valueBuilder, 'metadataService' => $this->_productMetadataService]); }
/** * Test NoSuchEntityException getAttributeMetadata * @expectedException \Magento\Framework\Exception\NoSuchEntityException * @expectedExceptionMessage No such entity with attributeCode = attr_code */ public function testGetAttributeMetadataNoSuchEntityException() { $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('getId'), array('data' => $data)); $this->eavConfigMock->expects($this->once())->method('getAttribute')->will($this->returnValue($attributeMock)); $attributeMock->expects($this->once())->method('getId')->will($this->returnValue(null)); $this->service->getAttributeMetadata('entity_type', 'attr_code'); }
/** * 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(); }