Question Updated

I am being try to find the discount amount which match the shopping cart rule based on product. I replicate the module 'Shopping Cart Price Rule' to another module which i want to create my discount rule under condition tab.My new module does not have coupon code.It has rule information and condition only.

So Here i want to get discount amount that matches my new module rule based on product details(product id, sku) with out coupon code.

 * Get rules collection for current object state
 * @return Mage_SalesRule_Model_Mysql4_Rule_Collection
protected function _getRules()
    $key = $this->getWebsiteId() . '_' . $this->getCustomerGroupId() . '_' . $this->getCouponCode();
    return $this->_rules[$key];

Here we dont use $this->getCouponCode() to find the rule match.

Before going to replicated module, i just want to know is it possible in shopping cart price rule module.

My question is , How do i find the discount amount based on product that matches shopping cart price rule with out giving coupon code ?

  • sorry this is not an answer but have you looked at stackoverflow.com/questions/13595296/… – David Manners Apr 1 '14 at 11:52
  • @DavidManners Is it possible to get shopping cart price rule from order ? – mymotherland Apr 1 '14 at 13:55
  • maybe if you add your cart rule it would be easier to understand and help – David Manners Apr 1 '14 at 14:10
  • @DavidManners i need some thing like Mage_CatalogRule_Model_Resource_Rule::getRulesForProduct(). I just want to know the product matches shopping(or my new module) rule once it is added and return its discount amount – mymotherland Apr 1 '14 at 14:16

I tried with external file,Given product id to find the matched sales rule conditions.



$pid = 53;
$_product= Mage::getModel('catalog/product')->load($pid);

$coll = Mage::getResourceModel('salesrule/rule_collection')->load();
foreach($coll as $rule){

 $quoteId = Mage::getSingleton('checkout/session')->getQuoteId(); 
 $real_quote = Mage::getSingleton('sales/quote')->load($quoteId);                
 $product = Mage::getModel('sales/quote_item')->setQuote($real_quote)->setProduct($_product);  
foreach($coll as $rule) 
    if ($rule->getConditions()->validate($product))  
       echo ':)';
       echo $rule->getData('discount_amount');
  • @DavidManners I almost came with one solution.Now i need to do the same with my replicated module. – mymotherland Apr 2 '14 at 10:23
  • @DavidManners Actually, I use flag to filter salerule grid and my module rule grid.I have changed my new module based on salerule table now.To avoid more complexity i use magento salerule module to validate :) – mymotherland Apr 2 '14 at 13:17
  • 1
    Great solution, Very helpful (y) – Aasim Goriya Dec 19 '17 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.