Guest Posted November 22, 2005 Share Posted November 22, 2005 Hello All, I have installed the Ship in Cart v2.10 contribution (it is an amazing contribution) but am having problems with the way it calculates (1) the subtotal and (2) tax, when they are showing. Basically, the subtotal and tax are calculated correctly when a user is not logged in. However, once the user is loged in, the subtotal appears with the amount of the tax for the product being deducted from the VAT exclusive price of the product! i.e. Product price = ?10.00 (exclusive of VAT) and ?11.75 (inclusive of VAT). Subtotal = ?8.25 (exclusive of VAT) I think that I am close to figuring this out, but having spent almost 3 days of looking at the same piece of code, I am getting very sore eyes and making more mistakes than sorting the actual problem out! If someone could let me know what needs to be added or changed to the following piece of code from catalog/includes/modules/shipping_estimator.php, it would be much appreciated (I can post entire source code to file if that would help): if (CARTSHIP_SHOWOT == 'true'){ // BOF get taxes if not logged in if (!tep_session_is_registered('customer_id')){ $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { $products_tax = tep_get_tax_rate($products[$i]['tax_class_id'], $order->delivery['country_id'],$order->delivery['zone_id']); $products_tax_description = tep_get_tax_description($products[$i]['tax_class_id'], $order->delivery['country_id'], $order->delivery['zone_id']); if (DISPLAY_PRICE_WITH_TAX == 'true') { //Modified by Strider 42 to correct the tax calculation when a customer is not logged in // $tax_val = ($products[$i]['final_price']-(($products[$i]['final_price']*100)/(100+$products_tax)))*$products[$i]['quantity']; $tax_val = (($products[$i]['final_price']/100)*$products_tax)*$products[$i]['quantity']; } else { $tax_val = (($products[$i]['final_price']*$products_tax)/100)*$products[$i]['quantity']; } // $order->info['tax'] += $tax_val; $order->info['tax_groups']["$products_tax_description"] += $tax_val; // Modified by Strider 42 to correct the order total figure when shop displays prices with tax if (DISPLAY_PRICE_WITH_TAX == 'true') { /* $order->info['total']; } else {*/ $order->info['total']+=$tax_val; } } } // EOF get taxes if not logged in (seems like less code than in order class) Anyone familiar with the above file/code will now that I have already slightly changed the code to show the subtotal/tax correctly when the user is NOT logged in (but it doesn't work when the user IS logged in!) I should add that the method by which I show both VAT exc/inc prices is by using the following pices of code: In catalog/includes/classes/currencies.php: function display_price($products_price, $products_tax, $quantity = 1) { return '<span class="VAT">(' . $this->format(tep_add_tax($products_price, $products_tax) * $quantity) . VAT_TEXT . ')</span>'; } function display_price_exc($products_price, $products_tax, $quantity = 1) { return $this->format(tep_tax_exc($products_price, $products_tax) * $quantity); } In catalog/includes/functions/general.php I add tep_tax_exc: //// // Add inc. tax to a products price function tep_tax_exc($price, $tax) { global $currencies; return tep_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) /* + tep_calculate_tax($price, $tax) */; } Then, where I require both/either Vat exc/inc prices to be shown I add either: (1) for VAT exc prices: $currencies->display_price_exc($featured_products['products_price'], tep_get_tax_rate($featured_products['products_tax_class_id'])) (2) for VAT inc prices: $currencies->display_price($featured_products['products_price'], tep_get_tax_rate($featured_products['products_tax_class_id'])) I cannot understand why this code would affect the subtotal/tax calculation only when a user is logged in in the Ship in Cart contribution? Apologies if I haven't been clear - let me know if further clarification is required, and thanks in advance for any help! Regards, Unified Quote Link to comment Share on other sites More sharing options...
Guest Posted November 22, 2005 Share Posted November 22, 2005 Dear All, I have found the solution using good old fashioned trial and error. Here is the solution: (1) Open catalog/includes/shipping_estimator.php. (2) Find the following code: if (CART_OT_SHOW == 'true'){ // bof damned we need the taxes if not logged in ... if (!tep_session_is_registered('customer_id')){ $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { $products_tax = tep_get_tax_rate($products[$i]['tax_class_id'], $order->delivery['country_id'],$order->delivery['zone_id']); $products_tax_description = tep_get_tax_description($products[$i]['tax_class_id'], $order->delivery['country_id'], $order->delivery['zone_id']); if (DISPLAY_PRICE_WITH_TAX == 'true') { //Modified by Strider 42 to correct the tax calculation when a customer is not logged in // $tax_val = ($products[$i]['final_price']-(($products[$i]['final_price']*100)/(100+$products_tax)))*$products[$i]['quantity']; $tax_val = (($products[$i]['final_price']/100)*$products_tax)*$products[$i]['quantity']; } else { $tax_val = (($products[$i]['final_price']*$products_tax)/100)*$products[$i]['quantity']; } $order->info['tax'] += $tax_val; $order->info['tax_groups']["$products_tax_description"] += $tax_val; // Modified by Strider 42 to correct the order total figure when shop displays prices with tax if (DISPLAY_PRICE_WITH_TAX == 'true') { $order->info['total']; } else { $order->info['total']+=$tax_val; } } } // eof damned we need the taxes if not logged in (seems like less code than in order class ???) (3) Replace above with: if (CART_OT_SHOW == 'true'){ // bof damned we need the taxes if not logged in ... if (!tep_session_is_registered('customer_id')){ $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { $products_tax = tep_get_tax_rate($products[$i]['tax_class_id'], $order->delivery['country_id'],$order->delivery['zone_id']); $products_tax_description = tep_get_tax_description($products[$i]['tax_class_id'], $order->delivery['country_id'], $order->delivery['zone_id']); if (DISPLAY_PRICE_WITH_TAX == 'true') { //Modified by Strider 42 to correct the tax calculation when a customer is not logged in // $tax_val = ($products[$i]['final_price']-(($products[$i]['final_price']*100)/(100+$products_tax)))*$products[$i]['quantity']; $tax_val = (($products[$i]['final_price']/100)*$products_tax)*$products[$i]['quantity']; } else { $tax_val = (($products[$i]['final_price']*$products_tax)/100)*$products[$i]['quantity']; } // $order->info['tax'] += $tax_val; $order->info['tax_groups']["$products_tax_description"] += $tax_val; // Modified by Strider 42 to correct the order total figure when shop displays prices with tax if (DISPLAY_PRICE_WITH_TAX == 'true') { // $order->info['total']; // } else { $order->info['total']+=$tax_val; } } } else { $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { $products_tax = tep_get_tax_rate($products[$i]['tax_class_id'], $order->delivery['country_id'],$order->delivery['zone_id']); $products_tax_description = tep_get_tax_description($products[$i]['tax_class_id'], $order->delivery['country_id'], $order->delivery['zone_id']); if (DISPLAY_PRICE_WITH_TAX == 'true') { //Modified by Strider 42 to correct the tax calculation when a customer is not logged in // $tax_val = ($products[$i]['final_price']-(($products[$i]['final_price']*100)/(100+$products_tax)))*$products[$i]['quantity']; // $tax_val = (($products[$i]['final_price']/100)*$products_tax)*$products[$i]['quantity']; //} else { $tax_val = (($products[$i]['final_price']*$products_tax)/100)*$products[$i]['quantity']; } $order->info['tax'] -= $tax_val; // $order->info['tax_groups']["$products_tax_description"] += $tax_val; // Modified by Strider 42 to correct the order total figure when shop displays prices with tax if (DISPLAY_PRICE_WITH_TAX == 'true') { $order->info['total']; // } else { // $order->info['total']+=$tax_val; } } } // eof damned we need the taxes if not logged in (seems like less code than in order class ???) My apologies for wasting everyones time! Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.