Jump to content

Prestashop 1.6 display custom field in Feature Add/Edit form


jawaid

Recommended Posts

I am able to display my custom field in Feature Value Add/Edit form by overriding AdminFeaturesController and overriding initFormFeatureValue() function. I want to do the same for Feature Add/Edit form but cannot find function to override. I tried renderForm() function but didn't work. Which file/class/controller/function should I look into to override Feature Add/Edit form to display my custom field?

Link to comment
Share on other sites

Hard to say. A developer have to see all your code and debug it.

 

I fixed the issue. Solution is available here http://stackoverflow.com/questions/30472428/prestashop-1-6-display-custom-field-in-feature-add-edit-form

 

But now there is new problem that my custom field doesn't get saved in database while other default fields are.

 

My code is available at GitHub https://github.com/mjawaids/advancedfeaturesvalues

 

If anyone can see what the issue is and if I'm missing anything.

Link to comment
Share on other sites

  • 2 weeks later...

I had the same trouble, i want to show categories and asign features to product categories. I did it, i make a dropdown list, but it only save to database form info when i'm adding a feature, if i try to edit it dosn't work. To make the form saves, you have to edit /classes/feature.php and add to feature class new fields you want to save. you have edit definition too.

 

I don't know how to update the file, but if you are interested to see it, put a reply.

Link to comment
Share on other sites

  • 6 months later...

Hello,
 
I've got the same problem with my override of Feature class.
 
I modified feature.php and AdminFeaturesController.php to add my custom field and I created the field in database. When I add a new feature, my custom field is correctly saved in database and appears in my form. But when I'm editing an existing feature, my custom field is not saved.
 
Weirdly, i made the same process with Category class and it works fine !

 

Here is my code (my custom field is named "reference_lcv") :
 
Feature override

<?php
 
class Feature extends FeatureCore
{

	public $reference_lcv;
	
    public function __construct($id = null, $id_lang = null, $id_shop = null)
    {
      self::$definition['fields']['reference_lcv'] = array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255, 'required' => true);
      parent::__construct($id, $id_lang, $id_shop);
    }
}

?>

AdminFeaturesController override

<?php

class AdminFeaturesController extends AdminFeaturesControllerCore {
	
	public function __construct() {
		parent::__construct();
	}
	
	public function renderForm()
    {
        $this->toolbar_title = $this->l('Add a new feature');
        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Feature'),
                'icon' => 'icon-info-sign'
            ),
            'input' => array(
				// AJOUT LSM
				array(
                    'type' => 'text',
                    'label' => $this->l('Référence LCV'),
                    'name' => 'reference_lcv',
                    'lang' => false,
                    'required' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}'
                ),
			
                array(
                    'type' => 'text',
                    'label' => $this->l('Name'),
                    'name' => 'name',
                    'lang' => true,
                    'size' => 33,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
                    'required' => true
                )
            )
        );

        if (Shop::isFeatureActive()) {
            $this->fields_form['input'][] = array(
                'type' => 'shop',
                'label' => $this->l('Shop association'),
                'name' => 'checkBoxShopAsso',
            );
        }

        $this->fields_form['submit'] = array(
            'title' => $this->l('Save'),
        );

        return AdminController::renderForm();
    }
}

?>

Thanks for any help !

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