0

Trying super hard to understand Magento's code.

I need a way to intercept coupon codes to prevent them working if an item in the cart is already discounted.

How can I achieve this?

1 Answer 1

5

This can be achieved by using an observer, subscribing to the controller_action_predispatch_checkout_cart_couponPost event.

Or by overriding the Cart controller. Specifically, the couponPostAction method

5
  • Thanks, how were you able to know where to look? For me it seems like guess work, just searching all files for the word 'coupon' and hoping something looks obvious. Is there some documentation you are using? Do you have a special tool helping you or did you keep guessing overtime until you eventually built some knowledge through trial and error? Also is it better that I learn the Zend framework first? Jun 13, 2012 at 14:29
  • 1
    @LucasScholten - over time, you will know where to look for things. Also, think what is involved in applying a coupon: you are posting data to a controller. So there will always be a predispatch event fired + actions to override if absolutely necessary Jun 13, 2012 at 14:37
  • Thanks for asking. I've been able to intercept the point at which a coupon is submitted in the function you suggested. I simply wrote die('you entered a coupon'); to test. I now want to be able to see what items are in the cart and whether any are discounted. How can I pull this information? Is there any way I can dump all the data relating to the products in cart, it would be useful to know for future projects. Jun 14, 2012 at 9:31
  • Which method did you go for - observer or controller override? Jun 14, 2012 at 9:32
  • 1
    At the moment I am literally editing the CartController.php file directly. Once I have a basic understanding I hope to be move the code to a separate module with observer. Jun 14, 2012 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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