JsonApi - Update services not working
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!
JsonApi - Update services not working
Laravel framework version: 10.13.5
Aimeos Laravel version: ~2023.04
PHP Version: 8.2.7
Environment: Linux
URL:
/jsonapi/basket?id=default&related=service&relatedid=delivery&_token=<token>
Data:
{"data":[{"id":"service","attributes":{"service.id":"13"}}]}
Result:
It adds a second (delivery) service instead of replacing the existing one.
The documentation says, that it should get replaced:
https://aimeos.org/docs/2023.x/frontend ... e-services
Update service code (I pass the service item and csrf object):
Aimeos Laravel version: ~2023.04
PHP Version: 8.2.7
Environment: Linux
URL:
/jsonapi/basket?id=default&related=service&relatedid=delivery&_token=<token>
Data:
{"data":[{"id":"service","attributes":{"service.id":"13"}}]}
Result:
It adds a second (delivery) service instead of replacing the existing one.
The documentation says, that it should get replaced:
https://aimeos.org/docs/2023.x/frontend ... e-services
Update service code (I pass the service item and csrf object):
Code: Select all
updateService( service, _csrf ) {
return new Promise( (resolve, reject) => {
var params = {'data': [{
'id': service.type,
'attributes': {
'service.id': service.id,
}
}]};
var url = service.links['basket/service']['href']; // from service response
if( _csrf ) { // add CSRF token if available and therefore required
var csrf = {};
csrf[_csrf.name] = _csrf.value;
url += (url.indexOf('?') === -1 ? '?' : '&') + $.param(csrf);
}
$.ajax({
url: url,
method: "PATCH",
dataType: "json",
data: JSON.stringify(params)
}).done( function( result ) {
resolve( result );
});
});
},
Last edited by kdim95 on 07 Jul 2023, 00:06, edited 1 time in total.
Re: JsonApi - Update services not working
This seems to be a conflict between the Autofill plugin and the JsonApi.
The JsonApi removes the service to add the other one, but AutoFill adds it back.
After that, the JsonApi adds a second delivery service to the basket.
Currently I have disabled the AutoFill only for the delivery service.
The JsonApi removes the service to add the other one, but AutoFill adds it back.
After that, the JsonApi adds a second delivery service to the basket.
Currently I have disabled the AutoFill only for the delivery service.