示例#1
0
        /// <summary>
        ///     Merge products options
        /// </summary>
        /// <param name="productBvin">Product unique identifier</param>
        /// <param name="subitems"><see cref="OptionList" /> instance</param>
        public void MergeList(string productBvin, OptionList subitems)
        {
            var storeId = Context.CurrentStore.Id;

            // Set Base Key Field
            foreach (var item in subitems)
            {
                item.StoreId = storeId;

                if (string.IsNullOrEmpty(item.Bvin))
                {
                    item.Bvin = Guid.NewGuid().ToString();
                }
            }

            var productGuid = DataTypeHelper.BvinToGuid(productBvin);
            var result      = MergeList(subitems,
                                        po => po.hcc_ProductXOption.Where(pxo => pxo.ProductBvin == productGuid).Count() > 0);

            var created = subitems.Where(i => !result.OldValues.Select(ov => ov.Bvin).Contains(i.Bvin)).ToList();
            var deleted = result.OldValues.Where(ov => !subitems.Select(i => i.Bvin).Contains(ov.Bvin)).ToList();

            foreach (var item in created)
            {
                optionCrosses.AddOptionToProduct(productBvin, item.Bvin);
            }

            foreach (var item in deleted)
            {
                optionCrosses.RemoveOptionFromProduct(productBvin, item.Bvin);
            }
        }
示例#2
0
        /// <summary>
        ///     Checks to see if a list of selection data contains a selection that isn't a valid variant in a list of options.
        /// </summary>
        /// <param name="options">The available options for the product.</param>
        /// <param name="selections">The options that have been selected.</param>
        /// <returns>If true, the selected options all match that available choices.</returns>
        public static bool ContainsInvalidSelectionForOptions(OptionList options, List <OptionSelection> selections)
        {
            var result = false;

            foreach (var sel in selections)
            {
                if (!options.ContainsVariantSelection(sel))
                {
                    return(true);
                }
            }

            return(result);
        }
示例#3
0
        public decimal GetWeightAdjustmentForSelections(OptionList allOptions)
        {
            decimal result = 0;

            foreach (var selection in this)
            {
                var subSelections = selection.SelectionData.Split(',');

                result += allOptions
                          .Where(o => o.Items != null)
                          .Sum(o => o.Items
                               .Where(oi => subSelections.Contains(OptionSelection.CleanBvin(oi.Bvin)))
                               .Sum(oi => oi.WeightAdjustment)
                               );
            }

            return(result);
        }
示例#4
0
        public Variant FindBySelectionData(OptionSelectionList selections, OptionList options)
        {
            var variantSelections = new OptionSelectionList();

            foreach (var opt in options)
            {
                if (opt.IsVariant)
                {
                    var sel = selections.FindByOptionId(opt.Bvin);
                    if (sel != null)
                    {
                        variantSelections.Add(sel);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            var selectionKey = OptionSelection.GenerateUniqueKeyForSelections(variantSelections);

            return(FindByKey(selectionKey));
        }