本文整理汇总了C#中OrderInfo.ClearCachedValues方法的典型用法代码示例。如果您正苦于以下问题:C# OrderInfo.ClearCachedValues方法的具体用法?C# OrderInfo.ClearCachedValues怎么用?C# OrderInfo.ClearCachedValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderInfo
的用法示例。
在下文中一共展示了OrderInfo.ClearCachedValues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOrUpdateOrderLine
/// <summary>
/// Create, Add, Update the orderline
/// </summary>
/// <param name="order"></param>
/// <param name="orderLineId">The Id of the orderline</param>
/// <param name="productId">The productId</param>
/// <param name="action">The action (add, update, delete, deleteall)</param>
/// <param name="itemCount">The amount of items to be added</param>
/// <param name="variantsList">The variants ID's added to the pricing</param>
/// <param name="fields">Custom Fields</param>
/// <exception cref="System.ArgumentException">
/// productId and orderLineId equal or lower to 0
/// or
/// itemCountToAdd can't be smaller than 0
/// </exception>
/// <exception cref="System.Exception">
/// Orderline not found
/// </exception>
public void AddOrUpdateOrderLine(OrderInfo order, int orderLineId, int productId, string action, int itemCount, IEnumerable<int> variantsList, Dictionary<string, string> fields = null)
{
//todo: function is too long
// separate control and logic
//todo: function needs testing
// todo: DIP
var isWishList = order != null && order.Status == OrderStatus.Wishlist;
if (!_cmsApplication.RequestIsInCMSBackend(HttpContext.Current) && !isWishList)
{
if (order == null || order.Paid.GetValueOrDefault(false) || (order.Status != OrderStatus.PaymentFailed && order.Status != OrderStatus.Incomplete && order.Status != OrderStatus.WaitingForPayment))
{
Log.Instance.LogDebug("Starting new order for user" + (order == null ? "" : ", previous order: " + order.UniqueOrderId));
order = OrderHelper.CreateOrder();
}
if (order.Status == OrderStatus.PaymentFailed || order.Status == OrderStatus.WaitingForPayment)
{
Log.Instance.LogDebug("Orderstatus WILL BE CHANGED FROM: " + order.Status);
order.Status = OrderStatus.Incomplete;
}
}
if (order == null) return;
// clear some stored values so they can be recalculated
order.ClearCachedValues();
if (itemCount == 0 && action != "update")
itemCount = 1;
if (productId <= 0 && orderLineId <= 0)
{
throw new ArgumentException("productId <= 0 && orderLineId <= 0");
}
if (itemCount < 0)
{
throw new ArgumentException("itemCount can't be smaller than 0");
}
Log.Instance.LogDebug("AddOrUpdateOrderLine Before action");
var variants = variantsList.Where(v => v != 0).OrderBy(v => v);
OrderLine orderLine = null;
if (orderLineId != 0 && action != "new")
{
orderLine = order.OrderLines.FirstOrDefault(line => line.OrderLineId == orderLineId);
}
if (orderLine == null && action != "new")
{
orderLine = order.OrderLines.FirstOrDefault(line => line.ProductInfo.Id == productId && line.VariantsMatch(variants));
}
if (orderLineId != 0 && orderLine == null && action != "new") throw new Exception("Orderline not found");
if (productId == 0 && orderLine != null) productId = orderLine.ProductInfo.Id;
if (action == "add" || action == "new")
{
action = "update";
if (orderLine != null)
{
itemCount = (int) (orderLine.ProductInfo.ItemCount + itemCount);
}
}
Log.Instance.LogDebug("AddOrUpdateOrderLine Before stock");
if (productId != 0 && !isWishList)
{
var requestedItemCount = itemCount;
var tooMuchStock = false;
var localization = StoreHelper.CurrentLocalization;
var product = _productService.GetById(productId, localization);
if (product == null)
{
Log.Instance.LogError("AddOrUpdateOrderLine can't find product with Id " + productId);
}
//.........这里部分代码省略.........