How to run workflow for Icart?

Vote:
 

commerce ver:12.4

Hi Team,

We switching the carthelper to Iorderrepository.In the validate cart code used in carthelper is below one 

 private string ValidateCart()
        {
            var workflowResult = OrderGroupWorkflowManager.RunWorkflow(CartHelper.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            var warnings = OrderGroupWorkflowManager.GetWarningsFromWorkflowResult(workflowResult).ToArray();
            return warnings.Any() ? warnings.First() : null;
        }

 we changed the above code for suitable to Icart like below,

        private string ValidateCart()
        {
            var workflowResult = OrderGroupWorkflowManager.RunWorkflow(Cart as OrderGroup, OrderGroupWorkflowManager.CartValidateWorkflowName);
            var warnings = OrderGroupWorkflowManager.GetWarningsFromWorkflowResult(workflowResult).ToArray();
            return warnings.Any() ? warnings.First() : null;
        }

Note: we are not using default epi inventory.

suggest me the above code is correct or it needs to change?

 

Please help me out.

Advance Thanks,

Regards,

karthik

#195418
Jul 24, 2018 15:48
Vote:
 

If you want to follow the standard convention I'd suggest downloading and looking at Quicksilver from GitHub. This is the reference project for using commerce, some examples of how they are using this for the RunWorkflow can be found here https://github.com/OXXAS/CommerceStarterKit/blob/master/src/common/Core/Services/CartService.cs 

#195419
Edited, Jul 24, 2018 15:58
Vote:
 

Sorry wrong link, that's a commerce starter kit Quicksilver is here https://github.com/episerver/Quicksilver  

#195420
Jul 24, 2018 15:59
Vote:
 

Not sure what you linked Scott, but I suppose you meant this? :P https://github.com/episerver/Quicksilver. The other one looks to be an old clone of Quicksilver, so it might work still :)

<insert slowpoke meme here>

#195421
Edited, Jul 24, 2018 16:01
Vote:
 

In later version (11+) you no longer have to use workflow to validate your cart. However for consistency between frontend and Commerce Manager you should use at least Commerce 12 (which you do).

Your code only works if the implementation of ICart is the "old" Cart. If you switch to SerializableCart mode then it will not be working.

#195423
Jul 24, 2018 16:28
Vote:
 

This is a fairly standard snippet of code to validate a cart, it should work with all implementation

            var validationIssues = new Dictionary<ILineItem, List<ValidationIssue>>();
            cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _lineItemValidator);
            cart.UpdatePlacedPriceOrRemoveLineItems(_customerContext.GetContactById(cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor);
            cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _inventoryProcessor);

            ApplyDiscounts(cart);

            // Try to validate gift items inventory and don't catch validation issues.
            cart.UpdateInventoryOrRemoveLineItems((item, issue) =>
            {
                validationIssues.AddValidationIssues(item, item.IsGift ? ValidationIssue.RemovedGiftDueToInsufficientQuantityInInventory : issue);
            }, _inventoryProcessor);
#195426
Jul 24, 2018 16:56
Vote:
 

Thank you team.

Quan,

by default( commerce 12.4) SerializableCart  will works or we need change any config. Cart operation and checkout api are same for SerializableCart   or else SerializableCart  have different process for cart and checkout 

#195429
Jul 24, 2018 19:36
Vote:
 

Thank you team

#195496
Jul 26, 2018 15:51
Vote:
 

Hi Quan,

How to set ProviderId in Icart .i am not able to set like below one.

CartHelper.Cart.ProviderId = Constants.FrontendCartProvider; // if this is not set explicitly, placed price does not get updated by workflow

Advance Thanks,

#195498
Edited, Jul 26, 2018 15:56
* 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.