我知道Magento如何按范围过滤价格。Magento价格过滤器“从x到无限制”
但是,如何过滤价格为X或更高的产品?我不想要价格的上限。
如果您需要进一步解释请询问。
一个小例子比较清楚。 我希望能够添加一个价格过滤器,例如支持从200美元到800 000美元$
我知道Magento如何按范围过滤价格。Magento价格过滤器“从x到无限制”
但是,如何过滤价格为X或更高的产品?我不想要价格的上限。
如果您需要进一步解释请询问。
一个小例子比较清楚。 我希望能够添加一个价格过滤器,例如支持从200美元到800 000美元$
下面是一个关于如何创建自己的过滤器的例子,并附有一些解释。我们用它为我们的免费产品提供过滤器,您将需要适应您的情况。 您需要覆盖类Mage_Catalog_Model_Layer_Filter_Price
在下面的代码中,$index
定义了价格范围过滤器中的索引。如果您有4个价格范围,则索引1是第一个,最后一个索引是4。 $range
是价格的范围,如果你有一个范围= 100和一个指数= 1,价格范围将介于1到100.如果你有索引= 4和范围= 1000,你会得到的产品价格范围从3000美元到4000美元(以美元为例)。
的代码可以得到改善,例如,你可以在方法_getItemsData()
,$data = parent::_getItemsData()
做,然后使用$的数据进行更改
class MyCompany_Catalog_Model_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price {
protected function _getItemsData()
{
$range = $this->getPriceRange();
$dbRanges = $this->getRangeItemCounts($range);
// Display an item Free Products to allow to select only them in the layer navigation block
if($count = $this->_getResource()->getCountFreeProducts($this)){
$data[] = array(
'label' => Mage::helper('catalog')->__('Free Products'),
'value' => '1,1',
'count' => $this->_getResource()->getCountFreeProducts($this));
}else{
$data = array();
}
foreach ($dbRanges as $index=>$count) {
$data[] = array(
'label' => $this->_renderItemLabel($range, $index),
'value' => $index . ',' . $range,
'count' => $count,
);
}
return $data;
}
}
这是添加过滤器的很好的解释,但我没有看到这里,我怎么能在1009加时启动的过滤器,并在500 000结束例如。 – Flyingmana
,如果你想这样
下50 $
$ 50 - $ 99(5)
$ 100 - $ 199(3)
$ 200 - $ 299(10)
$ 300 - $ 499(2)
$:500 - $ 699(17)
$ 700 - $ 899(1)
$ 900或上述(12)
您可以从http://www.codegyan.com/2012/01/06/customize-filter-price-range-in-magento/获得帮助
丑陋的答案:为了对价格字段应用限制,您需要恢复到(几乎)普通的旧SQ L.
首先有一点背景。
产品集合使用价格指数表catalog_product_index_price
中的预先计算的值。
当在集合上调用addPriceData()
时,索引表将使用表别名price_index
加入。
让我们假设我们有一个产品的收集和含初始化较低的价格极限的变量,如下所示:
$lowerPriceLimit = 200;
/** @var $products Mage_Catalog_Model_Resource_Product_Collection */
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name');
你可能想测试对现场final_price
,因为这是将时所使用的值购买产品(与price
,special_price
或其他)相比较。
这是一个例子,如何添加条件:
// Join the price_index table
$products->addPriceData();
// Apply price limit
$products->getSelect()->where('price_index.final_price >= ?', $lowerPriceLimit);
下面是另一种选择。如果你想做多一点Magento的方式(也就是使用更复杂的方法),使用此:
$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$websiteId = Mage::app()->getWebsite()->getId();
$products->joinField(
'filter_price', // field alias
'catalog/product_index_price', // table
'final_price', // real field name
'entity_id=entity_id', // primary condition
array( // additional conditions
'website_id' => $websiteId,
'customer_group_id' => $customerGroupId,
'final_price' => array('gteq' => $lowerPriceLimit)
)
);
如果你也是在这第二种方法使用addPriceData()
你会最终有一个双内部联接的价格指数,但它仍然会工作...
所有相当低的水平,但在事情上,至少这仍然是相当标准的兼容SQL,所以它应该是相当向上兼容,太。
也许你可以将它与Sylvain的答案结合起来,使其成为分层导航价格范围过滤器的一部分。
我使用下面的代码为我的filter.phtml。希望这个帮助。
<?php
$getLabel = $_item->getLabel();
if (strpos($getLabel, 'price')!== false) :?>
<a class="multi-select unselected" href="<?php echo $this->urlEscape($_item->getUrl()) ?>">
<?php
$getValue = $_item->getValue();
$fitlerPrices = str_replace('-', ' - ', $getValue);
$file = basename($fitlerPrices);
$parts = explode("-", $file);
$getCurency = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
$priceBefore = $getCurency . number_format($parts[0], 0);
$priceAfter = $getCurency . number_format($parts[1], 0); ?>
<?php
if($i == $count){
//Last Item
echo '<span class="price">' . $priceBefore . ' and Above</span>';
}elseif($i <= 1){
//First Item
echo '<span class="price">Under ' . $priceAfter . '</span>';
}else{
echo '<span class="price">' . $priceBefore . ' - ' .$priceAfter . '</span>';
}
?>
</a>
<?php else :?>
<a class="multi-select unselected" href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel(); ?></a>
<?php endif?>
仅仅回答代码的答案,因为他们没有提供给未来的读者很多信息,请提供一些解释你写的东西 – WhatsThePoint
你想让它像常规的分层导航过滤器一样工作吗?因此,在左列的过滤器块(通常) –
您是否试图以编程方式或通过网站上的某个界面执行此操作? – jprofitt
我知道这是不可能通过存在的接口。所以我寻找一个编程方式。 是的乔纳森日,它应该工作就像一个普通的分层导航过滤 – Flyingmana