Jump to content

How to add a new attribute group programmatically?


Recommended Posts

Hello,

 

I am trying to add a new attribute group, programmatically, by getting values from a form in the back office this way. I The values of the inputs to the php file using ajax.

$newGroup = new AttributeGroup();
$newGroup->name = $name[0];
$newGroup->public_name = $public_name;
$newGroup->group_type = 'select';
$newGroup->add();

but I get this error message in the console ""Uncaught PrestaShopException: Property AttributeGroup->name is empty"

A new attribute group with no name is added in the product attributes list

 

Is this an incorrect way of adding a new attribute group? If so, how can I do this?

 

Help will be greatly appreciated

Link to comment
Share on other sites

Hello,

You need to specify the language id.

You can set it this way:

$newGroup = new AttributeGroup(null, $id_lang);

Or this way:

$newGroup = new AttributeGroup();
$newGroup->name[$id_lang] = 'some name';
$newGroup->public_name[$id_lang] = 'some name';

Where the $id_lang is some language id, for example $this->context->language->id

  • Like 1
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...