Get discount amount for customer group in magento
-
09-10-2020 - |
Domanda
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!
Soluzione
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
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange