Beispiel #1
0
        public UserSpecificPrice(Product initialProduct, OptionSelections selections, StoreSettings storeSettings)
        {
            if (initialProduct == null)
            {
                throw new ArgumentNullException("Initial Product can not be null");
            }

            // init
            IsValid         = true;
            DiscountDetails = new List <DiscountDetail>();
            VariantId       = string.Empty;

            // Load from Product
            Sku = initialProduct.Sku;
            InitialListPrice = initialProduct.ListPrice;
            InitialBasePrice = initialProduct.SitePrice;
            OverrideText     = initialProduct.SitePriceOverrideText;

            if (initialProduct.IsUserSuppliedPrice || initialProduct.IsGiftCard)
            {
                OverrideText = " ";
            }

            PriceForSelections(initialProduct, selections, storeSettings);
        }
Beispiel #2
0
        /// <summary>
        ///     Return true if both objects are equal. Otherwise false.
        /// </summary>
        /// <param name="other">The other option selections</param>
        /// <returns></returns>
        public bool Equals(OptionSelections other)
        {
            var areEqual = OptionSelectionList.Equals(other.OptionSelectionList);

            if (areEqual)
            {
                foreach (var opSel in BundleSelectionList)
                {
                    var otherOpSelValue =
                        other.BundleSelectionList.Where(os => os.Key == opSel.Key)
                        .Select(os => os.Value)
                        .FirstOrDefault();
                    if (otherOpSelValue == null)
                    {
                        areEqual = false;
                        break;
                    }
                    areEqual &= opSel.Value.Equals(otherOpSelValue);
                    if (!areEqual)
                    {
                        break;
                    }
                }
            }
            return(areEqual);
        }
Beispiel #3
0
 private void Init()
 {
     Id             = 0;
     StoreId        = 0;
     CustomerId     = string.Empty;
     LastUpdatedUtc = DateTime.UtcNow;
     ProductId      = string.Empty;
     Quantity       = 1;
     SelectionData  = new OptionSelections();
 }
Beispiel #4
0
        private void PriceForSelections(Product p, OptionSelections selections, StoreSettings storeSettings)
        {
            if (selections == null || p == null)
            {
                return;
            }

            IsValid             = true;
            VariantId           = string.Empty;
            ModifierAdjustments = 0;

            if (!p.IsBundle)
            {
                // Check for Option Price Modifiers
                if (!p.HasOptions())
                {
                    return;
                }
                ModifierAdjustments = selections.OptionSelectionList.GetPriceAdjustmentForSelections(p.Options);

                // Check for Variant Changes
                if (!p.HasVariants())
                {
                    return;
                }
                var v = p.Variants.FindBySelectionData(selections.OptionSelectionList, p.Options);
                if (v == null)
                {
                    IsValid = false;
                    return;
                }

                // Assign Variant Attributes to this price data
                VariantId = v.Bvin;
                if (!string.IsNullOrWhiteSpace(v.Sku))
                {
                    Sku = v.Sku;
                }
                if (v.Price >= 0)
                {
                    InitialBasePrice = v.Price;
                }
            }
            else
            {
                // Check global store option
                foreach (var bundledProductAdv in p.BundledProducts)
                {
                    var bundledProduct = bundledProductAdv.BundledProduct;
                    if (bundledProduct == null || !bundledProduct.HasOptions())
                    {
                        continue;
                    }

                    var optionSelections = selections.GetSelections(bundledProductAdv.Id);

                    if (storeSettings.UseChildChoicesAdjustmentsForBundles)
                    {
                        var optionsAdjustments = optionSelections.GetPriceAdjustmentForSelections(bundledProduct.Options);
                        ModifierAdjustments += optionsAdjustments * bundledProductAdv.Quantity;
                    }

                    if (!bundledProduct.HasVariants())
                    {
                        continue;
                    }
                    var v = bundledProduct.Variants.FindBySelectionData(optionSelections, bundledProduct.Options);
                    if (v == null)
                    {
                        IsValid = false;
                    }
                }
            }
        }