I need to write a Shopware plugin that extends customer model with external_id
field. This field should be editable through the admin UI and API.
I've found, that I can add attribute to user like so:
public function addAttributes() {
$this->Application()->Models()->addAttribute(
's_user_attributes',
'bla',
'externalId',
'INT(11)',
true,
null
);
$this->Application()->Models()->generateAttributeModels(array(
's_user_attributes'
));
}
What should I do to show this field in the UI and API?
PS: Shopware 5
addAttribute
is deprecated in Shopware 5. Use shopware_attribute.crud_service
from the Shopware()
-container instead.
$service = Shopware()->Container()->get('shopware_attribute.crud_service');
$service->update('s_user_attributes', 'bla', 'integer', [
'label' => '',
'supportText' => '',
'helpText' => '',
'translatable' => false,
'displayInBackend' => true,
'position' => 1
]);
Shopware()->Models()->generateAttributeModels(
array(
's_user_attributes'
)
);
If you set displayInBackend
to true
, you can edit it in the Backend, where the user is.
More at the Shopware Developer Guide .
For the backend you have to to do some ExtJs coding .
For the API you have to extend the REST-API endpoint for the user :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.