Reputation: 21
Having gained no response on the official Prestashop forum, I thought I would try turning to you guys, my first post. Thanks for reading.
I am building a site that sells personalized items, and it is essential that i can limit the characters entered into the customization fields for each item, a feature that is still sadly missing from Prestashop, so I am endeavoring to incorporate the feature myself.
Having tinkered about a bit, I have the front end working nicely, using maxlength to limit the characters allowed in the customization input field using a value read from the database in a new field 'max_chars' in the ps_customization_field (entering the values manually at the moment)
But now I have reached the limit of my knowledge and as much as i hunt around and tinker I cannot get the last bit done, so hopefully someone more knowledgeable than I can help.
Basically, when creating the customization fields in the back office, I need an extra input field that allows me to enter the max_chars for each customization, I then need this value to be written to the database in the max_chars
field of ps_customization_field table.
TL:DR How do i create a new field in the back office product customization area and save the input to the db.
Kind regards, Clive
Upvotes: 2
Views: 9202
Reputation: 61
To display your inputs you need to override the method _displayLabelField
in controllers/admin/AdminProdutsController.php
.
To update the fields you need to override the method updateLabels
in classes/Product.php
.
Upvotes: 0
Reputation: 407
I think you should create a module for that. Simply make a module which add a tab to the admin product controller, and list all customized field created. Then, make a form with a simple id_customization => maxcharacter relationship.
The last thing you need is to create a hook in this module and add it in the product front controller where customizations are saved (inside initContent i think). This hook will do the validation and may cancel the process by throwing an error (a prestashop's error of course).
With that, you can add some extra validations for your fields, like a type validation, or anything else.
If you never made it, you should try this one : create a module
Here are some extra clues :
Hook for extra product tabs :
$this->registerHook('displayAdminProductsExtra')
Create the validation hook :
$this->registerHook('CFvalidation')
Handle it :
public function hookCFvalidation($param)
{
//Validate the customized values in the $_POST
//return formated errors if any or nothing if it's valid
}
Add it in the overrided product controller :
[...]
if (Tools::isSubmit('submitCustomizedDatas'))
{
$this->errors[] = Hook::exec('CFvalidation');
[...]
}
Upvotes: 0
Reputation: 5217
Your question about "how to save input to my db" is too broad to be answered in a single answer. Look up how SQL queries and PDO work, as they may give you an idea on how to start.
Displaying your customization fields in the frontend can be done as following with Smarty:
{foreach $inputfields as $field}
<input type="{$field.type}" name="{$field.name}" maxlength="{$field.maxlength}">
{/foreach}
Upvotes: 0