• Resolved corax0

    (@corax0)


    Hi,

    I think maybe there is some delay in using ‘add-item’ endpoint of api because when i use ‘add-item’ very fast. One is added others are not.

    For example.
    I have two products in cart and when user click ‘add to cart’, i run a loop and send both products ‘add-item’ request, only one item is added to the cart. I’m using ‘cart_key’.

    But if i do this slowly (using cart_key here also) after 5 seconds or more i think, It works.

    Calling ‘add-item’ api for all products is working their response is giving product details as usual and its not giving any error but in cart it add 1 one and others are somewhere else dont know where.

    I am using ‘cart_key’ and in ‘cart_key’ i provide customer id so it add items to customer cart sesson. (but as guest not using auth).

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Sébastien Dumont

    (@sebd86)

    I suggest not to run a loop.

    Thread Starter corax0

    (@corax0)

    Okay, But I am still curious if I am doing anything wrong or ‘add-item’ require delay in its request.

    You need to debounce your requests to your endpoint. You cannot hit any API so many times without waiting on the results and moving on to the next one. In a sense you either queue your calls from the frontend or on the backend, that isn’t something I think CoCart should handle. If you are using javascript you can await each API call. Alternatively you can debounce the requests (more info here).

    Thread Starter corax0

    (@corax0)

    JPPdesigns thank you for your reply.

    As you said, I should await for the request to complete before sending another request, Right?

    I guess i am already using that way, If there are 2 items in cart, I do not send the request for both at the same time.

    Loop runs, sends first product request and waits for it to be completed and then send next product request. As i stated in my question, I am getting the response from ‘add-item’ endpoint having same ‘cart_key’.

    • This reply was modified 4 years, 4 months ago by corax0.
    Plugin Author Sébastien Dumont

    (@sebd86)

    I guess i am already using that way, If there are 2 items in cart, I do not send the request for both at the same time.

    Are you checking if the items already exist in the cart when looping before adding the item? If so, is there a reason to need to check if the item is in the cart?

    Thread Starter corax0

    (@corax0)

    No, I am not checking if the items already exists in cart because i send the ‘clear’ request before running the ‘add-item’ loop.

    Plugin Author Sébastien Dumont

    (@sebd86)

    Why are you clearing the cart before adding?

    Thread Starter corax0

    (@corax0)

    So user can see the cart which they saw in their mobile app cart.

    PS A suggestion, maybe add a end-point to add multiple items in cart.

    Plugin Author Sébastien Dumont

    (@sebd86)

    I don’t follow. Do you mean your loading the cart from session on the web?

    Adding products in batches is in development. You can pre-order now and get it’s legacy price before it goes up.

    Thread Starter corax0

    (@corax0)

    What I am doing is adding products to CoCart specifying ‘cart_key’ equal to customer ID which is currently logged in mobile app without any Authorization ( as guest ). Then i open WebView and log the user in without loading the cart from session, Because I login the user with same customer ID used in ‘cart_key’, So i do not need to load cart from session.

    Plugin Author Sébastien Dumont

    (@sebd86)

    OK but why do you need to clear the cart if you are loading the same cart. The items will already be there since the last cart update. You don’t need to clear the cart before adding the items. Can you clarify? What’s your API request flow?

    Thread Starter corax0

    (@corax0)

    To be clear, ‘clear cart’ is called only one before execution of ‘add-item’.
    Because Mobile app cart doesnot load items from Website cart yet, So i clear the cart to clear all the items already in it and only add the items which user added in mobile cart.

    Plugin Author Sébastien Dumont

    (@sebd86)

    Thank you for clarifying. Does not load from web for guest customers yet, that is correct. It is an issue I am working on.

    Hope you have resolved your issue with the advice @jppdesigns has provided.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Cart Items not adding (delay maybe)’ is closed to new replies.