Negative taxes are saving into order product table

  • Posts: 64
  • Thank you received: 0
9 years 6 months ago #201315

-- HikaShop version -- : 2.3.0
-- Joomla version -- : Joomla! 3.3.0 Stable
-- PHP version -- : 5.4.13

I tried to create orders with tax. Tax and all calculations are correct during checkout and once order is created tax does not save for negative values.

If I add a product where it has two options product.
a)Main product price is zero
b)first options product has 70 price and tax does not apply to this
c)second option product has 50 price and tax does apply to this.
additionally there is a discount on main product of $50. In hikashop config Apply discounts is set to Before taxes.

On checkout page total shows 70$ for one quantity.But when order is confirmed in product order table it shows as below-

a)main product -> price = - 50$ , Tax = 0(It should be -2$ which is tax)
b)first option product -> price = -70$ , Tax = 0(correct)
b)second option product -> price = 50$ , Tax = 2$(correct)

When I tried to debug the code I found something wrong in below code(after_confirm)-

if(!empty($product->prices[0]->unit_price->price_value_with_tax) && bccomp($product->prices[0]->unit_price->price_value_with_tax,0,5)){
$tax = $product->prices[0]->unit_price->price_value_with_tax-$product->prices[0]->unit_price->price_value;
}

below should be true for -2$ but it is treated as false.
bccomp($product->prices[0]->unit_price->price_value_with_tax,0,5))

It would be great if you can help me to fix this.

I would like to add that in my localhost where BC Math extension is installed, it is working fine but on server, extension is not installed so it's using helper class custom bccomp function.
Thanks,

Last edit: 9 years 6 months ago by irfanhanfi.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
9 years 6 months ago #201340

Hi,

Change the code:

if(!empty($product->prices[0]->unit_price->price_value_with_tax) && bccomp($product->prices[0]->unit_price->price_value_with_tax,0,5)){
$tax = $product->prices[0]->unit_price->price_value_with_tax-$product->prices[0]->unit_price->price_value;
}
to:
if(!empty($product->prices[0]->unit_price->price_value_with_tax)){
$tax = $product->prices[0]->unit_price->price_value_with_tax-$product->prices[0]->unit_price->price_value;
}
and that should fix the problem.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 0
9 years 6 months ago #201344

Thank you for this fix.

It looks like issue is with bccomp definition.It would be great if you can provide fix for that function.I guess this needs to fix everywhere where we have called bccomp.


Thanks,

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 6 months ago #201473

Hi,

" bccomp " is like using " > " ; the code was there to check that the taxes are not negative.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Last edit: 9 years 6 months ago by Jerome.

Please Log in or Create an account to join the conversation.

Time to create page: 0.044 seconds
Powered by Kunena Forum