Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2006
    Posts
    126
    Plugin Contributions
    0

    Default Order update BCCed but only on despatch?

    I've signed up with TrustPilot and i'm manually entering customer details to request a review, not a massive chore given the number of orders we do.

    However if I send a BCC of the update email to TrustPilot when the order is despatched, this process will be automated.

    I can send a BCC for any/all order updates but cannot see a way of only sending a BCC specifically when the order is being marked as despatched.

    Any ideas?

  2. #2
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Order update BCCed but only on despatch?

    By what method/modification is the BCC email being sent? Do you know the "level" number associated with the status of despatched (sic)?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Aug 2006
    Posts
    126
    Plugin Contributions
    0

    Default Re: Order update BCCed but only on despatch?

    Quote Originally Posted by mc12345678 View Post
    By what method/modification is the BCC email being sent? Do you know the "level" number associated with the status of despatched (sic)?
    Despatched,
    "There is no difference between dispatch and despatch. The latter is an alternative spelling that was common in the 19th century". Yeah, yeah i'm living in the dark ages!

    Anyway thanks for your response, the level is [3] and I have used 'Send copy of admin order status update to' in admin.

    I have found the below in edit_orders.php and was thinking that if I knew how to speak the language and could crowbar 'and order status is 3' into there somehow, it would probably do what I need.

    //send extra emails
    if (SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_STATUS == '1' and SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO != '') {
    zen_mail('', SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO, SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_SUBJECT . ' ' . EMAIL_TEXT_SUBJECT . ' #' . $oID, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status_extra');
    }
    Last edited by Justrimless; 25 Nov 2015 at 05:00 PM.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Order update BCCed but only on despatch?

    Quote Originally Posted by Justrimless View Post
    Despatched,
    "There is no difference between dispatch and despatch. The latter is an alternative spelling that was common in the 19th century". Yeah, yeah i'm living in the dark ages!

    Anyway thanks for your response, the level is [3] and I have used 'Send copy of admin order status update to' in admin.

    I have found the below in edit_orders.php and was thinking that if I knew how to speak the language and could crowbar 'and order status is 3' into there somehow it would probably do what I need.

    //send extra emails
    if (SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_STATUS == '1' and SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO != '') {
    zen_mail('', SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO, SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO_SUBJECT . ' ' . EMAIL_TEXT_SUBJECT . ' #' . $oID, $message, STORE_NAME, EMAIL_FROM, $html_msg, 'order_status_extra');
    }
    Yeah, I wasn't going to correct what was otherwise acceptable long before computers were a twinkle in someone's eye and well what might be correct to everyone else but myself. :)

    That is the area of code that would be appropriate to modify. If it is your store, then may not need so much, but if someone else's I might suggest updating the text of the admin confiiguration bcc section to indicate how it is going to be modified for edit status of orders...

    The "language" you're looking for is located a few lines before that one where the customer's email is generated and refers to the status of the order. I don't have edit_orders installed to my cellphone and just realized it's probably on github, but anyways... There is a similar "feature" in admin/orders.php, there the variable is simply called $status, so could surround the code with:
    Code:
    if ($status == '3') {
    EXISTING SEND EMAIL CODE
    }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Aug 2006
    Posts
    126
    Plugin Contributions
    0

    Default Re: Order update BCCed but only on despatch?

    Oddly that doesn't make any difference.

  6. #6
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Order update BCCed but only on despatch?

    Quote Originally Posted by Justrimless View Post
    Oddly that doesn't make any difference.
    Well, it does again depend on how the status is being edited/updated and if there is possibly additional code beyond that area such as an observer that is waiting for the event so that it can send that BCC email...

    Might suggest using the developers toolkit to search for zen_mail as a possible method to find other uses/cases.

    As for the original issue, if this is in fact something to be done as a part of or when using edit orders, then may I suggest posting to that thread specifically others and more may benefit and be able to help.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Order update BCCed but only on despatch?

    Open up "/your-secret-admin/orders.php":

    Find (around line 229 in Zen Cart 1.5.4):
    Code:
                  $chk_downloads->MoveNext();
                }
              }
              $messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');
              zen_record_admin_activity('Order ' . $oID . ' updated.', 'info');
            } else {
              $messageStack->add_session(WARNING_ORDER_NOT_UPDATED, 'warning');
            }
            zen_redirect(zen_href_link(FILENAME_ORDERS, zen_get_all_get_params(array('action')) . 'action=edit', 'NONSSL'));
    Replace with:
    Code:
                  $chk_downloads->MoveNext();
                }
              }
              $messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');
              zen_record_admin_activity('Order ' . $oID . ' updated.', 'info');
            } else {
              $messageStack->add_session(WARNING_ORDER_NOT_UPDATED, 'warning');
            }
            // Notify observers the order was updated
            $zco_notifier->notify(
              'NOTIFY_ADMIN_ORDER_UPDATED',
              array(
                'order' => (int)$oID,
                'success' => $order_updated
              )
            );
            zen_redirect(zen_href_link(FILENAME_ORDERS, zen_get_all_get_params(array('action')) . 'action=edit', 'NONSSL'));
    Open up "/your-secret-admin/edit_orders.php":

    Find (around line 543 in Edit Orders 4.1.4):
    Code:
    		if($order_updated) {
    			$messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');
    		}
    		else {
    			$messageStack->add_session(WARNING_ORDER_NOT_UPDATED, 'warning');
    		}
    Replace with:
    Code:
    		if($order_updated) {
    			$messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');
    		}
    		else {
    			$messageStack->add_session(WARNING_ORDER_NOT_UPDATED, 'warning');
    		}
    		// Notify observers the order was updated
    		$zco_notifier->notify(
    			'NOTIFY_ADMIN_ORDER_UPDATED',
    			array(
    				'order' => (int)$oID,
    				'success' => $order_updated
    			)
    		);
    Create a new file "/your-secret-admin/includes/classes/OrderObserver.php":
    Code:
    <?php
    /**
     * Listen for custom observers added to "orders.php".
     *
     * Designed for ZC >= v1.5.4
     */
    
    class OrderObserver extends base {
    
    	private $zco_notifier;
    
    	public function __construct(notifier $zco_notifier = null) {
    		if ($zco_notifier === null) {
    			if($GLOBALS['zco_notifier'] === null) {
    				$GLOBALS['zco_notifier'] = new notifier();
    			}
    			$zco_notifier = $GLOBALS['zco_notifier'];
    		}
    		$this->notifier = $zco_notifier;
    		$this->notifier->attach($this, array('NOTIFY_ADMIN_ORDER_UPDATED'));
    	}
    
    	public function updateNotifyAdminOrderUpdated(&$class, $eventID, $data) {
    		global $db;
    
    		// Only do something if the order was updated
    		if($data['success']) {
    			// Retrieve the order information
    			$sql = 'SELECT `customers_name`, `customers_email_address`,
    					`orders_status`, `date_purchased` ' .
    				'FROM `' . TABLE_ORDERS . '` ' .
    				'WHERE `orders_id` = :oid:';
    			$sql = $db->bindVars($sql, ':oid:', $data['order'], 'integer');
    			$order = $db->Execute($sql);
    
    			// Do something if the order exists and the status is 3
    			if(!$order->EOF && 3 == $order->fields['orders_status']) {
    
    				// Check if the status has been changed multiple times
    				$sql = 'SELECT COUNT(`orders_id`) AS `count` ' .
    					'FROM `' . TABLE_ORDERS_STATUS_HISTORY . '` ' .
    					'WHERE `orders_id` = :oid: AND `orders_status_id` = :status:';
    				$sql = $db->bindVars($sql, ':oid:', $data['order'], 'integer');
    				$sql = $db->bindVars($sql, ':status:', $order->fields['orders_status'], 'integer');
    				$check = $db->Execute($sql);
    
    				$firstStatusUpdate = ($check->EOF || 1 >= $check->fields['count']);
    				if($firstStatusUpdate) {
    					// Do something with the order data.
    					// You may wish to hire someone to code this part.
    
    					// Probably best to use the Trust Pilot APIs to send the invitations.
    					// https://support.trustpilot.com/hc/en-us/articles/204379953-A-quick-guide-for-developers-sending-Product-Review-invitations-using-Trustpilot-APIs
    					// https://developers.trustpilot.com/product-reviews-api#Create%20product%20review%20invitation%20link
    					// http://stackoverflow.com/questions/29947191/trustpilot-api-not-sending-invitation-e-mails
    				}
    			}
    		}
    	}
    }
    Create a new file "/your-secret-admin/includes/auto_loaders/config.OrderObserver.php":
    Code:
    <?php
    /**
     * Load the observer
     *
     * Designed for v1.5.4+
     */
    $autoLoadConfig[1][] = array(
    	'autoType'=>'class',
    	'loadFile'=>'OrderObserver.php',
    	'classPath'=>DIR_WS_CLASSES
    );
    $autoLoadConfig[70][] = array(
    	'autoType'=>'classInstantiate',
    	'className'=>'OrderObserver',
    	'objectName'=>'orderObserver'
    );

    NOTE: There are many other ways to accomplish doing something when an order is updated to a specific status. The above is just one of many ways (with minimally invasive code changes). I would also recommend using TrustPilot's API versus just sending an email to TrustPilot.
    Last edited by lhungil; 25 Nov 2015 at 09:33 PM. Reason: Added note
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

 

 

Similar Threads

  1. Replies: 43
    Last Post: 2 Jan 2016, 04:48 PM
  2. Date of Despatch
    By Nick1973 in forum General Questions
    Replies: 3
    Last Post: 6 Oct 2011, 03:14 PM
  3. despatch note
    By irishshopper in forum Basic Configuration
    Replies: 2
    Last Post: 7 Jul 2011, 12:36 AM
  4. Change Email Subject of Status Update Messages e.g. Order Update XXXX
    By apemusic in forum Managing Customers and Orders
    Replies: 4
    Last Post: 13 Oct 2010, 08:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR