Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Pass additional charge to order data

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 03-19-2014, 06:31 AM
  vasilis's Avatar 
vasilis vasilis is offline
 

X-Adept
  
Join Date: Feb 2009
Posts: 758
 

Default 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:
function func_place_order($payment_method, $order_status, $order_details, $customer_notes, $extra = array(), $extras = array())

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
Reply With Quote
  #2  
Old 03-19-2014, 04:50 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default 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.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #3  
Old 03-20-2014, 04:04 AM
  vasilis's Avatar 
vasilis vasilis is offline
 

X-Adept
  
Join Date: Feb 2009
Posts: 758
 

Default Re: Pass additional charge to order data

  • I really need to pass this additional handling fee in the 'xcart_orders' table, I guess, so I can retrieve it both in the Order Details admin section and in the screen invoice and email notifications. (This additional charge is programmatically calculated for each product in the order, depending on the shipping address and the price of the product).
    For example, the 'order_data.tpl' template which renders the order details in the invoices, uses the '$order.extra' variable for displaying various types of order data that are stored in the 'extra' field of the 'xcart_orders' table, if I am correct.
    So, it seems to me that the more correct way is to pass this additional charge in this field ('extra') via the func_place_order() function, inside the '$extra' argument, so then I can retrieve it back wherever I need.
    Any comments on this?
  • On the other hand, I also need to pass this charge to the cart totals amount, so it sums up with the rest charges (subtotal + shipping cost + tax + additional charge).
    Up to now, I have tried passing it in the 'include/checkout.php' script, which has the '$cart['total_cost']' variable in scope and thus, I add it to it. But in this case, I wonder if the included additional charge passes in the cart total cost till the end.
    I was thinking if I should use 'cart_calculate_totals.php', passing it inside some insert data array, from those used in the script. Would this route be more correct, instead of passing it to the 'include/checkout.php' script, as referred above?
__________________
Vasilis Vrontisis
X-Cart Development, Maintenance & Customization
https://[URL="http://www.craftforweb.com"]craftforweb.com[/url]
vasilis@craftforweb.com
Reply With Quote
  #4  
Old 03-20-2014, 01:02 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default 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.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #5  
Old 03-20-2014, 02:03 PM
  vasilis's Avatar 
vasilis vasilis is offline
 

X-Adept
  
Join Date: Feb 2009
Posts: 758
 

Default Re: Pass additional charge to order data

  • As I described in my previous post,
    Quote:
    This additional charge is programmatically calculated for each product in the order, depending on the shipping address and the price of the product
    Not all products require this additional charge, this is defined programmatically, which ones.
    So, the hidden product solution would require, just before adding the hidden product to cart, changing programmatically it's price, to be the same as the sum of the additional charge per product in the order, is this what you mean?
  • On the other hand, dealing with the order functions is a more 'clean' solution as long as I make sure that the additional charge amount is passed through to the cart total amount and stored in the order record. Also, I need to display this additional charge in the screen invoice and email notifications as a separate charge, below the tax amount.

    By the way, would you happen to have any comments on my previous post, regarding the order functions and variables that I refer to?
__________________
Vasilis Vrontisis
X-Cart Development, Maintenance & Customization
https://[URL="http://www.craftforweb.com"]craftforweb.com[/url]
vasilis@craftforweb.com
Reply With Quote
  #6  
Old 03-20-2014, 02:42 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default Re: Pass additional charge to order data

Quote:
Originally Posted by vasilis
the hidden product solution would require, just before adding the hidden product to cart, changing programmatically it's price, to be the same as the sum of the additional charge per product in the order, is this what you mean?
Exactly.
Quote:
On the other hand, dealing with the order functions is a more 'clean' solution
I disagree and this is why:
Quote:
as long as I make sure that the additional charge amount is passed through to the cart total amount and stored in the order record.
Quote:
Also, I need to display this additional charge in the screen invoice and email notifications as a separate charge, below the tax amount.
Order products already display this info. You just customize the invoice to not show the product above and display it below. This is a much simpler change than tweaking php functions for calculating order totals, shipping, taxes, order history, order editing, etc.
Quote:
By the way, would you happen to have any comments on my previous post, regarding the order functions and variables that I refer to?
Nothing more than what I've already recommended. $extra can be used and you can pull stuff out of it, do calculations with it, and display it on invoices. While old, the other thread that discusses adding extra fields to the checkout goes into some of these details that should point you in the right direction. But it was for adding new fields to order_extras not related to calculations so I don't think this is the right way to go.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #7  
Old 03-20-2014, 03:29 PM
  vasilis's Avatar 
vasilis vasilis is offline
 

X-Adept
  
Join Date: Feb 2009
Posts: 758
 

Default Re: Pass additional charge to order data

'cherie', I really appreciate your input.
  • The hidden-product solution seems really much simpler, but I was wondering about the cart subtotal, which will include the hidden product's cost. This will need to be tweaked in the cart code and taken out from the subtotal, in case the hidden product exists in the cart. This way, the correct subtotal amount will display, with the hidden product's amount as the additional charge.
    Apart from this and the re-location of it's display in the screen invoice and email notifications, would you think of other tweaks that would be required elsewhere in the code?
  • Quote:
    While old, the other thread that discusses adding extra fields to the checkout goes into some of these details that should point you in the right direction.
    Are you referring to this post ?
__________________
Vasilis Vrontisis
X-Cart Development, Maintenance & Customization
https://[URL="http://www.craftforweb.com"]craftforweb.com[/url]
vasilis@craftforweb.com
Reply With Quote
  #8  
Old 03-20-2014, 03:37 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default 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
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #9  
Old 03-20-2014, 03:55 PM
  vasilis's Avatar 
vasilis vasilis is offline
 

X-Adept
  
Join Date: Feb 2009
Posts: 758
 

Default 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
Reply With Quote
  #10  
Old 04-14-2014, 01:44 AM
  vasilis's Avatar 
vasilis vasilis is offline
 

X-Adept
  
Join Date: Feb 2009
Posts: 758
 

Default 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:
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
__________________
Vasilis Vrontisis
X-Cart Development, Maintenance & Customization
https://[URL="http://www.craftforweb.com"]craftforweb.com[/url]
vasilis@craftforweb.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:45 AM.

   

 
X-Cart forums © 2001-2020