Example #1
0
        /// <summary>
        /// Updates the price matrix.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="sitecoreItem">The sitecore item.</param>
        /// <param name="fieldName">Name of the field.</param>
        private void UpdatePriceMatrix([NotNull] Category category, [NotNull] Item sitecoreItem, [NotNull] string fieldName)
        {
            Assert.ArgumentNotNull(category, "category");
            Assert.ArgumentNotNull(sitecoreItem, "sitecoreItem");
            Assert.ArgumentNotNull(fieldName, "fieldName");

            foreach (Category subCategory in category.Categories)
            {
                foreach (CategoryItem item in subCategory.Items)
                {
                    PriceToInvariantConverter converter = new PriceToInvariantConverter();
                    string value     = item.Amount;
                    bool   converted = converter.Convert(ref value);
                    if (!converted && item.Amount != value)
                    {
                        this.Write("Numbers converting: Unable to convert value \"{0}\", item id \"{1}\", item path \"{2}\", field name \"{3}\".".FormatWith(item.Amount, sitecoreItem.ID, sitecoreItem.Paths.FullPath, fieldName), Level.WARN);
                        continue;
                    }

                    this.Write("Numbers converting: Updating number value from \"{0}\" to \"{1}\", item id \"{2}\", item path \"{3}\", field name \"{4}\".".FormatWith(item.Amount, value, sitecoreItem.ID, sitecoreItem.Paths.FullPath, fieldName), Level.INFO);
                    item.Amount = value;
                }

                if (subCategory.Categories.Count > 0)
                {
                    this.UpdatePriceMatrix(subCategory, sitecoreItem, fieldName);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Formats the prices.
        /// </summary>
        /// <param name="templateId">The template id.</param>
        /// <param name="fields">The fields.</param>
        private void FormatPrices([NotNull] string templateId, [NotNull] ListString fields)
        {
            Assert.ArgumentNotNullOrEmpty(templateId, "templateId");
            Assert.ArgumentNotNull(fields, "fields");

            Item[] items = Database.GetDatabase("master").GetRootItem().Axes.SelectItems(".//*[@@templateid='{0}']".FormatWith(templateId));
            if (items == null)
            {
                this.Write("Numbers converting: No items found to convert for \"{0}\" template.".FormatWith(templateId), Level.WARN);
                return;
            }

            PriceToInvariantConverter converter = new PriceToInvariantConverter();

            using (new SecurityDisabler())
            {
                foreach (Item item in items)
                {
                    foreach (string field in fields)
                    {
                        string value     = item[field];
                        bool   converted = converter.Convert(ref value);
                        if (!converted && item[field] != value)
                        {
                            this.Write("Numbers converting: Unable to convert value \"{0}\", item id \"{1}\", item path \"{2}\", field name \"{3}\".".FormatWith(item[field], item.ID, item.Paths.FullPath, field), Level.WARN);
                            continue;
                        }

                        if (item[field] == value)
                        {
                            continue;
                        }

                        using (new EditContext(item))
                        {
                            this.Write("Numbers converting: Updating value from \"{0}\" to \"{1}\", item id \"{2}\", item path \"{3}\", field name \"{4}\".".FormatWith(item[field], value, item.ID, item.Paths.FullPath, field), Level.INFO);
                            item[field] = value;
                        }
                    }
                }
            }
        }
    /// <summary>
    /// Updates the price matrix.
    /// </summary>
    /// <param name="category">The category.</param>
    /// <param name="sitecoreItem">The sitecore item.</param>
    /// <param name="fieldName">Name of the field.</param>
    private void UpdatePriceMatrix([NotNull] Category category, [NotNull] Item sitecoreItem, [NotNull] string fieldName)
    {
      Assert.ArgumentNotNull(category, "category");
      Assert.ArgumentNotNull(sitecoreItem, "sitecoreItem");
      Assert.ArgumentNotNull(fieldName, "fieldName");

      foreach (Category subCategory in category.Categories)
      {
        foreach (CategoryItem item in subCategory.Items)
        {
          PriceToInvariantConverter converter = new PriceToInvariantConverter();
          string value = item.Amount;
          bool converted = converter.Convert(ref value);
          if (!converted && item.Amount != value)
          {
            this.Write("Numbers converting: Unable to convert value \"{0}\", item id \"{1}\", item path \"{2}\", field name \"{3}\".".FormatWith(item.Amount, sitecoreItem.ID, sitecoreItem.Paths.FullPath, fieldName), Level.WARN);
            continue;
          }

          this.Write("Numbers converting: Updating number value from \"{0}\" to \"{1}\", item id \"{2}\", item path \"{3}\", field name \"{4}\".".FormatWith(item.Amount, value, sitecoreItem.ID, sitecoreItem.Paths.FullPath, fieldName), Level.INFO);
          item.Amount = value;
        }

        if (subCategory.Categories.Count > 0)
        {
          this.UpdatePriceMatrix(subCategory, sitecoreItem, fieldName);
        }
      }
    }
    /// <summary>
    /// Formats the prices.
    /// </summary>
    /// <param name="templateId">The template id.</param>
    /// <param name="fields">The fields.</param>
    private void FormatPrices([NotNull] string templateId, [NotNull] ListString fields)
    {
      Assert.ArgumentNotNullOrEmpty(templateId, "templateId");
      Assert.ArgumentNotNull(fields, "fields");

      Item[] items = Database.GetDatabase("master").GetRootItem().Axes.SelectItems(".//*[@@templateid='{0}']".FormatWith(templateId));
      if (items == null)
      {
        this.Write("Numbers converting: No items found to convert for \"{0}\" template.".FormatWith(templateId), Level.WARN);
        return;
      }

      PriceToInvariantConverter converter = new PriceToInvariantConverter();

      using (new SecurityDisabler())
      {
        foreach (Item item in items)
        {
          foreach (string field in fields)
          {
            string value = item[field];
            bool converted = converter.Convert(ref value);
            if (!converted && item[field] != value)
            {
              this.Write("Numbers converting: Unable to convert value \"{0}\", item id \"{1}\", item path \"{2}\", field name \"{3}\".".FormatWith(item[field], item.ID, item.Paths.FullPath, field), Level.WARN);
              continue;
            }

            if (item[field] == value)
            {
              continue;
            }

            using (new EditContext(item))
            {
              this.Write("Numbers converting: Updating value from \"{0}\" to \"{1}\", item id \"{2}\", item path \"{3}\", field name \"{4}\".".FormatWith(item[field], value, item.ID, item.Paths.FullPath, field), Level.INFO);
              item[field] = value;
            }
          }
        }
      }
    }