Php 添加Magento的AttributeToFilter,仅获取具有特殊价格的产品
我的客户想要一个页面,其中有所有的产品与特殊价格只。我试图将此代码放在list.phtml页面上,但没有显示任何内容,您能帮助我吗Php 添加Magento的AttributeToFilter,仅获取具有特殊价格的产品,php,magento,Php,Magento,我的客户想要一个页面,其中有所有的产品与特殊价格只。我试图将此代码放在list.phtml页面上,但没有显示任何内容,您能帮助我吗 $todayDate = date('m/d/y'); $tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y')); $tomorrowDate = date('m/d/y', $tomorrow); $_productCollection = $this->get
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
$_productCollection = $this->getLoadedProductCollection();
$_productCollection = $_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or' => array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');
我会试试这个,如果跑性感,我会点击接受你的答案;我尝试了你的方法,但在这种方法中,如果我使用侧边栏中的过滤器,页面内容不会发生任何变化,就像过滤器不适用于页面一样。对于所有类别页面??是的,页面将显示商店中所有特价产品。
**Setup a Magento Special Price Products Page**
**First step:**
Create a new page named “Specials” (or whatever you want) in Admin->CMS->Pages and insert into “Custom Layout XML” field this code:
<reference name="content">
<block after="-" type="catalog/product_list" name="offerte.new" alias="offerte" template="catalog/product/specials.phtml">
<action method="setProductsCount"><count>15</count></action>
</block>
</reference>
select your layout (2columns-left,2columns-right or 3 columns ) and save.
**Second Step:**
Create this file:
app/design/frontend/default/YOURTHEME/template/catalog/product/specials.phtml
Populate the file with this content:
Mage::getSingleton('core/session', array('name' => 'frontend'));
$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection);
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');
and with the content taken from
app/design/frontend/default/YOURTHEME/template/catalog/product/list.phtml
WITHOUT THIS LINE:
$_productCollection=$this->getLoadedProductCollection();
Save your template file and enjoy your specials page…
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
$_productCollection = $this->getLoadedProductCollection();
//I put the clear() thing there and BUM!, and load() after to ;)
$_productCollection->clear()->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))->addAttributeToFilter('special_to_date', array('or' => array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')->load();