/** * Change order status * * @param int $order_id Order identifier * @param string $status_to New order status (one char) * @param string $status_from Old order status (one char) * @param array $force_notification Array with notification rules * @param boolean $place_order True, if this function have been called inside of fn_place_order function. * @return boolean */ function fn_change_order_status($order_id, $status_to, $status_from = '', $force_notification = array(), $place_order = false) { $order_info = fn_get_order_info($order_id, true); if (!$order_info) { return false; } if (defined('CART_LOCALIZATION') && $order_info['localization_id'] && CART_LOCALIZATION != $order_info['localization_id']) { Registry::get('view')->assign('localization', fn_get_localization_data(CART_LOCALIZATION)); } $order_statuses = fn_get_statuses(STATUSES_ORDER, array(), true, false, $order_info['lang_code'] ? $order_info['lang_code'] : CART_LANGUAGE, $order_info['company_id']); if (empty($status_from)) { $status_from = $order_info['status']; } if (empty($order_info) || empty($status_to) || $status_from == $status_to) { return false; } if (fn_allowed_for('MULTIVENDOR')) { if ($order_info['is_parent_order'] == 'Y') { $child_ids = db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $order_id); $res = $_res = true; foreach ($child_ids as $child_order_id) { $_res = fn_change_order_status($child_order_id, $status_to, '', $force_notification, $place_order); } $res = $res && $_res; return $res; } } $_updated_ids = array(); $_error = false; foreach ($order_info['products'] as $k => $v) { // Generate ekey if EDP is ordered if (!empty($v['extra']['is_edp']) && $v['extra']['is_edp'] == 'Y') { continue; // don't track inventory } // Update product amount if inventory tracking is enabled if (Registry::get('settings.General.inventory_tracking') == 'Y') { if ($order_statuses[$status_to]['params']['inventory'] == 'D' && $order_statuses[$status_from]['params']['inventory'] == 'I') { // decrease amount if (fn_update_product_amount($v['product_id'], $v['amount'], @$v['extra']['product_options'], '-') == false) { $status_to = 'B'; //backorder $_error = true; fn_set_notification('W', __('warning'), __('low_stock_subj', array('[product]' => fn_get_product_name($v['product_id']) . ' #' . $v['product_id']))); break; } else { $_updated_ids[] = $k; } } elseif ($order_statuses[$status_to]['params']['inventory'] == 'I' && $order_statuses[$status_from]['params']['inventory'] == 'D') { // increase amount fn_update_product_amount($v['product_id'], $v['amount'], @$v['extra']['product_options'], '+'); } } } if ($_error) { if (!empty($_updated_ids)) { foreach ($_updated_ids as $id) { // increase amount fn_update_product_amount($order_info['products'][$id]['product_id'], $order_info['products'][$id]['amount'], @$order_info['products'][$id]['extra']['product_options'], '+'); } unset($_updated_ids); } if ($status_from == $status_to) { return false; } } fn_set_hook('change_order_status', $status_to, $status_from, $order_info, $force_notification, $order_statuses, $place_order); if ($status_from == $status_to) { if (!empty($_updated_ids)) { foreach ($_updated_ids as $id) { // increase amount fn_update_product_amount($order_info['products'][$id]['product_id'], $order_info['products'][$id]['amount'], @$order_info['products'][$id]['extra']['product_options'], '+'); } unset($_updated_ids); } return false; } fn_promotion_post_processing($status_to, $status_from, $order_info, $force_notification); // Log order status change fn_log_event('orders', 'status', array('order_id' => $order_id, 'status_from' => $status_from, 'status_to' => $status_to)); if (!empty($order_statuses[$status_to]['params']['appearance_type']) && ($order_statuses[$status_to]['params']['appearance_type'] == 'I' || $order_statuses[$status_to]['params']['appearance_type'] == 'C') && !db_get_field("SELECT doc_id FROM ?:order_docs WHERE type = ?s AND order_id = ?i", $order_statuses[$status_to]['params']['appearance_type'], $order_id)) { $_data = array('order_id' => $order_id, 'type' => $order_statuses[$status_to]['params']['appearance_type']); $order_info['doc_ids'][$order_statuses[$status_to]['params']['appearance_type']] = db_query("INSERT INTO ?:order_docs ?e", $_data); } // Check if we need to remove CC info if (!empty($order_statuses[$status_to]['params']['remove_cc_info']) && $order_statuses[$status_to]['params']['remove_cc_info'] == 'Y' && !empty($order_info['payment_info'])) { fn_cleanup_payment_info($order_id, $order_info['payment_info'], true); } $edp_data = fn_generate_ekeys_for_edp(array('status_from' => $status_from, 'status_to' => $status_to), $order_info); $order_info['status'] = $status_to; fn_order_notification($order_info, $edp_data, $force_notification); db_query("UPDATE ?:orders SET status = ?s WHERE order_id = ?i", $status_to, $order_id); return true; }
} $suffix = ".details?order_id={$_REQUEST['order_id']}"; } if ($mode == 'bulk_print' && !empty($_REQUEST['order_ids'])) { fn_print_order_invoices($_REQUEST['order_ids'], Registry::get('runtime.dispatch_extra') == 'pdf'); exit; } if ($mode == 'packing_slip' && !empty($_REQUEST['order_ids'])) { fn_print_order_packing_slips($_REQUEST['order_ids'], Registry::get('runtime.dispatch_extra') == 'pdf'); exit; } if ($mode == 'remove_cc_info' && !empty($_REQUEST['order_ids'])) { fn_set_progress('parts', sizeof($_REQUEST['order_ids'])); foreach ($_REQUEST['order_ids'] as $v) { $payment_info = db_get_field("SELECT data FROM ?:order_data WHERE order_id = ?i AND type = 'P'", $v); fn_cleanup_payment_info($v, $payment_info); } fn_set_notification('N', __('notice'), __('done')); if (count($_REQUEST['order_ids']) == 1) { $o_id = array_pop($_REQUEST['order_ids']); $suffix = ".details?order_id={$o_id}"; } else { exit; } } if ($mode == 'export_range') { if (!empty($_REQUEST['order_ids'])) { if (empty($_SESSION['export_ranges'])) { $_SESSION['export_ranges'] = array(); } if (empty($_SESSION['export_ranges']['orders'])) {