public void ProductOptionManager_UpdateSpecificationValueDisplayOrder_ShouldChangeDisplayOrder() { var product = CreateProduct("Product"); var option = CreateOption("Size"); var value1 = new ProductSpecificationValue { Product = product, ProductSpecificationAttributeOption = new ProductSpecificationAttributeOption { ProductSpecificationAttribute = option, Name = "11" } }; var value2 = new ProductSpecificationValue { Product = product, ProductSpecificationAttributeOption = new ProductSpecificationAttributeOption { ProductSpecificationAttribute = option, Name = "13" } }; product.SpecificationValues.Add(value1); product.SpecificationValues.Add(value2); Session.Transact(session => session.Save(option)); Session.Transact(session => session.Save(product)); var sortItems = product.SpecificationValues.OrderBy(x => x.DisplayOrder) .Select( arg => new SortItem { Order = arg.DisplayOrder, Id = arg.Id, Name = arg.SpecificationName }) .ToList(); sortItems[0].Order = 0; sortItems[1].Order = 1; _productOptionManager.UpdateSpecificationValueDisplayOrder(sortItems); Session.QueryOver<ProductSpecificationValue>().Where(x => x.DisplayOrder != 0).RowCount().Should().BeGreaterThan(0); }
public void DeleteSpecificationValue(ProductSpecificationValue specification) { specification.Product.SpecificationValues.Remove(specification); _session.Transact(session => session.Delete(specification)); }
public void SetSpecificationValue(Product product, ProductSpecificationAttribute productSpecificationAttribute, string value) { ProductSpecificationValue valueAlias = null; ProductSpecificationAttributeOption optionAlias = null; ProductSpecificationValue specificationValue = _session.QueryOver(() => valueAlias) .JoinAlias( () => valueAlias.ProductSpecificationAttributeOption, () => optionAlias) .Where( () => valueAlias.Product == product && optionAlias.ProductSpecificationAttribute == productSpecificationAttribute ).Cacheable().SingleOrDefault(); ProductSpecificationAttributeOption option = productSpecificationAttribute.Options.FirstOrDefault( attributeOption => string.Equals(attributeOption.Name, value, StringComparison.InvariantCultureIgnoreCase)); if (option == null) { option = new ProductSpecificationAttributeOption { ProductSpecificationAttribute = productSpecificationAttribute, Name = value }; _session.Save(option); } if (specificationValue != null) { specificationValue.ProductSpecificationAttributeOption = option; _session.Transact(session => session.Update(specificationValue)); } else { var productSpecificationValue = new ProductSpecificationValue { Product = product, ProductSpecificationAttributeOption = option }; product.SpecificationValues.Add(productSpecificationValue); _session.Transact(session => session.Update(product)); } }
private void RemoveValue(Product product, ProductSpecificationValue value) { product.SpecificationValues.Remove(value); _session.Delete(value); }
private static void SetSpecificationValues(NopImportContext nopImportContext, HashSet<ProductSpecificationValueData> specificationValues, Product product) { foreach ( ProductSpecificationValueData valueData in specificationValues) { var specificationValue = new ProductSpecificationValue { ProductSpecificationAttributeOption = nopImportContext.FindNew<ProductSpecificationAttributeOption>(valueData.OptionId), Product = product, DisplayOrder = valueData.DisplayOrder }; product.SpecificationValues.Add(specificationValue); nopImportContext.AddEntry(valueData.Id, specificationValue); } }
private ProductSpecificationValue CreateValue(Product product, ProductSpecificationAttribute option, string value) { var specValue = new ProductSpecificationValue { Product = product, ProductSpecificationAttributeOption = new ProductSpecificationAttributeOption { ProductSpecificationAttribute = option, Name = value } }; Session.Transact(session => session.Save(specValue)); return specValue; }