
Originally Posted by
DivaVocals
Sure I'm interested.. please make sure your code is clearly commented/highlighted.. In the v1.5 ready version I'm doing away with the super_orders.php file
Well, that surely changes how this could be integrated, as I've included it in the class, but I suppose it could be a function as well.
New function to update stock:
PHP Code:
// Updates product stock upon order cancellation
function update_stock($action) {
global $db;
$order = $db->Execute("select products_id, products_quantity
from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . (int)$this->oID . "'");
// if order cancelled, return stock
if($action=='cancel')
{
while (!$order->EOF) {
$db->Execute("update " . TABLE_PRODUCTS . "
set products_quantity = products_quantity + " . $order->fields['products_quantity'] . ", products_ordered = products_ordered - " . $order->fields['products_quantity'] . " where products_id = '" . (int)$order->fields['products_id'] . "'");
$order->MoveNext();
}
}
// if re-opening a cancelled order, take stock
elseif($action=='reopen')
{
while (!$order->EOF) {
$db->Execute("update " . TABLE_PRODUCTS . "
set products_quantity = products_quantity - " . $order->fields['products_quantity'] . ", products_ordered = products_ordered + " . $order->fields['products_quantity'] . " where products_id = '" . (int)$order->fields['products_id'] . "'");
$order->MoveNext();
}
}
}
Updated the mark cancelled and reopen functions
PHP Code:
// timestamp the date_cancelled field in orders table
// will also NULL out date_completed field if set (you can't have both at once!)
function mark_cancelled() {
global $db;
if ($this->status == false || $this->status == "completed") {
$db->Execute("UPDATE " . TABLE_ORDERS . " SET date_cancelled = now(), order_followup = 0 WHERE orders_id = '" . $this->oID . "'");
if ($this->status == "completed") {
$db->Execute("UPDATE " . TABLE_ORDERS . " SET date_completed = NULL, order_followup = 0 WHERE orders_id = '" . $this->oID . "'");
}
if (STATUS_ORDER_CANCELLED != 0) {
update_status($this->oID, STATUS_ORDER_CANCELLED);
}
$this->status = "cancelled";
$this->status_date = zen_datetime_short(date('Y-m-d H:i:s'));
$this->update_stock('cancel'); // return stock
}
}
// removes the cancelled/completed timestamp
function reopen() {
global $db;
$db->Execute("update " . TABLE_ORDERS . " set
date_completed = NULL, date_cancelled = NULL
where orders_id = '" . $this->oID . "' limit 1");
if (STATUS_ORDER_REOPEN != 0) {
update_status($this->oID, STATUS_ORDER_REOPEN);
}
// if order was cancelled, update and take stock
if($this->status == "cancelled")
{
$this->update_stock('reopen');
}
$this->status = false;
$this->status_date = false;
}
Bookmarks