Results 1 to 7 of 7

Hybrid View

  1. #1
    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

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