3

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 ?

4
  • sorry this is not an answer but have you looked at stackoverflow.com/questions/13595296/… Commented Apr 1, 2014 at 11:52
  • @DavidManners Is it possible to get shopping cart price rule from order ? Commented Apr 1, 2014 at 13:55
  • maybe if you add your cart rule it would be easier to understand and help Commented Apr 1, 2014 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 Commented Apr 1, 2014 at 14:16

1 Answer 1

6

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

require_once("app/Mage.php");

Mage::app('default'); 

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

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

 $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);  
 $product->setAllItems(array($_product));                 
 $product->getProduct()->setProductId($_product->getEntityId());    
foreach($coll as $rule) 
{  
    if ($rule->getConditions()->validate($product))  
    {            
       echo ':)';
       echo $rule->getData('discount_amount');
  }        
}   
exit; 
3
  • @DavidManners I almost came with one solution.Now i need to do the same with my replicated module. Commented Apr 2, 2014 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 :) Commented Apr 2, 2014 at 13:17
  • 1
    Great solution, Very helpful (y) Commented Dec 19, 2017 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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