1

I have customer group id.
I need to get sales rule for this customer group.
And after that I want to get discount amount in % for this sales rule;

$customer_from_session = Mage::getSingleton('customer/session')->getCustomer();
$customer_from_db = Mage::getModel('customer/customer')->load($customer_from_session->getId());
$group_id = $customer_from_db->getGroupId();


And by $group_id I need to find actual discounts

Much thanks!

4
  • Just as a not ... you can get the customer group ID with Mage::getSingleton('customer/session')->getCustomerGroupId()
    – sv3n
    Jun 12, 2017 at 20:47
  • Do you want to get the discount amount for a single rule?
    – sv3n
    Jun 12, 2017 at 20:54
  • @sv3n yes, I want to get single sales rule applied to this customer group and discount amount for this rule Jun 13, 2017 at 5:55
  • Please let me know if the code from below works for you :)
    – sv3n
    Jun 13, 2017 at 11:52

1 Answer 1

1

Please try this code:

$websiteId  = Mage::app()->getWebsite()->getId();
$groupId    = Mage::getSingleton('customer/session')->getCustomerGroupId();
$ruleName   = /* your rule name */;

$rules = Mage::getResourceModel('salesrule/rule_collection')
    ->setValidationFilter($websiteId, $groupId);
$rules->addFieldToFilter('name', $ruleName);
$rules->getSelect()->limit(1);

$rule = $rules->getFirstItem();

echo $rule->getSimpleAction(); // by percent ...
echo $rule->getDiscountAmount(); // amount

Edit: to get all rules you can try this (not tested yet)

$websiteId  = Mage::app()->getWebsite()->getId();
$groupId    = Mage::getSingleton('customer/session')->getCustomerGroupId();

$rules = Mage::getResourceModel('salesrule/rule_collection')
    ->setValidationFilter($websiteId, $groupId);

foreach ($rules->getItems() as $rule) {
    echo $rule->getSimpleAction(); // by percent ...
    echo $rule->getDiscountAmount(); // amount
}
8
  • What to do if I want to get all rules ? Jun 13, 2017 at 19:25
  • See updated answer.
    – sv3n
    Jun 13, 2017 at 20:27
  • $rules->getItems() works Jun 13, 2017 at 20:36
  • Do you know how to make smth like this for catalog rules ? Jun 13, 2017 at 20:37
  • 1:.) update code for getItems ... if this isn't correct please suggest an edit. 2) catalogrule has bit different behavior ... if you need this, please post another question.
    – sv3n
    Jun 13, 2017 at 20:40

Your Answer

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

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