VD : debug
require_once('../logger/include.php');
// <- VD
require('includes/application_top.php');
// include the appropriate functions & classes
include('order_editor/functions.php');
include('order_editor/cart.php');
include('order_editor/order.php');
include('order_editor/shipping.php');
include('order_editor/http_client.php');
// Include currencies class
require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();
// my_phptrace("edit_order - begin");
//orders status
$orders_statuses = array();
$orders_status_array = array();
$orders_status_query = tep_db_query("SELECT orders_status_id, orders_status_name
FROM " . TABLE_ORDERS_STATUS . "
WHERE language_id = '" . (int)$languages_id . "'");
while ($orders_status = tep_db_fetch_array($orders_status_query)) {
$orders_statuses[] = array('id' => $orders_status['orders_status_id'],
'text' => $orders_status['orders_status_name']);
$orders_status_array[$orders_status['orders_status_id']] = $orders_status['orders_status_name'];
}
$action = (isset($_GET['action']) ? $_GET['action'] : 'edit');
$firephp->log($action, 'edit_orders.php : action');
if (isset($action)) {
switch ($action) {
////
// Update Order
case 'update_order':
$oID = tep_db_prepare_input($_GET['oID']);
$status = tep_db_prepare_input($_POST['status']);
// Set this Session's variables
if (isset($_POST['billing_same_as_customer'])) $_SESSION['billing_same_as_customer'] = $_POST['billing_same_as_customer'];
if (isset($_POST['shipping_same_as_billing'])) $_SESSION['shipping_same_as_billing'] = $_POST['shipping_same_as_billing'];
// Update Order Info
//figure out the new currency value
$currency_value_query = tep_db_query("SELECT value
FROM " . TABLE_CURRENCIES . "
WHERE code = '" . $_POST['update_info_payment_currency'] . "'");
$currency_value = tep_db_fetch_array($currency_value_query);
//figure out the country, state
$update_customer_state = tep_get_zone_name($_POST['update_customer_country_id'], $_POST['update_customer_zone_id'], $_POST['update_customer_state']);
$update_customer_country = tep_get_country_name($_POST['update_customer_country_id']);
$update_billing_state = tep_get_zone_name($_POST['update_billing_country_id'], $_POST['update_billing_zone_id'], $_POST['update_billing_state']);
$update_billing_country = tep_get_country_name($_POST['update_billing_country_id']);
$update_delivery_state = tep_get_zone_name($_POST['update_delivery_country_id'], $_POST['update_delivery_zone_id'], $_POST['update_delivery_state']);
$update_delivery_country = tep_get_country_name($_POST['update_delivery_country_id']);
// -> OSC-1 : suppression des '/' après mise à jour sans AJAX
$sql_data_array = array(
'customers_name' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_name']))),
'customers_company' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_company']))),
'customers_street_address' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_street_address']))),
'customers_suburb' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_suburb']))),
'customers_city' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_city']))),
'customers_state' => stripslashes(tep_db_input(tep_db_prepare_input($update_customer_state))),
'customers_postcode' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_postcode']))),
'customers_country' => stripslashes(tep_db_input(tep_db_prepare_input($update_customer_country))),
'customers_telephone' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_telephone']))),
'customers_email_address' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_customer_email_address']))),
'billing_name' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_name'] : $_POST['update_billing_name'])))),
'billing_company' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_company'] : $_POST['update_billing_company'])))),
'billing_street_address' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_street_address'] : $_POST['update_billing_street_address'])))),
'billing_suburb' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_suburb'] : $_POST['update_billing_suburb'])))),
'billing_city' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_city'] : $_POST['update_billing_city'])))),
'billing_state' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $update_customer_state : $update_billing_state)))),
'billing_postcode' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_postcode'] : $_POST['update_billing_postcode'])))),
'billing_country' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['billing_same_as_customer']) && $_POST['billing_same_as_customer'] == 'on') ? $update_customer_country : $update_billing_country)))),
'delivery_name' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_name'] : $_POST['update_billing_name']) : $_POST['update_delivery_name'])))),
'delivery_company' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_company'] : $_POST['update_billing_company']) : $_POST['update_delivery_company'])))),
'delivery_street_address' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_street_address'] : $_POST['update_billing_street_address']) : $_POST['update_delivery_street_address'])))),
'delivery_suburb' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_suburb'] : $_POST['update_billing_suburb']) : $_POST['update_delivery_suburb'])))),
'delivery_city' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_city'] : $_POST['update_billing_city']) : $_POST['update_delivery_city'])))),
'delivery_state' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $update_customer_state : $update_billing_state) : $update_delivery_state)))),
'delivery_postcode' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $_POST['update_customer_postcode'] : $_POST['update_billing_postcode']) : $_POST['update_delivery_postcode'])))),
'delivery_country' => stripslashes(tep_db_input(tep_db_prepare_input(((isset($_POST['shipping_same_as_billing']) && $_POST['shipping_same_as_billing'] == 'on') ? (($_POST['billing_same_as_customer'] == 'on') ? $update_customer_country : $update_billing_country) : $update_delivery_country)))),
'payment_method' => stripslashes(tep_db_input(tep_db_prepare_input($_POST['update_info_payment_method']))),
'currency' => tep_db_input(tep_db_prepare_input($_POST['update_info_payment_currency'])),
'currency_value' => tep_db_input(tep_db_prepare_input($currency_value['value'])),
'cc_type' => tep_db_prepare_input($_POST['update_info_cc_type']),
'cc_owner' => tep_db_prepare_input($_POST['update_info_cc_owner']),
'cc_number' => tep_db_input(tep_db_prepare_input($_POST['update_info_cc_number'])),
'cc_expires' => tep_db_prepare_input($_POST['update_info_cc_expires']),
'last_modified' => 'now()',
'orders_comments' => tep_db_prepare_input($_POST['general_comment']));
// <- OSC-1 : suppression des '/' après mise à jour sans AJAX
// echo tep_db_input(tep_db_prepare_input($_POST['update_customer_name']));
// var_dump($sql_data_array);
tep_db_perform(TABLE_ORDERS, $sql_data_array, 'update', 'orders_id = \'' . tep_db_input($oID) . '\'');
$order_updated = true;
// UPDATE STATUS HISTORY & SEND EMAIL TO CUSTOMER IF NECESSARY #####
$check_status_query = tep_db_query("
SELECT customers_name, customers_email_address, orders_status, date_purchased
FROM " . TABLE_ORDERS . "
WHERE orders_id = '" . (int)$oID . "'");
$check_status = tep_db_fetch_array($check_status_query);
if (($check_status['orders_status'] != $_POST['status']) || (tep_not_null($_POST['comments']))) {
tep_db_query("UPDATE " . TABLE_ORDERS . " SET
orders_status = '" . tep_db_input($_POST['status']) . "',
last_modified = now()
WHERE orders_id = '" . (int)$oID . "'");
// Notify Customer ?
$customer_notified = '0';
if (isset($_POST['notify']) && ($_POST['notify'] == 'on')) {
$notify_comments = '';
if (isset($_POST['notify_comments']) && ($_POST['notify_comments'] == 'on')) {
$notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, stripslashes(($_POST['comments']))) . "\n\n";
}
$email = STORE_NAME . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . (int)$oID . "\n" .
EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . (int)$oID, 'SSL') . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "\n\n" . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]) . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE2);
tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
$customer_notified = '1';
}
tep_db_query("INSERT into " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
values ('" . tep_db_input($_GET['oID']) . "',
'" . tep_db_input($_POST['status']) . "',
now(),
" . tep_db_input($customer_notified) . ",
'" . tep_db_input(tep_db_prepare_input($_POST['comments'])) . "')");
// '" . tep_db_input(html_entity_decode(stripslashes(tep_db_prepare_input($_POST['comments'])))) . "')");
}
// Update Products
if (is_array($_POST['update_products'])) {
foreach($_POST['update_products'] as $orders_products_id => $products_details) {
// Update Inventory Quantity
$order_query = tep_db_query("
SELECT products_id, products_quantity
FROM " . TABLE_ORDERS_PRODUCTS . "
WHERE orders_id = '" . (int)$oID . "'
AND orders_products_id = '" . (int)$orders_products_id . "'");
$order_products = tep_db_fetch_array($order_query);
// First we do a stock check
if ($products_details['qty'] != $order_products['products_quantity']){
$quantity_difference = ($products_details['qty'] - $order_products['products_quantity']);
if (STOCK_LIMITED == 'true'){
tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET
products_quantity = products_quantity - " . $quantity_difference . ",
products_ordered = products_ordered + " . $quantity_difference . "
WHERE products_id = '" . (int)$order_products['products_id'] . "'");
} else {
tep_db_query ("UPDATE " . TABLE_PRODUCTS . " SET
products_ordered = products_ordered + " . $quantity_difference . "
WHERE products_id = '" . (int)$order_products['products_id'] . "'");
}
}
if ( (isset($products_details['delete'])) && ($products_details['delete'] == 'on') ) {
//check first to see if product should be deleted
//update quantities first
if (STOCK_LIMITED == 'true'){
tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET
products_quantity = products_quantity + " . $products_details["qty"] . ",
products_ordered = products_ordered - " . $products_details["qty"] . "
WHERE products_id = '" . (int)$order_products['products_id'] . "'");
} else {
tep_db_query ("UPDATE " . TABLE_PRODUCTS . " SET
products_ordered = products_ordered - " . $products_details["qty"] . "
WHERE products_id = '" . (int)$order_products['products_id'] . "'");
}
tep_db_query("DELETE FROM " . TABLE_ORDERS_PRODUCTS . "
WHERE orders_id = '" . (int)$oID . "'
AND orders_products_id = '" . (int)$orders_products_id . "'");
tep_db_query("DELETE FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . "
WHERE orders_id = '" . (int)$oID . "'
AND orders_products_id = '" . (int)$orders_products_id . "'");
tep_db_query("DELETE FROM " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . "
WHERE orders_id = '" . (int)$oID . "'
AND orders_products_id = '" . (int)$orders_products_id . "'");
} else {
//not deleted=> updated
// Update orders_products Table
?>
OSC-1 : Edition des produits livres dans les commandes ?>
$attributes_details) {
$Query = "UPDATE " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " set
products_options = '" . $attributes_details["option"] . "',
products_options_values = '" . $attributes_details["value"] . "',
options_values_price ='" . $attributes_details["price"] . "',
price_prefix ='" . $attributes_details["prefix"] . "'
where orders_products_attributes_id = '$orders_products_attributes_id';";
tep_db_query($Query);
}//end of foreach($products_details["attributes"]
}// end of if(isset($products_details[attributes]))
} //end if/else product details delete= on
} //end foreach post update products
}//end if is-array update products
//update any downloads that may exist
if (is_array($_POST['update_downloads'])) {
foreach($_POST['update_downloads'] as $orders_products_download_id => $download_details) {
$Query = "UPDATE " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " SET
orders_products_filename = '" . $download_details["filename"] . "',
download_maxdays = '" . $download_details["maxdays"] . "',
download_count = '" . $download_details["maxcount"] . "'
WHERE orders_id = '" . (int)$oID . "'
AND orders_products_download_id = '$orders_products_download_id';";
tep_db_query($Query);
}
} //end downloads
//delete or update comments
if (is_array($_POST['update_comments'])) {
foreach($_POST['update_comments'] as $orders_status_history_id => $comments_details) {
if (isset($comments_details['delete'])){
$Query = "DELETE FROM " . TABLE_ORDERS_STATUS_HISTORY . "
WHERE orders_id = '" . (int)$oID . "'
AND orders_status_history_id = '$orders_status_history_id';";
tep_db_query($Query);
} else {
// -> VD : suppression des caracteres bizarres dans les commentaires mises a jour
$Query = "UPDATE " . TABLE_ORDERS_STATUS_HISTORY . " SET
comments = '" . tep_db_input(tep_db_prepare_input($comments_details["comments"])) . "'
WHERE orders_id = '" . (int)$oID . "'
AND orders_status_history_id = '$orders_status_history_id';";
tep_db_query($Query);
// <- VD
}
}
}//end comments update section
$shipping = array();
if (is_array($_POST['update_totals'])) {
foreach($_POST['update_totals'] as $total_index => $total_details) {
extract($total_details, EXTR_PREFIX_ALL, "ot");
if ($ot_class == "ot_shipping") {
$shipping['cost'] = $ot_value;
$shipping['title'] = $ot_title;
$shipping['id'] = $ot_id;
} // end if ($ot_class == "ot_shipping")
} //end foreach
} //end if is_array
if (tep_not_null($shipping['id'])) {
tep_db_query("UPDATE " . TABLE_ORDERS . " SET shipping_module = '" . $shipping['id'] . "' WHERE orders_id = '" . (int)$oID . "'");
}
$order = new manualOrder($oID);
$order->adjust_zones();
$cart = new manualCart();
$cart->restore_contents($oID);
$total_count = $cart->count_contents();
$total_weight = $cart->show_weight();
// Get the shipping quotes- if we don't have shipping quotes shipping tax calculation can't happen
$shipping_modules = new shipping;
$shipping_quotes = $shipping_modules->quote();
if (DISPLAY_PRICE_WITH_TAX == 'true') {//extract the base shipping cost or the ot_shipping module will add tax to it again
$module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));
$tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
$order->info['total'] -= ( $order->info['shipping_cost'] - ($order->info['shipping_cost'] / (1 + ($tax /100))) );
$order->info['shipping_cost'] = ($order->info['shipping_cost'] / (1 + ($tax /100)));
}
//this is where we call the order total modules
require( 'order_editor/order_total.php');
$order_total_modules = new order_total();
$order_totals = $order_total_modules->process();
$current_ot_totals_array = array();
$current_ot_titles_array = array();
$current_ot_totals_query = tep_db_query("select class, title from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$oID . "' order by sort_order");
while ($current_ot_totals = tep_db_fetch_array($current_ot_totals_query)) {
$current_ot_totals_array[] = $current_ot_totals['class'];
$current_ot_titles_array[] = $current_ot_totals['title'];
}
tep_db_query("DELETE FROM " . TABLE_ORDERS_TOTAL . " WHERE orders_id = '" . (int)$oID . "'");
$j=1; //giving something a sort order of 0 ain't my bag baby
$new_order_totals = array();
if (is_array($_POST['update_totals'])) { //1
foreach($_POST['update_totals'] as $total_index => $total_details) { //2
extract($total_details, EXTR_PREFIX_ALL, "ot");
if (!strstr($ot_class, 'ot_custom')) { //3
for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) { //4
$firephp->table('edit_orders : order_totals', $order_totals);
if ($order_totals[$i]['code'] == 'ot_tax') { //5
$new_ot_total = ((in_array($order_totals[$i]['title'], $current_ot_titles_array)) ? false : true);
} else { //within 5
$new_ot_total = ((in_array($order_totals[$i]['code'], $current_ot_totals_array)) ? false : true);
} //end 5 if ($order_totals[$i]['code'] == 'ot_tax')
if ( ( ($order_totals[$i]['code'] == 'ot_tax') && ($order_totals[$i]['code'] == $ot_class) && ($order_totals[$i]['title'] == $ot_title) ) || ( ($order_totals[$i]['code'] != 'ot_tax') && ($order_totals[$i]['code'] == $ot_class) ) ) { //6
//only good for components that show up in the $order_totals array
if ($ot_title != '') { //7
$new_order_totals[] = array('title' => $ot_title,
'text' => (($ot_class != 'ot_total') ? $order_totals[$i]['text'] : '' . $currencies->format($order->info['total'], true, $order->info['currency'], $order->info['currency_value']) . ''),
'value' => (($order_totals[$i]['code'] != 'ot_total') ? $order_totals[$i]['value'] : $order->info['total']),
'code' => $order_totals[$i]['code'],
'sort_order' => $j);
$written_ot_totals_array[] = $ot_class;
$written_ot_titles_array[] = $ot_title;
$j++;
} else { //within 7
$order->info['total'] += ($ot_value*(-1));
$written_ot_totals_array[] = $ot_class;
$written_ot_titles_array[] = $ot_title;
} //end 7
} elseif ( ($new_ot_total) && (!in_array($order_totals[$i]['title'], $current_ot_titles_array)) ) { //within 6
$new_order_totals[] = array('title' => $order_totals[$i]['title'],
'text' => $order_totals[$i]['text'],
'value' => $order_totals[$i]['value'],
'code' => $order_totals[$i]['code'],
'sort_order' => $j);
$current_ot_totals_array[] = $order_totals[$i]['code'];
$current_ot_titles_array[] = $order_totals[$i]['title'];
$written_ot_totals_array[] = $ot_class;
$written_ot_titles_array[] = $ot_title;
$j++;
//echo $order_totals[$i]['code'] . "
"; for debugging- use of this results in errors
} elseif ($new_ot_total) { //also within 6
$order->info['total'] += ($order_totals[$i]['value']*(-1));
$current_ot_totals_array[] = $order_totals[$i]['code'];
$written_ot_totals_array[] = $ot_class;
$written_ot_titles_array[] = $ot_title;
}//end 6
$firephp->table('edit_orders : new_order_totals', $new_order_totals);
}//end 4
} elseif ( (tep_not_null($ot_value)) && (tep_not_null($ot_title)) ) { // this modifies if (!strstr($ot_class, 'ot_custom')) { //3
$new_order_totals[] = array('title' => $ot_title,
'text' => $currencies->format($ot_value, true, $order->info['currency'], $order->info['currency_value']),
'value' => $ot_value,
'code' => 'ot_custom_' . $j,
'sort_order' => $j);
$order->info['total'] += $ot_value;
$written_ot_totals_array[] = $ot_class;
$written_ot_titles_array[] = $ot_title;
$j++;
} //end 3
//save ot_skippy from certain annihilation
if ( (!in_array($ot_class, $written_ot_totals_array)) && (!in_array($ot_title, $written_ot_titles_array)) && (tep_not_null($ot_value)) && (tep_not_null($ot_title)) && ($ot_class != 'ot_tax') && ($ot_class != 'ot_loworderfee') ) { //7
//this is supposed to catch the oddball components that don't show up in $order_totals
$new_order_totals[] = array(
'title' => $ot_title,
'text' => $currencies->format($ot_value, true, $order->info['currency'], $order->info['currency_value']),
'value' => $ot_value,
'code' => $ot_class,
'sort_order' => $j);
//$current_ot_totals_array[] = $order_totals[$i]['code'];
//$current_ot_titles_array[] = $order_totals[$i]['title'];
$written_ot_totals_array[] = $ot_class;
$written_ot_titles_array[] = $ot_title;
$j++;
} //end 7
} //end 2
} else {//within 1
// $_POST['update_totals'] is not an array => write in all order total components that have been generated by the sundry modules
for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) { //8
$new_order_totals[] = array('title' => $order_totals[$i]['title'],
'text' => $order_totals[$i]['text'],
'value' => $order_totals[$i]['value'],
'code' => $order_totals[$i]['code'],
'sort_order' => $j);
$j++;
} //end 8
} //end if (is_array($_POST['update_totals'])) { //1
/*
array(6) {
[0]=> array(5) {
["title"]=> string(14) "Sous-Total HT:"
["text"]=> string(9) "990.00EUR"
["value"]=> float(990)
["code"]=> string(17) "ot_subtotal_wotax"
["sort_order"]=> int(1) }
[1]=> array(5) {
["title"]=> string(18) "Code avoir Z3LC3D:"
["text"]=> string(9) "-13.16EUR"
["value"]=> string(6) "-13.16"
["code"]=> string(18) "ot_discount_coupon"
["sort_order"]=> int(2) }
[2]=> array(5) {
["title"]=> string(69) "Retrait en magasin (Showroom vente en gros LP Divertissements"
["text"]=> string(7) "0.00EUR"
["value"]=> string(4) "0.00"
["code"]=> string(11) "ot_shipping"
["sort_order"]=> int(3) }
[3]=> array(5) {
["title"]=> string(9) "Total HT:"
["text"]=> string(9) "990.00EUR"
["value"]=> float(990)
["code"]=> string(14) "ot_total_wotax"
["sort_order"]=> int(4) }
[4]=> array(5) {
["title"]=> string(8) "TVA 20%:"
["text"]=> string(9) "198.00EUR"
["value"]=> float(198)
["code"]=> string(6) "ot_tax"
["sort_order"]=> int(5) }
[5]=> array(5) {
["title"]=> string(6) "Total:"
["text"]=> string(18) "1,188.00EUR"
["value"]=> float(1188)
["code"]=> string(8) "ot_total"
["sort_order"]=> int(6) } }*/
// quand il y a un avoir, recalcul sur les totaux
if ($new_order_totals[1]['code'] == 'ot_discount_coupon')
{
//total HT
if ( ((float)$new_order_totals[0]['value']+(float)$new_order_totals[1]['value']) >= 0 ) {
(float)$new_order_totals[3]['value'] = (float)$new_order_totals[0]['value']+(float)$new_order_totals[1]['value']+(float)$new_order_totals[2]['value'];
} else {
(float)$new_order_totals[3]['value'] = (float)$new_order_totals[2]['value'];
}
$new_order_totals[3]['value'] = round($new_order_totals[3]['value'], 2, PHP_ROUND_HALF_UP);
$new_order_totals[3]['text'] = $new_order_totals[3]['value'].'EUR';
//total TTC
(float)$new_order_totals[5]['value'] = (float)$new_order_totals[3]['value']*1.2;
$new_order_totals[5]['value'] = round($new_order_totals[5]['value'], 2, PHP_ROUND_HALF_UP);
$new_order_totals[5]['text'] = $new_order_totals[5]['value'].'EUR';
//TVA
(float)$new_order_totals[4]['value'] = (float)$new_order_totals[5]['value']-(float)$new_order_totals[3]['value'];
$new_order_totals[4]['value'] = round($new_order_totals[4]['value'], 2, PHP_ROUND_HALF_UP);
$new_order_totals[4]['text'] = $new_order_totals[4]['value'].'EUR';
}
for ($i=0, $n=sizeof($new_order_totals); $i<$n; $i++) {
$sql_data_array = array('orders_id' => $oID,
// -> VD : suppression des '/' dans les titres des totaux
'title' => stripslashes(oe_iconv($new_order_totals[$i]['title'])),
'text' => stripslashes($new_order_totals[$i]['text']),
// <- VD
'value' => $new_order_totals[$i]['value'],
'class' => $new_order_totals[$i]['code'],
'sort_order' => $new_order_totals[$i]['sort_order']);
tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
}
if (isset($_POST['subaction'])) {
switch($_POST['subaction']) {
case 'add_product':
tep_redirect(tep_href_link(FILENAME_ORDERS_EDIT, tep_get_all_get_params(array('action')) . 'action=edit#products'));
break;
}
}
/*if ( $_GET['oID'] == 75706 ) {
die(var_dump($new_order_totals));
}*/
// 1.5 SUCCESS MESSAGE #####
// CHECK FOR NEW EMAIL CONFIRMATION
if ( (isset($_POST['nC1'])) || (isset($_POST['nC2'])) || (isset($_POST['nC3'])) ) {
//then the user selected the option of sending a new email
tep_redirect(tep_href_link(FILENAME_ORDERS_EDIT, tep_get_all_get_params(array('action')) . 'action=email'));
//redirect to the email case
} else {
//email? email? We don't need no stinkin email!
if ($order_updated) {
$messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');
}
tep_redirect(tep_href_link(FILENAME_ORDERS_EDIT, tep_get_all_get_params(array('action')) . 'action=edit'));
}
break;
// 3. NEW ORDER EMAIL ###############################################################################################
case 'email':
$oID = tep_db_prepare_input($_GET['oID']);
$order = new manualOrder($oID);
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
//loop all the products in the order
$products_ordered_attributes = '';
if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
$products_ordered_attributes .= "\n\t" . $order->products[$i]['attributes'][$j]['option'] . ' ' . $order->products[$i]['attributes'][$j]['value'];
}
}
$products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . $products_model . ' = ' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . $products_ordered_attributes . "\n";
}
//Build the email
$email_order = STORE_NAME . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . (int)$oID . "\n" .
EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . (int)$oID, 'SSL') . "\n" .
EMAIL_TEXT_DATE_MODIFIED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
EMAIL_SEPARATOR . "\n" .
$products_ordered .
EMAIL_SEPARATOR . "\n";
for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
$email_order .= strip_tags($order->totals[$i]['title']) . ' ' . strip_tags($order->totals[$i]['text']) . "\n";
}
if ($order->content_type != 'virtual') {
$email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" .
EMAIL_SEPARATOR . "\n" .
$order->delivery['name'] . "\n";
if ($order->delivery['company']) {
$email_order .= $order->delivery['company'] . "\n";
}
$email_order .= $order->delivery['street_address'] . "\n";
if ($order->delivery['suburb']) {
$email_order .= $order->delivery['suburb'] . "\n";
}
$email_order .= $order->customer['city'] . "\n";
if ($order->delivery['state']) {
$email_order .= $order->delivery['state'] . "\n";
}
$email_order .= $order->customer['postcode'] . "\n" .
$order->delivery['country'] . "\n";
}
$email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
EMAIL_SEPARATOR . "\n" .
$order->billing['name'] . "\n";
if ($order->billing['company']) {
$email_order .= $order->billing['company'] . "\n";
}
$email_order .= $order->billing['street_address'] . "\n";
if ($order->billing['suburb']) {
$email_order .= $order->billing['suburb'] . "\n";
}
$email_order .= $order->customer['city'] . "\n";
if ($order->billing['state']) {
$email_order .= $order->billing['state'] . "\n";
}
$email_order .= $order->customer['postcode'] . "\n" .
$order->billing['country'] . "\n\n";
$email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
EMAIL_SEPARATOR . "\n";
$email_order .= $order->info['payment_method'] . "\n\n";
// if ( ($order->info['payment_method'] == ORDER_EDITOR_SEND_INFO_PAYMENT_METHOD) && (EMAIL_TEXT_PAYMENT_INFO) ) {
// $email_order .= EMAIL_TEXT_PAYMENT_INFO . "\n\n";
// }
//I'm not entirely sure what the purpose of this is so it is being shelved for now
if (EMAIL_TEXT_FOOTER) {
$email_order .= EMAIL_TEXT_FOOTER . "\n\n";
}
//code for plain text emails which changes the sign to EUR, otherwise the email will show ? instead of
$email_order = str_replace("","EUR",$email_order);
$email_order = str_replace(" "," ",$email_order);
//code which replaces the
tags within EMAIL_TEXT_PAYMENT_INFO and EMAIL_TEXT_FOOTER with the proper \n
$email_order = str_replace("
","\n",$email_order);
//send the email to the customer
tep_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
// send emails to other people as necessary
if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
}
//do the dirty
$messageStack->add_session(SUCCESS_EMAIL_SENT, 'success');
tep_redirect(tep_href_link(FILENAME_ORDERS_EDIT, tep_get_all_get_params(array('action')) . 'action=edit'));
break;
////
// Edit Order
case 'edit':
if (!isset($_GET['oID'])) {
$messageStack->add(ERROR_NO_ORDER_SELECTED, 'error');
break;
}
$oID = tep_db_prepare_input($_GET['oID']);
$orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . (int)$oID . "'");
$order_exists = true;
if (!tep_db_num_rows($orders_query)) {
$order_exists = false;
$messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
break;
}
$order = new manualOrder($oID);
$shippingKey = $order->adjust_totals($oID);
$order->adjust_zones();
$cart = new manualCart();
$cart->restore_contents($oID);
$total_count = $cart->count_contents();
$total_weight = $cart->show_weight();
// Get the shipping quotes
$shipping_modules = new shipping;
$shipping_quotes = $shipping_modules->quote();
break;
}
}
$account_query = tep_db_query("select is_partner,coeff_partner from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$order->customer['id'] . "'");
$account = tep_db_fetch_array($account_query);
$coeff_partner = $account['coeff_partner'];
$is_partner = $account['is_partner'];
// currecies drop-down array
$currency_query = tep_db_query("select distinct title, code from " . TABLE_CURRENCIES . " order by code ASC");
$currency_array = array();
while($currency = tep_db_fetch_array($currency_query)) {
$currency_array[] = array('id' => $currency['code'],
'text' => $currency['code'] . ' - ' . $currency['title']);
}
// $order->customer['name'] = ($order->customer['name']);
?>
>