Magento 马根托。如何知道产品列表中是否使用了属性?
我需要知道哪些属性“在产品列表中使用”被选中为是,但没有找到任何函数,比如$attribute->getIsVisibleOnFront() 事实上,我不知道如何从属性的“前端属性”中获取选项值(用于快速搜索,用于高级搜索,…) 我的代码是这样的:Magento 马根托。如何知道产品列表中是否使用了属性?,magento,attributes,Magento,Attributes,我需要知道哪些属性“在产品列表中使用”被选中为是,但没有找到任何函数,比如$attribute->getIsVisibleOnFront() 事实上,我不知道如何从属性的“前端属性”中获取选项值(用于快速搜索,用于高级搜索,…) 我的代码是这样的: <?php $attributes = $_product->getAttributes(); foreach ($attributes as $attribute) { if ($att
<?php $attributes = $_product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsUsedInProductListing()) {
echo $attribute->getStoreLabel();
}
}
?>
getIsUsedInProductListing()不存在;-)
谢谢……是的,这很容易做到
$product = Mage::getModel('catalog/product')->load($productId); // Or, use your product
$attributes = $product->getTypeInstance(true)->getSetAttributes($product);
foreach ($attributes as $attribute){
var_dump($attribute); // You will be able to see all of the attribute settings here.
if ($attribute->getUsedInProductListing()) {
// Do cool things here.
}
if ($attribute->getIsHtmlAllowedOnFront()) {
// Do cool things here.
}
if ($attribute->getIsVisibleInAdvancedSearch()) {
// Do cool things here.
}
if ($attribute->getUsedForSortBy()) {
// Do cool things here.
}
}
哦,伙计!!!非常感谢。只有一点修正(至少对我来说):$attributes=$product->getTypeInstance(true)->getSetAttributes($product);