Send email on order complete.

Discuss everything related to PHP Shopping Cart. All versions. Any questions related to the PHP Shopping Cart developing or using should be posted to this forum.

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

paragate
Master
Master
Posts: 151
Joined: Nov 13th, '14, 13:04
Location: Denmark, Odense

Send email on order complete.

Postby paragate » Sep 30th, '16, 16:51

hi,
is there an easier workaround to send email in shopping cart.
than my small approach:
Database used for email templates:
mysql tables: email_templates and email_template_translations
insert following code into CheckoutController.php

Code: Select all

$firstName = $customer->first_name;
          $lastName = $customer->last_name;
          $orderNumber = $order->order_number;
          if($customer->first_name == '' && $customer->last_name == '') $lastName = A::t('shoppingcart', 'Customer');
                    $customerEmail = $customer->email;
                    $emailResult = true;
                    $defaultLang = array();
                    $defaultLang['code'] = 'en';
                    $adminLang = 'en';
                    $this->_settings = Bootstrap::init()->getSettings();
                    $approvalType = 'by_email';

                    // Send notification to admin about order
                    $emailResult = Website::sendEmailByTemplate(
                        $this->_settings->general_email,
                        'shoppingcart_mail_order_to_admin',
                        $adminLang,
                        array('{FIRST_NAME}'=>$firstName, '{LAST_NAME}'=>$lastName, '{USER_EMAIL}'=>$customerEmail, '{ORDER_NUMBER}'=>$orderNumber)
                    );
                    // Send notification to customer about order
                    $emailResult = Website::sendEmailByTemplate(
                      $customerEmail,
                      'shoppingcart_mail_order_customer',
                      A::app()->getLanguage(),
                      array('{FIRST_NAME}'=>$firstName, '{LAST_NAME}'=>$lastName, '{USER_EMAIL}'=>$customerEmail, '{ORDER_NUMBER}'=>$orderNumber)
                    );


regards

ne_moj
Master
Master
Posts: 243
Joined: Jan 1st, '16, 14:11

Re: Send email on order complete.

Postby ne_moj » Oct 3rd, '16, 16:06

Good day paragate :)


All the changes that occur in the payment are in the Orders in paymentHandler method (this is one of the few exceptions when the control code is not placed in the controller).
And thank you for your initiative a few bugs in the code has been found when sending an e-mail.

These corrections will be available in the next version of the Shopping Cart. I can also send you Orders.php file if you do not want to wait.

Regards Sergey

paragate
Master
Master
Posts: 151
Joined: Nov 13th, '14, 13:04
Location: Denmark, Odense

Re: Send email on order complete.

Postby paragate » Oct 5th, '16, 17:18

Hello Sergey
Yes please that would be nice
Thank You. Have a good day
regards Henrik Paragate

mdony
Newbie
Newbie
Posts: 6
Joined: May 28th, '17, 04:42

Re: Send email on order complete.

Postby mdony » May 28th, '17, 04:57

Hello ,

I an using ApPHP Shopping Cart Pro 4.1.4,
I think I've encountered a problem on Orders.php on funciton PaymentHandler:

// Find the user to know send or not send a message of email
$customer = Customers::model()->find($order->customer_id);

seems like it returns different customer row , it's not the one intended as specified by $order->customer_id.

I found that it always return the default account John Carter(account_id 1) although the order is made by another account , in my case it's account_id 3 .
I put $order->customer_id on the last_name variable for email content
array(
'{FIRST_NAME}' => $customer->first_name,
'{LAST_NAME}' => $customer->last_name.':'.$order->customer_id,
'{ORDER_NUMBER}' => $order->order_number,

and as expected it shows , that it's showing the correct order.customer_id 3, but customer show below is for account_id 1
Dear Jon Carter:3!

Thank you for reservation request!

Your order ztuadzwxq has been placed in our system and will be processed shortly.
Status: Paid

Date Created: 2017-05-28 09:31:22
Payment Date: 1495938686-- ::
Payment Type: PayPal
Currency: USD
Price: 235.75

is this ever reported before ?

mdony
Newbie
Newbie
Posts: 6
Joined: May 28th, '17, 04:42

Re: Send email on order complete.

Postby mdony » May 28th, '17, 06:41

looking into codes in checkoutcontroller , i ve found a solutioin :

// $customer = Customers::model()->find($order->customer_id);
$customer = Customers::model()->find('account_id = :account_id AND is_active = 1', array(':account_id'=>$order->customer_id));

ne_moj
Master
Master
Posts: 243
Joined: Jan 1st, '16, 14:11

Re: Send email on order complete.

Postby ne_moj » May 29th, '17, 18:40

Hello mdony

Thank you for finding this error and helping to fix it, you are the first who discovered it.

owizard
Newbie
Newbie
Posts: 9
Joined: Nov 30th, '13, 21:05

Re: Send email on order complete.

Postby owizard » Jun 26th, '17, 05:25

In reference to issues being tracked and fixed with work-around - are users being notified in any way other than coming to the forum to find out?

ne_moj
Master
Master
Posts: 243
Joined: Jan 1st, '16, 14:11

Re: Send email on order complete.

Postby ne_moj » Jun 27th, '17, 04:42

Hello

As far as I know - notification is only on the forum, but maybe I'm wrong.


Return to “ApPHP Shopping Cart Talk {developers/users}”