I’m trying to make a loose connection between a Magento installation and another application. In particular, there are only two things I care about at the moment – customers and their purchases. What I edited thus far is the file app/code/core/Mage/Customer/controllers/AccountController.php – function createPostAction() is augmented to send the customer’s info to the other application. Another modification was made in success.phtml file to send out the details of the order once it’s placed.
The problem I’m having is that if a user just places items in a cart (as a guest) and then registers as part of the checkout process – the customer’s record in the second application is never created. It only works if the user first explicitly registers, and then checks out separately.
I suppose AccountController.php may be the wrong file to modify to achieve my desired result, which file should I use instead?
Edit: I am not including the code samples, as it’s largely irrelevant – the problem is not with the code, but with the fact that it’s apparently in the wrong place. Where would be a good place to add custom code which should run when a new customer is registered?
This is a bit tricky to do cleanly in Magento but possible to achieve. I’ve had the same task a while ago and solved using observers
First you need to create an observer which listens controller_action_postdispatch event:
Then in your observer method you can check action names as follows
Something similar can be done for checkout registration. In general observers are great (and proper) way to extend Magento functionality. Read more about them here