PhpMadman Posted February 14, 2016 Share Posted February 14, 2016 I'm trying to add a product from my module. The idea it so use PrestaShop webservice to get product information from our second server and then use the PS classes to create a product on the first server. I get the info with WebService without any problems. And the product gets created, but it's not complete. $nlProduct = new Product(1596); // Remove ID later $nlProduct->id_category_default = 2; $nlProduct->id_category[]=$nlProduct->id_category_default; $nlProduct->new; $nlProduct->type = "simple"; $nlProduct->reference = $sgProduct->reference; $nlProduct->weight = $sgProduct->weight; $nlProduct->price = ceil($sgProduct->wholesale_price*1.25); $nlProduct->wholesale_price = $sgProduct->wholesale_price; $nlProduct->active = 0; $nlProduct->available_for_order = 1; $nlProduct->show_price = 1; $languages = Language::getLanguages(); foreach($languages as $lang){ $nlProduct->name[$lang['id_lang']] = $sgProduct->name->language; $nlProduct->description[$lang['id_lang']] = $sgProduct->description->language; } echo($sgProduct->name->language); // $nlProduct->add(); $nlProduct->update(); I added the ID number for the new product and changed to update while testing. $sgProduct is the data from WebService, and $sgProduct->name->language does contain the name I want. But the $nlProduct does no write any name to PrestaShop. And also, the category does not get set, it has not categories selected in PS. What am I missing here? Link to comment Share on other sites More sharing options...
PhpMadman Posted February 14, 2016 Author Share Posted February 14, 2016 If I use PrestaShop's BO and add category and a random name to the product, the code works and updates to the correct name and category. But if I use the code to add() the product, still no name and category, and if i change to update() again it does not set the name, and it give me a 500 Internal Error only visible in FireBug. Link to comment Share on other sites More sharing options...
PhpMadman Posted February 15, 2016 Author Share Posted February 15, 2016 (edited) Another update. Even this small code causes 500 Error, and second ECHO is not displayed in browser, but still updates the reference. echo('Test Code<br>'); $resource = new Product(1599); $resource->reference = 'TEST '.date('Y-m-d H:i:s'); $resource->update(); $resource = null; echo('Test Code End<br>'); Edited February 15, 2016 by PhpMadman (see edit history) Link to comment Share on other sites More sharing options...
jgamio Posted February 18, 2016 Share Posted February 18, 2016 These is a question why you use $resource->update(); instead of $resource->save(); Link to comment Share on other sites More sharing options...
PhpMadman Posted February 29, 2016 Author Share Posted February 29, 2016 These is a question why you use $resource->update(); instead of $resource->save(); Beacuse i'm updateing a product. But neither update, add or save works, all of them gives me a 500 Error, Link to comment Share on other sites More sharing options...
jgamio Posted March 1, 2016 Share Posted March 1, 2016 Ok 1- if you use save the object create or update the record with the id 2- Do you have develop mode on ? 3- do you have access to your server log? To find out the error we need to know where is the mistake Link to comment Share on other sites More sharing options...
PhpMadman Posted March 2, 2016 Author Share Posted March 2, 2016 (edited) Hmm. Seems I never uploaded the file to enable dev mode. It's the little things. It was missing link_rewrite. Added that, name and description and my test code worked just fine. And also, this error did not produce any error / server log *EDIT* Real code works fine, all text / price file gets updated. Now I'll just need to figure out how to download and add the product images... Thanks for you help. Edited March 2, 2016 by PhpMadman (see edit history) 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