Forums / General Questions / email order confirmation to third party

email order confirmation to third party

Views: 11,287

Results 21 to 40 of 47
23 May 2013, 5:29 PM
#21
imanerd avatar

imanerd

New Zenner

Join Date:
Oct 2012
Posts:
4
Plugin Contributions:
0

email order confirmation to third party

I need something similar and I'm having a hard time figuring it out. The website is for a medical office that sells nutritional supplements. They have a referral program, and the customer chooses the referring provider from a drop-down during the sign-up process. The client wants an order confirmation email to also go to the referring provider upon checkout. Any ideas on how to do this?

Thank you in advance for your time.

23 May 2013, 5:45 PM
#22
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: email order confirmation to third party

Change the SQL query to retrieve the appropriate destination email address, instead of doing customer-group lookup.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

23 May 2013, 7:13 PM
#23
imanerd avatar

imanerd

New Zenner

Join Date:
Oct 2012
Posts:
4
Plugin Contributions:
0

Re: email order confirmation to third party

DrByte:

Change the SQL query to retrieve the appropriate destination email address, instead of doing customer-group lookup.

Am I going in the right direction?

<?php
/**
 * observer class to send custom extra order emails to referring clinic/doctor
 *
 * @package classes
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: class.sendReferralOrderNotices.php  2010-05-26 20:05:22Z drbyte $
 */
class sendReferralOrderNotices extends base {

 /**  constructor method !
   *
   * Attach observer class to the global $zco_notifier and watch for a single notifier event.
   */
  function sendReferralOrderNotices() {
    $this->attach($this, array('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL'));

    /**
     * Set the email subject line for the messages being sent to the external supplier
     * Use EMAIL_TEXT_SUBJECT for the default subject, or replace with 'My Custom Subject Line' instead.
     */
    $this->orderEmailSubjectPrefix = 'Order Fulfillment Request from ' . STORE_NAME;
  }


 /**   Actual Method that does the desired activity
   *
   * Called by observed class when any of the notifiable events occur
   *
   * @param object $class
   * @param string $eventID
   */
  function update(&$class, $eventID, $paramsArray = array()) {
    global $db;
    list($zf_insert_id, $email_order, $extra_info, $html_msg) = $paramsArray;

    //$group_query = $db->Execute("select customers_group_pricing from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");

    $referral_query = $db->Execute("SELECT sources.sources_email AS sources_email
                                    FROM sources INNER JOIN customers ON sources.sources_id = customers.customers_info_source_id
                                    WHERE customers.customers_id = '" . (int)$_SESSION['customer_id'] . "'");

    //if (!$referral_query->EOF && $referral_query->fields['customers_group_pricing'] == $this->specialReferralId) {
    
    if (!$referral_query->EOF) {
    
          $this->specialReferralEmailAddress = $referral_query->fields['sources_email'];

          zen_mail('', $this->specialReferralEmailAddress,
          $this->orderEmailSubjectPrefix . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
          $email_order . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', $this->attachArray);
    }
  }
}

Sorry I'm relatively new to zen cart. Thank you for your help.

23 May 2013, 11:16 PM
#24
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: email order confirmation to third party

Looks good, assuming the SQL query pulls back the right data.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 May 2013, 4:00 PM
#25
imanerd avatar

imanerd

New Zenner

Join Date:
Oct 2012
Posts:
4
Plugin Contributions:
0

Re: email order confirmation to third party

DrByte:

Looks good, assuming the SQL query pulls back the right data.

Do you know of any reason this wouldn't work with v1.3.8? I can't get it to send an email even when I hard code the recipient email address in the zen_mail function in the class file. Upgrading is not an option at this time.

This was the only difference in order.php:

    //$zco_notifier->notify('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL');

    $zco_notifier->notify('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL', array($zf_insert_id, $email_order, $extra_info, $html_msg));
26 Sep 2013, 4:43 AM
#26
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

Is this will work with 1.5.1?

I need to add something really similar to specific products. Maybe as an attribute...? The store will sell many products but one of them is a membership card that will need an approbation from clubs who are affiliated with the store. So on these specific products the customer should have to select his club in the buying process. Each club needs to be associated with an email adress wich will be used to send a copy of the email order confirmation. Then the club will have to reply to confirm that the customer is a member. Not sure how to implement this...

26 Sep 2013, 3:58 PM
#27
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: email order confirmation to third party

Yes, you could rework all the code to focus on purchased attributes of specific products instead of customer-groups.

So, instead of testing whether the shopper is a member of a specific customer-group, test whether the $order->products array contains specific products, and whether the attributes sub-array contains the specific attribute you want to notify about. And then based on which attribute, send an email to the correspondingly appropriate email address.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 Sep 2013, 12:32 PM
#28
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

I see. Seems a hard work to "rework all the code" but should be doable. Thanks for the input, I'll try to figure it out. :thumbsup:

28 Sep 2013, 5:07 PM
#29
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

I installed it and it's working like a charm, the way it's suppose to work. Beautiful job Dr! But I tested it before I make any modification and I realized that it unfortunately do not really do what I need...

I made the attributes with all the clubs in a dropdow list than, by testing the attribute as a customer I understood that the selected option really needs to be linked to the customer and should be relative to him instead of a product. I could add this drop down menu to the inscription page but it's only needed if the customer want to buy something in a specific product category member cards). To be a member of one of the affiliated clubs is an absolute prerequisite to buy a member card but for all other item the customer do not need it at all... Every year the customer will be able to renew his membership card with the info in his account.

And as explained, when the customer buy the member card, the selected club needs to be contacted for a confirmation that this customer is really one of its member. In a perfect world the club representant who will receive the confirmation request could just follow a link in the email that would bring him on a page where he'll be able to gives his confirmation by clicking on a button, then the order status would pass to the approved status and the customer + administration would receive the update email. That would be so nice!

Do you have an idea on how implement that?

29 Sep 2013, 1:54 AM
#30
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: email order confirmation to third party

I'm glad you were able to use the code examples above to make things work as you initially described.

But your last question describes a situation that is a LOT more complex than the subject of this discussion thread. Your specialized needs should be discussed in a new thread: You need more than just email-confirmation-to-third-party ... I suspect you really need real-time verification of membership status from those 3rd-party sites before allowing the purchase to happen on your site.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

29 Sep 2013, 9:27 AM
#31
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

In an ideal world, yes. But only for this specific category of product. But in the real world I could live with the possibility to have to give back the customer's money if the confirmation fails. And with a price over 100$ the customers will probably never buy the card if they have to select a club in the list without being a member of one of them. But I'll follow your idea and start a new thread on my needs. Thanks for all the help and hope you'll be able to help me with this.

29 Sep 2013, 9:22 PM
#32
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

Sorry for bugging you with this DrBytes but I worked the idea and I think this addon could do the work with some little modification, but I will surely need your help... So lets simplify that.

I added the double email confirmation addon (http://www.zen-cart.com/downloads.php?do=file&id=107), so that double check with the fact that it will be really clear in the product description that they have to be a member of the affiliated clubs listed + the fact that they will have to choose the club they are from in a list as an attribute to by the product + the fact that customers will have to pay like 100$ in the process for their member card... All that will certainly confirm that they take care of what they do. And if mistake happens we could refund them without any problem since we'll use Paypal, or have them becoming a member of one of the affiliated clubs. So, I consider the login confirmation fixed for now, I'll live with the result of this decision.

Now, the other problem was to have the email send to the third party selected by the attribute. That's what I would like to have explained, if you have the time. I suspect it will all be done in the config.xxxxxx.php file, so could it be possible to also ad a condition which could be something like "If the product, or one of the products is in the category #x, send the xxxxxx email to (adress linked to the atribute of this product)".

Also, in the same way the third email will have a specific subject, is it possible to have a specific email send to that third party? It could contain only the information that the club need, which would be the name, adress, phone and email.

With these modifications it will be quite perfect for my needs. ;)

8 Oct 2013, 9:59 PM
#33
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: email order confirmation to third party

Yes, adjust the class file (not the config file) and add the custom logic required, by determining the attributes on each product, and taking action accordingly. The $class variable contains many strings and arrays of all the information you need about the present order and its products and their associated attributes. You can change subject-line strings and destination email address strings based on your findings.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 Oct 2013, 3:42 PM
#34
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

Ok, majority of the zencart layout problem was fixed (some still pending, posted elsewhere on the forum) so I'm now ready to work on this specific function to make it work. I will give time on this in the next few days and will try to make this to work before the weekend. I know I'll need help and I hope you'll be able to help me a little, through this. Regards.

17 Oct 2013, 1:24 AM
#35
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

Well... I started from the start with this and from the moment I created the config.sendGroupOrderNotices.php file I get the blank page error an the main page. As soon as I remove this file Zencart came back. I retried this few times without any succes.

Man I didn't even tried to change the code... Here's my link again. http://www.fc4x4q.com/boutique Any clue on why it does that?

Thanks in advance for your time!

17 Oct 2013, 3:10 PM
#36
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: email order confirmation to third party

Find out the actual error message and take action based on that. See: http://www.zen-cart.com/content.php?124-blank-page

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Oct 2013, 1:14 AM
#37
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

Thanks for the link. I found the issue. I misspelled the name of the file by forgetting the "s" at the end of config.sendGroupOrderNotices.php... what a dumb mistake. Had some difficulties ti fond time to work on this today... Now I'm back on the track. Took off at the job tomorrow so I'll work on this tonight and tomorrow like if my life was depending of it. I need to make this work for Sunday.

18 Oct 2013, 6:50 AM
#38
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

Is there a way to get the exact table name in the DB? One of the frustration in this project is that I have to built this on a not fully accessible server... Since I don't have all the access I had to use some imagination. But first, here's the code I use in the file I called class.sendClubOrderNotices.php:

<?php
/**
 * observer class to send custom extra order emails to supplier based on customer group membership
 *
 * @package classes
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: class.sendClubsOrderNotices.php  2010-05-26 20:05:22Z drbyte $
 */
class sendClubsOrderNotices extends base {

 /**  constructor method !
   *
   * Attach observer class to the global $zco_notifier and watch for a single notifier event.
   */
  function sendClubsOrderNotices() {
    $this->attach($this, array('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL'));
    /**
     * Set the email subject line for the messages being sent to the external supplier
     * Use EMAIL_TEXT_SUBJECT for the default subject, or replace with 'My Custom Subject Line' instead.
     */
    $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par ' . STORE_NAME;
  }


 /**   Actual Method that does the desired activity
   *
   * Called by observed class when any of the notifiable events occur
   *
   * @param object $class
   * @param string $eventID
   */
  function update(&$class, $eventID, $paramsArray = array()) {
    global $db;
    list($zf_insert_id, $email_order, $extra_info, $html_msg) = $paramsArray;
    $group_query = $db->Execute("select products_option_value_id from " . customers_basket_attributes . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
  if (!$group_query->EOF) {
      $this->ClubEmailAddress = '';
      switch($group_query->fields['products_option_value_id']) {
        case '6':
          $this->ClubEmailAddress = '[email protected]';
          $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par ' . STORE_NAME;
          break;
        case '9':
          $this->ClubEmailAddress = '[email protected]';
          $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par ' . STORE_NAME;
          break;
        case '10':
          $this->ClubEmailAddress = '[email protected]';
          $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par ' . STORE_NAME;
          break;
        case '12':
          $this->ClubEmailAddress = '[email protected]';
          $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par ' . STORE_NAME;
          break;
        default:
      }
      if ($this->ClubEmailAddress != '') 
        zen_mail('', $this->ClubEmailAddress,
          $this->orderEmailSubjectPrefix . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
          $email_order . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', $this->attachArray);
    }
  }
}

Off course, I also corrected the name of the config. file and his content. Note also that the class. file currently on the server has real email addresses in the code to test the differents options.

So, I was able to load the store without any blank page, which is great. :cool: I was also able to complete an order but after the payment on Paypal I get an error message on a blank page saying "WARNING: An Error occurred, please refresh the page and try again.". After a refresh the store loads up properly but I had this message in a red box:

10415 Transaction refused because of an invalid argument. See additional error messages for details. - A successful transaction has already been completed for this token.

With a quick search on the Forum I found a thread where you suggest a problem linked to a miscalled table : http://www.zen-cart.com/showthread.php?179524-10415-PayPal-Express-error-code&p=1028104#post1028104 This makes a lot of sens to me since I can't be sure about the table name. I suspected that the error was from this SQL query:

$group_query = $db->Execute("select products_option_value_id from " . customers_basket_attributes . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");

By looking in the logs I found this error which confirm my thoughts:

PHP Fatal error:  1146:Table 'fc41320205382856.customers_basket_attributes' doesn't exist :: select products_option_value_id from customers_basket_attributes where customers_id = '10' in /home/content/06/8442606/html/boutique/includes/classes/db/mysql/query_factory.php on line 120

The payment was received on the Paypal account but Paypal send an email about this 10415 error and didn't returned any info about the payment to ZenCart. So the order details of the admin stayed empty.

So, the question is, is there a way to get the exact name of the table from distance?
And off course, do you see any other error in that code?

18 Oct 2013, 2:21 PM
#39
alexthibo avatar

alexthibo

New Zenner

Join Date:
Jul 2012
Posts:
99
Plugin Contributions:
0

Re: email order confirmation to third party

I was able to get access to the DB this morning, the server owner gave me the access. There was 2 error in the names, customers_basket_attributes is suppose to be zen_customers_basket_attributes and products_option_value_id is products_optionS_value_id. So I fixed them and it's working!! :laugh: Woohoo!!

Now, i'm trying to set a specific email that could be send to the clubs. They do not need all the information send in the checkout confirmation. I'll see if I can use the existant template and work it a little.

22 Oct 2013, 2:03 AM
#40
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: email order confirmation to third party

AlexThibo:

There was 2 error in the names, customers_basket_attributes is suppose to be zen_customers_basket_attributes
FYI, that's why in ZC core we use predefined constants, like TABLE_CUSTOMERS_BASKET_ATTRIBUTES which will automagically include the "zen_" prefix if the store uses that prefix, or "fred_" if that's what's being used, or even nothing if the store isn't using any prefixes.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.