| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Pass additional charge to order data | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||||
|
|||||||||
Pass additional charge to order data
I have been working on a 4.4.5 Gold version and I have coded the calculation of an additional handling fee which needs to be passed to the order details data , so the admin can view it in the Orders section and also display it in the order invoice and order notifications.
My question is how do I pass this additional charge in the "func_place_order()" function. The prototype of this function is: Code:
Can I use for example, the '$extra' or '$extras' arguments for passing this charge, so it will appear in the admin Order Details page in the admin, or do I need to add a custom field in the 'xcart_order_details' table for inserting this additional charge? By the way, I have checked this related thread ("Add special handling charge to cart totals"), but the code has changed significantly since then. Appreciate any help.
__________________
Vasilis Vrontisis X-Cart Development, Maintenance & Customization https://[URL="http://www.craftforweb.com"]craftforweb.com[/url] vasilis@craftforweb.com |
|||||||||
#2
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
Yep, you can try using $extra. There is an old thread about adding extra fields to checkout which might point you in the right direction.
If it can't be handled by the Extra Charge associated with the Payment Method or with Shipping Markups, I would use a hidden product and customize how/when it appears in the cart. That avoids getting into the order functions. |
|||||||||
#3
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
__________________
Vasilis Vrontisis X-Cart Development, Maintenance & Customization https://[URL="http://www.craftforweb.com"]craftforweb.com[/url] vasilis@craftforweb.com |
|||||||||
#4
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
Is there a reason you want to go that route over calculating a hidden product's price in cart.php and letting the existing functions do the rest of the calculations for you? This gets into tricky areas where you have to ensure the cart totals are correct everywhere (cart, checkout, shipping, tax, invoice, order editing, etc.). I recommend only doing that as a very last resort.
|
|||||||||
#5
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
__________________
Vasilis Vrontisis X-Cart Development, Maintenance & Customization https://[URL="http://www.craftforweb.com"]craftforweb.com[/url] vasilis@craftforweb.com |
|||||||||
#6
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
Quote:
Quote:
Quote:
Quote:
Quote:
|
|||||||||
#7
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
'cherie', I really appreciate your input.
__________________
Vasilis Vrontisis X-Cart Development, Maintenance & Customization https://[URL="http://www.craftforweb.com"]craftforweb.com[/url] vasilis@craftforweb.com |
|||||||||
#8
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
It sounds like you don't want the additional charge to appear in the subtotal. I wouldn't try to tweak the subtotal if you can help it. The subtotal would just include the additional charge. You can do things like uncheck apply discounts, make it free shipping, and make it non-taxable so it doesn't affect those calculations.
Here is the old thread about $extras: http://forum.x-cart.com/showthread.php?p=185108#post185108 |
|||||||||
#9
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
Yes, I don't want to include the additional charge in the subtotal, you are right. This is because the subtotal, by definition as an invoice term, is the sum of the ordered products' cost and the additional charge amount does not refer to a 'real' product ordered. So, I would list it under the tax amount, as 'handling fee' or something like that.
I will take a look in the post you sent me. Thanks again for the input. Any further comments regarding the above, especially for my previous post in this thread (#3) would be welcome.
__________________
Vasilis Vrontisis X-Cart Development, Maintenance & Customization https://[URL="http://www.craftforweb.com"]craftforweb.com[/url] vasilis@craftforweb.com |
|||||||||
#10
|
|||||||||
|
|||||||||
Re: Pass additional charge to order data
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:
and then called the order placement function passing the $extra argument: PHP Code:
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:
I really welcome any comments/corrections on the above
__________________
Vasilis Vrontisis X-Cart Development, Maintenance & Customization https://[URL="http://www.craftforweb.com"]craftforweb.com[/url] vasilis@craftforweb.com |
|||||||||
|
|||
X-Cart forums © 2001-2020
|