Jump to content

New Product Attribute Type


Daenu

Recommended Posts

Hi there

 

I'm an absolute newbie to PrestaShop but not in programming.

I'm trying to create a new product attribute type besides of

  • Dropdown list
  • Radio buttons
  • Color texture

I'd like to have a simple text field to choose (label).

What I did so far (not working)

  • I created a class in overrides/classes:
class Attribute extends AttributeCore
{
    /**
     * @see ObjectModel::$definition
     */
    public static $definition = array(
        'table' => 'attribute',
        'primary' => 'id_attribute',
        'multilang' => true,
        'fields' => array(
            'id_attribute_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
            'color' =>                array('type' => self::TYPE_STRING, 'validate' => 'isColor'),
            'position' =>            array('type' => self::TYPE_INT, 'validate' => 'isInt'),

            /* Lang fields */
            'name' =>                array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
        ),
'cable_label' =>                array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
        )
    );

}
  • I created a controller in overrides/controller:
class AdminAttributesGroupsController extends AdminAttributesGroupsControllerCore
{
/**
* AdminController::renderForm() override
* @see AdminController::renderForm()
*/
public function renderForm()
{
//...
$group_type = array(
array(
'id' => 'select',
'name' => $this->l('Drop-down list')
),
array(
'id' => 'radio',
'name' => $this->l('Radio buttons')
),
array(
'id' => 'color',
'name' => $this->l('Color or texture')
),
// My code
array(
'id' => 'cable_label',
'name' => $this->l('Cable Label')
),
// My code
);
// ...
}

public function renderFormAttributes()
{
// ...
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('Cable Label'),
'name' => 'cable_label',
'hint' => array(
$this->l('Lorem Ipsum.'),
$this->l('Dolor si ...!')
)
);


);
//...

}

Can anyone give me a hint or link to a tutorial on how to achieve that?

 

Thanks in advance

Edited by Daenu (see edit history)
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...