Try our conversational search powered by Generative AI!

Cart has ObjectState Deleted after purchase

Vote:
 

Hi!

We are using Quicksilver and are having some problems with our cart.

After a purchase we use the _checkoutService.DeleteCart() but what happens is that the Cart.ObjectState set to Deleted, the cart doesn't seem to be removed. So when the user tries to add a new item to the cart a DeletedObjectInaccessibleException is thrown. How can I do to be sure that the cart is deleted and new one initiated?

Thanks!

/Kristoffer

#146948
Mar 31, 2016 14:36
Vote:
 

If I clear the browser cache it works. How do I clear the cart cache?

#146951
Mar 31, 2016 15:09
Vote:
 

Where are you calling this method.  Calling DeleteCart should delete the cart and invalidate the cache with out any additional steps needed.   

#146954
Mar 31, 2016 15:22
Vote:
 

Thanks for your reply Mark!
Using the Quicksilver, it is called in the CheckoutController and method Finish. Just before the confirmation email is sent.

I think it has worked before but it suddenly stopped working. What could cause the cache to not invalidate?

The cart is delete from the Commerce Manager, so that is working.

#146956
Edited, Mar 31, 2016 15:46
Vote:
 
public void DeleteCart()
        {
            var cart = CartHelper.Cart;
                       
            CartHelper.Delete();

            cart.AcceptChanges();
        }

Can you try changing to this I dont think the other calls are needed and there was a recent bug fix when deleting addresss it might be trying to delete the shipment that was just deleted before.

#146957
Mar 31, 2016 15:52
Vote:
 

I actually found me doing this:

CartHelper.Cart.CustomerId = customerId;
CartHelper.Cart.CustomerName = customerName;

And after looking into the CartHelper code it looks lite the CustomerId is used for caching. I guess manipulating the CustomerId could be the problem.

#146958
Mar 31, 2016 16:07
Vote:
 

So that was the problem!

During checkout I create a new contact and customer if it is an anonymous user and I want that customer connected to the cart. To do this I add the newly created customer to the cart by using:

CartHelper.Cart.CustomerId = customerId;

It works just fine and the purchase order is created with the new customer connected. BUT, since I changed the CustomerId the cart cache is not invalid because the CustomerId is used in the cache key.

The work around is to create the purchase order first and then connect new customer to the purchase order instead of the cart.

purchaseOrder.CustomerId = Guid.Parse(customerContact.PrimaryKeyId.ToString());
purchaseOrder.CustomerName = organization.Name;

/Kristoffer

#146962
Edited, Mar 31, 2016 16:53
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.