Jump to content

Add products


ansonete
 Share

Recommended Posts

Hi,

Im trying to add dynamically a product but i don't manage. My main issue is that i am able to add it to the database but i can never see it displayed neither in the frontend nor in the admin part. Also when i do insert it through the admin part, in the database the column "indexed" in the table "ps_product" is true, but when i do by code always false although i put the member class of the Product class to true.

Any idea?

Here is my code:

Note: the manufacturer, supplier and category i put harcoded the ones prestashop added me by default

$product = new Product();

$product->name = "test book";
$product->price = "10";
$product->id_manufacturer=2;
$product->id_supplier=2;
$product->id_tax=1;
$product->id_category_default=3;
$product->indexed = true;
$product->quantity=10;

if ($product->add())
{
....

And in here in theory my product is added, appears in the database but never anywhere in the website...

Thanks in advance.

Share this post


Link to post
Share on other sites

First the name property needs to be an array in the form of (id_lang=>name). Then you also need to link it with a category, even if you set the default category.

$product->updateCategories(array(3));

You should do that after you add the product.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More