After upgrade to Commerce 11 the CartValidate and CartCheckout workflows behavies strange. Well at least the CartCheckout.
The CartValidate works fine and keeps my item in the cart, but after creating a purchase order I run the CartCheckout workflow which removes my items from the cart with this message:
Item X has been removed from the cart because there is not enough available quantity
The item has > 10 in stock but still gets removed.
If I create an order on site it works fine, but this is Klarna Checkout so our solution gets a push and we load the cart again from the push info adn creates the order. After loading the cart the maxumum quantity is 0 and there for the items gets removed. During the CartValidate the maximum quantity is 999 which is the correct value.
That's very strange. LineItem.MaxQuantity should be set in ValidateLineItemsActivity, which is run in CartValidate flow. Did you save the cart after running CartValidate?
Yes, well we set it before creating the order in Klarna. When the push arrives from Klarna we do an OrderContext.Current.FindCarts to get the cart using the Klarna order id. Works fine. We then modify the cart and save it. Then we create an purchase order using the cart.SaveAsPurchaseOrder(); Works fine aswell. After that we run the CartCheckout workflow and then the item gets removed.
I have tried an ugly workaround. Before the workflow is run I do this:
var orderForm = cart.OrderForms;
foreach (LineItem lineItem in orderForm.LineItems)
lineItem.MaxQuantity = 999;
Then the item doesn't get removed but instead we get:
Can not request inventory due to not enough quantity.
Another strange thing is that when I load the purchase order it has added an empty OrderForm, so the purchase order suddenly contains two OrderForms. And finally, the order in then Manager has no rows.
I am really confused!