TomBar Posted May 19, 2020 Share Posted May 19, 2020 (edited) Hello, I'm trying to create a product programatically using ProductCore class. Product is being created but quantity always stays at 0 while in my code I set it to 5. Any suggestions? Code that I'm using and working perfectly apart quantity: $product = new ProductCore(); $product->reference = '123456'; $product->quantity = 5; $product->name = "Sample product"; $product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => Tools::str2url("Sample product")); $product->id_category_default = 2; $product->category = 2; $product->price = 50; $product->add(); Using Prestashop 1.7.6.5 Edited May 19, 2020 by TomBar (see edit history) Link to comment Share on other sites More sharing options...
gusman126 Posted May 20, 2020 Share Posted May 20, 2020 try use StockAvailable::setQuantity($id_product, $id_attribute, $quantity, $id_shop = null); 1 Link to comment Share on other sites More sharing options...
TomBar Posted May 20, 2020 Author Share Posted May 20, 2020 1 hour ago, gusman126 said: try use StockAvailable::setQuantity($id_product, $id_attribute, $quantity, $id_shop = null); This is the solution. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now