GLUE API /carts GET/POST endpoint issue


#1

We recently updated Spryker Core.

Two, not expected, behaviors occured at the GET & POST /carts entpoints in GLUE API:

  1. Requesing a list of customers shopping carts if none is present (in spy_quote) with:

    GET https://glue.de.suite.local/carts

Creates a new cart insteadof returning that there is no cart existing.

  1. Requesting to create a new shopping cart for a customer in none is present (in spy_quote) with:

    POST https://glue.de.suite.local/carts

Payload:

{
    "data": {
        "type": "carts",
        "attributes": {
            "priceMode": "GROSS_MODE",
            "currency": "EUR",
            "store": "DE"
        }
    }
}

creates a new cart, but responses with error:

422 Unprocessable Entity

{
    "errors": [
        {
            "code": "110",
            "status": 422,
            "detail": "Customer already has a cart."
        }
    ]
}

Please help!


#2

Hello sheinrich!

We have changed behavior and now we creating a cart for every registered customer, so whenever you make a call as an authenticated customer via API system will create cart automatically if no exists.
And because by default we provide a single cart strategy - you are not able to have more than one cart.
You can change this behavior by providing a new plugin in CartsRestApi module.

Cheers!


#3

Hi Ole_Gi!

Thanks for your quick reply.

Besides the “single cart strategy” and the “creating a cart on the list all carts request” issue:

We get the “Customer already has a cart.” error response at “POST /carts” if no cart exists for the customer (it creates correctly a new cart, but responses with an error).

Can you confirm this issue?


#4

Hi Steffen,

Sorry for the late reply. Yes, I can confirm this as well.
Internal ticket is created.

Best regards,
Valerii


#5

Hi Valerii,

I investigated the issue.

The CustomersRestApi plugin:

\Spryker\Glue\CustomersRestApi\Plugin\SetCustomerBeforeActionPlugin

triggers the PersistentCart plugin:

\Spryker\Client\PersistentCart\Plugin\GuestCartUpdateCustomerSessionSetPlugin

which triggers:

$this->quoteFacade->createQuote($quoteTransfer);

in:

\Spryker\Zed\PersistentCart\Business\Model\QuoteStorageSynchronizer

if quote is not present in spy_quote db table.

As a result of that, the cart is created before the request to create a cart (POST /carts) is entered and so the error “EXCEPTION_MESSAGE_CUSTOMER_ALREADY_HAS_CART” is raised in SingleQuoteCreator.

Best regards