【发布时间】:2016-09-01 05:59:42
【问题描述】:
如何从属性集获取magento 2中的产品属性组。 我想通过使用一个组在 listing page 上显示属性,以便将来添加更多属性
【问题讨论】:
标签: magento2
如何从属性集获取magento 2中的产品属性组。 我想通过使用一个组在 listing page 上显示属性,以便将来添加更多属性
【问题讨论】:
标签: magento2
您只需通过$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 />';
}
}
【讨论】:
你可以获得以下所有属性:
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
$attribute->getCode();
}
【讨论】:
要获取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');
【讨论】: