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)

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.


All times are GMT -8. The time now is 05:17 AM.

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