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

Add special handling charge to cart totals

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #21  
Old 10-15-2011, 07:41 AM
 
Powertrain Powertrain is offline
 

Senior Member
  
Join Date: Mar 2011
Posts: 101
 

Default 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.
__________________
x-cart 4.4.2 Gold
Reply With Quote
  #22  
Old 10-15-2011, 09:30 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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)
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #23  
Old 10-15-2011, 12:09 PM
 
Powertrain Powertrain is offline
 

Senior Member
  
Join Date: Mar 2011
Posts: 101
 

Default 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.
__________________
x-cart 4.4.2 Gold
Reply With Quote
  #24  
Old 10-15-2011, 01:28 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #25  
Old 10-15-2011, 03:23 PM
 
Powertrain Powertrain is offline
 

Senior Member
  
Join Date: Mar 2011
Posts: 101
 

Default 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.
__________________
x-cart 4.4.2 Gold
Reply With Quote
  #26  
Old 10-15-2011, 06:03 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #27  
Old 10-16-2011, 07:44 PM
 
Powertrain Powertrain is offline
 

Senior Member
  
Join Date: Mar 2011
Posts: 101
 

Default 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.
__________________
x-cart 4.4.2 Gold
Reply With Quote
  #28  
Old 10-17-2011, 05:46 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Add special handling charge to cart totals

Replied
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #29  
Old 10-24-2011, 08:05 PM
 
Powertrain Powertrain is offline
 

Senior Member
  
Join Date: Mar 2011
Posts: 101
 

Default 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.
__________________
x-cart 4.4.2 Gold
Reply With Quote
  #30  
Old 02-22-2012, 11:51 PM
 
bjt bjt is offline
 

Advanced Member
  
Join Date: Jul 2008
Location: Vietnam
Posts: 32
 

Default 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.
__________________
X-Cart Gold 4.3.2 (Windows)
X-Cart Gold Plus 4.6.1 (Linux)
Magic Toolbox slider and zoom
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:05 AM.

   

 
X-Cart forums © 2001-2020