X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Add special handling charge to cart totals (https://forum.x-cart.com/showthread.php?t=24318)

mikalou 08-23-2006 11:41 AM

Add special handling charge to cart totals
 
Some of the products that our client sells are classified as hazardous materials and so they must be shipped by ground on a special truck. So if a customer adds one or more of these products to their cart, we needed to add an additional flat handling fee of $20 to the shopping cart totals. Regardless of how many of these products are added to the cart, the handling charge would remain $20 per cart. So using the shipping_freight field in the products table would not work since it▓s designed to be incremented each time an additional product is added.

Here▓s the procedure for the solution we came up with:

Step 1:
Add an extra field: handling_special
Default value: (leave blank)
Show: Dont check (Doesn▓t really matter, since this is going to be used only in the codework.)

Step 2:
Create new label:
Variable: lbl_handling_special
Description: Special Handling
Value: Special Handling

Step 3:
The client wanted to track the special handling cost separate from shipping costs so we created a new field in the ⌠xcart_orders■ table called ⌠handling_special■ using the same definition parameters as the field ⌠shipping_cost■. Later, we▓ll need to modify the INSERT query in func_place_order within func.php to save this new value.

Step 4:
You will be editing these files: (remember to make backup copies of these files before you make any changes)
1. /include/func.php
2. /skin1/customer/main/cart_totals.tpl
3. /skin1/main/order_info.tpl
4. /skin1/mail/order_data.tpl

Edit: /include/func.php

In Function: func_calculate_shippings
Add this code under other initial definition statements:
Code:

$handling_special = 0;

In Function: func_calculate_shippings
Add this code just before the closing bracket of the code: foreach($products as $k=>$product) {
Code:

              $int_hdl = func_query_first("SELECT * FROM $sql_tbl[extra_field_values]
        WHERE fieldid=3 AND productid=$product[productid]");
        if (!empty($int_hdl["value"]))
                $handling_special = 20.00;       
        }         

Purpose: The query statement is placed within the foreach loop that iterates through the products in the shopping cart filtering the query by the productid and the fieldid of the extra field that was created above. The if statement then checks if there is a value in that field and if there is sets the value of the variable to 20 which is what our handling fee is for hazardous materials.

ALERT: The value ⌠3■ that is hard coded in the query statement above for fieldid is the value that xcart defined for the extra_field when it was created in step 1. You may need to change that value. Look at the xcart_extra_fields table to see what the value is for the extra field you create.

In Function: func_calculate_shippings
Add this code before: return $return;
(this allows the skin1/customer/main/cart_totals.tpl file to retrieve this value.)
Code:

$return["handling_special"] = $handling_special;

In function: func_calculate_single
Revise:
Code:

$total = $discounted_subtotal + $shipping_cost + $total_tax;
To:
Code:

$total = $discounted_subtotal + $shipping_cost + $total_tax + $handling_special;

In function: func_calculate_single
Add this code after: "shipping_cost"=>price_format($shipping_cost),
(This allows skin1/main/order_info.tpl to retrieve the value of the new handling charge.)
Code:

"handling_special"=>price_format($handling_special),
"display_handling_special"=>price_format($handling_special),


In function: func_select_order
Add this code just above: return $order; which is located near the end of the function
(This allows skin1/main/order_info.tpl to retrieve the value of the new handling charge.)
Code:

$order["display_handling_special"] = $order["handling_special"];

In function: func_place_order
Add: handling_special to the first part of query statement as shown here:
Code:

db_query("INSERT INTO $sql_tbl[orders] (login, membership, total, giftcert_discount,
giftcert_ids, subtotal, shipping_cost, handling_special,...

And add:'$current_order[handling_special]' to the second part of query statement as shown here:
(This will now save the special handling charge in the xcart_orders table along with the other order information.)
Code:

VALUES ('".addslashes($userinfo["login"])."', '".addslashes($userinfo["membership"])."',
'$current_order[total_cost]', '$giftcert_discount', '".@$giftcert_str."',
'$current_order[subtotal]','$current_order[shipping_cost]',
'$current_order[handling_special]',...

Now you▓ll need to edit some of the template files to display the value in the shopping cart, invoices and confirmation emails.

Edit: skin1/customer/main/cart_totals.tpl

Add the following code wherever you want the special handling charge to be displayed within the cart totals:
Code:

{if $handling_special ne ""}
<TR>
<TD nowrap>
<FONT class="ProductTitle">{$lng.lbl_handling_special}:</FONT><sup>(a)</sup></TD>
<TD><IMG src="{$ImagesDir}/null.gif" width="5" height="1" alt=""><BR></TD>
<TD nowrap align="right"><FONT class="ProductPriceSmall">{include file="currency.tpl"
value=$handling_special}</FONT></TD>
<TD nowrap align="right"></TD>
</TR>
{/if}


Edit: skin1/main/order_info.tpl

Add this code after sub total amount: (This will display the new special handling charge when the customer and administrator view the order history.)
Code:

{if $order.display_handling_special gt 0}
<TR>
<TD align="right" height="20"><B>{$lng.lbl_handling_special}:</B>&nbsp;</TD>
<TD align="right">{include file="currency.tpl"
value=$order.display_handling_special}&nbsp;&nbsp;&nbsp;</TD>
</TR>
{/if}       


Edit: skin1/mail/order_data.tpl

Add this code above the line showing shipping cost: (This will show special handling charge in emails that are sent to customer and administrator.)
Code:

{if $order.display_handling_special gt 0}
{$lng.lbl_handling_special|truncate:$max_truncate:"...":true|cat:":"|string_format:$max_space}
{include file="currency.tpl" value=$order.display_handling_special}
{/if}

That▓s it. Now just add a ⌠Y■ to the extra field ⌠handling_special■ to any product that you want the special handling charge to apply. When the customer adds one of these products to their cart. The cart totals should show a $20 handling charge in the cart totals and $20 will be added to the total cart amount. This code is not being used in production yet but it has been tested quite abit on the development site. I searched and search on these forums for a solution for this problem and finally just tried to tackle it myself. I hope it is of use to someone else.

borodimer 08-24-2006 04:02 PM

Re: Add special handling charge to cart totals
 
Very nice! Exactly what I was looking for.

I modified your scenario to one where the store charges a flat transaction fee per order.

Thanks for taking the time to post this.

cheaperplanet 08-26-2006 09:45 AM

Re: Add special handling charge to cart totals
 
How would you charge a handling fee only if the order total is less than a certain amount?

mikalou 08-28-2006 04:45 AM

Re: Add special handling charge to cart totals
 
I don't think you can do what you want in the markup feature under shipping charges. I believe you'd need to modify the code in /include/func.php. Use a conditional statement to check the cart total and if that total is below a specific dollar amount then you'd add the extra handling fee to the total.

Try this...
In function: func_calculate_single
After this code: $total = $discounted_subtotal + $shipping_cost + $total_tax;

Add:
Code:

if ($total < 100)
  $total = $total + 25

Change the dollar amounts (100 and 25) to whatever you need.

If you need the extra handling fee to show up as a line item in the cart totals for the shopping cart, invoices, order history and confirmation emails, then you'd need to do extra programming similar to my original example.

I think I've seen other posts discussing what you want to do so try doing a search. There may be a better way than what I'm suggesting.

tomcarlson 02-26-2008 02:47 PM

Re: Add special handling charge to cart totals
 
Has anyone tried this recently? I followed the steps exactly, and my total cost includes the handling, but the handling cost does not show up on the order information. It is like the tpl files are being passed a $handling_special that is NULL, but when I look in the orders table, the correct value is there.

I even tried removing the {if $handling_special ne ""}, but all it showed then was a "$" and no value.

It displays when I log into the administrative end to check the order, but does not show up upon checkout or the email invoice.

I wonder if some other xcart updates have made this procedure outdated. I did realize that func.php is now split into func.order.php and func.cart.php with their respective functions.

Any comments would be greatly appreciated!!!

tomcarlson 02-26-2008 05:14 PM

Re: Add special handling charge to cart totals
 
Phew! I resolved the issue using the following:


Edit: skin1/customer/main/cart_totals.tpl

Add the following code wherever you want the special handling charge to be displayed within the cart totals:

Code:

{if $cart.display_handling_special gt 0}
<TR>  <TD nowrap>  <FONT class="ProductTitle">{$lng.lbl_handling_special}:</FONT></TD>
<TD><IMG src="{$ImagesDir}/null.gif" width="5" height="1" alt=""><BR></TD>
<TD nowrap align="right"><FONT class="ProductPriceSmall">{include file="currency.tpl"
value=$cart.display_handling_special}</FONT></TD>  <TD nowrap align="right"></TD>  </TR>  {/if}



--- ALSO ---



Edit: skin1/mail/html/order_data.tpl

Add this code above the line showing shipping cost: (This will show special handling charge in emails and invoices that are sent to customer and administrator.)

Code:

{if $order.display_handling_special gt 0}
  <tr>
  <td align="right" height="20"><b>{$lng.lbl_handling_special}:</b>&nbsp;</td>
  <td align="right">{include file="currency.tpl" value=$order.display_handling_special}&nbsp;&nbsp;&nbsp;</td>
  </tr>
  {/if}


Owl 05-12-2008 10:23 PM

Re: Add special handling charge to cart totals
 
Hmm I wounder if this could be used to add extra charge for different type of payment ways in 4.018?

Otis 06-18-2008 08:17 PM

Re: Add special handling charge to cart totals
 
ok...i was wondering if anyne had an idea to make this work in this scenario. I want to charge a "handling fee" in a way only for international orders. Actually, the fee is for a gov't import certificate that i have to purchase for international orders.

Is there a way to write a conditional statement to check which shipping zone this customer is in before adding this "handling fee"?

THanks

Otis

mikalou 06-19-2008 06:39 AM

Re: Add special handling charge to cart totals
 
Yes, I believe that would be possible. Although I haven't checked it myself, I think the variable for the shipping zone for the customer is "$customer_zone" which you would use in the conditional statement.

if ($customer_zone == 122)
$handling_fee = 20.0;

Jerrad 06-20-2008 12:02 AM

Re: Add special handling charge to cart totals
 
Any idea how this modification can be used to add a 'handling fee' to certain payment methods?

Thanks! :D

Dongan 06-20-2008 02:32 AM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by Jerrad
Any idea how this modification can be used to add a 'handling fee' to certain payment methods?

Thanks! :D


definitely, you need to write a custom code to apply the fee for specific payment methods.

Jerrad 06-20-2008 02:59 AM

Re: Add special handling charge to cart totals
 
Thanks for your message, Dongan.
Any suggestion how this custom code would look? 8O

Dongan 06-20-2008 03:19 AM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by Jerrad
Thanks for your message, Dongan.
Any suggestion how this custom code would look? 8O


if you are able to understand and do basic programming, we can give some tips to implement.

otherwise, i would recommend to get quote from the developers, proceed further.

Jerrad 06-20-2008 03:28 AM

Re: Add special handling charge to cart totals
 
It's always worth trying, so tips are very welcomed, Dongan!

Thanks in advance! :D

hues 08-29-2008 02:17 AM

Re: Add special handling charge to cart totals
 
Nice mod. But it seems this works on x-cart 4.0.x

Has anyone tried to modify this for x-cart 4.1.x?

I need to add the facility to my x-cart, where, I can add handling charges per order for specific products, irrespective of the number of items purchased.

MommyDesigns 09-22-2008 01:36 PM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by mikalou
I don't think you can do what you want in the markup feature under shipping charges. I believe you'd need to modify the code in /include/func.php. Use a conditional statement to check the cart total and if that total is below a specific dollar amount then you'd add the extra handling fee to the total.

Try this...
In function: func_calculate_single
After this code: $total = $discounted_subtotal + $shipping_cost + $total_tax;

Add:
Code:

if ($total < 100)
  $total = $total + 25

Change the dollar amounts (100 and 25) to whatever you need.

If you need the extra handling fee to show up as a line item in the cart totals for the shopping cart, invoices, order history and confirmation emails, then you'd need to do extra programming similar to my original example.

I think I've seen other posts discussing what you want to do so try doing a search. There may be a better way than what I'm suggesting.


Does anyone know if this is do-able in 4.1.10??

Thanks!

sjrconsulting 02-17-2009 08:39 AM

Re: Add special handling charge to cart totals
 
I like this solution.

Is there a way to easily assign different charges based on the shipping method? (ie. FedEx Ground =$30.00, International Economy=$50.00, etc.)


Thanks
Steve

Powertrain 10-14-2011 01:15 PM

Re: Add special handling charge to cart totals
 
Great info :)

Has anyone tried this in 4.4.x ?
Or can post different files (if any) that will need modify?

Also can we use extra_field value as the amount to be charged extra?

Any tips would be greatly appreciated.

Powertrain 10-14-2011 08:16 PM

Re: Add special handling charge to cart totals
 
Seems like func.php does not exist anymore :(
I see now there is a folder called "func" with bunch of func_xxx files.

Can anyone suggest which files will need this changes for 4.4.2 ?

Thanks.

cflsystems 10-14-2011 08:39 PM

Re: Add special handling charge to cart totals
 
func.order.php is the one for orders functions

Powertrain 10-15-2011 07:41 AM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by cflsystems
func.order.php is the one for orders functions


Thank you Steve :)

I actually followed instructions and got it to work in Gold 4.4.2 but my situation is a bit different. We have extra field that certain products use (extra charge) and so far it works if one product is added to the cart but if you add two or more products it pulls only one extra field value (extra charge).
It needs to add this field value for each product in the cart.

I played with the code adding foreach ( but no luck. Here is the sample code:

PHP Code:

$int_hdl func_query_first("SELECT * FROM $sql_tbl[extra_field_values] WHERE fieldid=1 AND productid=$product[productid]");
if (!empty(
$int_hdl["value"])) {

foreach (
$int_hdl as $handling_special) {

           
$handling_special field_value;

        }
        } 

I don't know if "foreach" is the right way to go about it but logically value needs to be added for each product. Any suggestions?

Thanks for your help.

cflsystems 10-15-2011 09:30 AM

Re: Add special handling charge to cart totals
 
Because your code assigns new value to $handling_special with each loop without adding the old one to the cart. You need to also include in the foreach code to add the value to cart if any then go to the next one. Something like

foreach ($int_hdl as $handling_special) {

$handling_special = field_value;
cart_total += $handling_special;

}
}


replace cart_total with the actual cart total field (or the field you are adding value to)

Powertrain 10-15-2011 12:09 PM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by cflsystems
Because your code assigns new value to $handling_special with each loop without adding the old one to the cart. You need to also include in the foreach code to add the value to cart if any then go to the next one. Something like

foreach ($int_hdl as $handling_special) {

$handling_special = field_value;
cart_total += $handling_special;

}
}


replace cart_total with the actual cart total field (or the field you are adding value to)


Thank you so much Steve for taking time to look at this, it's a headache.

I actually got it to calculate subtotal that includes these extra charges with this code :

PHP Code:

$int_hdl func_query_first("SELECT * FROM $sql_tbl[extra_field_values] WHERE fieldid=1 AND productid=$product[productid]"); 
if (!empty(
$int_hdl["value"])) {

foreach (
$int_hdl as $handling_special) {

$handling_special $int_hdl['value'];
}
}

$subtotal += $handling_special


but for some reason if I add product that does not have the extra field, it adds extra charge to it as well and than ads discounted total line, subtracts one extra charge.
Than at the end shows total plus one extra charge.


Seems like the code needs to be somewhere where it calculates $product price, I don't know.

cflsystems 10-15-2011 01:28 PM

Re: Add special handling charge to cart totals
 
That's way I had the code added inside the foreach loop so it will execute only if the foreach executes - so only if the added product has this extra field value

Powertrain 10-15-2011 03:23 PM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by cflsystems
That's way I had the code added inside the foreach loop so it will execute only if the foreach executes - so only if the added product has this extra field value


Man, it's so close but still adds this charge for all items including item that does not have this extra field.

This is the code again (keeping $subtotal inside foreach loop:
PHP Code:

$int_hdl func_query_first("SELECT * FROM $sql_tbl[extra_field_values] WHERE fieldid=1 AND productid=$product[productid]"); 
if (!empty(
$int_hdl["value"])) {

foreach (
$int_hdl as $handling_special) {

$handling_special $int_hdl['value'];
$subtotal += $handling_special;
}



This is placed just before the closing bracket of the code: foreach($products as $k=>$product) { - as instructed by the author of this post even tho he states it is in "In Function: func_calculate_shippings" but in xcart 4.4.2 code is a lot different, so maybe this code needs to go in different place??

Or some of the code in other places (as he instructs to put) needs also foreach loop???

I really appreciate all you help Steve.

cflsystems 10-15-2011 06:03 PM

Re: Add special handling charge to cart totals
 
Then there is soemthign wrong in the above code - you need to debug it and print every value/array to make sure all is adding properly. Could be your sql, could be the foreach you are using

Powertrain 10-16-2011 07:44 PM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by cflsystems
Then there is soemthign wrong in the above code - you need to debug it and print every value/array to make sure all is adding properly. Could be your sql, could be the foreach you are using


Hey Steve, I sent you an email this morning "Re: Add special handling charge to cart totals", please take a look when you have a minute.
Thanks.

cflsystems 10-17-2011 05:46 AM

Re: Add special handling charge to cart totals
 
Replied

Powertrain 10-24-2011 08:05 PM

Re: Add special handling charge to cart totals
 
I just wanted to thank everyone that posted here but mostly Steve as he ended up doing this modification for us and we can't be more happy with his work. Professional, fast and very reasonable rates. I would recommend him to anyone looking for x-cart modification.

Thanks.

bjt 02-22-2012 11:51 PM

Re: Add special handling charge to cart totals
 
I've got this working in my store for good classified as dangerous goods.
We want to add $40 charge including tax.
So I have set the value of $handling_special to be 36.36 which is working well, however I also need to know where to put the code to add the 10% tax to this.

We offer free freight on all orders over $200 so adding the $handling_special charge to the shipping value is pointless as it gets set back to zero when the order gets over $200. Any help much appreciated.

Otis 08-31-2012 03:43 AM

Re: Add special handling charge to cart totals
 
Hello,

I tried to do this for X-Cart 4.5.2 Gold but the handling special charge will just not show up on checkout. Has anyone got this code working for X-Cart 4.5.2 Gold or can anyone please share some thoughts on how to make this work for X-Cart 4.5.2 Gold.

Thanks.

Otis 09-03-2012 12:23 AM

Re: Add special handling charge to cart totals
 
Anybody no answer for this?

microdaq 12-26-2013 12:45 PM

Re: Add special handling charge to cart totals
 
Is there a 4.6.1 solution to this?


Steve

kosmos 09-03-2014 10:23 AM

Re: Add special handling charge to cart totals
 
Quote:

Originally Posted by microdaq
Is there a 4.6.1 solution to this?


Steve


Also, for 4.6.x?


All times are GMT -8. The time now is 01:17 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.