Posted on 28/03/2026 08:07:44
This extension is from Dynamiccweb 10:
/// <summary>
/// Checks if the product is in the cart
/// </summary>
/// <param name="product">The product view model</param>
/// <param name="orderContextId">The order context ID</param>
/// <returns>True if the product is in the cart, false otherwise</returns>
public static bool IsProductInCart(this ProductViewModel product, string orderContextId = null)
{
Orders.Order cart;
if (!string.IsNullOrEmpty(orderContextId))
{
Orders.OrderContext orderContext = Services.OrderContexts.GetOrderContextById(orderContextId);
if (orderContext == null)
{
return false;
}
cart = Common.Context.GetCart(orderContext);
}
else
{
cart = Common.Context.Cart;
}
if (cart != null)
{
return cart.IsProductInOrder(product.Id, product.VariantId);
}
return false;
}