View Single Post
  #1  
Old 08-23-2006, 11:41 AM
 
mikalou mikalou is offline
 

Advanced Member
  
Join Date: Jun 2005
Posts: 71
 

Default 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.
__________________
X-Cart Gold 4.2.2 - 3.1.19
Reply With Quote