Question

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!

Was it helpful?

Solution

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top