当前位置: 首页>>代码示例>>C#>>正文


C# OrderInfo.ClearCachedValues方法代码示例

本文整理汇总了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);
				}

//.........这里部分代码省略.........
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:101,代码来源:OrderUpdatingService.cs


注:本文中的OrderInfo.ClearCachedValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。