Eventually, I came up with a solution and I describe it below for anyone coming into a similar issue.
In the
include/cart_calculate_totals.php script I included the additional charge calculation code, which once done, it is added to the cart total cost amount which is represented by the
$cart['total_cost'] variable. This customization also takes care of the total amount update that is displayed through Ajax, when in the checkout page, the customer switches to another shipping method, for example. This is because, through the Ajax procedure, the same script is called, so the additional charge is indeed re-calculated.
The additional charge amount and any other type of custom variable related to an order, is stored in the
'extra' field of the '
xcart_orders' table, in serialized form, along with other order parameters. To do this, in the payment scripts that cover offline and online payment methods, wherever the
func_place_order() function is called, (payment_offline.php, payment_cc.php, gcheckout_callback.php, payment_giftcert.php, modules\Amazon_Checkout\order_notifications.php), I added before the function call the following snippet:
PHP Code:
if(!empty($cart['additional_charge']))
$extra['additional_charge'] = $cart['additional_charge'];
and then called the order placement function passing the
$extra argument:
PHP Code:
$orderids = func_place_order(stripslashes($payment_method) . " (" . $module_params['module_name'] . (get_cc_in_testmode($module_params) ? ", in test mode" : '') . ")",
'I',
$order_details,
$customer_notes,
$extra
);
Then, for retrieving the additional charge from inside the 'extra' field of the order in Smarty, I used the
{$order.extra.additional_charge} variable in the respective template files for the screen invoice, email notifications and in the order info section in the admin (where admin views an order's details).
Whatever checkout module is used for checkout, it shouldn't make any difference in the above code methodology, since all checkout modules will pass through the core cart code, including the
cart_calculate_total.php script, so the additional charge will be calculated, anyway. The only thing needed to be taken care of, is the insertion of the additional charge line in the checkout template of the corresponding checkout module.
With the above method, any custom variable related to an order, can be stored in the '
extra' field of the order record (
xcart_orders table) via the '
func_place_order()' function, passing it to the '
$extra' argument of the function, considering that this variable is an array (ie, using this snippet:
PHP Code:
$extra['custom_variable')] = $custom_variable
) and then retrieved back to Smarty (for screen invoice, email notifications and order info in admin) through
{$order.extra.custom_variable}
I really welcome any comments/corrections on the above