JsonApi - Update services not working

Help for integrating the Laravel package
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!
kdim95
Advanced
Posts: 207
Joined: 26 Aug 2022, 12:17

JsonApi - Update services not working

Post by kdim95 » 06 Jul 2023, 23:54

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):

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.

kdim95
Advanced
Posts: 207
Joined: 26 Aug 2022, 12:17

Re: JsonApi - Update services not working

Post by kdim95 » 07 Jul 2023, 00:04

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.

Post Reply