I would like to take a moment to reflect on the concept of restocking a deleted order:
I thought this would be a wonderful idea (even though 1.4 is going to implement inventory based on attributes, there are folks out there who need / want it now).
It all lies in the /admin/includes/functions/general.php (and please correct me if I missed or overlooked something)
Very simply, in the function zen_remove_order replace, the declaration line with this
PHP Code:
function zen_remove_order($order_id, $restock = false, $stock_by_attribute = false) {
In the function, in the check for $restock, add this check:
PHP Code:
if($stock_by_attribute == 'on')
{
$order_stock_by_att = $db->Execute("select op.products_id, op.products_quantity,
opa.products_options_id, opa.products_options_values_id
from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa
where op.orders_id = '" . (int)$order_id . "'
AND opa.orders_id = op.orders_id ");
$options_id = $order_stock_by_att->fields['products_options_id'];
$options_values_id = $order_stock_by_att->fields['products_options_values_id'];
$prod_id = $order_stock_by_att->fields['products_id'];
while(!$order_stock_by_att->EOF){
$attribute_stock_sql = "select pas.stock_id from " .
TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pas, ". TABLE_PRODUCTS_ATTRIBUTES ." pa
where pa.options_id = '$options_id'
and pa.options_values_id = '$options_values_id'
and pa.products_attributes_id = pas.stock_attributes
and pas.products_id = '$prod_id' ";
$attribute_stock = $db->Execute($attribute_stock_sql);
$db->Execute("update ".TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " set
quantity = quantity + " .$order_stock_by_att->fields['products_quantity'] . "
where stock_id = '".$attribute_stock->fields['stock_id']."'");
$order_stock_by_att->MoveNext();
}
}
The final function should look something like this:
PHP Code:
function zen_remove_order($order_id, $restock = false, $stock_by_attribute = false) {
global $db;
if ($restock == 'on') {
$order = $db->Execute("select products_id, products_quantity
from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . (int)$order_id . "'");
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($stock_by_attribute == 'on')
{
$order_stock_by_att = $db->Execute("select op.products_id, op.products_quantity,
opa.products_options_id, opa.products_options_values_id
from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " opa
where op.orders_id = '" . (int)$order_id . "'
AND opa.orders_id = op.orders_id ");
$temp_string = "";
$options_id = $order_stock_by_att->fields['products_options_id'];
$options_values_id = $order_stock_by_att->fields['products_options_values_id'];
$prod_id = $order_stock_by_att->fields['products_id'];
while(!$order_stock_by_att->EOF){
$attribute_stock_sql = "select pas.stock_id from " .
TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pas, ". TABLE_PRODUCTS_ATTRIBUTES ." pa
where pa.options_id = '$options_id'
and pa.options_values_id = '$options_values_id'
and pa.products_attributes_id = pas.stock_attributes
and pas.products_id = '$prod_id' ";
$attribute_stock = $db->Execute($attribute_stock_sql);
$db->Execute("update ".TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " set
quantity = quantity + " .$order_stock_by_att->fields['products_quantity'] . "
where stock_id = '".$attribute_stock->fields['stock_id']."'");
$order_stock_by_att->MoveNext();
}
}
}
$db->Execute("delete from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . "
where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_STATUS_HISTORY . "
where orders_id = '" . (int)$order_id . "'");
$db->Execute("delete from " . TABLE_ORDERS_TOTAL . "
where orders_id = '" . (int)$order_id . "'");
}
Ok, now that the function itself has been modified to adapt to what we need, we need to change the necessary calls to allow the new features to be activated.
For me (most of my clients use Super Orders in their zen carts), I modify the /admin/super_orders.php file. Default orders page is the /admin/orders.php file.
Look for the call of
PHP Code:
zen_remove_order($oID,$_POST['restock']);
and change that to
PHP Code:
zen_remove_order($oID, $_POST['restock'],$_POST['restock']);
I hope this helps, I tested it a few times, but not thoroughly.
Bookmarks