Problem using multiple basket - cannot save basket
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!
- FaheemAbrar
- Posts: 2
- Joined: 04 Jan 2021, 05:00
Problem using multiple basket - cannot save basket
Aimeos Version: 2020.10
PHP version: 7.4
Environment: Windows 10 WSL2
According to aimeos docs, we can create multiple baskets by passing different values for the "id" parameter, e.g.
When I try to use this functionality to work with a basket of custom ID, I encounter problem when I try to save the basket.
Everything works fine for the other basket functionalities - products are added properly, delivery and payment address added properly, delivery and payment method added properly. However, when I try to use the basket resource href to save the basket, I always encounter the following error -
I tried using the basket without a custom ID, and saving the basket worked flawlessly in this case. The problem only occurs when I define a custom basket ID to get multiple baskets.
Can anyone please help me out here?
PHP version: 7.4
Environment: Windows 10 WSL2
According to aimeos docs, we can create multiple baskets by passing different values for the "id" parameter, e.g.
Code: Select all
curl -b cookies.txt -c cookies.txt \
-X GET 'http://localhost:8000/jsonapi/basket?id=second'
Everything works fine for the other basket functionalities - products are added properly, delivery and payment address added properly, delivery and payment method added properly. However, when I try to use the basket resource href to save the basket, I always encounter the following error -
Code: Select all
Basket empty
Can anyone please help me out here?
Re: Problem using multiple basket - cannot save basket
Can you please investigate a bit further what might be the problem?
A JSON API POST request to store the basket is done here and uses the custom ID:
https://github.com/aimeos/ai-client-jso ... d.php#L191
The store() method of the basket frontend controller is implemented here:
https://github.com/aimeos/ai-controller ... d.php#L122
Does the error (exception) occurs in this line?
https://github.com/aimeos/ai-controller ... d.php#L180
or in that line?
https://github.com/aimeos/ai-controller ... d.php#L183
You should also enable the debug setting of the JSON REST API to see the stack trace:
Can you post the stack trace that is then returned?
A JSON API POST request to store the basket is done here and uses the custom ID:
https://github.com/aimeos/ai-client-jso ... d.php#L191
The store() method of the basket frontend controller is implemented here:
https://github.com/aimeos/ai-controller ... d.php#L122
Does the error (exception) occurs in this line?
https://github.com/aimeos/ai-controller ... d.php#L180
or in that line?
https://github.com/aimeos/ai-controller ... d.php#L183
You should also enable the debug setting of the JSON REST API to see the stack trace:
Code: Select all
client/jsonapi/debug => 1
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
- FaheemAbrar
- Posts: 2
- Joined: 04 Jan 2021, 05:00
Re: Problem using multiple basket - cannot save basket
Apologies for the delay. I have described the error in detail below, and also propose a solution for it.
The error happens in the following link -
https://github.com/aimeos/ai-client-jso ... d.php#L188
Here's the error from the json response -
The problem here is that when is called, the controller does not have the basket id set at that point, so the controller thinks the basket is empty. The solution is to set the basket id in the controller before the check function is called, e.g.
I tried in on my end, seems to be working fine.
I'll try to create a PR for it if I have some time. Please let me know if the fix is good.
Update: Opened a PR - https://github.com/aimeos/ai-client-jsonapi/pull/10
The error happens in the following link -
https://github.com/aimeos/ai-client-jso ... d.php#L188
Here's the error from the json response -
Code: Select all
"errors": [{"title":"Basket empty","detail":"#0 \/app\/ext\/ai-client-jsonapi\/client\/jsonapi\/src\/Client\/JsonApi\/Basket\/Standard.php(188): Aimeos\\MShop\\Order\\Item\\Base\\Standard->check()\n#1 \/app\/vendor\/aimeos\/aimeos-laravel\/src\/Aimeos\/Shop\/Controller\/JsonapiController.php(72): Aimeos\\Client\\JsonApi\\Basket\\Standard->post()\n#2 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Controller.php(54): Aimeos\\Shop\\Controller\\JsonapiController->postAction()\n#3 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction()\n#4 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Route.php(254): Illuminate\\Routing\\ControllerDispatcher->dispatch()\n#5 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Route.php(197): Illuminate\\Routing\\Route->runController()\n#6 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(693): Illuminate\\Routing\\Route->run()\n#7 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()\n#8 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Middleware\/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#9 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()\n#10 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Middleware\/ThrottleRequests.php(127): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#11 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Middleware\/ThrottleRequests.php(103): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequest()\n#12 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Middleware\/ThrottleRequests.php(55): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequestUsingNamedLimiter()\n#13 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle()\n#14 \/app\/vendor\/laravel\/sanctum\/src\/Http\/Middleware\/EnsureFrontendRequestsAreStateful.php(33): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#15 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(128): Laravel\\Sanctum\\Http\\Middleware\\EnsureFrontendRequestsAreStateful->Laravel\\Sanctum\\Http\\Middleware\\{closure}()\n#16 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#17 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()\n#18 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Session\/Middleware\/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#19 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Session\/Middleware\/StartSession.php(63): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest()\n#20 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Session\\Middleware\\StartSession->handle()\n#21 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Cookie\/Middleware\/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#22 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()\n#23 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Cookie\/Middleware\/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#24 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()\n#25 \/app\/vendor\/laravel\/sanctum\/src\/Http\/Middleware\/EnsureFrontendRequestsAreStateful.php(26): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#26 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(149): Laravel\\Sanctum\\Http\\Middleware\\EnsureFrontendRequestsAreStateful->Laravel\\Sanctum\\Http\\Middleware\\{closure}()\n#27 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#28 \/app\/vendor\/laravel\/sanctum\/src\/Http\/Middleware\/EnsureFrontendRequestsAreStateful.php(34): Illuminate\\Pipeline\\Pipeline->then()\n#29 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Laravel\\Sanctum\\Http\\Middleware\\EnsureFrontendRequestsAreStateful->handle()\n#30 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#31 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(695): Illuminate\\Pipeline\\Pipeline->then()\n#32 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(670): Illuminate\\Routing\\Router->runRouteWithinStack()\n#33 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(636): Illuminate\\Routing\\Router->runRoute()\n#34 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(625): Illuminate\\Routing\\Router->dispatchToRoute()\n#35 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Kernel.php(166): Illuminate\\Routing\\Router->dispatch()\n#36 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()\n#37 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#38 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()\n#39 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#40 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()\n#41 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Middleware\/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#42 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()\n#43 \/app\/vendor\/fideloper\/proxy\/src\/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#44 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Fideloper\\Proxy\\TrustProxies->handle()\n#45 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Http\/Middleware\/TrustHosts.php(48): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#46 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Illuminate\\Http\\Middleware\\TrustHosts->handle()\n#47 \/app\/vendor\/fruitcake\/laravel-cors\/src\/HandleCors.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#48 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Fruitcake\\Cors\\HandleCors->handle()\n#49 \/app\/vendor\/sentry\/sentry-laravel\/src\/Sentry\/Laravel\/Tracing\/Middleware.php(46): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#50 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(167): Sentry\\Laravel\\Tracing\\Middleware->handle()\n#51 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()\n#52 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Kernel.php(141): Illuminate\\Pipeline\\Pipeline->then()\n#53 \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Http\/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()\n#54 \/app\/public\/index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle()\n#55 {main}"}]
Code: Select all
$this->controller->get()->check()
Code: Select all
try
{
$this->controller->setType( $view->param( 'id', 'default' ) );
$this->controller->get()->check();
$this->clearCache();
$item = $this->controller->store();
$this->getContext()->getSession()->set( 'aimeos/order.baseid', $item->getId() );
$view->item = $item;
$status = 200;
}
I'll try to create a PR for it if I have some time. Please let me know if the fix is good.
Update: Opened a PR - https://github.com/aimeos/ai-client-jsonapi/pull/10
Re: Problem using multiple basket - cannot save basket
Thanks a lot, your fix has been merged into dev-master and 2020.10.x-dev
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