2

I have looked at various ways of doing this, but is there a simple way to simply capture the email address entered on the Billing Information form and overriding the Account Email address when committing the order?

SCENARIO: We have a system where only a set number of retailers will assist the customer in the order process and then take delivery of the products (the customer will need to pick the product(s) up from the Retailer's Shipping address). Each Retailer has an account set up to use when ordering with the customer in store.

The process we want to follow is as follows when we reach the checkout:

  1. Retailer logs in (using their backend account id - email + password
  2. Billing information is shown - this is forced to be a new Billing Address with an email address field - all fields are empty
  3. Once complete, the Retailer's Shipping Address is shown, text only, not as a form
  4. The shipping method is selected
  5. The payment method is selected
  6. The Order Review page is selected
  7. The Place Order button is clicked
  8. The user is redirected to Worldpay where.... the Account email address is always displayed.

Therefore, we want the customer to enter their email address at the Billing Info stage and use this when it goes to Worldpay or Paypal for the Payment/Order confirmation email.

However, even though I can display the email address input field in the Billing Info form, the Account holders email address is sent to Worldpay (i.e. with the confirmed order).

Best method to do this please - if possible.

UPDATE ON PROGRESS OF APPLYING SOLUTION on 17/11 at 16:02
Reviewing other posts on the recommended methods to create an observer, I did the following, but as it has not worked, I have either used incorrect rendering tags, or misunderstood how it is achieved.

UPDATED on 25/11 at 12:55
I have still not managed to get this (probably simple) solution working. I have made some changes and retested, but to no avail. If anyone can shed some light on what is wrong with my configurations, I would appreciate it.

Firstly, I created the module declaration Pmw.xml in public_html/app/etc/modules/Pmw

    <config>
        <modules>
            <PMW_SwitchAccountEmail>
                <codePool>local</codePool>
                <active>true</active>
            </PMW_SwitchAccountEmail>
        </modules>
    </config>

I commented out: in case this was stopping it working.

I then created my config.xml file in public_html/app/code/local/Pmw/SwitchAccountEmail/etc/config.xml

    <config>
        <modules>
            <Pmw_SwitchAccountEmail>
                <version>0.0.1</version>
            </Pmw_SwitchAccountEmail>
        </modules>
        <global>
            <models>
                <Pmw_SwitchAccountEmail>
                    <class>Pmw_SwitchEmailAccount_Model</class>
                </Pmw_SwitchAccountEmail>
            </models>
            <events>
              <pmw_switch_account_email>
                 <observers>
                    <sales_model_order_payment_observer>
                        <type>singleton></type>
                        <class>Pmw_SwitchAccountEmail_Observer</class>
                        <method>copyBillingEmailToAccountEmail</method>
                    </sales_model_order_payment_observer>
                 </observers>
              </pmw_switch_account_email>
            </event>
        </global>
    </config>

Finally, I created my observer module, Observer.php in public_html/app/code/local/Pmw/SwitchAccountEmail/Model/Observer.php

    public function copyBillingEmailToAccountEmail(Varien_Event_Observer $observer)
    {

    // Start Logging the process
    Mage::log('PMW - Email Switch observer Start ------');

    Mage::log($order->debug());

        $order = $observer->getPayment()->getOrder();
        $customer = $order->getCustomer();

        $billingEmail = $order->getBillingAddress()->getEmail();
        $customer->setEmail($billingEmail);
    Mage::log('Value of $billingEmail=', $billingEmail);
        $customer->save();

    // End of Logging
    Mage::log('PMW - Email Switch observer End ------');

    }

I ran a further couple of transactions through and the same result occurred, the Account email was being passed to Worldpay, not the Billing Email address entered.

No data was logged in the system log either, so I guess the observer didn't even see the light of day. I assume writing to the log is allowed in the module?

I still have every faith that the observer (if set up correctly) will work.

I still suspect that it is the URL rendering not working, i.e. I have confused the system with incorrect tags and names. While we are looking for a different approach (long term), I am still keen to get this working in the interim.

  • "I have looked at various ways of doing this" - What did you try? If you used observers you were on the right track. – Fabian Schmengler Nov 16 '14 at 21:58
  • Well, I am new to the [more complex side of Magento] and real coding, beyond PHP/XML/PHTML. The various ways I have considered were through other posts, but I haven't implemented anything for real yet. I'm hoping that someone may advise before spending wasted time. But yes, it looks like a custom observer may be required. If you can oblige, I am happy to be advised :-) – Eyeful Of Life Nov 16 '14 at 22:19
  • Hoping that fschmengler or someone can review and enlighten me on what I may have configured incorrectly. – Eyeful Of Life Nov 18 '14 at 15:04
  • Pay attention to upper and lower case, Magento has some strict conventions: 1) the module name should be CamelCased and must start with an upper case letter, 2) the file name for PMW_SwitchAccountEmail_Model_Observer must match the case of the class (Observer.php, not observer.php) – Fabian Schmengler Nov 18 '14 at 15:57
  • I have re-visited this issue a couple of time over the last few days and simplified the tags / folder names to match, but still it does not work. If @Marius (whose original article I used as an example), or anyone else can throw more light on what I have wrongly configured, I would be grateful. Thanks. – Eyeful Of Life Nov 25 '14 at 13:14
2

Try it with an observer on the sales_order_payment_place_start event, which is triggered when a payment process begins (usually with an authorize request to the payment gateway). It is triggered in Mage_Sales_Model_Order_Payment::place() with the payment model as parameter.

I'll skip the steps where you create a module and configure the observer, you should easily find information about this, and go directly into the interesting parts - your observer method. It should look like this:

public function copyBillingEmailToAccountEmail(Varien_Event_Observer $observer)
{
    $order = $observer->getPayment()->getOrder();
    $customer = $order->getCustomer();

    $billingEmail = $order->getBillingAddress()->getEmail();
    $customer->setEmail($billingEmail);
    $customer->save();
}

You'll probably want to switch the email address back after successful payment so that the retailer will be able to log in with his own address again. I'll leave the following open for exercise:

  • create customer attribute "original_email"
  • save original customer email in the observer above
  • create another observer that sets the account email back to the original email after payment has been proceeded (or cancelled!). Have a look at the other events in Mage_Sales_Model_Order_Payment to find a suitable one for your payment method.
  • Great feedback, I'm grateful. I will look into this and respond once I (hopefully) get it all to work. – Eyeful Of Life Nov 16 '14 at 23:40

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.