Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento 2:如何在状态为可见的自定义模块块文件中获取产品属性集合=>;对_Php_Magento_Magento2.2 - Fatal编程技术网

Php Magento 2:如何在状态为可见的自定义模块块文件中获取产品属性集合=>;对

Php Magento 2:如何在状态为可见的自定义模块块文件中获取产品属性集合=>;对,php,magento,magento2.2,Php,Magento,Magento2.2,这是我调用产品属性集合的函数。我已经获得了产品的产品属性,这些属性已启用,但我在根据它们自己的可见性筛选它们时遇到了问题。即,我只想要那些状态设置为从管理员处可见的产品属性集合 class ProductList extends \Magento\Framework\View\Element\Template { protected $_attributeFactory; public function __construct( \Magento\Catalog\Model\

这是我调用产品属性集合的函数。我已经获得了产品的产品属性,这些属性已启用,但我在根据它们自己的可见性筛选它们时遇到了问题。即,我只想要那些状态设置为从管理员处可见的产品属性集合

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;
 }                                                                    } 

没有测试,但它会为你做的工作

$attributeInfo = $this->_attributeFactory->getCollection()
                 ->addFieldToFilter(\Magento\Eav\Model\Entity\Attribute\Set::KEY_ENTITY_TYPE_ID, 4)
                 ->addFieldToFilter('is_visible_on_front',1);

要获取所有产品属性,需要使用inject类

app/code/Mendor/Mymodule/Model/Attributes.php

 public function __construct(Context $context,   
    \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $coll
    ){
 $this->_coll=$coll;
        parent::__construct($context);
}

 public function getAllAttributes()
    {
        $this->_coll->addFieldToFilter(\Magento\Eav\Model\Entity\Attribute\Set::KEY_ENTITY_TYPE_ID, 4);
        $attrAll = $this->_coll->load()->getItems();
 echo '<pre>'; var_dump($attrAll);'</pre>';
        exit;
}
public function\u构造(Context$Context,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection$coll
){
$this->_coll=$coll;
父项::_构造($context);
}
公共函数getAllAttributes()
{
$this->\u coll->addFieldToFilter(\Magento\Eav\Model\Entity\Attribute\Set::KEY\u Entity\u TYPE\u ID,4);
$attrAll=$this->\u coll->load()->getItems();
echo'';var_dump($attrAll);'';
出口
}

如何筛选仅用于产品或所有属性集的属性?@Magecode follow它没有用处。我必须从与产品相关的所有属性集中获取所有属性。@Magecode这正是您所要求的。否则我不清楚你在问什么