コード例 #1
0
        /// <summary>
        /// Gets the name of the selected option choice
        /// </summary>
        /// <param name="choices">Collection of option choices</param>
        /// <returns>The name of the selected option choice</returns>
        public string GetSelectedOptionChoiceName(OptionChoiceCollection choices)
        {
            int index = choices.IndexOf(this.Option1);

            if (index > -1)
            {
                return(choices[index].Name);
            }

            index = choices.IndexOf(this.Option2);
            if (index > -1)
            {
                return(choices[index].Name);
            }

            index = choices.IndexOf(this.Option3);
            if (index > -1)
            {
                return(choices[index].Name);
            }

            index = choices.IndexOf(this.Option4);
            if (index > -1)
            {
                return(choices[index].Name);
            }

            index = choices.IndexOf(this.Option5);
            if (index > -1)
            {
                return(choices[index].Name);
            }

            index = choices.IndexOf(this.Option6);
            if (index > -1)
            {
                return(choices[index].Name);
            }

            index = choices.IndexOf(this.Option7);
            if (index > -1)
            {
                return(choices[index].Name);
            }

            index = choices.IndexOf(this.Option8);
            if (index > -1)
            {
                return(choices[index].Name);
            }

            return("");
        }
コード例 #2
0
 /// <summary>
 /// Calculates variant
 /// </summary>
 /// <returns><b>true</b> if calculation successful, <b>false</b> otherwise</returns>
 public bool CalculateVariant()
 {
     _Calculated = false;
     int[] choiceIds = this.GetOptionChoices(OptionCountBehavior.ActualCount);
     if (choiceIds != null && choiceIds.Length > 0)
     {
         //INITIALIZE THE CALCULATED VALUES
         _CalculatedPrice  = 0;
         _CalculatedWeight = 0;
         //BUILD CRITERIA TO LOAD CORRECT OPTIONS
         string criteria;
         if (choiceIds.Length == 1)
         {
             criteria = "OptionChoiceId = " + choiceIds[0].ToString();
         }
         else
         {
             string idList = AlwaysConvert.ToList(",", choiceIds);
             criteria = "OptionChoiceId IN (" + idList + ")";
         }
         //RECALCULATE ALL ITEMS
         OptionChoiceCollection choices = OptionChoiceDataSource.LoadForCriteria(criteria);
         OptionChoice           choice;
         List <string>          names = new List <string>();
         StringBuilder          sku   = new StringBuilder();
         sku.Append(this.Product.Sku);
         //LOOP ALL CHOICES INDICATED FOR THIS VARIANT AND CALCULATE THE MODIFIERS
         foreach (int optionChoiceId in choiceIds)
         {
             int index = choices.IndexOf(optionChoiceId);
             if (index > -1)
             {
                 choice = choices[index];
                 names.Add(choice.Name);
                 _CalculatedPrice  += choice.PriceModifier;
                 _CalculatedWeight += choice.WeightModifier;
                 sku.Append(choice.SkuModifier);
             }
         }
         //SET THE CALCULATED VALUES
         _CalculatedName = String.Join(", ", names.ToArray());
         _CalculatedSku  = sku.ToString();
         if (this.VariantName == string.Empty)
         {
             this.VariantName = _CalculatedName;
         }
         if (this.Price == 0)
         {
             this.Price = _CalculatedPrice;
         }
         if (this.Weight == 0)
         {
             this.Weight = _CalculatedWeight;
         }
         if (this.Sku == string.Empty)
         {
             this.Sku = _CalculatedSku;
         }
         _Calculated = true;
     }
     return(_Calculated);
 }