function tep_upload_order($order_id, $delimiter = ',', $upload_dir = '') { if (empty($upload_dir)) { $upload_dir = UPLOAD_DIR . 'orders1/'; } // $order_info_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'"); // if (tep_db_num_rows($order_info_query) < 1) return false; $order_info = tep_db_fetch_array($order_info_query); $insert_id = $order_info['orders_id']; $insert_id = $order_id; $order = new order($insert_id); $shop_info_query = tep_db_query("select shops_url, shops_ssl, shops_prefix, shops_database from " . TABLE_SHOPS . " where shops_id = '" . (int) $order->info['shops_id'] . "'"); $shop_info = tep_db_fetch_array($shop_info_query); $domain_zone = $shop_info['shops_prefix']; $payment_modules = tep_get_payment_modules($order->info['shops_id']); $shipping_modules = tep_get_shipping_modules($order->info['shops_id']); $order_file = $upload_dir . $domain_zone . $insert_id . '.csv'; if (!file_exists($order_file)) { $fp = fopen($order_file, 'w'); $order_history_link = ($order->info['enabled_ssl'] == '1' && tep_not_null($shop_info['shops_ssl']) ? $shop_info['shops_ssl'] : $shop_info['shops_url']) . '/account_history_info.php?order_id=' . $insert_id; $order_total_sum = 0; $order_shipping_sum = 0; $order_discount_sum = 0; reset($order->totals); while (list(, $order_total) = each($order->totals)) { if ($order_total['class'] == 'ot_total') { $order_total_sum = $order_total['value']; } elseif ($order_total['class'] == 'ot_shipping') { $order_shipping_sum = $order_total['value']; $order_shipping_title = $order_total['title']; } elseif (($order_total['class'] == 'ot_discount' || $order_total['class'] == 'ot_custom') && $order_total['value'] < 0) { $order_discount_sum = $order_total['value']; } } $order_payment_id = $order->info['payment_method_class']; if (empty($order_payment_id)) { reset($payment_modules); $payment_found = false; while (list($k, $v) = each($payment_modules)) { if (strpos($v, $order->info['payment_method']) !== false) { $order_payment_id = $k; break; } } if (empty($order_payment_id)) { $order_payment_id = $order->info['payment_method']; } } $order_shipping_id = $order->delivery['delivery_method_class']; if (empty($order_shipping_id)) { reset($shipping_modules); $shipping_found = false; while (list($k, $v) = each($shipping_modules)) { if (strpos($v, $order_shipping_title) !== false) { $order_shipping_id = $k; break; } } if (empty($order_shipping_id)) { $order_shipping_id = $order_shipping_title; } } $self_delivery_id = $order->delivery['delivery_self_address_id']; if (tep_not_null($order->delivery['delivery_self_address']) && (int) $self_delivery_id <= 0) { $shop_info_query = tep_db_query("select shops_database from " . TABLE_SHOPS . " where shops_id = '" . (int) $order->info['shops_id'] . "'"); $shop_info = tep_db_fetch_array($shop_info_query); tep_db_select_db($shop_info['shops_database']); $self_delivery_query = tep_db_query("select self_delivery_id, self_delivery_cost, self_delivery_free, entry_suburb as suburb, entry_city as city, entry_street_address as street_address, entry_telephone as telephone, self_delivery_description from " . TABLE_SELF_DELIVERY . " where 1 order by city, street_address"); while ($self_delivery = tep_db_fetch_array($self_delivery_query)) { $self_delivery_address = tep_address_format($order->delivery['format_id'], $self_delivery, 1, '', ', '); if (strpos($order->delivery['delivery_self_address'], $self_delivery_address) !== false) { $self_delivery_id = $self_delivery['self_delivery_id']; break; } } tep_db_select_db(DB_DATABASE); if ($self_delivery_id == 0) { $self_delivery_id = $order->info['self_delivery']; } } $date_purchased = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5:$6', $order->info['date_purchased']); $date_purchased = preg_replace('/\\s{2,}/', ' ', $date_purchased); $is_europe = ''; $europe_check_query = tep_db_query("select count(*) as total from setbook_eu." . TABLE_COUNTRIES . " where countries_name like '" . tep_db_input($order->delivery['country']) . "' or countries_ru_name like '" . tep_db_input($order->delivery['country']) . "' or countries_iso_code_2 like '" . tep_db_input($order->delivery['country']) . "' or countries_iso_code_3 like '" . tep_db_input($order->delivery['country']) . "'"); $europe_check = tep_db_fetch_array($europe_check_query); if ($europe_check['total'] > 0) { $is_europe = 'e'; } $order_delivery_country_code = ''; $country_code_info_query = tep_db_query("select countries_iso_code_2 from " . $shop_info['shops_database'] . "." . TABLE_COUNTRIES . " where countries_name = '" . tep_db_input($order->delivery['country']) . "' or countries_ru_name = '" . tep_db_input($order->delivery['country']) . "'"); $country_code_info = tep_db_fetch_array($country_code_info_query); $order_delivery_country_code = $country_code_info['countries_iso_code_2']; if ($order_delivery_country_code == '') { $order_delivery_country = strtolower($order->delivery['country']); $all_countries_file = UPLOAD_DIR . 'csv/all_countries.csv'; $fc = fopen($all_countries_file, 'r'); while ((list($country_name, $country_ru_name, $country_iso_code_2, $country_iso_code_3) = fgetcsv($fc, 40000, ";")) !== FALSE) { $country_name = strtolower($country_name); $country_ru_name = strtolower($country_ru_name); $country_iso_code_3 = strtolower($country_iso_code_3); if ($order_delivery_country == $country_name || $order_delivery_country == $country_ru_name || $order_delivery_country == $country_iso_code_3) { $order_delivery_country_code = $country_iso_code_2; break; } } fclose($fc); } if ($order_delivery_country_code == '') { $fc = fopen($all_countries_file, 'r'); while ((list($country_name, $country_ru_name, $country_iso_code_2, $country_iso_code_3) = fgetcsv($fc, 40000, ";")) !== FALSE) { $country_name = strtolower($country_name); $country_ru_name = strtolower($country_ru_name); if (strpos($country_name, $order_delivery_country) !== false || strpos($country_ru_name, $order_delivery_country) !== false || strpos($country_iso_code_3, $order_delivery_country) !== false) { $order_delivery_country_code = $country_iso_code_2; break; } } fclose($fc); } $common_data = array($insert_id, $date_purchased, $order->info['shops_id'], $order->customer['id'], $order->customer['email_address'], $order->delivery['name'], '', '', $order_payment_id, $order_shipping_id, str_replace(',', '.', $order_shipping_sum), $order->info['currency'], str_replace(',', '.', $order->info['currency_value']), tep_html_entity_decode($order->delivery['state']), tep_html_entity_decode($order->delivery['suburb']), tep_html_entity_decode($order->delivery['city']), $order->delivery['postcode'], tep_html_entity_decode($order->delivery['street_address']), $order->delivery['telephone'], tep_html_entity_decode($order->info['comments']), $self_delivery_id, $order_history_link, str_replace(',', '.', $order_total_sum), str_replace(',', '.', abs($order_discount_sum)), tep_html_entity_decode($order->customer['company']), $order->customer['company_inn'], $order->customer['company_kpp'], $order->customer['company_address_corporate'], $is_europe, $order->info['delivery_transfer_days'], $order->info['code'], $order->delivery['country'], tep_html_entity_decode($order_delivery_country_code), $order->customer['company_corporate']); fputcsvsafe($fp, $common_data, $delimiter); // tep_db_query("update " . TABLE_ORDERS . " set payment_method_class = '" . tep_db_input($order_payment_id) . "', delivery_method_class = '" . tep_db_input($order_shipping_id) . "', delivery_self_address_id = '" . (int)$self_delivery_id . "' where orders_id = '" . (int)$insert_id . "'"); reset($order->products); while (list(, $product) = each($order->products)) { $product_code = (int) str_replace('bbk', '', $product['code']); $common_data = array($product['type'], $product_code, $product['qty'], str_replace(',', '.', $product['final_price']), $product['id'], $product['seller_code'], $product['name'], tep_get_products_name($product['id']), $product['code'], $product['warranty']); fputcsvsafe($fp, $common_data, $delimiter); } fclose($fp); } }
if ($is_default_shop['shops_default_status'] == '1' && empty($HTTP_GET_VARS['oID'])) { $rows = 0; $files = tep_get_files(UPLOAD_DIR . 'changed_orders/', '.csv'); $new_files = array(); reset($files); while (list($i, $file) = each($files)) { if (substr($file, 0, 2) == 'aa') { $new_files[] = $file; } } if (sizeof($new_files) > 0) { // tep_set_time_limit(300); $all_shipping_modules = array(); $shops_query = tep_db_query("select shops_id from " . TABLE_SHOPS . " where 1"); while ($shops = tep_db_fetch_array($shops_query)) { $all_shipping_modules[$shops['shops_id']] = tep_get_shipping_modules($shops['shops_id']); } $statuses_asc = array(); $statuses_query = tep_db_query("select orders_status_id, sort_order from " . TABLE_ORDERS_STATUS . " order by sort_order"); while ($statuses = tep_db_fetch_array($statuses_query)) { $statuses_asc[$statuses['orders_status_id']] = $statuses['sort_order']; } $operator = 'robot'; reset($new_files); while (list($i, $file) = each($new_files)) { if ($fp = @fopen(UPLOAD_DIR . 'changed_orders/' . $file, 'r')) { list($update_order_id, $update_customer_address, $update_customer_telephone, $update_customer_name, $update_customer_email_address, $update_order_currency, $update_order_currency_value, $comments, $update_order_status, $update_shipping_cost, $update_shipping_method) = fgetcsv($fp, '10000', ';'); $order_check_query = tep_db_query("select advance_orders_id, advance_orders_status, shops_id from " . TABLE_ADVANCE_ORDERS . " where advance_orders_id = '" . (int) $update_order_id . "'"); if (tep_db_num_rows($order_check_query) > 0 && $update_order_status > 0) { $order_check = tep_db_fetch_array($order_check_query); $shipping_modules = $all_shipping_modules[$order_check['shops_id']];