Jose Castillo
Jose Castillo

Reputation: 47

Prestashop products inserted by db not showing

I'm making a script for Prestashop 1.7.2 which one auto insert feed of data taken by an api, I create the products, categories (linking them), but when I go to the back office is not showed, I think about a field in database with wrong value or empty, this is my first script for PS and I´m learning the structure of the database. Any clue is helpfull.

Here you have the insert code.

INSERT into ps_product (id_product, id_category_default, ean13, quantity, price, reference, width, height, depth, weight, id_supplier, id_shop_default, id_tax_rules_group, available_for_order, state) 
VALUES (".$id_nova." ,'".$categoria."', '".$ean."', '".$cantidad."', '".$precio."', '".$referencia."', '".$ancho."', '".$altura."', '".$profundidad."', '".$peso."', '0', '1','1', '1', '1') 

Also I insert this for the name and description.

INSERT into ps_product_lang ( id_product, id_shop, id_lang, description, description_short, link_rewrite,  name )
VALUES ('".$id_nova."', '1', '".$x."', '".$contenido."', '".$contenido."', '".str_replace(" ","-",$nombre)."', '".$nombre."')"

Upvotes: 0

Views: 1258

Answers (3)

Marcin Jaworski
Marcin Jaworski

Reputation: 340

You need to insert also to ps_product_shop. Adding products by SQL is not good idea becouse there is many dependencis. Better way is use API or CSV import. In product class you have $definitons array it is kinda of map for DB.

https://devdocs.prestashop.com/1.7/development/database/objectmodel/

Upvotes: 0

Jose Castillo
Jose Castillo

Reputation: 47

Finally I desist doing this by queries, now im using prestashop clases, and they work in good way and realy easy, just I dont know why all is working fine but the stock isnt updated, I post the code that worked for my inserts.

Code here

Some fields arent taken, so I update them with queries, and also I´m having troubles with the rewrite_link field, the class cant validate it sometimes but I have created the products and also the image attachment.

Upvotes: 1

Hamed
Hamed

Reputation: 26

you have missing ' in your first query, try this :

insert into ps_product (id_product, id_category_default, ean13, quantity, price, reference, width, height, depth, weight, id_supplier, id_shop_default, id_tax_rules_group, available_for_order, state) VALUES ('".$id_nova."' ,'".$categoria."', '".$ean."', '".$cantidad."', '".$precio."', '".$referencia."', '".$ancho."', '".$altura."', '".$profundidad."', '".$peso."', '0', '1','1', '1', '1')

Upvotes: 0

Related Questions