简体   繁体   English

隐藏Magento中按列表排序的产品中的属性

[英]Hide attributes from product sort by list in Magento

Is there a way to only show attributes in the Sort By list if there are products with that attribute on the page? 如果页面上有具有该属性的产品,有没有办法仅在“排序依据”列表中显示属性? My catalog has many different attributes but only one or two may apply to each product. 我的目录具有许多不同的属性,但每种产品只能应用一个或两个。

ie if I have attributes height, weight, color and I am looking at a page of t-shirts, I want to not sort by height or weight as these are irrelevent. 即,如果我具有身高,体重,肤色属性,并且正在查看T恤页面,则我不想按身高或体重排序,因为这些都是无关紧要的。 On another page I might be listing boxes, so height and weight then do become relevent and should be added to the sort by list. 在另一页上,我可能正在列出框,因此身高和体重确实不相关,应将其添加到“按列表排序”。

In Manage attributes, set " Use In Layered Navigation " as Filterable(with results) instead of Filterable(no results) to those attributes which you don't want to show when that attribute value doesn't exist on products 在“管理属性”中,将“ 在分层导航中使用 ”设置为“可过滤的(有结果)”而不是“可过滤的(无结果)” ,将其设置为产品上不存在该属性值时不希望显示的那些属性

在此处输入图片说明

After performing the above solution. 执行以上解决方案后。 in Toolbar.phtml (or whereever if your extending),do the following, 在Toolbar.phtml中 (或在您要扩展的任何位置),执行以下操作,

 <?php
$orders=$this->getAvailableOrders();
$new_orders[]=array();
echo "<pre>";
print_r($orders);

$layer = Mage::getModel("catalog/layer");
$category=Mage::getModel('catalog/layer')->getCurrentCategory();
$category = Mage::getModel("catalog/category")->load($category->getId());
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();


$attributesCodes[]=array();
foreach ($attributes as $attribute)
{

    $filterBlockName = 'catalog/layer_filter_attribute';
    $attributesCodes[]=$attribute->getAttributeCode();

    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();

}
print_r($attributesCodes);

foreach($orders as $key_order=>$lbl_order){
    if(!in_array($key_order,$attributesCodes)) continue;
    $new_orders[]=$key_order;
}
print_r($new_orders);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM