Forums / General Questions / email order confirmation to third party

email order confirmation to third party

Views: 11,287

Results 41 to 47 of 47
22 Oct 2013, 3:43 AM
#41
alexthibo avatar

alexthibo

New Zenner

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

email order confirmation to third party

Thanks for the addition of information.

28 Oct 2013, 2:34 AM
#42
alexthibo avatar

alexthibo

New Zenner

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

Re: email order confirmation to third party

I was making some more testing than sometime it was working and some other time it didn't. Strange situation... So I found a problem in the code. In this part:

<?php

  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_options_value_id from " . zen_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:
      }
 

I'm trying to get the "products_options_value_id" in the "zen_customers_basket_attributes" but it's not logical since it's not in the basket that I need to look but in the order! In "zen_orders_products_attributes" in fact. The basket is getting empty after the transaction that why it wasn't working. I don figure why it works few times but It's logical if it doesn't

So instead of

Execute("select products_options_value_id from " . zen_customers_basket_attributes . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'")

I think I should ask for something more like

Execute("select products_options_values_id from " . zen_orders_products_attributes . " where orders_products_id = '" . (int)$_SESSION['orders_products_id'] . "' and where products_options_id = '8'")

Am I ok with this code? Does it make sens?

29 Oct 2013, 7:45 PM
#43
alexthibo avatar

alexthibo

New Zenner

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

Re: email order confirmation to third party

I know everyone are very busy but I need help here please to have this query to work.

Concretely, I need to get the option value id of the current order when there is a specific type of option in it. What I use is the following but it's not working and I need help to make it work.

When I run this in phpMyAdmin it gives me the result I'm looking for.
SELECT products_options_values_id
FROM zen_orders_products_attributes
WHERE orders_products_id =27
AND products_options_id =4

Off course the current order is #27. But the following code I use is not working:

$group_query = $db->Execute("select products_options_values_id from " . zen_orders_products_attributes . " where orders_products_id = '" . $zf_insert_id . "' and products_options_id = '4'"). 

I'm pretty sure the problem is about getting current order number which is the "order product id" in the table. I don't know much about the variable transfert data syntax so I really need your help please! :(

29 Oct 2013, 10:10 PM
#44
drbyte avatar

drbyte

Sensei

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

Re: email order confirmation to third party

This speaks to an ongoing ambiguity in all your posts here, where there seems to be an assumption that your customers are always ONLY purchasing ONE product with only ONE attribute selected, because your code does nothing to accommodate different notices to other vendors based on a purchase of multiple items in the cart.

For example, your query above only works if the FIRST option value id is a match, and ignores all other option value ids.

Better to loop through the $class->products array, and for each product in that array, loop through the corresponding $class->products[$i]['attributes'] array to find all the ['values_id'] elements, and compare those against your list of special cases. This is the most accurate data to work from, and is more efficient instead of making a number of new database queries needlessly.

    for ($i=0, $n=sizeof($class->products); $i<$n; $i++) {
      if (isset($this->products[$i]['attributes'])) {
        for ($j=0, $n2=sizeof($class->products[$i]['attributes']); $j<$n2; $j++) {
          switch($class->products[$i]['attributes'][$j]['value_id']) {

//.... all your case statements here ...

          } // end switch
        }  // end for
      }  // end if
    } // end for

.
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 Oct 2013, 11:24 PM
#45
alexthibo avatar

alexthibo

New Zenner

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

Re: email order confirmation to third party

In fact, customers can buy many other products as they want but only one member card, which has this attribute (products_options_id = '4'). There's an extra email that needs to be send to the address associated to this attribute's value selected from a drop down list.

So yes, only one item by order will need this email to be send.

I hope my understanding of what you said is good, my english is far than perfect...

30 Oct 2013, 9:44 PM
#46
alexthibo avatar

alexthibo

New Zenner

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

Re: email order confirmation to third party

That's what works:

  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_options_values_id from zen_orders_products_attributes where orders_products_id ='". intval($zf_insert_id) ."' and products_options_id = '4'");

    if (!$group_query->EOF) {
      $this->ClubEmailAddress = '';
      switch($group_query->fields['products_options_values_id']) {
        case '6':
          $this->ClubEmailAddress = '[email protected]';
          $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par la ' . STORE_NAME;
          break;
        case '7':
          $this->ClubEmailAddress = '[email protected]';
          $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par la ' . STORE_NAME;
          break;
        case '8':
          $this->ClubEmailAddress = '[email protected]';
          $this->orderEmailSubjectPrefix = 'Demande de confirmation de membre par la ' . STORE_NAME;
          break;
		default:
		   $this->ClubEmailAddress = '';
          break;
	  }
	  if ($this->ClubEmailAddress != '') 
		zen_mail('', $this->ClubEmailAddress,
		  $this->orderEmailSubjectPrefix,
		  $email_order . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', $this->attachArray);
  	}
  }
}
27 Jan 2014, 10:29 AM
#47
vescera avatar

vescera

New Zenner

Join Date:
Sep 2010
Posts:
24
Plugin Contributions:
0

Re: email order confirmation to third party

DrByte:

valnoren, using Zen Cart v1.3.9x, it's very simple.

You could hard-code lotsa stuff into the orders class, or you could go with a more sophisticated approach using notifiers/observers as I've outlined below:

  1. Edit /includes/classes/order.php and change just one line near the very end of the file:$this->notify('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL');becomes this:```
    $this->notify('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL'[B], array($zf_insert_id, $email_order, $extra_info, $html_msg)[/B]);
> 
> 2. Create a new file with the following content:
> /includes/classes/observers/class.sendGroupOrderNotices.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.sendGroupOrderNotices.php  2010-05-26 20:05:22Z drbyte $
 */
class sendGroupOrderNotices extends base {

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

[B]    /**
     * Set the specialGroupId to the number of the customer-group assigned in your admin
     */
    $this->specialGroupId = 1;
    /**
     * Set the proper email address for the additional copy of order confirmations to be sent to
     */
    $this->specialGroupEmailAddress = 'noreply@mail_domain.com';
    /**
     * 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;[/B]
  }


 /**   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'] . "'");
    if (!$group_query->EOF && $group_query->fields['customers_group_pricing'] == $this->specialGroupId) {
      zen_mail('', $this->specialGroupEmailAddress,
          $this->orderEmailSubjectPrefix . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
          $email_order . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra', $this->attachArray);
    }
  }
}
```You can **customize the section in red, as needed.
> **
> 
> 3. Create a new file with the following content:
> /includes/auto_loaders/config.sendGroupOrderNotices.php```
<?php
/**
 * autoloader activation point for custom group order email notices
 *
 * @package initSystem
 * @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: config.sendGroupOrderNotices.php  2010-05-26 20:05:22Z drbyte $
 */
/**
 * Autoloader to instantiate observer class
 */
$autoLoadConfig[90][] = array('autoType'=>'class',
                              'loadFile'=>'observers/class.sendGroupOrderNotices.php');
$autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                              'className'=>'sendGroupOrderNotices',
                              'objectName'=>'sendGroupOrderNotices');

Can this be done for manufacturer? If customer order some product manufacturer also receive confirmation email. :unsure: