Hi,
Just upgraded from v1.2.4 to v1.3.0.2. I need the use the module edit_order contribution which was available for v1.2.4. I added this module in, did some changes, all working except the order total. It is giving me S$0 always. So for v1.3.0.2, what changes are made in the way they calculate the total?
The way they calculate order total is attached, the edited module is also attached.
// Update Products
$RunningSubTotal = 0;
$RunningTax = 0;
$update_products = $_POST['update_products'];
foreach($update_products as $orders_products_id => $products_details)
{
// Update orders_products Table
//UPDATE_INVENTORY_QUANTITY_START################################################# #############################################################
#$order = zen_db_fetch_array($order_query);
if ($products_details["qty"] != $order_query->fields['products_quantity']){
$differenza_quantita = ($products_details["qty"] - $order_query->fields['products_quantity']);
$db -> Execute("update " . TABLE_PRODUCTS . " set products_quantity = products_quantity - " . $differenza_quantita . ", products_ordered = products_ordered + " . $differenza_quantita . " where products_id = '" . (int)$order_query->fields['products_id'] . "'");
}
//UPDATE_INVENTORY_QUANTITY_END################################################### ###########################################################
if($products_details["qty"] > 0)
{
$Query = "update " . TABLE_ORDERS_PRODUCTS . " set
products_model = '" . $products_details["model"] . "',
products_name = '" . str_replace("'", "'", $products_details["name"]) . "',
final_price = '" . $products_details["final_price"] . "',
products_tax = '" . $products_details["tax"] . "',
products_quantity = '" . $products_details["qty"] . "'
where orders_products_id = '$orders_products_id';";
$db -> Execute($Query);
// Update Tax and Subtotals
$RunningSubTotal += $products_details["qty"] * $products_details["final_price"];
$RunningTax += (($products_details["tax"]/100) * ($products_details["qty"] * $products_details["final_price"]));
// Update Any Attributes
if(IsSet($products_details[attributes]))
{
foreach($products_details["attributes"] as $orders_products_attributes_id => $attributes_details)
{
$Query = "update " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " set
products_options = '" . $attributes_details["option"] . "',
products_options_values = '" . $attributes_details["value"] . "'
where orders_products_attributes_id = '$orders_products_attributes_id';";
$db -> Execute($Query);
}
}
}
else
{
// 0 Quantity = Delete
$Query = "delete from " . TABLE_ORDERS_PRODUCTS . " where orders_products_id = '$orders_products_id';";
$db -> Execute($Query);
//UPDATE_INVENTORY_QUANTITY_START################################################# #############################################################
#$order = zen_db_fetch_array($order_query);
if ($products_details["qty"] != $order['products_quantity']){
$differenza_quantita = ($products_details["qty"] - $order['products_quantity']);
$db -> Execute("update " . TABLE_PRODUCTS . " set products_quantity = products_quantity - " . $differenza_quantita . ", products_ordered = products_ordered + " . $differenza_quantita . " where products_id = '" . (int)$order['products_id'] . "'");
}
//UPDATE_INVENTORY_QUANTITY_END################################################### ###########################################################
$Query = "delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_products_id = '$orders_products_id';";
$db -> Execute($Query);
}
$order_query -> MoveNext();
}
// Shipping Tax
$update_totals = $_POST['update_totals'];
foreach($update_totals as $total_index => $total_details)
{
extract($total_details,EXTR_PREFIX_ALL,"ot");
if($ot_class == "ot_shipping")
{
$RunningTax += (($AddShippingTax / 100) * $ot_value);
}
}
// Update Totals
$RunningTotal = 0;
$sort_order = 0;
// Do pre-check for Tax field existence
$ot_tax_found = 0;
foreach($update_totals as $total_details)
{
extract($total_details,EXTR_PREFIX_ALL,"ot");
if($ot_class == "ot_tax")
{
$ot_tax_found = 1;
break;
}
}
foreach($update_totals as $total_index => $total_details)
{
extract($total_details,EXTR_PREFIX_ALL,"ot");
if( trim(strtolower($ot_title)) == "tax" || trim(strtolower($ot_title)) == "tax:" )
{
if($ot_class != "ot_tax" && $ot_tax_found == 0)
{
// Inserting Tax
$ot_class = "ot_tax";
$ot_value = "x"; // This gets updated in the next step
$ot_tax_found = 1;
}
}
if( trim($ot_title) && trim($ot_value) )
{
$sort_order++;
// Update ot_subtotal, ot_tax, and ot_total classes
if($ot_class == "ot_subtotal")
$ot_value = $RunningSubTotal;
if($ot_class == "ot_tax")
{
$ot_value = $RunningTax;
// print "ot_value = $ot_value<br>\n";
}
if($ot_class == "ot_total")
$ot_value = $RunningTotal;
// Set $ot_text (display-formatted value)
// $ot_text = "\$" . number_format($ot_value, 2, '.', ',');
$order = new order($oID);
$ot_text = $currencies->format($ot_value, true, $order->info['currency'], $order->info['currency_value']);
if($ot_class == "ot_total")
$ot_text = "<b>" . $ot_text . "</b>";
if($ot_total_id > 0)
{
// In Database Already - Update
$Query = "update " . TABLE_ORDERS_TOTAL . " set
title = '$ot_title',
text = '$ot_text',
value = '$ot_value',
sort_order = '$sort_order'
where orders_total_id = '$ot_total_id'";
$db -> Execute($Query);
}
else
{
// New Insert
$Query = "insert into " . TABLE_ORDERS_TOTAL . " set
orders_id = '$oID',
title = '$ot_title',
text = '$ot_text',
value = '$ot_value',
class = '$ot_class',
sort_order = '$sort_order'";
$db -> Execute($Query);
}
$RunningTotal += $ot_value;
}
elseif($ot_total_id > 0)
{
// Delete Total Piece
$Query = "delete from " . TABLE_ORDERS_TOTAL . " where orders_total_id = '$ot_total_id'";
$db -> Execute($Query);
}
}
if ($order_updated)
{
$messageStack->add_session(SUCCESS_ORDER_UPDATED, 'success');
}
zen_redirect(zen_href_link("edit_orders.php", zen_get_all_get_params(array('action')) . 'action=edit'));
Regards,
Yee Ling
http://www.whoopeekiddies.com



