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); } }
for ($i = 0, $n = sizeof($directory_array); $i < $n; $i++) { $file = $directory_array[$i]; include DIR_FS_CATALOG_LANGUAGES . $language . '/modules/order_total/' . $file; include $module_directory . $file; $class = substr($file, 0, strrpos($file, '.')); if (tep_class_exists($class)) { $module = new $class(); $order_total_modules[$class] = trim($module->title) . (substr(trim($module->title), -1) != ':' ? ':' : ''); } } $operator = 'robot'; $all_payment_modules = array(); $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_payment_modules[$shops['shops_id']] = tep_get_payment_modules($shops['shops_id']); $all_shipping_modules[$shops['shops_id']] = tep_get_shipping_modules($shops['shops_id']); } } reset($new_files); while (list($i, $file) = each($new_files)) { if ($fp = @fopen(UPLOAD_DIR . 'changed_orders/' . $file, 'r')) { list($update_order_id, $payment_class, $shipping_class, $ot_shipping_value, $delivery_state, $delivery_suburb, $delivery_city, $delivery_postcode, $delivery_street_address, $delivery_telephone, $delivery_self_address_id, $ot_total_value, $ot_discount_value, $update_order_status, $comments, $update_customer_id, $delivery_name, $update_company_name, $update_company_inn, $update_company_kpp, $update_company_address_corporate, $order_paid_sum, $update_order_code) = fgetcsv($fp, '10000', ';'); $order_check_query = tep_db_query("select count(*) as total from " . TABLE_ORDERS . " where orders_id = '" . (int) $update_order_id . "'"); $order_check = tep_db_fetch_array($order_check_query); if ($order_check['total'] > 0 && $update_order_status > 0) { $order = new order($update_order_id); $shop_info_query = tep_db_query("select shops_database, shops_currency from " . TABLE_SHOPS . " where shops_id = '" . (int) $order->info['shops_id'] . "'"); $shop_info = tep_db_fetch_array($shop_info_query); if (tep_not_null($order->info['payment_method']) && $payment_class == $order->info['payment_method_class']) { $payment_method = $order->info['payment_method'];