Jump to content

Custom field in ps_category_shop


bvelichkov

Recommended Posts

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

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,

  • Like 1
Link to comment
Share on other sites

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

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

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
×
×
  • Create New...