Kir*_*rar 3 php magento magento2.2
这是我用来调用产品属性集合的函数,我已经获取了已启用产品的产品属性,但是在根据其自身的可见性过滤它们时遇到了问题,即我只希望状态从admin可见的那些产品属性集合。 ...
class ProductList extends \Magento\Framework\View\Element\Template
{
protected $_attributeFactory;
public function __construct(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeFactory
){
parent::__construct($context);
$this->_attributeFactory = $attributeFactory;
}
public function getallattributes()
{
$arr = [];
$attributeInfo = $this->_attributeFactory->getCollection()->addFieldToFilter(\Magento\Eav\Model\Entity\Attribute\Set::KEY_ENTITY_TYPE_ID, 4);
foreach($attributeInfo as $attributes)
{
$attributeId = $attributes->getAttributeId();
// You can get all fields of attribute here
$arr[$attributes->getAttributeId()] = $attributes->getFrontendLabel();
}
return $arr;
} }
Run Code Online (Sandbox Code Playgroud)
未经测试,但可以为您工作
$attributeInfo = $this->_attributeFactory->getCollection()
->addFieldToFilter(\Magento\Eav\Model\Entity\Attribute\Set::KEY_ENTITY_TYPE_ID, 4)
->addFieldToFilter('is_visible_on_front',1);
Run Code Online (Sandbox Code Playgroud)