I created simple shopping cart rule(using Discount Qty Step (Buy X)) for all products.its working fine in shopping cart.For user awareness I have written following code.

I created one function in Mage_Salesrule_Model_Validator

public function petdreamsrule($rule, $address=null, $myitem)
        if ($this->_canProcessRule($rule, $address) && $rule->getActions()->validate($myitem)) {
               // var_dump($rule);
               return $rule;

and I'm calling in deafult.phtml(design.checkout/cart/item/) like this

            $rules = Mage::getResourceModel('salesrule/rule_collection')->load();
            foreach ($rules as $rule) {
                if ($rule->getIsActive()) {
                    $rule = Mage::getModel('salesrule/rule')->load($rule->getId());
                    $ruleinfo= $val->petdreamsrule($rule, $address=null ,$_item);

upto this point working fine.

But i need to call same function in product view page.I'm getting null for ruleinfo.anyone can guide how to do it?

  • Did you find any solution? I need to validate 'salesrule' on list & view page. – user13676 Aug 29 '14 at 8:57
  • I assume the issue here is that on the product page you are passing the product but the validator needs a quote item – David Manners Jan 25 '15 at 9:55

The problem here I think is that you are working on the product page so you are passing a product to the validator but the validator expects a quote item and not a product.

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.