Try our conversational search powered by Generative AI!

ValidateCart workflow issue after upgrade to Commerce 10

Vote:
 

Hi!

After upgrading to Commerce 10 the ValidateCart workflow has a strange behavior. It doesn't always update the cart totals.
When I add an item to the cart I run the ValidateCart workflow and before Commerce upgrade the cart totals got updated.
After upgrading it doesn't upgrade the cart totals. But when I enter the checkout page where I also run ValidateCart the cart totals gets updated, also when I remove an item from the cart and run ValidateCart it works fine so I guess I'm missing something.

So the question is, do you have to do something special to get the ValidateCart to run properly? Something like, make sure to AcceptChanges() or make sure cart in i a specific state before running ValidateCart?

As I said, it worked just fine before upgrading. Has something changed?

Thanks!

/Kristoffer

#173486
Dec 29, 2016 8:33
Vote:
 

Hi,

Can you post your code here (from adding the line item to running the workflow)?

/Q

#173490
Dec 29, 2016 10:32
Vote:
 

Looks like I found the problem.

We have a special price calculation that doesn't always pick the lowest price, there for I have built my own workflows but it is only the ValidateLineItemsActivity that I have changed.

My workflow looks like this:

[ActivityFlowConfiguration(Name = "DrCartValidate")]
    public class DrCartValidateWorkflow : ActivityFlow
    {
        public override ActivityFlowRunner Configure(ActivityFlowRunner activityFlow)
        {

            return
                activityFlow.Do<DrValidateLineItemsActivity>()
                    .Do<GetFulfillmentWarehouseActivity>()
                    .If((Func<bool>)(() => this.ShouldCheckInstoreInventory()))
                    .Do<CheckInstoreInventoryActivity>()
                    .Else()
                    .Do<CheckInventoryActivity>()
                    .EndIf()
                    .Do<ProcessShipmentsActivity>()
                    .Do<CalculateTotalsActivity>()
                    .Do<RemoveDiscountsActivity>()
                    .Do<CalculateTotalsActivity>()
                    .Do<CalculateDiscountsActivity>()
                    .Do<CalculateTotalsActivity>()
                    .Do<CalculateTaxActivity>()
                    .Do<CalculateTotalsActivity>();
        }
    }

After upgrade I thought I had to change to this to get the VNext to work:

[ActivityFlowConfiguration(Name = "DrCartValidate")]
    public class DrCartValidateWorkflow : ActivityFlow
    {
        public override ActivityFlowRunner Configure(ActivityFlowRunner activityFlow)
        {
            return activityFlow.Do<DrValidateLineItemsActivity>()
                .Do<GetFulfillmentWarehouseActivity>()
                .If((Func<bool>)(this.ShouldCheckInstoreInventory))
                .Do<CheckInstoreInventoryActivity>()
                .Else()
                .Do<CheckInventoryActivity>().EndIf()
                .Do<RemoveDiscountsVNextActivity>()
                .Do<CalculateDiscountsVNextActivity>()
                .Do<UpdateTotalsVNextActivity>();
        }
    }
Using the first version updates the cart totals when I add an item to the cart, but then the discounts are not calculated.
Using the second version I need to go to the checkout page to get the cart totals to update but then discounts are calculated correctly.
I have tried to added this as well when I use the first version:
var cart = (ICart) CartHelper.Cart;
            cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings());
But the discounts are not calculated anyway.
So I'm not really sure which way to go here, please guide me! :)
Thanks Quan!
/Kristoffer
#173499
Edited, Dec 29, 2016 12:36
Vote:
 

I tried to add this to my version 1 workflow:

.Do<RemoveDiscountsVNextActivity>()
.Do<CalculateDiscountsVNextActivity>()

Then the discount calculation was made when I entered the checkout but not when adding item to the cart.

/Kristoffer

#173501
Edited, Dec 29, 2016 12:50
Vote:
 

Hi Quan!

Happy New Year!

Any suggestions hos to get this to work properly?

Thanks!

/Kristoffer

#173545
Jan 02, 2017 9:52
Vote:
 

In the ShoppingCart page I do this:

But still the totals are not updated:

[HttpGet]
        public ActionResult Index(ShoppingCartPage currentPage)
        {
            this._cartHelper(Cart.DefaultName);

            _cartService.RunWorkflow(Constants.CartValidateWorkflow);
            _cartService.SaveCart();
            
            var cartItems = _cartService.GetCartItems();

            ShoppingCartViewModel viewModel = new ShoppingCartViewModel(currentPage, cartItems)
                                                  {
                                                        SubTotal = _cartService.GetSubTotal(),                                                      
                                                        Total = _cartService.GetTotal() - _cartService.GetShippingTotal(),
                                                        ShowVat = _currencyService.GetCurrentCurrency().CurrencyCode != Constants.CurrencyWithOutWat,
                                                        DiscountTotal = _cartService.GetOrderDiscountTotal() * -1
                                                    };

            return this.View(viewModel);
        }
#173549
Jan 02, 2017 12:17
Vote:
 

Hi!

So it seems to be problems with my code for adding an entry. If i use:

LineItem lineItem = CartHelper.AddEntry(entry);

The cart is updated fine. But, since I want to be able to add the same entry twice without having the quantity to be updated on the existing item I have to add the line item by myself using this:

lineItem = CreateLineItem(entry, code, productCode, quantity);
lineItem["Configuration"] = configuration;
            
CartHelper.OrderForm.LineItems.Add(lineItem);

Doing this the item was not added to any shipment and there for it is excluded in the total calculation.
Adding this fixed my problem:

var item = CartHelper.OrderForm.LineItems[CartHelper.OrderForm.LineItems.Count - 1];
shipment.AddLineItemIndex(CartHelper.OrderForm.LineItems.Count - 1, item.Quantity);
shipment.AcceptChanges();

The absoluty best thing would be to add an option in the CartHelper where you can add an item with the same code as a new row instead of always updating the quantity.
Anything that might be done in the future?

/Kristoffer

#173599
Jan 03, 2017 12:31
Vote:
 

Hi,

CartHelper is in Mediachase.Commerce.Website, which is open source by Episerver. You are free to modify it as you like :)

This is one of the reasons we recommend to move to the new abstraction APIs instead because it makes it much easier to work with such issues.

#173600
Jan 03, 2017 12:37
Vote:
 

I definitly would like to rebuild all with the new api, so much better! I just have to convince my customer about the upside. Is the plan to remove the workflows completly or will they remain?

So, the basic is that the item needs to be placed in a shipement do be included in the cart calculations?

Thans Quan!

#173604
Jan 03, 2017 13:59
Vote:
 

Hi,

Yes. On the "old" APIs - which you are using - the lineitems belong to the OrderForm, you will have to modify the LineItemIndex to "add" it to the Shipment (shipment.AddLineItemIndex in your code). The calculations, however, will calculate on Shipments. So if you have "orphan" lineitems which were not added to any Shipments, they will be left behind.

The concept of new APIs is shipment "owns" the lineitems. You always add lineitem to shipment, explicitly, so this kind of issue is now non-problem.

#173607
Jan 03, 2017 14:16
Vote:
 

Any plans to provide the source code for the new order processing classes, such as DefaultLineItemValidator and DefaultInventoryProcessor, for extension purposes?

We used to have the code for the workflows which enabled us to add our own business logic on the top of it. Hopefully we can get the same for the new one.

Thanks!

#174197
Edited, Jan 20, 2017 19:59
Vote:
 

The code inside new order processing classes is actually the same as the code inside activities. However yes, we have a plan to release them.

#174215
Jan 21, 2017 9:40
* 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.