0

I am working a project a where i need to set discount on the highest price in the cart i have looked in to shopping cart price rules for this but cant find such a thing like this.

Is there i need a custom coding for this? Any one having any idea for on this.

2

Yes indeed. You need a module which will do it. Assuming that you know how to write a Magento module I would suggest to observe sales_quote_collect_totals_before event:

<frontend>
    <events>
        <sales_quote_collect_totals_before>
            <observers>
                <your_module>
                    <type>singleton</type>
                    <class>Your_Module_Model_Observer</class>
                    <method>salesQuoteAddressCollectTotalsBefore</method>
                </your_module>
            </observers>
        </sales_quote_collect_totals_before>
    </events>
</frontend>

Loop through the items:

$quote = $observer->getEvent()->getQuote();
$quote_items = $quote->getItemsCollection();

foreach ($quote_items as $item) {
    ...
}

Find out the most expansive one and apply a discount using $item->setCustomPrice($new_price) and/or $item->setOriginalCustomPrice($new_price) methods.

You may also need to set $item->getProduct()->setIsSuperMode(true) afterwards.

Grau, teurer Freund, ist alle Theorie, und Grün des Lebens goldner Baum.

This code is only a theory and not tested live. So field work is left to you. But if you will have problems implementing it please let me know and I will put some more life into it.

  • Thanks a lot for this code snippet this will surely help me reaching some where in this journey, i will let you know if i found trouble. – ravisoni May 4 '13 at 12:20
  • How to get the posted data in sales_quote_collect_totals_before observer i am trying Mage::app()->getRequest()->getParam('XXX'); this but not working – Milople Inc Nov 21 '13 at 11:32
  • What kind of data do you need? – user487772 Nov 21 '13 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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