我需要能够在将产品添加到购物车之前,将“购物车价格规则”应用于产品页面上的价格。不使用“目录价格规则”的原因是它没有提供足够的功能。所讨论的产品在同一页面上具有相关产品,如果满足条件,例如添加x相关产品,则提供折扣。我需要将此价格变化显示给用户。
我无法找到Magento在购物车中应用这些规则的位置,因此无法开始尝试将它们添加到产品页面。非常感谢任何有助于推动这种运行的反馈。
谢谢:)
答案 0 :(得分:0)
您可以使用以下功能
在产品页面上获取应用购物车价格规则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;
}
其中$ product是产品对象已存在于产品页面上。