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


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

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