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:
<events>
<controller_action_postdispatch>
<observers>
<yourmodule_anything>
<type>singleton</type>
<class>yourmodule/observer</class>
<method>someMethod</method>
</yourmodule_anything>
</observers>
</controller_action_postdispatch>
</events>
Then in your observer method you can check action names as follows
<?php
$action = $observer->getEvent()->getControllerAction();
if ($action->getFullActionName() == 'customer_account_createpost') {
if (Mage::getSingleton('customer/session')->isLoggedIn()) { // this check allows to determine if customer session was created which means successfull registration
}
}
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
Anton S is right - you should check if Magento is firing an event when this occurs. If so, your code should respond to that event.
If that is not the case, or you need custom logic to run before the account is created, please consider overriding/overloading the controller using a custom module: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller
This keeps the original core code intact. It essentially tells Magento to use your custom controller instead. If the method it needs to execute is not found in your controller, it will use the code from the core instead.
Related
I wanted to run some code via PrestanShop when a specific button is pressed, before/after the designed action is happened.It's not alter the designed action, just is send some notification to an external system (notify the 3-rd party that we have a new sale and maybe with sales detalis: product, prices, etc)
To be more specific the action is finish a sale(or make an order) when click the related button.
I read something related (hooks and module) but maybe someone have the same issue then any help is appreciated.(even with no code, but good hints)
Maybe what hook is to be triggered here or some hints how to alter the code using PS-standards.
(light way and not just adding some php code to alter in the hard way the core)
Note: language on interface is romanian and the action is when a sale is post into the system (became an order, payments is not relevant/order_status).
Thank you,
Traian
You can use actionValidateOrder and make your call to your 3rd party in this function.
This hook is called here :
classes/PaymentModule.php line 716
I'm a french student (sorry for my bad English) and I have a problem with one thing in Magento. I would like to insert a customer, when he created his account, in a custom table named 'membre' in my database (of Magento).
So I created an Observer and the methods for, and when I test, I have an error HTTP 500 and in the logs file, I have few pieces of information.
But when I refresh the page the customer is registered but in my database I have nothing....
In my local module I have these files :
/www/app/code/local/Magentix/Gestion/etc/config.xml
config.xml file
/www/app/code/local/Magentix/Gestion/Model/Observer.php
Observer.php File
I'm lost and I don't understand what it is bad or not..
If you want more information, said it and I will try my best for realized that
Thanks.
I have two different modules and with installing that modules i am creating two events, names are different, event's trigger is same (i.e. admin/model/customer/customer/addCustomer/after) and action are also different in OpenCart 2.3.
My Problem is when i add the customer from admin side it executs only for first module. It does not execute for second module.
if i uninstall the first module and add the customer then event for my second module is working fine,
I want to execute some code from two different modules when customer will be added by administrator,
Can anybody help me with this.
I had similar issue in my event call. Kindly check that in your custom event function you are not returning anything after function call.
If you are returning it anything it will come out from the event logic and will not run your or any other module's event.
So kindly comment any return done in your function and test.
Hope it helps.
Never return values incase you are calling any CURL or third party API.
instead of returning values you can store it in any global variables and go ahead.
I'm helping someone set up a Magento shop which was bought from another company. The shop allows users to upload items and users can message each other on the site. It all works very nicely, except that a user doesn't receive an email notification when he receives a new message.
How would I go about implementing the sending of an automatic email each time a user receives a new message?
Thanks
You could add an event observer. You have code somewhere that takes care of the messages sent by the users. I'm sorry I cannot be more specific but it sounds like the site has a custom made module so I couldn't tell you where to look.
Once you find the function where the messaging magic happens, in there, you could dispatch your own event like so
Mage::dispatchEvent('user_message_sent_after');
Then, in the custom module, you look for the config.xml file (it should be in the etc/ folder). There you add something like
<frontend>
<events>
<user_message_sent_after>
<observers>
<your_name_for_this_tag>
<type>singleton</type>
<class>Packagename_Modulename_Model_Observer</class>
<method>sendEmailNotification</method>
</your_name_for_this_tag>
</observers>
</user_message_sent_after>
</events>
</frontend>
If there is an events tag already, you add to it rather than making a second one. 'user_message_sent_after' is not a default Magento event. I made up the name, you could use any other name, as long as it's equal to the name you used in your dispatchEvent call.
Define an email template. In the app\locale\yourlanguage_yourcountrycode\template\email\ folder, add a file called message_notification
Hi {{var name}},<br>
{{var sender}} has sent you a message!<br>
Bye
Next, you finally add the actual observer. Find the model folder in your custom module and add a file called Observer.php. In this file you add something like
<?php
class Packagename_Modulename_Model_Observer {
public function sendEmailNotification($observer) {
// add emailing functionality
}
Old but still very useful and basic explanation on how to send email is here: http://inchoo.net/ecommerce/magento/magento-custom-emails/
I've been stuck on this for a couple of days now. For some reason, duplicating the Magento Authorize.net (Mage_Paygate) module just doesn't work on the front-end. I've managed to duplicate the module and have it show up with its own configuration options in the back-end, but I can't get the payment method to show up on front-end during check out.
So far I've tried copying the module and changing every single instance of the model names to avoid conflict, I've done this multiple times from scratch so I'm confident that it's not an issue of an invalid class call...
There's some kind of magic button that I'm missing. I'm really hoping to hear from someone who's successfully duplicated a core payment module, specifically Authorize.net
I need to create duplicates for accounting purposes. There is no other solution than to duplicate the authorize.net modules.
Thanks
EDIT: Some insight into why I need multiple copies of the authorize.net module: My company processes high volume sales, more than most merchant services will allow. The idea is that we will have several authorize.net modules pre-loaded with multiple authorize.net API credentials that each correspond to a different merchant, so that when one of the merchants caps out we can disable that payment method and enable the next one.
The reason I can't just switch the information in a single authorize.net module is that we need the funds for each credit card to be deposited into separate bank accounts - ECC, the software we use to transfer data from magento to quickbooks, accepts the payment method based on the Title field. In order to differentiate which credit card processor we are transferring funds for, we append a (ACRONYM) to the title field. When this title field changes, ECC poops itself because it suddenly doesn't know where the funds came from for the transactions it's downloading.
We've tried various things and feel that making copies of an authorize.net module would be the best solution. Thanks.
I managed to figure it out, here's what I did in case anyone else runs into this, it's very handy to be able to duplicate payment and shipping modules that follow different rules without having to rely on store view changes:
Create new module Namespace_Modulename , I used Mage_Paygate1 until my concept was proven.
Copy the etc folder from the module you'd like to duplicate
Copy the main model file, in my case Mage/Paygate/Model/Authorizenet.php
Edit the system.xml:
change group name so that a new block of configuration options will appear in the admin panel config, leave the module="" alone. We're going to refer to the original module files rather than copy them. I used authorizenet1.
Change the label node if you'd like, for clarity. In my case I named my copies Authorize.net (processor name)
Edit config.xml:
Module name, change to Namespace_Modulename, I used Mage_Paygate1.
Make sure there is a blocks declaration if the original config.xml didn't have one. We want to refer to the blocks folder in the original module, ie:
<blocks>
<directpost><class>Mage_Paygate_Block</class></directpost>
</blocks>
change the node in the bottom under
<default><section> (<default><payment>) to the group name used in system.xml
(authorizenet1)
Make sure the model node is correctly pointing to the new module, not the old. (paygate1/authorizenet)
Now edit the new model, (Authorizenet.php):
rename the Class to match the new Namespace_Modulename (Mage_Paygate1)
Make sure the $_code equals your group name from the config.xml file (authorize1)
That's what worked for me. The idea is to only copy the pieces that change the module's configuration and just recycle all of the original code.
There's probably an even cleaner way to do this but I'm no magento master by any means, so I very much welcome any advice on how to future-proof this sort of hack.
Along with below code we need to change the model also, in config.xml. if you not make below change new payment method will not displayed in checkout
<models>
<authorizenet1>
<class>Mage_Paygate1_Model</class>
</authorizenet1>
</models>