I am using Magento 1.9.
When I want to destroy a specific session in Magento I run this code:
Mage::getSingleton('core/session')->unsPcPayment();
But I want to execute this code when an order is completed.
How can I do this? Where should I put this code?
NOTE: I do not want to destroy this session when the order is paid, I just want to destroy the session when the order is simply received.
Best Answer
You can try to create an observer in a module, preferrable your own module in the local code pool:
Don't know how this works? See here:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
Once you declare the observer, build it out:
You'll want to customize this to your needs, obviously. And put some verification checks in there as well.
EDIT: As per laketuna's suggestion, I changed the target event to
sales_order_place_after
, as it seems to be the most reliable one to observe.