bvelichkov Posted April 22, 2013 Share Posted April 22, 2013 Hi, guys, Can somebody tell me how to save a custom field into ps_category_shop? So far I have created the custom value (boolean) and I'm getting and showing without any troubles it's value in the renderForm() function of the AdminCategoriesController. But where I have to put the code to save the value of this field when user presses Save? I have already written save procedure in the Category.php class, but I do not know where to call it. Sorry for this dumb question, any suggestions are highly appreciated. Thanks! Link to comment Share on other sites More sharing options...
Terragg Posted April 22, 2013 Share Posted April 22, 2013 My immediate thoughts are: Make sure you can actually see changes that you make directly to the database, and not just the default values. Make sure that you have a variable defined in your Category override to hold the value of the field. PrestaShop uses the object to update the database, if it's not in the object PS doesn't save it. Double check that when you define the extra column in the override's $definition['fields'] array, you make sure to use 'shop' => true after defining the type of column. PrestaShop usually does that right thing after all the definitions are taken care of. HTH, 1 Link to comment Share on other sites More sharing options...
bvelichkov Posted April 23, 2013 Author Share Posted April 23, 2013 Thanks for your answer. The new column is named 'active_frontpage' and exists in ps_category_shop Then, in the override/classes/Category.php I have public $active_frontpage = 1; then, in the $definition['fields'] I'm putting 'active_frontpage' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => false, 'shop' => true) and this gives SQL exception, because it tries to update ps_category, but the column is in the ps_category_shop Link to comment Share on other sites More sharing options...
Terragg Posted April 23, 2013 Share Posted April 23, 2013 Add the column to the category table as well. Think of any *_shop table as holding a 'shop specific' version of the data that overrides any data in the main table. HTH, Link to comment Share on other sites More sharing options...
bvelichkov Posted April 25, 2013 Author Share Posted April 25, 2013 Yes, you are right, that did the trick. But now saving the category makes any image associated to it to disappear. Link to comment Share on other sites More sharing options...
Terragg Posted April 25, 2013 Share Posted April 25, 2013 I haven't done much work with category images, but since category images are hard-coded to the category's id ( tehy should be in [store_directory]/img/c/ or where ever your store's _PS_CAT_IMG_DIR_ is pointing ) either the save form generated by AdminCategoryController is telling your store to remove them, or the id_category is changing. I would definitely focus on the form. HTH, 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