DELETING ALL BASKET SERVICES BY TYPE
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!
DELETING ALL BASKET SERVICES BY TYPE
I would like to delete all payment services of my current basket in one time :
1/ I tried :
But it doesn't seem to work... do you know what is wrong?
2/ Is there a way to do that with JSON API?
Thank you very much,
sbn
1/ I tried :
Code: Select all
$context = app()->make('\Aimeos\Shop\Base\Context')->get();
$controller = \Aimeos\Controller\Frontend\Factory::createController($context, 'basket' );
$basket = $controller->get();
$basket->deleteService('payment' );
2/ Is there a way to do that with JSON API?
Thank you very much,
sbn
Re: DELETING ALL BASKET SERVICES BY TYPE
In principle, your code is correct. The only thing that might be a problem is that you might not have the right locale available if you don't pass the same site/language/currency parameters to your controller action that are available in Aimeos controller actions.
Sure, you can use the JSON REST API to remove the delivery or payment service from the basket. The JSON basket representation you get contains something like this:
Use the links/self/href URL in combination with the DELETE HTTP method to remove the service item from the basket.
Sure, you can use the JSON REST API to remove the delivery or payment service from the basket. The JSON basket representation you get contains something like this:
Code: Select all
"included": [{
"id": "delivery",
"type": "basket/service",
"attributes": {
"order.base.service.id": null,
"order.base.service.code": "demo-dhl",
"order.base.service.serviceid": "10",
"order.base.service.name": "DHL",
"order.base.service.mediaurl": "http://demo.aimeos.org/media/service/dhl.png",
"order.base.service.type": "delivery",
"order.base.service.price": "0.00",
"order.base.service.costs": "5.90",
"order.base.service.rebate": "0.00",
"order.base.service.taxrate": "20.00"
},
"links": {
"self": {
"href": "http://localhost/jsonapi/basket/default/service/delivery",
"allow": ["DELETE"]
}
}
}]
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
Re: DELETING ALL BASKET SERVICES BY TYPE
Ok thank you very much !
If I well understand, with JSON API, I need to :
- make an OPTIONS request
- then make another request to get the current basket content
- then create a loop on the response data and send a DELETE request for each 'basket/service' item
Is there a way to delete all services in only one request?
If I well understand, with JSON API, I need to :
- make an OPTIONS request
- then make another request to get the current basket content
- then create a loop on the response data and send a DELETE request for each 'basket/service' item
Is there a way to delete all services in only one request?
Re: DELETING ALL BASKET SERVICES BY TYPE
You always need the OPTIONS request first to know what are your available resources but that request is only required once during/after the page load.
You are right, you need to get the basket but you can remove all delivery or payment service items in the basket at once using that link provided in the basket:
You are right, you need to get the basket but you can remove all delivery or payment service items in the basket at once using that link provided in the basket:
Code: Select all
"links": {
"self": {
"href": "http://localhost/jsonapi/basket/default/service/delivery",
"allow": ["DELETE"]
}
}
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
Re: DELETING ALL BASKET SERVICES BY TYPE
Ok !! Thank you very much