你可以得到應用的產品頁面上的購物車價格規則,下面的功能
public function getShoppingCartRules($product) {
$now = Mage::getModel('core/date')->date('Y-m-d');
$productData = new Varien_Object();
$data = array(
'product' => $product,
'qty' => 1,
'price' => $product->getFinalPrice(),
'base_row_total' => $product->getFinalPrice()
);
$productData->setData($data);
$allItems = new Varien_Object();
$allItems->setAllItems(array($productData));
$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$ruleCollection = Mage::getResourceModel('salesrule/rule_collection')
->addFieldToFilter('discount_amount', array("gt" => '0'))
->addFieldToFilter('coupon_type', array(1,2,3))
->setOrder('sort_order', 'DESC')
->addWebsiteGroupDateFilter(Mage::app()->getStore()->getWebsiteId(), $customerGroupId);
$ruleCollection->getSelect()
->where('from_date is null or from_date <= ?', $now)
->where('to_date is null or to_date >= ?', $now);
if ($ruleCollection->count()) {
if ($rule->getActions()->validate($productData) && $rule->validate($allItems)) {
$shoppingCartRules[] = $rule;
}
}
return $shoppingCartRules;
}
return null;
}
其中$產品是產品對象產品頁面上已經存在。