kentico 13 shopping cart validation

Matthew Butler asked on August 1, 2022 13:10

Hi,

Is it possible to register custom Cart validation steps?

Thanks

Mat

Correct Answer

Sean Wright answered on August 5, 2022 14:57

Matthew,

You can also decorate system services when inheritance is not an option. This would let you customize behavior in IShoppingService where you want and delegate the rest of its methods to the original.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Matthew Butler answered on August 1, 2022 16:44

Thanks David, its a useful reference, but I don't see how it helps with my question as the sample doesn't provide any additional validation to the shopping cart. it just calls ValidateShoppingCart which applies the standard checks.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on August 3, 2022 08:29

Hi Matthew,

We typically add extra validation via the custom code on checkout page when displaying the cart before proceeding to payment.

0 votesVote for this answer Mark as a Correct answer

Sean Wright answered on August 5, 2022 07:52

Matthew,

There's nothing to 'register'. The validation logic is baked into the ShoppingCartInfoProvider class.

However, you can customize the behavior of many methods for Xperience's built-in types, like ShoppingCartInfoProvider.

Here's an example of customizing the OrderInfoProvider. The process is identical for ShoppingCartInfoProvider. You will want to make sure that customized code is referenced by both the Administration application and Live site application.

You'll want to override protected virtual IEnumerable<IValidationError> ValidateShoppingCartInternal(ShoppingCartInfo cart) which uses the ShoppingCartValidator on the cart and ShoppingCartItemValidator on each item in the cart.

1 votesVote for this answer Mark as a Correct answer

Matthew Butler answered on August 5, 2022 09:21

Thanks Sean.

I was hoping to add custom validation step to ensure consistent validation, when saving etc..

Your approach is better than my current approach, which is a custom separate validator, but it looks like the _shoppingService.SaveCart() calls the ShoppingCartValidator directly, and I don't believe I can override that?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.