0
votes

I need to be able to apply 'Shopping Cart Price Rules' to the price on the product page, prior to the product being added to the shopping cart. The reason for not using 'Catalog Price Rules' is that it doesn't offer enough functionality. The product(s) in question have associated products on the same page, if a condition is met, such as x amount of associated products being added, then a discount is provided. I need this price change to be displayed to the user.

I have not been able to find where Magento applies these rules in the shopping cart, so have been unable to start trying to add them to the product page. Any feedback to help get this running is greatly appreciated.

Thank you :)

1

1 Answers

0
votes

you can get applied shopping cart price rules on product page with below function

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;
}

where $product is product object already exist on product page.