ATTENTION: Restock Feature has been FIXED!!!!
Sorry for the caps, but I am just too excited
I really had to get the functionality of this feature to start working, well because, a typical order for my store might contain numerous products, and having to manually edit the stock for each product when I deleted a large order was not practical.
So without further Adieu! -
In \admin\includes\functions\general.php look for the following code:
Code:
function zen_remove_order($order_id, $restock = false) {
global $db, $order;
if ($restock == 'on') {
$order = $db->Execute("select products_id, products_quantity
from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . (int)$order_id . "'");
while (!$order->EOF) {
//restored db
$restored_attributes = $db->Execute("select pa.products_attributes_id
from ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." opa, ".TABLE_PRODUCTS_ATTRIBUTES." pa
where opa.orders_id='".(int)$order_id."'
and opa.products_options_id = pa.options_id
and pa.options_values_id = opa.products_options_values_id
and pa.products_id='".(int)$order->fields['products_id']."'
ORDER BY pa.products_attributes_id ASC
");
while(!$restored_attributes->EOF) {
$attr_array[] = $restored_attributes->fields['products_attributes_id'];
$restored_attributes->MoveNext();
}
//echo implode(',', $attr_array);die;
$db->Execute("update ".TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK."
set quantity = quantity + " . $order->fields['products_quantity'] . "
where products_id = '" . (int)$order->fields['products_id'] . "'
and stock_attributes = '".implode(',', $attr_array)."'
");
$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();
}
}
And replace with...
Code:
function zen_remove_order($order_id, $restock = false) {
global $db, $order;
if ($restock == 'on') {
$order = $db->Execute("select orders_products_id, products_id, products_quantity
from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . (int)$order_id . "'");
while (!$order->EOF) {
//restored db
$restored_attributes = $db->Execute("select pa.products_attributes_id
from ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." opa, ".TABLE_PRODUCTS_ATTRIBUTES." pa
where opa.orders_id='".(int)$order_id."'
and opa.products_options_id = pa.options_id
and opa.products_options_values_id = pa.options_values_id
and opa.orders_products_id='".(int)$order->fields['orders_products_id']."'
and pa.products_id='".(int)$order->fields['products_id']."'
ORDER BY pa.products_attributes_id ASC
");
while(!$restored_attributes->EOF) {
$attr_array[] = $restored_attributes->fields['products_attributes_id'];
$restored_attributes->MoveNext();
}
$db->Execute("update ".TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK."
set quantity = quantity + " . $order->fields['products_quantity'] . "
where products_id = '" . (int)$order->fields['products_id'] . "'
and stock_attributes = '".implode(',', $attr_array)."'
");
$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'] . "'");
unset($attr_array);
$order->MoveNext();
}
}
But just a little background and forewarning, I am by no means a programmer, just a noobie, but proficient computer nerd who has had a little background in programming back in college. I sat down for the past 12 hours trying to dissect the logic of tying the line items of the ORDERS_PRODUCTS table (which records each of your unique products sold and in what quantities) to the PRODUCTS_WITH_ATTRIBUTES_STOCK table (which contains your master list of stock for each unique attribute of your product inventory) in the zen-cart database, and realized that the arguments utilized were not specific enough to appropriately identify tie the two tables together accurately.
Furthermore, $attr_array needs to be unset after each iteration, or else data just gets appended to the end of it, causing the whole function to simply not work.
PLEASE NOTE:
This needs more testing and input from the rest of you guys who use this module, because my store's attributes are set up where the only unique attribute I use is color.
So if your store's products are similar to mine, I'm sure that the fix above will work, but if you have multiple attribute combinations (such as size and color), then please test cautiously, and provide your feedback. From looking at the code, I believe it should work in all scenarios...but I can't be for certain.
Also, PLEASE test with caution!!! I would suggest creating a few dummy orders and taking note of your quantities before and after placing your dummy order then monitoring the stock levels after you delete the dummy order and choose to restock the items! It should go without saying, but...obviously don't test this on real live orders :)
Hopefully this helps out a lot of you out there, and this code (or at least the logic to make the restock feature work) make it to the 1.5 version of SBA!
Bookmarks