Aimeos Autofill plugin conflict with jsonapi service update
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Aimeos Autofill plugin conflict with jsonapi service update
Laravel framework version: 10.16.1
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux
Hello,
There is a conflict between the built-in autofill plugin and the jsonapi.
If a service is updated (changed) through the jsonapi, the autofill plugin prevents the service from being changed.
I think this is because the service gets removed before getting replaced with a different service, causing it to be re-added by the autofill plugin.
Can you look into this?
Thanks!
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux
Hello,
There is a conflict between the built-in autofill plugin and the jsonapi.
If a service is updated (changed) through the jsonapi, the autofill plugin prevents the service from being changed.
I think this is because the service gets removed before getting replaced with a different service, causing it to be re-added by the autofill plugin.
Can you look into this?
Thanks!
Re: Aimeos Autofill plugin conflict with jsonapi service update
We've made a little change in dev-master and 2023.07.x-dev to be able to replace existing service options even if the Autofill plugin is active. Can you give it a try?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

Re: Aimeos Autofill plugin conflict with jsonapi service update
I can't update from 2023.04.*, because it breaks changes I've done in the backend.
You've been changing the backend structure to add Vue JS support.
It will take some time before I understand how you've changed the backend before I can update it and implement my changes, and I'm working on other things right now.
Can you tell me what exactly you changed to make it work?
You've been changing the backend structure to add Vue JS support.
It will take some time before I understand how you've changed the backend before I can update it and implement my changes, and I'm working on other things right now.
Can you tell me what exactly you changed to make it work?
Re: Aimeos Autofill plugin conflict with jsonapi service update
These are the changes:
https://github.com/aimeos/ai-client-jso ... 1ff1bb67f9
https://github.com/aimeos/ai-client-jso ... 1ff1bb67f9
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,

Re: Aimeos Autofill plugin conflict with jsonapi service update
Yes, that seems to work.
https://aimeos.org/docs/2023.x/config/c ... et/#name_4
https://aimeos.org/docs/2023.x/config/c ... et/#name_4
Code: Select all
'client' => [
'jsonapi' => [
'basket' => [
'service' => [
'name' => 'StandardCustom',
]
]
],
],
Code: Select all
<?php
namespace Aimeos\Client\JsonApi\Basket\Service;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
class StandardCustom extends Standard
{
private \Aimeos\Controller\Frontend\Basket\Iface $controller;
/**
* Initializes the client
*
* @param \Aimeos\MShop\ContextIface $context MShop context object
*/
public function __construct( \Aimeos\MShop\ContextIface $context )
{
parent::__construct( $context );
$this->controller = \Aimeos\Controller\Frontend::create( $this->context(), 'basket' );
}
/**
* Updates the resource or the resource list partitially
*
* @param \Psr\Http\Message\ServerRequestInterface $request Request object
* @param \Psr\Http\Message\ResponseInterface $response Response object
* @return \Psr\Http\Message\ResponseInterface Modified response object
*/
public function patch( ServerRequestInterface $request, ResponseInterface $response ) : \Psr\Http\Message\ResponseInterface
{
$view = $this->view();
try
{
$this->clearCache();
$this->controller->setType( $view->param( 'id', 'default' ) );
$body = (string) $request->getBody();
if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) ) {
throw new \Aimeos\Client\JsonApi\Exception( 'Invalid JSON in body', 400 );
}
if( !is_array( $payload->data ) ) {
$payload->data = [$payload->data];
}
$cntl = \Aimeos\Controller\Frontend::create( $this->context(), 'service' );
if( $type = $view->param( 'relatedid' ) ) {
$this->controller->deleteService( $type );
}
foreach( $payload->data as $pos => $entry )
{
if( !isset( $entry->id ) ) {
throw new \Aimeos\Client\JsonApi\Exception( 'Service type (ID) is missing', 400 );
}
if( !isset( $entry->attributes ) ) {
throw new \Aimeos\Client\JsonApi\Exception( 'Service attributes are missing', 400 );
}
if( !isset( $entry->attributes->{'service.id'} ) ) {
throw new \Aimeos\Client\JsonApi\Exception( 'Service ID in attributes is missing', 400 );
}
$item = $cntl->uses( ['media', 'price', 'text'] )->get( $entry->attributes->{'service.id'} );
unset( $entry->attributes->{'service.id'} );
$this->controller->addService( $item, (array) $entry->attributes, $pos );
}
$view->item = $this->controller->get();
$status = 200;
}
catch( \Aimeos\MShop\Plugin\Provider\Exception $e )
{
$status = 409;
$errors = $this->translatePluginErrorCodes( $e->getErrorCodes() );
$view->errors = $this->getErrorDetails( $e, 'mshop' ) + $errors;
}
catch( \Aimeos\MShop\Exception $e )
{
$status = 404;
$view->errors = $this->getErrorDetails( $e, 'mshop' );
}
catch( \Exception $e )
{
$status = $e->getCode() >= 100 && $e->getCode() < 600 ? $e->getCode() : 500;
$view->errors = $this->getErrorDetails( $e );
}
return $this->render( $response, $view, $status );
}
}
Re: Aimeos Autofill plugin conflict with jsonapi service update
There is another problem.
Now the notifications get called multiple times for the same service.
'addService.after' and 'addService.before' get called twice when the service is updated.
The first time notification occurs, is when the service is added with its default values by the AutoFill plugin.
The second time is with my updated values of the service.
That makes it impossible to track changes in the service through my plugin, because every time it's the default value.
Now the notifications get called multiple times for the same service.
'addService.after' and 'addService.before' get called twice when the service is updated.
The first time notification occurs, is when the service is added with its default values by the AutoFill plugin.
The second time is with my updated values of the service.
That makes it impossible to track changes in the service through my plugin, because every time it's the default value.
Re: Aimeos Autofill plugin conflict with jsonapi service update
I found a solution.
I added a bool parameter to every method that sends notifications in this class:
Aimeos\MShop\Order\Item\Base
The AutoFill plugin should set that bool parameter to false when calling deleteService(), addService(), etc.
I added a bool parameter to every method that sends notifications in this class:
Aimeos\MShop\Order\Item\Base
The AutoFill plugin should set that bool parameter to false when calling deleteService(), addService(), etc.
Re: Aimeos Autofill plugin conflict with jsonapi service update
This is a side effect of the event system which calls the plugins whenever the basket is modified.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
