Esempio n. 1
0
		/// <summary>
		/// Get the initial price including preselected attributes
		/// </summary>
		/// <param name="product">Product</param>
		/// <param name="context">Object with cargo data for better performance</param>
		/// <returns>Preselected price</returns>
		public virtual decimal GetPreselectedPrice(Product product, PriceCalculationContext context)
		{
			if (product == null)
				throw new ArgumentNullException("product");

			var result = decimal.Zero;

			if (context == null)
				context = CreatePriceCalculationContext();

			if (product.ProductType == ProductType.BundledProduct)
			{
				var bundleItems = _productService.GetBundleItems(product.Id);

				var productIds = bundleItems.Select(x => x.Item.ProductId).ToList();
				productIds.Add(product.Id);

				context.Collect(productIds);

				foreach (var bundleItem in bundleItems.Where(x => x.Item.Product.CanBeBundleItem()))
				{
					// fetch bundleItems.AdditionalCharge for all bundle items
					var unused = GetPreselectedPrice(bundleItem.Item.Product, context, bundleItem, bundleItems);
				}

				result = GetPreselectedPrice(product, context, null, bundleItems);
			}
			else
			{
				result = GetPreselectedPrice(product, context, null, null);
			}

			return result;
		}
Esempio n. 2
0
        public virtual decimal GetPreselectedPrice(Product product, Customer customer, Currency currency, PriceCalculationContext context)
        {
            Guard.NotNull(product, nameof(product));

            var result = decimal.Zero;

            if (context == null)
            {
                context = CreatePriceCalculationContext(customer: customer);
            }

            if (product.ProductType == ProductType.BundledProduct)
            {
                var bundleItems = context.ProductBundleItems
                                  .GetOrLoad(product.Id)
                                  .Select(x => new ProductBundleItemData(x))
                                  .ToList();

                var productIds = bundleItems.Select(x => x.Item.ProductId).ToList();
                productIds.Add(product.Id);
                context.Collect(productIds);

                // Fetch bundleItems.AdditionalCharge for all bundle items.
                foreach (var bundleItem in bundleItems.Where(x => x.Item.Product.CanBeBundleItem()))
                {
                    var unused = GetPreselectedPrice(bundleItem.Item.Product, customer, currency, context, bundleItem, bundleItems);
                }

                result = GetPreselectedPrice(product, customer, currency, context, null, bundleItems);
            }
            else
            {
                result = GetPreselectedPrice(product, customer, currency, context, null, null);
            }

            return(result);
        }
        /// <summary>
        /// Get the initial price including preselected attributes
        /// </summary>
        /// <param name="product">Product</param>
        /// <param name="context">Object with cargo data for better performance</param>
        /// <returns>Preselected price</returns>
        public virtual decimal GetPreselectedPrice(Product product, PriceCalculationContext context)
        {
            if (product == null)
                throw new ArgumentNullException("product");

            var result = decimal.Zero;

            if (context == null)
                context = CreatePriceCalculationContext();

            if (product.ProductType == ProductType.BundledProduct)
            {
                var bundleItems = _productService.GetBundleItems(product.Id);

                var productIds = bundleItems.Select(x => x.Item.ProductId).ToList();
                productIds.Add(product.Id);

                context.Collect(productIds);

                foreach (var bundleItem in bundleItems.Where(x => x.Item.Product.CanBeBundleItem()))
                {
                    // fetch bundleItems.AdditionalCharge for all bundle items
                    var unused = GetPreselectedPrice(bundleItem.Item.Product, context, bundleItem, bundleItems);
                }

                result = GetPreselectedPrice(product, context, null, bundleItems);
            }
            else
            {
                result = GetPreselectedPrice(product, context, null, null);
            }

            return result;
        }