| 1 | <?php
|
|---|
| 2 | /* -----------------------------------------------------------------------------------------
|
|---|
| 3 | $Id: header.php 3808 2012-10-28 20:39:04Z web28 $
|
|---|
| 4 |
|
|---|
| 5 | modified eCommerce Shopsoftware
|
|---|
| 6 | http://www.modified-shop.org
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 2009 - 2013 [www.modified-shop.org]
|
|---|
| 9 | -----------------------------------------------------------------------------------------
|
|---|
| 10 | Released under the GNU General Public License
|
|---|
| 11 | ---------------------------------------------------------------------------------------*/
|
|---|
| 12 |
|
|---|
| 13 | function xtc_restock_order($order_id) {
|
|---|
| 14 | $order_query = xtc_db_query("SELECT orders_products_id,
|
|---|
| 15 | products_id,
|
|---|
| 16 | products_quantity
|
|---|
| 17 | FROM ".TABLE_ORDERS_PRODUCTS."
|
|---|
| 18 | WHERE orders_id = '".(int)$order_id."'");
|
|---|
| 19 | while ($order = xtc_db_fetch_array($order_query)) {
|
|---|
| 20 | $products_update = true;
|
|---|
| 21 | $orders_attributes_query = xtc_db_query("SELECT pa.products_options,
|
|---|
| 22 | pa.products_options_values,
|
|---|
| 23 | opd.orders_products_filename
|
|---|
| 24 | FROM ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." pa
|
|---|
| 25 | LEFT JOIN ".TABLE_ORDERS_PRODUCTS_DOWNLOAD." opd
|
|---|
| 26 | ON opd.orders_products_id = pa.orders_products_id
|
|---|
| 27 | WHERE pa.orders_id = '" . (int)$order_id . "'
|
|---|
| 28 | AND pa.orders_products_id = '" . $order['orders_products_id'] . "'");
|
|---|
| 29 | if (xtc_db_num_rows($orders_attributes_query) > 0) {
|
|---|
| 30 | while ($orders_attributes = xtc_db_fetch_array($orders_attributes_query)) {
|
|---|
| 31 | if ($orders_attributes['orders_products_filename'] == '') {
|
|---|
| 32 | $ids_query = xtc_db_query("SELECT po.products_options_id, pov.products_options_values_id FROM
|
|---|
| 33 | `".TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS."` AS pov2po, `".TABLE_PRODUCTS_OPTIONS_VALUES."` AS pov, `".TABLE_PRODUCTS_OPTIONS."` AS po
|
|---|
| 34 | WHERE
|
|---|
| 35 | pov.products_options_values_id=pov2po.products_options_values_id
|
|---|
| 36 | AND po.products_options_id=pov2po.products_options_id
|
|---|
| 37 | AND po.language_id=pov.language_id
|
|---|
| 38 | AND po.products_options_name='".$orders_attributes['products_options']."'
|
|---|
| 39 | AND pov.products_options_values_name='".$orders_attributes['products_options_values']."'
|
|---|
| 40 | ");
|
|---|
| 41 | if (xtc_db_num_rows($ids_query) > 0) {
|
|---|
| 42 | $options_values_id_list = array();
|
|---|
| 43 | while ($id_result = xtc_db_fetch_array($ids_query)) {
|
|---|
| 44 | $options_values_id_list[] = $id_result['products_options_values_id'];
|
|---|
| 45 | }
|
|---|
| 46 | if(!empty($options_values_id_list)) {
|
|---|
| 47 | xtc_db_query("UPDATE ".TABLE_PRODUCTS_ATTRIBUTES."
|
|---|
| 48 | SET attributes_stock = attributes_stock + ".$order['products_quantity']."
|
|---|
| 49 | AND options_values_id IN(" . implode(',',$options_values_id_list) . ")
|
|---|
| 50 | AND products_id = '" . $order['products_id'] . "'");
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 | } else {
|
|---|
| 54 | $products_update = false;
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | if ($products_update === true) {
|
|---|
| 59 | xtc_db_query("UPDATE ".TABLE_PRODUCTS."
|
|---|
| 60 | SET products_quantity = products_quantity + ".$order['products_quantity'].",
|
|---|
| 61 | products_ordered = products_ordered - ".$order['products_quantity']."
|
|---|
| 62 | WHERE products_id = '".$order['products_id']."'");
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | ?>
|
|---|