Best solution to remove unpublished products from cart

When a customer has items in the checkout and an admin is unpublishing any of thoose items the customer can still buy theese. (Reload etc dosent help). SO my question. Where do I do the check that the items in the checkout is ok? I’ve tried some solutions but nothing feels 100%. So was wondering if anyone from Litium had suggestions or if anyone had already done something like this?

Litium version: 6.9

Did you try creating a IPreOrderValidationRule that checks that all products in cart are published (=has URL)? There are some examples of validation rules in the standard Accelerator.

Something like this would show a message, but not alter the cart.

public void Validate(OrderCarrier orderCarrier, CheckoutFlowInfo checkoutFlowInfo)
{
	var products = orderCarrier.OrderRows
		.Where(row => !row.CarrierState.IsMarkedForDeleting && !row.IsAutoGenerated)
		.Select(x => x.ProductID);

	var variants = _variantService.Get(products);

	foreach (var variant in variants)
	{
		if (!variant.IsPublished(CurrentState.Current.WebSite.ID))
		{
			throw new PreOrderValidationException(
				CurrentState.Current.WebSite.As<CheckoutPageWebsiteStrings>().ProductIsNotPublished);
		}
	}
} 
1 Like

Nope. But now I have! Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.