duncanmcclean / simple-commerce

A simple, yet powerful e-commerce addon for Statamic.
https://statamic.com/addons/duncanmcclean/simple-commerce
Other
143 stars 36 forks source link

Error on cart update route after switching to Database orders #927

Closed Web10-Joris closed 7 months ago

Web10-Joris commented 11 months ago

Description

I've created my own one-page checkout that updates the cart using axios after a country was filled in (to retrieve shipping options). This was working fine when using file-based orders, but now I get the following 500 server error on Axios call to update cart route. Any idea why this is happening? Could also be something in my custom view for the checkout, but it was working perfectly before changing to database orders.

Full error: `[2023-10-02 14:38:12] local.ERROR: Maximum stack depth exceeded {"userId":1,"exception":"[object] (InvalidArgumentException(code: 0): Maximum stack depth exceeded at /var/www/html/vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php:88) [stacktrace]

0 /var/www/html/vendor/symfony/http-foundation/JsonResponse.php(49): Illuminate\Http\JsonResponse->setData()

1 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php(32): Symfony\Component\HttpFoundation\JsonResponse->__construct()

2 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(101): Illuminate\Http\JsonResponse->__construct()

3 /var/www/html/vendor/doublethreedigital/simple-commerce/src/Http/Controllers/BaseActionController.php(18): Illuminate\Routing\ResponseFactory->json()

4 /var/www/html/vendor/doublethreedigital/simple-commerce/src/Http/Controllers/CartController.php(158): DoubleThreeDigital\SimpleCommerce\Http\Controllers\BaseActionController->withSuccess()

5 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): DoubleThreeDigital\SimpleCommerce\Http\Controllers\CartController->update()

6 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction()

7 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): Illuminate\Routing\ControllerDispatcher->dispatch()

8 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()

9 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(799): Illuminate\Routing\Route->run()

10 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}()

11 /var/www/html/vendor/doublethreedigital/simple-commerce/src/Http/Middleware/EnsureFormParametersArriveIntact.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

12 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): DoubleThreeDigital\SimpleCommerce\Http\Middleware\EnsureFormParametersArriveIntact->handle()

13 /var/www/html/vendor/aryehraber/statamic-impersonator/src/ImpersonatorMiddleware.php(15): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

14 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): AryehRaber\Impersonator\ImpersonatorMiddleware->handle()

15 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

16 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle()

17 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

18 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()

19 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

20 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle()

21 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

22 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()

23 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle()

24 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

25 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()

26 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

27 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle()

28 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

29 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(798): Illuminate\Pipeline\Pipeline->then()

30 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(777): Illuminate\Routing\Router->runRouteWithinStack()

31 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(741): Illuminate\Routing\Router->runRoute()

32 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(730): Illuminate\Routing\Router->dispatchToRoute()

33 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\Routing\Router->dispatch()

34 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()

35 /var/www/html/vendor/statamic/cms/src/Http/Middleware/DisableFloc.php(17): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

36 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\Http\Middleware\DisableFloc->handle()

37 /var/www/html/vendor/statamic/cms/src/Http/Middleware/CheckMultisite.php(14): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

38 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\Http\Middleware\CheckMultisite->handle()

39 /var/www/html/vendor/statamic/cms/src/Http/Middleware/CheckComposerJsonScripts.php(14): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

40 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\Http\Middleware\CheckComposerJsonScripts->handle()

41 /var/www/html/vendor/statamic/cms/src/Http/Middleware/PoweredByHeader.php(18): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

42 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\Http\Middleware\PoweredByHeader->handle()

43 /var/www/html/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

44 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()

45 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

46 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()

47 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()

48 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

49 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()

50 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()

51 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

52 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()

53 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

54 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()

55 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

56 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\HandleCors->handle()

57 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

58 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle()

59 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

60 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\Pipeline\Pipeline->then()

61 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()

62 /var/www/html/public/index.php(51): Illuminate\Foundation\Http\Kernel->handle()

63 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php(16): require_once('...')

64 {main}

"} `

Steps to reproduce

  1. Create page with axios cart update after particular field is filled in.
  2. Change from file-based to database orders.
  3. Get error listed above on axios post.

Environment

Application Name: localhost Laravel Version: 10.15.0 PHP Version: 8.1.5 Composer Version: 2.5.5 Environment: local Debug Mode: ENABLED URL: localhost Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: NOT CACHED

Drivers Broadcasting: log Cache: statamic Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file

Simple Commerce Currencies: EUR, EUR, EUR, EUR Gateways: Mollie Repository: Customer: DoubleThreeDigital\SimpleCommerce\Customers\EloquentCustomerRepository Repository: Order: DoubleThreeDigital\SimpleCommerce\Orders\EloquentOrderRepository Repository: Product: DoubleThreeDigital\SimpleCommerce\Products\EntryProductRepository Shipping Methods: MTC Pallet Zending, PostNL International Tax Engine: DoubleThreeDigital\SimpleCommerce\Tax\BasicTaxEngine

Statamic Addons: 9 Antlers: runtime Stache Watcher: Enabled Static Caching: Disabled Version: 4.11.0 PRO

Statamic Addons aerni/advanced-seo: 2.1.3 appswithlove/statamic-one-click-content-translation: 4.18.1 aryehraber/statamic-impersonator: 2.6.0 aryehraber/statamic-logbook: 3.1.0 doublethreedigital/runway: 5.3.0 doublethreedigital/simple-commerce: 5.6.0 heidkaemper/statamic-toolbar: 1.1.0 rias/statamic-data-import: 1.3.0 statamic/collaboration: 0.7.2

duncanmcclean commented 11 months ago

Are you able to share a repository so I can easily reproduce?

Web10-Joris commented 11 months ago

@duncanmcclean Yes. I've never shared a private repo before but if it worked you've had an invite. Try adding product to shopping cart and proceed to checkout. Then fill in all the details (at country the axios post goes to cart update start). But it eventually fails and gives this error. Don't mind the messy repo, still learning how to work with everything :)

duncanmcclean commented 11 months ago

@duncanmcclean Yes. I've never shared a private repo before but if it worked you've had an invite. Try adding product to shopping cart and proceed to checkout. Then fill in all the details (at country the axios post goes to cart update start). But it eventually fails and gives this error. Don't mind the messy repo, still learning how to work with everything :)

Thanks! I've got the code invite. Are you able to send a database dump to duncan@doublethree.digital? I don't have any content in my database so I'm getting lots of errors.

duncanmcclean commented 11 months ago

Thanks for sending over the content & a database dump. I can replicate the issue now.

Unfortunately, it doesn't look like a quick one to fix (I've been at it 30 minutes or so 😅 ). For now, if you remove the orders field from your customer blueprint, it should fix the issue.

duncanmcclean commented 10 months ago

I've found a solution for this issue 🎉

Although, to implement, it'll require some breaking changes in both Runway and Simple Commerce so it'll be fixed when both of those packages have their next major versions (within the next few months).

Apologies for the wait.

duncanmcclean commented 7 months ago

This will be fixed in the next release - v6.

Web10-Joris commented 7 months ago

Thanks @duncanmcclean, sorry to keep you bothered but I have again an issue with the Status Log fieldtype... The request to /admin/simple-commerce/fieldtype-api/status-log has failed because the payload was completely empty. Therefore this is the response:

{
    "message": "The given data was invalid.",
    "errors": {
        "order_id": [
            "This field is required."
        ]
    }
}

Any idea why that happens?

duncanmcclean commented 7 months ago

I'm not sure off the top of my head. Are you able to open another issue for that?