通过magento 2中的产品属性组获取产品属性

get product attribute by product attribute group in magento 2

如何从 属性集 在 magento 2 中获取产品 属性组 。 我想通过使用群组在 列表页面 上显示属性,以便我可以在将来添加更多属性

您可以获得如下所有属性:

$attributes = $product->getAttributes();
foreach ($attributes as $attribute) { 
     $attribute->getCode();
}

参考。 https://magento.stackexchange.com/questions/98945/magento-2-how-can-i-get-all-product-attributes-and-get-the-value-yes-no

您只需通过 $product->getAttributes();

获取所有产品属性
$productAttributes=$product->getAttributes();
        $group_id=9;
        $attributeSetId=4;
        foreach ($productAttributes as $attribute) {
            if ($attribute->isInGroup($attributeSetId, $group_id)) {
             echo $attribute->getFrontendLabel().' : '.$attribute->getFrontend()->getValue($product).'<br />';
            }

    }

获取groupId,

//groupCollection - Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory object


$groupCollection = $this->_groupCollection->create();
$groupCollection->addFieldToFilter('attribute_set_id',$attributeSetId);        $groupCollection>addFieldToFilter('attribute_group_name','sample_group_name');
$firstItem = $groupCollection->getFirstItem();
echo $firstItem->getData('attribute_group_id');