views:

777

answers:

1

Hi all,

I'm struggling to figure out how to display the percentage or the amount of discount that is applied to a product in Magento via the Catalog Price Rules.

For example: I want the price to be displayed in the front-end as follows: [old-price] [special-price] [discount info] where [old-price] has a css strike through.

The [old-price] and [special-price] is available by default through the tax helper. I've tried using the CatalogRule model, but I have no way to load it with a product id as the load function expects an entity id and from what I can tell, there aren't any other useful methods to load by product ID. I've var dumped (as well as using *get_class_methods*) just about everything that I found in the price.phtml file (apart from $this of course), but nothing helps.

I could just use a simple calculation to work out the discount percentage or amount, but I have no way of knowing whether the catalog rule is based on a percentage, or fixed amount.

I hope this all makes sense?
Thanks for the help.
Rémy

A: 

Hi Remy, I do agree Magento makes this kind of thing a bit too hard. I wanted to display the description of the coupon code next to the entered coupon code. I suspect my code will be able to help you on your way. I put this code at the top in the template checkout/cart/coupon.phtml:

<?php $c = Mage::getResourceModel('salesrule/rule_collection'); $c->addBindParam('coupon_code', $this->getCouponCode()); $c->getSelect()->where("coupon_code is null or coupon_code='' or coupon_code=:coupon_code"); foreach ($c->getItems() as $item) { $coupon_description = $item->getDescription(); } ?>

So you can see $coupon_description now holds the description of the Shopping Cart Price Rule as long as the user specified a coupon code. You can add more properties from the coupon this way.

Vincent