I want to show catalog rule details like(Rule name and Description) at Cart page.
But i don't get any methods for that.
I also tried getAppliedRuleIds()
method over product object. But not getting any things in result. I think this methods used for Shopping cart rule.
If you know any methods for catalog rule. Please answer my question.
You can try the below code get these details. I am assuming the rule id is 1 which you want to get
$rule = Mage::getModel('salesrule/rule')->load(1);
$rule->setWebsiteIds("1");
echo $rule->name;
echo $rule->description;
for catalog rule try below code
$rule = Mage::getModel('catalogrule/rule')->load(1);
$rule->setWebsiteIds("1");
echo $rule->name;
echo $rule->description;
You can get the applied rules of product using below method. Add this method in app/code/core/Mage/CatalogRule/Model/Rule.php.
You can get the applied rule id of a product by passing the product object.
$ruleid = Mage::getModel('catalogrule/rule')->getProductPriceRuleId(Mage::getModel('catalog/product')->load($product->getId()));
Once you get the ruleid you can retrieve the title and description using ram sharma code.
$rule = Mage::getModel('catalogrule/rule')->load($ruleid);
$rule->setWebsiteIds("1");
echo $rule->name;
echo $rule->description;
Rule.php
public function getProductPriceRuleId(Mage_Catalog_Model_Product $product)
{
$priceRules = null;
$productId = $product->getId();
$storeId = $product->getStoreId();
$websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
if ($product->hasCustomerGroupId()) {
$customerGroupId = $product->getCustomerGroupId();
} else {
$customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
}
$rulesData = $this->_getResource()->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId);
$dateTs = Mage::app()->getLocale()->storeTimeStamp($storeId);
$cacheKey = date('Y-m-d', $dateTs) . "|$websiteId|$customerGroupId|$productId|ruleid";
$rule_id = '';
if (!array_key_exists($cacheKey, self::$_priceRulesData)) {
$rulesData = $this->_getResource()->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId);
if ($rulesData) {
foreach ($rulesData as $ruleData) {
if ($product->getParentId()) {
$rule_id = $ruleData['rule_id'];
if ($ruleData['action_stop']) {
break;
}
} else {
$rule_id = $ruleData['rule_id'];
if ($ruleData['action_stop']) {
break;
}
}
}
return self::$_priceRulesData[$cacheKey] = $rule_id;
} else {
self::$_priceRulesData[$cacheKey] = null;
}
} else {
return self::$_priceRulesData[$cacheKey];
}
return null;
}