Jump to content

[SOLVED in 1.3] Multiple tax rates are generated while doing product import (v1.3.0.1)


Recommended Posts

When i import a CSV with products then for every product also a new Tax rate is generated.
So when i have 100 products i get 100 new tax rates.
That is annoying because i have to delete all the tax rates and edit each product again.

Anybody has an idea how to solve this?
I checked the AdminImport.php file and Tax.php of both 1.2.5 and 1.3.0.1, but they are identical.
This code is responsible for checking if a Tax rate is already present in the database :

// Find id_tax corresponding to given values for product taxe
           if (isset($product->tax_rate))
               $product->id_tax = intval(Tax::getTaxIdByRate(floatval($product->tax_rate)));

           if (isset($product->tax_rate) AND !$product->id_tax)
           {
               $tax = new Tax();
               $tax->rate = floatval($product->tax_rate);
               $tax->name = self::createMultiLangField(strval($product->tax_rate));
               if (($fieldError = $tax->validateFields(UNFRIENDLY_ERROR, true)) === true AND ($langFieldError = $tax->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true AND $tax->add())
                   $product->id_tax = intval($tax->id);
               else
               {
                   $this->_errors[] = 'TAX '.$tax->name[$defaultLanguageId].' '.Tools::displayError('cannot be saved');
                   $this->_errors[] = ($fieldError !== true ? $fieldError : '').($langFieldError !== true ? $langFieldError : '').mysql_error();
               }
           }



and this is the code in the Tax.php

static public function getTaxIdByRate($rate)
   {
       $tax = Db::getInstance()->getRow('
           SELECT `id_tax`
           FROM `'._DB_PREFIX_.'tax`
           WHERE `rate` LIKE '.floatval($rate));
       return $tax ? intval($tax['id_tax']) : false;
   }



So is there some code error here?

Link to comment
Share on other sites

I have looked briefly in the AdminImport file.
The importing of manufacturers, (for example) is working fine.
I will try to see what code is not working here.

When a taxrate is updated in the table it uses a 19.000 format. Maybe the floatval gives a different number?
Or is the LIKE operand not correct ?

Link to comment
Share on other sites

I have changed the code in the /classess/Tax.php file and now the import does not create multiple tax rates.
Here is the new code (line 225)

static public function getTaxIdByRate($rate)
   {
       $tax = Db::getInstance()->getRow('
           SELECT `id_tax`
           FROM `'._DB_PREFIX_.'tax`
           WHERE `rate` = '.floatval($rate));
       return $tax ? intval($tax['id_tax']) : false;
   }



In the old code there was a LIKE statement in the WHERE clause. That didnt work.
Here is the old code :

    static public function getTaxIdByRate($rate)
   {
       $tax = Db::getInstance()->getRow('
           SELECT `id_tax`
           FROM `'._DB_PREFIX_.'tax`
           WHERE `rate` LIKE '.floatval($rate));
       return $tax ? intval($tax['id_tax']) : false;
   }



I reported it also in the Bug tracker. Hopefully it will be fixed in a2

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...