public function testGetAttributeById()
 {
     /** @var $product \Magento\Catalog\Model\Product */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product')->load(1);
     $this->assertNull($this->_model->getAttributeById(-1, $product));
     $this->assertNull($this->_model->getAttributeById(null, $product));
     $sku = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'sku');
     $this->assertSame($sku, $this->_model->getAttributeById($sku->getId(), $product));
 }
Exemplo n.º 2
0
 /**
  * Retrieve product attribute by identifier
  * Difference from abstract: any attribute is available, not just the ones from $product's attribute set
  *
  * @param  int $attributeId
  * @param  \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Resource\Eav\Attribute
  */
 public function getAttributeById($attributeId, $product)
 {
     $attribute = parent::getAttributeById($attributeId, $product);
     return $attribute ?: $this->_eavAttributeFactory->create()->load($attributeId);
 }