Prestashop duplicate products error
May 2, 2009 – 9:01 pmThe admin tool for Prestashop is slick, but the pure ajax pages slows me down when pages have to refresh. One good thing about zencart was that I could modify attributes without having to load other information about the products. Plus, I could switch from one product to another very easily.
As soon as I add an attribute to a product, like telling the system that I want to sell the mask in blue, the system has to reload a lot of information. So, there’s always a pause before I can add another color mask. It would have been been nice to take an existing product and just duplicate it a few times since practically all the masks have the same colors. Unfortunately, the duplicate product feature isn’t working for me, and I wind up with a “an error occurred while creating object” error message.
It duplicates the product in the “ps_products” and “ps_products_lang” tables, but not in the important “ps_category_product”, “ps_product_attribute” and “ps_product_attribute_combinations” tables. The ps_category_product table is easy to modify and there’s very little needed to get the product into the table. I’ve figured out the other two tables, but they require a little coordination. I’m going to try skipping that routine tonight and try the product attribute import feature. I hope that will make things easier. I really ought to import products to speed things up!
update:
Well, the import of attributes worked once I realized that the fields were separated by semi-colons. I should have figured that out sooner, but when the tool says to import a CSV file, that notion gets confusing. A comma separated file implies that fields are separated by commas! So, I had to load my CSV file in Excel and search/replace the commas to be semi-colons.
So, the import did work, but one problem is that it duplicates options in the database. I don’t need more than one “blue” attribute in the database. It would be nice if it I could have provided the id value for blue instead of it creating a new attribute. So, this isn’t going to work for me.
The answer is straight database hacking inserts for now … The ps_product_attribute table is only important to me for 3 fields: id_product_attribute (auto_increment), id_product, and default_on. So, my insert will just be
“insert into ps_product_attribute (id_product, default_on) values (126, 0)”, and I’ll run that statement for each attribute I want to insert for a product. For the first attribute, I’ll change that 0 to a 1 to designate it as the default attribute. All this does is tell the database that I want to create an attribute for the product, and it produces a primary key id_product_attribute that I’ll use to actually specify what the attribute is.
So, in the “ps_product_attribute_combination” table, I will run
“insert into ps_product_attribute_combination (id_attribute, id_product_attribute) values (75, 245)” where the 75 is the id value for blue attribute, and the 245 is the primary key I just created. If I do this properly, I should be able to have a file with all the insert statements and just run through it all at once. As long as I keep my primary keys in order, this should work. Heh, if it doesn’t work, I’ll have to add an another update to this post!