4

我需要知道哪些属性“在产品列表中使用”被选中为“是”,但没有找到任何功能,例如 $attribute->getIsVisibleOnFront()

事实上,我不知道如何从属性的“前端属性”中获取选项值(在快速搜索中使用,在高级搜索中使用,...)

我的代码是这样的:

<?php $attributes = $_product->getAttributes();             
    foreach ($attributes as $attribute) {
        if ($attribute->getIsUsedInProductListing()) {
                       echo $attribute->getStoreLabel();
                    }
            }
    ?>

getIsUsedInProductListing() 不存在 ;-)

谢谢...

4

1 回答 1

5

是的,这很容易做到。

$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.
     }
}
于 2012-11-26T21:14:08.917 回答