/// <summary> /// Allows you to add a new OptionItem to the current Option. /// </summary> /// <param name="itemName">The name that you want the new OptionItem to have. This is a localizable value.</param> /// <returns>If true, the OptionItem was added successfully.</returns> public bool AddItem(string itemName) { var maxSortOrder = Items.Max(i => (int?)i.SortOrder) ?? 0; var oi = new OptionItem(); oi.Name = itemName; oi.SortOrder = maxSortOrder + 1; return(AddItem(oi)); }
/// <summary> /// Allows you to add a new OptionItem to the current Option. /// </summary> /// <param name="item">A pre-populated instance of an OptionItem.</param> /// <returns>If true, the OptionItem was added successfully.</returns> public bool AddItem(OptionItem item) { if (item == null) { return(false); } item.OptionBvin = Bvin; Items.Add(item); return(true); }
/// <summary> /// Use this method to create a copy of the current option item. /// </summary> /// <returns>A duplicate of the current OptionItem.</returns> public OptionItem Clone() { var result = new OptionItem(); result.Bvin = string.Empty; result.IsLabel = IsLabel; result.Name = Name; result.OptionBvin = OptionBvin; result.PriceAdjustment = PriceAdjustment; result.SortOrder = SortOrder; result.StoreId = StoreId; result.WeightAdjustment = WeightAdjustment; result.IsDefault = IsDefault; return(result); }
/// <summary> /// Allows you to populate the current product option object using an instance of OptionDTO /// </summary> /// <param name="dto">An instance of the product option from the REST API</param> public void FromDto(OptionDTO dto) { if (dto == null) { return; } Bvin = dto.Bvin ?? string.Empty; IsShared = dto.IsShared; IsVariant = dto.IsVariant; Items.Clear(); Name = dto.Name ?? string.Empty; NameIsHidden = dto.NameIsHidden; StoreId = dto.StoreId; var typeCode = OptionTypes.DropDownList; typeCode = (OptionTypes)dto.OptionType; SetProcessor(typeCode); foreach (var oi in dto.Items) { var opt = new OptionItem(); opt.FromDto(oi); AddItem(opt); } Settings = new OptionSettings(); foreach (var set in dto.Settings) { Settings.AddOrUpdate(set.Key, set.Value); } TextSettings = new OptionSettings(); foreach (var txtSet in dto.TextSettings) { TextSettings.AddOrUpdate(txtSet.Key, txtSet.Value); } }
/// <summary> /// Update option item /// </summary> /// <param name="item"><see cref="OptionItem" /> instance</param> /// <returns>Returns true if option updated successfully.</returns> public bool OptionItemUpdate(OptionItem item) { return(itemRepository.Update(item)); }