我试图在价格规则中直接在我的标题上显示横幅,而不必每次都进行编码。
我创建了一个看起来像的文件:
<?php
/* Gets all the Magento store rules */
require 'app/Mage.php';
umask(0);
Mage::app('default');
//echo "test1<br>";
$todayDate = date("Y-m-d");
//echo $todayDate;
$limit = 1;
/* Get all the active Catalog Rules */
$catalogrules = Mage::getModel('catalogrule/rule')->getCollection()
->addFieldToFilter('is_active', 1)
// ->addFieldToFilter('sort_order', 1)
->addFieldToFilter('from_date', array('lteq' => $todayDate))
->addFieldToFilter('to_date', array('gteq' => $todayDate))
->addFieldToSelect('description');
foreach ($catalogrules as $rule)
{
//echo "catalog rule:<br>";
echo $rule->getData('description');
echo "<br>";
}
/* Get all active Shopping Cart Rules */
$cartrules = Mage::getModel('salesrule/rule')->getCollection()
->addFieldToFilter('is_active', 1)
// ->addFieldToFilter('sort_order', 1)
->addFieldToFilter('from_date', array('lteq' => $todayDate))
->addFieldToFilter('to_date', array('gteq' => $todayDate))
->addFieldToSelect('description');
foreach ($cartrules as $rule)
{
//echo "cart rule:<br>";
echo $rule->getData('description');
echo "<br>";
}
?>
我需要从目录规则和购物车规则中过滤它只需要最近启动(from_date)规则的代码。
请建议!!
谢谢!
答案 0 :(得分:1)
<?php
/* Gets all the Magento store rules */
require 'app/Mage.php';
umask(0);
Mage::app('default');
//echo "test1<br>";
$todayDate = date("Y-m-d");
//echo $todayDate;
$limit = 1;
/* Get all the active Catalog Rules */
$catalogrules = Mage::getModel('catalogrule/rule')->getCollection()
->addFieldToFilter('is_active', 1)
// ->addFieldToFilter('sort_order', 1)
->addFieldToFilter('from_date', array(array('gteq' => $todayDate), array('null' => true)))//Make these changes
->addFieldToFilter('to_date', array(array('lteq' => $todayDate), array('null' => true)))//Make these changes
->addFieldToSelect('description');
foreach ($catalogrules as $rule)
{
//echo "catalog rule:<br>";
echo $rule->getData('description');
echo "<br>";
}
/* Get all active Shopping Cart Rules */
$cartrules = Mage::getModel('salesrule/rule')->getCollection()
->addFieldToFilter('is_active', 1)
// ->addFieldToFilter('sort_order', 1)
->addFieldToFilter('from_date', array(array('gteq' => $todayDate), array('null' => true)))//Make these changes
->addFieldToFilter('to_date', array(array('lteq' => $todayDate), array('null' => true)))//Make these changes
->addFieldToSelect('description');
foreach ($cartrules as $rule)
{
//echo "cart rule:<br>";
echo $rule->getData('description');
echo "<br>";
}
?>