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.
Bookmarks