Today I encountered a “Code already exists.” error in Magento when trying to save a massive amount of Tax Rates to a Tax Rule.
After some debugging, I noticed that I could only save up to a certain amount of Tax Classes to a rule, before receiving the following error message:
Code already exists.
Magento’s error message wasn’t very helpful, so I dove into the Models & Controllers and found the cause was due to the
$_POST data not being submitted in full; leaving off important data required for Magento to save the rule to the database.
To fix this, I had to modify the
max_input_vars for PHP, which by default limits the variables passed through
1000. Since I was saving close to 2500 tax rates to the rule, only half of those were being passed, and the tax rule id data at the end of the Magento object was being cut off.
1. Open your
php.ini file (the location may vary for you)
2. Update (or add if it doesn’t exist) the following line:
3. Save your php.ini file
4. Try saving your Tax Rule in Magento.
I had the same issue, but another solution. In our case a module create an identical named tax rule programmatically. So changing this manually didn’t work until we changed the name of the other rule to something else.