Magento在产品页面上显示购物车价格规则


Magento Display Shopping Cart Price Rules on Product Page

在将产品添加到购物车之前,我需要能够将"购物车价格规则"应用于产品页面上的价格。不使用"目录价格规则"的原因是它没有提供足够的功能。有问题的产品在同一页面上有关联产品,如果满足条件,例如添加的关联产品数量为 x,则会提供折扣。我需要向用户显示此价格更改。

我无法找到Magento在购物车中应用这些规则的位置,因此无法开始尝试将它们添加到产品页面。非常感谢任何有助于运行此操作的反馈。

谢谢:)

您可以使用以下功能在产品页面上获取应用的购物车价格规则

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产品对象已存在于产品页面上。