Ikoshop Posted 17 hours ago Share Posted 17 hours ago I have a function attached to a hook which should add a category $category = new Category(); $category->name = 'foobar'; $category->active = true; $category->id_parent = 2; $category->level_depth = 2; $category->add(); When I click the button, the function runs but returns this error Property Category->name is empty. I double-check by logging the value of $category->name before the add() call and it's correct. Why would it give this error? Link to comment Share on other sites More sharing options...
Ikoshop Posted 17 hours ago Author Share Posted 17 hours ago Going off the definition of the Category class, if I replace the add(); by Hook::exec('actionCategoryAdd', ['category' => $category]); then it adds the category and category shop entries to the database but not the category_lang entry, so that's a bit useless. Might as well just insert the three tables manually I guess. Bit weird to have these functions that don't do what they're supposed to though Link to comment Share on other sites More sharing options...
Nickz Posted 17 hours ago Share Posted 17 hours ago What are you trying to accomplish? What addon, module or theme you wish to add? Link to comment Share on other sites More sharing options...
Ikoshop Posted 15 hours ago Author Share Posted 15 hours ago Thank you. It's my own module. I'm trying to sychronise products between Prestashop and a POS database. In this particular instance a new category has been added to the POS database and when I click a button in Prestashop it should get this new info from the POS DB and add a new category to the Prestashop DB. The SQL request equivalent of what I want to do is (roughly) this: But I'd prefer a more elegant solution with Prestashop's own methods, if possible. Link to comment Share on other sites More sharing options...
Prestashop Addict Posted 13 hours ago Share Posted 13 hours ago Hi, the name is required filed of the class Link to comment Share on other sites More sharing options...
Ikoshop Posted 13 hours ago Author Share Posted 13 hours ago Yes, that's why I added the name and checked that the name was set before calling add() . Have I done it wrong? Link to comment Share on other sites More sharing options...
QuickUpdate.net Posted 13 hours ago Share Posted 13 hours ago (edited) regarding your first question, in some versions of prestashop (>1.6) the name field is actually an array with the indexes being the language id for the respective string so in your case what may work is: $category->name = [1 => 'foobar', 2=> 'foobar_2'], "1" and "2" being the language ids you want to update, can be only one or more / but must be at least you default shop language id Edited 9 hours ago by QuickUpdate.net (see edit history) Link to comment Share on other sites More sharing options...
Prestashop Addict Posted 12 hours ago Share Posted 12 hours ago Yes change your code to $category->name[$idLang]; 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