Extending Aimeos JSON API to Include Custom Customer Fields
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- Paulus-Ragnarr
- Posts: 15
- Joined: 15 Oct 2024, 07:02
Extending Aimeos JSON API to Include Custom Customer Fields
Hi Aimeos,
I've added a new column, national_id, to the customer (Users) table following the steps outlined in the documentation:
https://aimeos.org/docs/2024.x/models/extend-managers/
https://aimeos.org/docs/2024.x/models/e ... /#easy-way
https://aimeos.org/docs/2024.x/models/e ... custom-way
I would like to know how to extend the JSON API to include this new field, specifically for the "Change Customer Data" and "Fetch Customer Data" routes. I attempted to add national_id in the request body, but it didn’t update the field in the database.
Are there additional configurations needed to enable this custom field in the API responses and allow it to be updated correctly?
Thanks in advance!
I've added a new column, national_id, to the customer (Users) table following the steps outlined in the documentation:
https://aimeos.org/docs/2024.x/models/extend-managers/
https://aimeos.org/docs/2024.x/models/e ... /#easy-way
https://aimeos.org/docs/2024.x/models/e ... custom-way
I would like to know how to extend the JSON API to include this new field, specifically for the "Change Customer Data" and "Fetch Customer Data" routes. I attempted to add national_id in the request body, but it didn’t update the field in the database.
Are there additional configurations needed to enable this custom field in the API responses and allow it to be updated correctly?
Thanks in advance!
Code: Select all
Enviroment: Aimeos-headless
Aimeos version: 2024.07.*
Laravel: 11
Mac OS
Re: Extending Aimeos JSON API to Include Custom Customer Fields
This one should be sufficient:
https://aimeos.org/docs/2024.x/models/e ... /#easy-way
Can you show your code and configuration you've added?
https://aimeos.org/docs/2024.x/models/e ... /#easy-way
Can you show your code and configuration you've added?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
- Paulus-Ragnarr
- Posts: 15
- Joined: 15 Oct 2024, 07:02
Re: Extending Aimeos JSON API to Include Custom Customer Fields
Hello, Here's the codes
Schema
Customer Decorator
Mshop config
Schema
Code: Select all
<?php
return array(
'table' => array(
'users' => function ( \Aimeos\Upscheme\Schema\Table $table ) {
$table->string('national_id', 20)->null( true );
$table->string('provider_id')->null( true );
$table->string('provider_name', 20)->null( true );
},
),
);
Code: Select all
<?php
namespace Aimeos\MShop\Product\Manager\Decorator;
/**
* Manager decorator for Catalog
*
* @see https://aimeos.org/docs/2024.x/models/extend-managers/#easy-way
*/
class CustomerDecorator extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
private $attr = [
'national_id' => [
'internalcode' => 'mcus."national_id"',
'label' => 'National ID',
'type' => 'string',
],
'provider_id' => [
'internalcode' => 'mcus."provider_id"',
'label' => 'Provider ID',
'type' => 'string',
],
'provider_name' => [
'internalcode' => 'mcus."provider_name"',
'label' => 'Provider name',
'type' => 'string',
],
];
/**
* @return array
*/
public function getSaveAttributes() : array
{
return parent::getSaveAttributes() + $this->createAttributes( $this->attr );
}
/**
* @param bool $withsub
* @return array|\Aimeos\Base\Criteria\Attribute\Iface[]
*/
public function getSearchAttributes( bool $sub = true ) : array
{
return parent::getSearchAttributes( $sub ) + $this->createAttributes( $this->attr );
}
}
Code: Select all
<?php
return [
'customer' => [
'manager' => [
'decorator' => [
'local' => ['CustomerDecorator']
]
]
]
];
Re: Extending Aimeos JSON API to Include Custom Customer Fields
The namespace of your decorator is wrong and must be:
Code: Select all
namespace Aimeos\MShop\Customer\Manager\Decorator;
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star