mizzer Posted August 3, 2010 Share Posted August 3, 2010 Guys, today guess what - I found a bug in prestashop about the tax display! This is so weird, because right after that happened I saw JFK walk by followed by Elvis, then Bigfoot, but then they were all abducted by aliens. So weird!I would happilly submit this to the bug tracker, but all registrations for the bug tracker are turned off. LoL.So here's the bug: the product display page shows the price with tax..sorry "taxe"...on the page when it's told not to when an item is on sale.The template calls: convertPrice price=$product->getPriceWithoutReduct(true) which calls the function reference (explicitly saying DONOTSHOWTAXE) getPriceWithoutReduct($notax = false) but alas, Pierre got confused and spilled some cheese on his keyboard, because later on, when it computes the final price, we have this fine piece of programming logic here: if (!Tax::excludeTaxeOption() || $notax) return ($res['price'] * (1 + $tax / 100)); Basically, the fine double negative logic (note to PS: terrible programming practice to set booleans like that, should be a positive include TAXE option, but whatever...its just your reputation here on the line.) I think you were trying to say:** edit: LOLOLOL the actual correct logic to put in here actually breaks PS, because the entire software is built around this bug being broken. you have explicitly check NOTAXE because the global option excludeTAXEoption works correct enough, but the NOTAXE flag doesnt, so the template shows TAXE for every item not on sale. LOLOLOLOLOZZZ so that's why this fix looks ugly, because the code doesn't support regression tests or anything like that, so good luck if you want use this! if ($notax) { return ($res['price']); } if (!Tax::excludeTaxeOption() || $notax) return ($res['price'] * (1 + $tax / 100)); return ($res['price']); ** it still has the TAXE flag computing TAXE, but honestly at this point who cares. I don't care enough to fix this thing correctly, and PS sure doesn't care. Let's join the Open Sores Revolution!!!!!!Saying if DONOTSHOWTAXE is set, gee whiz guys, lets compute the TAXE and include it anyway. yay!If i wrote code like this at a job, I would be fired the first day. The fact that this software is in production makes me want to abort myself 30 years ago. Link to comment Share on other sites More sharing options...
tomerg3 Posted August 3, 2010 Share Posted August 3, 2010 Most likely there is a javascript error on your site, that makes the prices show with tax instead of without Link to comment Share on other sites More sharing options...
Patric Posted August 3, 2010 Share Posted August 3, 2010 I would happilly submit this to the bug tracker, but all registrations for the bug tracker are turned off. LoL. Turned off? Where did you see that?Please try (everything) from another browser and tell us. Link to comment Share on other sites More sharing options...
Laurence Posted August 24, 2010 Share Posted August 24, 2010 I too can confirm this bug. But it is not quite as easy.There is a problem with $product->getPriceWithoutReduct(). It returns the same value if either true or false is passed into it. (I have tested this on pages with and without JS, with and without product combos.)If the product has multiple product combos then the JS seems to come in and overwrite it with the correct price.This means that regardless to which way you have tax, the crossed out value will always be including tax if there no combination on a product.I do not understand the where the function is used enough to know if it is safe to fix it inside the $product->getPriceWithoutReduct function but i will try and post results here later.If someone else could confirm this bug would be good. Link to comment Share on other sites More sharing options...
Laurence Posted September 1, 2010 Share Posted September 1, 2010 I have fully checked this out and it seems to be a bug.There is two ways of fixing this. The first is to correct the function.Original classes\product.php public function getPriceWithoutReduct($notax = false) { $res = Db::getInstance()->getRow(' SELECT p.`price`, t.`rate`, t.`id_tax` FROM `'._DB_PREFIX_.$this->table.'` p LEFT JOIN `'._DB_PREFIX_.'tax`t ON (p.`id_tax` = t.`id_tax`) WHERE p.`id_product` = '.intval($this->id)); if (!$res) return false; $tax = floatval(Tax::getApplicableTax(intval($res['id_tax']), floatval($res['rate']))); if (!Tax::excludeTaxeOption()) return (Tools::convertPrice($res['price']) * (1 + $tax / 100)); return (Tools::convertPrice($res['price'])); } Updated classes\product.php public function getPriceWithoutReduct($notax = false) { $res = Db::getInstance()->getRow(' SELECT p.`price`, t.`rate`, t.`id_tax` FROM `'._DB_PREFIX_.$this->table.'` p LEFT JOIN `'._DB_PREFIX_.'tax`t ON (p.`id_tax` = t.`id_tax`) WHERE p.`id_product` = '.intval($this->id)); if (!$res) return false; $tax = floatval(Tax::getApplicableTax(intval($res['id_tax']), floatval($res['rate']))); if (!Tax::excludeTaxeOption() && !$notax) return (Tools::convertPrice($res['price']) * (1 + $tax / 100)); return (Tools::convertPrice($res['price'])); } This will work without breaking anything else that i can find but is hard to read.The second brings it into line with the other prestashop functions (ie getpricestatic) which have a false passed for notax and the default (true) includes tax. This shouldn't need any changes in prestashop unless a template is overriding the default tax display (on specials). The default theme does not do this. public function getPriceWithoutReduct($usetax = true) { $res = Db::getInstance()->getRow(' SELECT p.`price`, t.`rate`, t.`id_tax` FROM `'._DB_PREFIX_.$this->table.'` p LEFT JOIN `'._DB_PREFIX_.'tax`t ON (p.`id_tax` = t.`id_tax`) WHERE p.`id_product` = '.intval($this->id)); if (!$res) return false; if (!Tax::excludeTaxeOption() && $usetax) ( $tax = floatval(Tax::getApplicableTax(intval($res['id_tax']), floatval($res['rate']))); return (Tools::convertPrice($res['price']) * (1 + $tax / 100)); ) return (Tools::convertPrice($res['price'])); } Can someone who is better fitted for this please test this and tell me i'm wrong? And if not then can we see about getting this fixed in the beta?Thanks.[edited] To fix a error in the suggested code. Link to comment Share on other sites More sharing options...
Laurence Posted September 8, 2010 Share Posted September 8, 2010 No Comments? I guess i will submit it as a bug then. Link to comment Share on other sites More sharing options...
Recommended Posts