public void SaveSorting(ProductOption option, List<ProductOptionValueSortingData> sortingInfo)
        {
            IList<ProductOptionValueSort> productOptionValueSorts = GetProductOptionValueSorts(option);

            _session.Transact(session =>
            {
                foreach (ProductOptionValueSortingData data in sortingInfo)
                {
                    ProductOptionValueSort existingSort =
                        productOptionValueSorts.FirstOrDefault(sort => sort.Value == data.Value);
                    if (existingSort != null)
                    {
                        existingSort.DisplayOrder = data.DisplayOrder;
                        session.Update(existingSort);
                        continue;
                    }
                    existingSort = new ProductOptionValueSort
                    {
                        ProductOption = option,
                        DisplayOrder = data.DisplayOrder,
                        Value = data.Value
                    };
                    session.Save(existingSort);
                }
            });
        }
Пример #2
0
 private ProductOptionValue CreateValue(ProductVariant product, ProductOption option, string value)
 {
     var specValue = new ProductOptionValue
     {
         ProductVariant = product,
         ProductOption = option,
         Value = value
     };
     Session.Transact(session => session.Save(specValue));
     return specValue;
 }
Пример #3
0
        public void ProductOptionManager_UpdateAttributeOption_AllowsNameToBeUpdated()
        {
            var option = new ProductOption {Name = "Test"};
            Session.Transact(session => session.Save(option));
            var id = option.Id;
            option.Name = "Updated";

            _productOptionManager.UpdateAttributeOption(option);

            Session.Evict(option);
            Session.QueryOver<ProductOption>().Where(productOption => productOption.Id == id).SingleOrDefault().Name.Should().Be("Updated");
        }
Пример #4
0
        public void ProductOptionManager_UpdateAttributeOption_DoesNotAllowNameToBeAnEmptyString()
        {
            var option = new ProductOption {Name = "Test"};
            Session.Transact(session => session.Save(option));
            var id = option.Id;
            option.Name = "";

            _productOptionManager.UpdateAttributeOption(option);

            Session.Evict(option);
            var name = Session.QueryOver<ProductOption>().Where(productOption => productOption.Id == id).SingleOrDefault().Name;
            name.Should().Be("Test", "because {0} is wrong", name);
        }
Пример #5
0
        public string ProcessOptions(NopCommerceDataReader dataReader, NopImportContext nopImportContext)
        {
            var productOptionDatas = dataReader.GetProductOptions();

            _session.Transact(session =>
            {
                foreach (ProductOptionData productOptionData in productOptionDatas)
                {
                    var productOption = new ProductOption
                    {
                        Name = productOptionData.Name
                    };
                    session.Save(productOption);
                    nopImportContext.AddEntry(productOptionData.Id, productOption);
                }
            });

            return string.Format("{0} product options processed", productOptionDatas.Count);
        }
 public void RemoveOption(Product product, ProductOption productOption)
 {
     if (productOption != null && product != null)
     {
         product.Options.Remove(productOption);
         productOption.Products.Remove(product);
         _session.Transact(session =>
             {
                 foreach (var variant in product.Variants.ToList())
                 {
                     foreach (var productOptionValue in variant.OptionValues.Where(value => value.ProductOption == productOption).ToList())
                     {
                         variant.OptionValues.Remove(productOptionValue);
                         session.Delete(productOptionValue);
                     }
                 }
                 session.Update(product);
                 session.Update(productOption);
             });
     }
 }
        public List<ProductOptionValueSortingData> GetOptions(ProductOption productOption)
        {
            ProductOption productOptionAlias = null;
            List<ProductOptionValue> productOptionValues = _session.QueryOver<ProductOptionValue>()
                .JoinAlias(value => value.ProductOption, () => productOptionAlias)
                .Where(() => productOptionAlias.Id == productOption.Id)
                .Cacheable().List().DistinctBy(value => value.Value).ToList();

            IList<ProductOptionValueSort> productOptionValueSorts = GetProductOptionValueSorts(productOption);

            return productOptionValues
                .Select(value =>
                {
                    ProductOptionValueSort order =
                        productOptionValueSorts.FirstOrDefault(sort => sort.Value == value.Value);
                    return new ProductOptionValueSortingData
                    {
                        Value = value.Value,
                        DisplayOrder = order == null ? productOptionValues.Count() : order.DisplayOrder
                    };
                }).OrderBy(data => data.DisplayOrder).ThenBy(data => data.Value).ToList();
        }
 public void AddOption(Product product, ProductOption productOption)
 {
     if (productOption != null && product != null)
     {
         product.Options.Add(productOption);
         productOption.Products.Add(product);
         foreach (var variant in product.Variants)
         {
             variant.OptionValues.Add(new ProductOptionValue
                 {
                     ProductOption = productOption,
                     ProductVariant = variant,
                     Value = string.Empty,
                 });
         }
         _session.Transact(session =>
             {
                 session.Update(product);
                 session.Update(productOption);
             });
     }
 }
Пример #9
0
 public bool AnyExistingAttributeOptionsWithName(ProductOption option)
 {
     return _session.QueryOver<ProductOption>()
         .Where(
             specificationOption =>
                 specificationOption.Name.IsInsensitiveLike(option.Name, MatchMode.Exact))
         .RowCount() > 0;
 }
Пример #10
0
 public void DeleteAttributeOption(ProductOption option)
 {
     _session.Transact(session => session.Delete(option));
 }
Пример #11
0
 public void UpdateAttributeOption(ProductOption option)
 {
     if (option == null || string.IsNullOrWhiteSpace(option.Name))
         return;
     if (AnyExistingAttributeOptionsWithName(option))
         return;
     _session.Transact(session => session.Update(option));
 }
Пример #12
0
 private int GetOptionSortValue(OptionInfo optionInfo, HashSet<ProductOptionValueSort> sorts, ProductOption option, List<OptionInfo> values)
 {
     var productOptionValueSort =
         sorts.FirstOrDefault(sort => sort.ProductOption == option && sort.Value == optionInfo.Value);
     return productOptionValueSort != null
         ? productOptionValueSort.DisplayOrder
         : values.Count;
 }
Пример #13
0
 public void AddAttributeOption(ProductOption productOption)
 {
     if (string.IsNullOrWhiteSpace(productOption.Name))
         return;
     if (!AnyExistingAttributeOptionsWithName(productOption))
         _session.Transact(session => session.Save(productOption));
 }
Пример #14
0
        public void ProductOptionManager_DeleteAttributeOption_DeletesOption()
        {
            var option = new ProductOption {Name = "Test"};
            Session.Transact(session => session.Save(option));

            _productOptionManager.DeleteAttributeOption(option);

            Session.QueryOver<ProductOption>().RowCount().Should().Be(0);
        }
 public ProductOption Add(ProductOption productOption)
 {
     _session.Transact(session => session.Save(productOption));
     return productOption;
 }
Пример #16
0
 private ProductOption CreateOption(string name)
 {
     var option = new ProductOption { Name = name };
     Session.Transact(session => session.Save(option));
     return option;
 }
 private IList<ProductOptionValueSort> GetProductOptionValueSorts(ProductOption productOption)
 {
     return _session.QueryOver<ProductOptionValueSort>()
         .Where(sort => sort.ProductOption.Id == productOption.Id)
         .Cacheable().List();
 }
Пример #18
0
        private void SetOptions(ProductImportDataTransferObject dataTransferObject, Product product)
        {
            List<string> optionsToAdd =
                dataTransferObject.Options.Where(
                    s => !product.Options.Select(option => option.Name).Contains(s, StringComparer.OrdinalIgnoreCase))
                    .ToList();
            List<ProductOption> optionsToRemove =
                product.Options.Where(option => !dataTransferObject.Options.Contains(option.Name)).ToList();

            foreach (string option in optionsToAdd)
            {
                ProductOption existingOption =
                    _session.QueryOver<ProductOption>()
                        .Where(productOption => productOption.Name.IsInsensitiveLike(option, MatchMode.Exact))
                        .Take(1).SingleOrDefault();
                if (existingOption == null)
                {
                    existingOption = new ProductOption
                    {
                        Name = option,
                    };

                    _session.Transact(session => session.Save(existingOption));
                }
                product.Options.Add(existingOption);
                existingOption.Products.Add(product);
            }
            foreach (ProductOption option in optionsToRemove)
            {
                product.Options.Remove(option);
                option.Products.Remove(product);
            }
        }