Jump to content

Add new field Suppliers


naulacambra

Recommended Posts

Hello,

 

i'm trying to add a field to suppliers, and let edit from admin panel.

 

The field is a list of categories.

 

I created a new AdminSuppliersController in 'override' folder. Overrided the function renderForm so now shows categories in a list of checkboxes.

 

 public function renderForm() {

/*NOT MODIFIED FROM ORIGINAL FUNCTION*/

//Categories
        $cat_opts = array();
        foreach (Category::getChildren((int) Category::getRootCategory()->id, Context::getContext()->language->id) as $category) {
            $cat_opts[] = array(
                'id' => (int) $category['id_category'],
                'name' => $category['name'],
                'val' => (int) $category['id_category']
            );
        }

$this->fields_form = array(
/*NOT MODIFIED FROM ORIGINAL FUNCTION*/
array(
                    'type' => 'checkbox',
                    'label' => $this->l('Categories'),
                    'name' => 'categories',
                    'values' => array(
                        'query' => $cat_opts,
                        'id' => 'id',
                        'name' => 'name'
                    )
                ),
/*NOT MODIFIED FROM ORIGINAL FUNCTION*/
}
I've overrided the Supplier class to add a new field.

 

class Supplier extends SupplierCore {

    public $categories;

    public function __construct($id = null, $id_lang = null) {
        self::$definition['fields']['categories'] = array(
            'type' => self::TYPE_STRING,
            'validate' => 'isGenericName');

        parent::__construct($id, $id_lang);
    }

}
But i can't imagine how to get and save the value of the checkboxes.

 

Anyone could help?

Link to comment
Share on other sites

I haven't found any proper way of handling checkboxes after a quick look, hopefully someone else will know one

 

If there isn't a default way of doing so, the only way I can think of offhand would be to also override the validateController (from ObjectModel) inside Supplier, putting in an action for the name of the field like it does with anything called 'passwd' (which you'd have to change from being categories due to not being specific enough)

 

You could then loop through all the checkboxes and store them as a serialized string of some kind, which you'd need to unserialize before the helperForm gets called again

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...