小编Kir*_*rar的帖子

Magento 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)

php magento magento2.2

3
推荐指数
1
解决办法
4586
查看次数

标签 统计

magento ×1

magento2.2 ×1

php ×1