Ejemplo n.º 1
0
        public void DeserializeFromXml(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                return;
            }

            try
            {
                Clear();

                var sr  = new StringReader(xml);
                var doc = XDocument.Load(sr);

                var selections = doc.XPathSelectElements("/OptionSelections/OptionSelection").
                                 Select(os => new
                {
                    OptionBvin    = os.Element("OptionBvin").Value,
                    SelectionData = os.Element("SelectionData").Value
                });

                foreach (var selection in selections)
                {
                    var sel = new OptionSelection();
                    sel.OptionBvin    = selection.OptionBvin;
                    sel.SelectionData = selection.SelectionData;
                    OptionSelectionList.Add(sel);
                }

                var bundleSelections = doc.XPathSelectElements("/OptionSelections/OptionSelections");

                foreach (var bundleSelection in bundleSelections)
                {
                    var bundledProductIdString = bundleSelection.Attribute("BundledProductId").Value;
                    var bundledProductId       = long.Parse(bundledProductIdString);
                    BundleSelectionList[bundledProductId] = new OptionSelectionList();

                    selections = bundleSelection.XPathSelectElements("OptionSelection").
                                 Select(os => new
                    {
                        OptionBvin    = os.Element("OptionBvin").Value,
                        SelectionData = os.Element("SelectionData").Value
                    });

                    foreach (var selection in selections)
                    {
                        var sel = new OptionSelection();
                        sel.OptionBvin    = selection.OptionBvin;
                        sel.SelectionData = selection.SelectionData;
                        GetSelections(bundledProductId).Add(sel);
                    }
                }
            }
            catch (Exception ex)
            {
                Clear();
                EventLog.LogEvent(ex);
            }
        }
Ejemplo n.º 2
0
        public void AddBundleSelections(long bundledProductId, OptionSelection option)
        {
            if (!BundleSelectionList.Keys.Contains(bundledProductId))
            {
                BundleSelectionList[bundledProductId] = new OptionSelectionList();
            }

            BundleSelectionList[bundledProductId].Add(option);
        }
Ejemplo n.º 3
0
        private bool HasEmptySelection(OptionSelection os, List <Option> options)
        {
            var opt = options.FirstOrDefault(o => o.Bvin.Replace("-", string.Empty) == os.OptionBvin);

            if (opt != null)
            {
                return(opt.IsRequired && string.IsNullOrEmpty(os.SelectionData));
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool ContainsVariantSelection(OptionSelection selection)
        {
            // look through a list of options to see if it contains a valid option
            // for the given selection data

            var result = false;

            foreach (var o in VariantsOnly())
            {
                if (o.Bvin.Replace("-", string.Empty) == selection.OptionBvin.Replace("-", string.Empty))
                {
                    if (o.ItemsContains(selection.SelectionData))
                    {
                        return(true);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Allows you to populate the current wish list item object using a WishListItemDTO instance
        /// </summary>
        /// <param name="dto">An instance of the wish list item from the REST API</param>
        public void FromDto(WishListItemDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            Id             = dto.Id;
            StoreId        = dto.StoreId;
            CustomerId     = dto.CustomerId;
            LastUpdatedUtc = dto.LastUpdatedUtc;
            ProductId      = dto.ProductId ?? string.Empty;
            Quantity       = dto.Quantity;
            SelectionData.Clear();
            if (dto.SelectionData != null)
            {
                foreach (var op in dto.SelectionData)
                {
                    var o = new OptionSelection();
                    o.FromDto(op);
                    SelectionData.OptionSelectionList.Add(o);
                }
            }
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Allows you to get a list of the names of each option that makes up the variant. Used for displaying the variant in
        ///     administration.
        /// </summary>
        /// <param name="options">List of Option - the options to parse for the returned list</param>
        /// <returns>List of String - a list of all option names in the variant</returns>
        public List <string> SelectionNames(List <Option> options)
        {
            var result = new List <string>();

            foreach (var opt in options)
            {
                var sel = Selections.FindByOptionId(opt.Bvin);
                if (sel != null)
                {
                    var itemBvin = sel.SelectionData;
                    foreach (var oi in opt.Items)
                    {
                        var cleaned = OptionSelection.CleanBvin(oi.Bvin);
                        if (cleaned == itemBvin)
                        {
                            result.Add(oi.Name);
                            break;
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
 /// <summary>
 ///     This method returns a unique ID that is comprised of the Bvins, separated by a pipe character.
 /// </summary>
 /// <returns>String - a unique ID using the Bvins of each selection</returns>
 public string UniqueKey()
 {
     return(OptionSelection.GenerateUniqueKeyForSelections(Selections));
 }