本文整理汇总了C#中Nop.Core.Domain.Catalog.ProductCategory类的典型用法代码示例。如果您正苦于以下问题:C# ProductCategory类的具体用法?C# ProductCategory怎么用?C# ProductCategory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProductCategory类属于Nop.Core.Domain.Catalog命名空间,在下文中一共展示了ProductCategory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteProductCategory
/// <summary>
/// Deletes a product category mapping
/// </summary>
/// <param name="productCategory">Product category</param>
public virtual void DeleteProductCategory(ProductCategory productCategory)
{
if (productCategory == null)
throw new ArgumentNullException("productCategory");
_productCategoryRepository.Delete(productCategory);
//cache
_cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY);
//event notification
_eventPublisher.EntityDeleted(productCategory);
}
示例2: Can_save_and_load_productCategory
public void Can_save_and_load_productCategory()
{
var productCategory = new ProductCategory
{
IsFeaturedProduct = true,
DisplayOrder = 1,
Product = new Product()
{
Name = "Name 1",
Published = true,
Deleted = false,
CreatedOnUtc = new DateTime(2010, 01, 01),
UpdatedOnUtc = new DateTime(2010, 01, 02)
},
Category = new Category()
{
Name = "Books",
Description = "Description 1",
MetaKeywords = "Meta keywords",
MetaDescription = "Meta description",
MetaTitle = "Meta title",
SeName = "SE name",
ParentCategoryId = 2,
PictureId = 3,
PageSize = 4,
PriceRanges = "1-3;",
ShowOnHomePage = false,
Published = true,
Deleted = false,
DisplayOrder = 5,
CreatedOnUtc = new DateTime(2010, 01, 01),
UpdatedOnUtc = new DateTime(2010, 01, 02),
}
};
var fromDb = SaveAndLoadEntity(productCategory);
fromDb.ShouldNotBeNull();
fromDb.IsFeaturedProduct.ShouldEqual(true);
fromDb.DisplayOrder.ShouldEqual(1);
fromDb.Product.ShouldNotBeNull();
fromDb.Product.Name.ShouldEqual("Name 1");
fromDb.Category.ShouldNotBeNull();
fromDb.Category.Name.ShouldEqual("Books");
}
示例3: ImportProductsFromXlsx
//.........这里部分代码省略.........
var picture1 = manager.GetProperty("Picture1").StringValue;
var picture2 = manager.GetProperty("Picture2").StringValue;
var picture3 = manager.GetProperty("Picture3").StringValue;
product.UpdatedOnUtc = DateTime.UtcNow;
if (isNew)
{
_productService.InsertProduct(product);
}
else
{
_productService.UpdateProduct(product);
}
//search engine name
_urlRecordService.SaveSlug(product, product.ValidateSeName(seName, product.Name, true), 0);
var _seName = product.ValidateSeName(seName, product.Name, true);
//search engine name
_urlRecordService.SaveSlug(product, _seName, 0);
product.SeName = _seName;
_productService.UpdateProduct(product);
//category mappings
if (!String.IsNullOrEmpty(categoryIds))
{
foreach (var id in categoryIds.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (product.ProductCategories.FirstOrDefault(x => x.CategoryId == id) == null)
{
//ensure that category exists
var category = _categoryService.GetCategoryById(id);
if (category != null)
{
var productCategory = new ProductCategory
{
_id = ObjectId.GenerateNewId().ToString(),
Id = product.ProductCategories.Count > 0 ? product.ProductCategories.Max(x => x.Id) + 1 : 1,
ProductId = product.Id,
CategoryId = category.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_categoryService.InsertProductCategory(productCategory);
}
}
}
}
//manufacturer mappings
if (!String.IsNullOrEmpty(manufacturerIds))
{
foreach (var id in manufacturerIds.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (product.ProductManufacturers.FirstOrDefault(x => x.ManufacturerId == id) == null)
{
//ensure that manufacturer exists
var manufacturer = _manufacturerService.GetManufacturerById(id);
if (manufacturer != null)
{
var productManufacturer = new ProductManufacturer
{
_id = ObjectId.GenerateNewId().ToString(),
Id = product.ProductManufacturers.Count > 0 ? product.ProductManufacturers.Max(x => x.Id) + 1 : 1,
ProductId = product.Id,
ManufacturerId = manufacturer.Id,
IsFeaturedProduct = false,
示例4: ImportProductsFromXlsx
//.........这里部分代码省略.........
product.MarkAsNew = markAsNew;
product.MarkAsNewStartDateTimeUtc = markAsNewStartDateTimeUtc;
product.MarkAsNewEndDateTimeUtc = markAsNewEndDateTimeUtc;
product.Weight = weight;
product.Length = length;
product.Width = width;
product.Height = height;
product.Published = published;
product.CreatedOnUtc = createdOnUtc;
product.UpdatedOnUtc = DateTime.UtcNow;
if (newProduct)
{
_productService.InsertProduct(product);
}
else
{
_productService.UpdateProduct(product);
}
//search engine name
_urlRecordService.SaveSlug(product, product.ValidateSeName(seName, product.Name, true), 0);
//category mappings
if (!String.IsNullOrEmpty(categoryIds))
{
foreach (var id in categoryIds.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (product.ProductCategories.FirstOrDefault(x => x.CategoryId == id) == null)
{
//ensure that category exists
var category = _categoryService.GetCategoryById(id);
if (category != null)
{
var productCategory = new ProductCategory
{
ProductId = product.Id,
CategoryId = category.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_categoryService.InsertProductCategory(productCategory);
}
}
}
}
//manufacturer mappings
if (!String.IsNullOrEmpty(manufacturerIds))
{
foreach (var id in manufacturerIds.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (product.ProductManufacturers.FirstOrDefault(x => x.ManufacturerId == id) == null)
{
//ensure that manufacturer exists
var manufacturer = _manufacturerService.GetManufacturerById(id);
if (manufacturer != null)
{
var productManufacturer = new ProductManufacturer
{
ProductId = product.Id,
ManufacturerId = manufacturer.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}
示例5: ProductCategoryInsert
public ActionResult ProductCategoryInsert(GridCommand command, ProductModel.ProductCategoryModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
var productId = model.ProductId;
var categoryId = Int32.Parse(model.Category); //use Category property (not CategoryId) because appropriate property is stored in it
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null)
{
var product = _productService.GetProductById(productId);
if (product != null && product.VendorId != _workContext.CurrentVendor.Id)
{
return Content("This is not your product");
}
}
var existingProductCategories = _categoryService.GetProductCategoriesByCategoryId(categoryId, 0, int.MaxValue, true);
if (existingProductCategories.FindProductCategory(productId, categoryId) == null)
{
var productCategory = new ProductCategory()
{
ProductId = productId,
CategoryId = categoryId,
DisplayOrder = model.DisplayOrder
};
//a vendor cannot edit "IsFeaturedProduct" property
if (_workContext.CurrentVendor == null)
{
productCategory.IsFeaturedProduct = model.IsFeaturedProduct;
}
_categoryService.InsertProductCategory(productCategory);
}
return ProductCategoryList(command, productId);
}
示例6: CopyProduct
//.........这里部分代码省略.........
{
productCopy.ProductTags.Add(productTag);
}
//ensure product is saved before updating totals
_productService.UpdateProduct(product);
foreach (var productTag in product.ProductTags)
{
_productTagService.UpdateProductTagTotals(productTag);
}
// product pictures
if (copyImages)
{
foreach (var productPicture in product.ProductPictures)
{
var picture = productPicture.Picture;
var pictureCopy = _pictureService.InsertPicture(
_pictureService.LoadPictureBinary(picture),
picture.MimeType,
_pictureService.GetPictureSeName(newName),
true);
_productService.InsertProductPicture(new ProductPicture()
{
ProductId = productCopy.Id,
PictureId = pictureCopy.Id,
DisplayOrder = productPicture.DisplayOrder
});
}
}
// product <-> categories mappings
foreach (var productCategory in product.ProductCategories)
{
var productCategoryCopy = new ProductCategory()
{
ProductId = productCopy.Id,
CategoryId = productCategory.CategoryId,
IsFeaturedProduct = productCategory.IsFeaturedProduct,
DisplayOrder = productCategory.DisplayOrder
};
_categoryService.InsertProductCategory(productCategoryCopy);
}
// product <-> manufacturers mappings
foreach (var productManufacturers in product.ProductManufacturers)
{
var productManufacturerCopy = new ProductManufacturer()
{
ProductId = productCopy.Id,
ManufacturerId = productManufacturers.ManufacturerId,
IsFeaturedProduct = productManufacturers.IsFeaturedProduct,
DisplayOrder = productManufacturers.DisplayOrder
};
_manufacturerService.InsertProductManufacturer(productManufacturerCopy);
}
// product <-> releated products mappings
foreach (var relatedProduct in _productService.GetRelatedProductsByProductId1(product.Id, true))
{
_productService.InsertRelatedProduct(
new RelatedProduct()
{
ProductId1 = productCopy.Id,
ProductId2 = relatedProduct.ProductId2,
示例7: ProductCategoryInsert
public ActionResult ProductCategoryInsert(GridCommand command, ProductModel.ProductCategoryModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var productId = model.ProductId;
var categoryId = Int32.Parse(model.Category); //use Category property (not CategoryId) because appropriate property is stored in it
var existingProductCategories = _categoryService.GetProductCategoriesByCategoryId(categoryId, 0, int.MaxValue, true);
if (existingProductCategories.FindProductCategory(productId, categoryId) == null)
{
var productCategory = new ProductCategory()
{
ProductId = productId,
CategoryId = categoryId,
IsFeaturedProduct = model.IsFeaturedProduct,
DisplayOrder = model.DisplayOrder
};
_categoryService.InsertProductCategory(productCategory);
}
return ProductCategoryList(command, productId);
}
示例8: EditIB
public ActionResult EditIB(ProductModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
bool continueEditing = false;
var product = _productService.GetProductById(model.Id);
if (product == null || product.Deleted)
//No product found with the specified id
return RedirectToAction("List");
model.ShowOnHomePage = true;
model.ProductTypeId = 5;
model.VisibleIndividually = true;
model.ProductTemplateId = 1;
model.Published = true;
var catId = model.CategoryId;
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id)
return RedirectToAction("List");
if (ModelState.IsValid)
{
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null)
{
model.VendorId = _workContext.CurrentVendor.Id;
}
var prevStockQuantity = product.GetTotalStockQuantity();
//product
product = model.ToEntity(product);
product.UpdatedOnUtc = DateTime.UtcNow;
_productService.UpdateProduct(product);
//search engine name
model.SeName = product.ValidateSeName(model.SeName, product.Name, true);
_urlRecordService.SaveSlug(product, model.SeName, 0);
//locales
UpdateLocales(product, model);
//tags
SaveProductTags(product, ParseProductTags(model.ProductTags));
//warehouses
SaveProductWarehouseInventory(product, model);
//ACL (customer roles)
SaveProductAcl(product, model);
//Stores
SaveStoreMappings(product, model);
//picture seo names
UpdatePictureSeoNames(product);
//discounts
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToSkus, showHidden: true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
{
//new discount
if (product.AppliedDiscounts.Count(d => d.Id == discount.Id) == 0)
product.AppliedDiscounts.Add(discount);
}
else
{
//remove discount
if (product.AppliedDiscounts.Count(d => d.Id == discount.Id) > 0)
product.AppliedDiscounts.Remove(discount);
}
}
if(catId>0)
{
// delete existing category
var extCat = _categoryService.GetProductCategoriesByProductId(product.Id,true);
if(extCat.Count >0 && !extCat.Any(c=>c.CategoryId == catId))
{
foreach (var item in extCat)
{
_categoryService.DeleteProductCategory(item);
}
}
var categoryMapping = new ProductCategory();
categoryMapping.CategoryId = catId;
categoryMapping.ProductId = product.Id;
categoryMapping.DisplayOrder = 1;
_categoryService.InsertProductCategory(categoryMapping);
}
_productService.UpdateProduct(product);
_productService.UpdateHasDiscountsApplied(product);
//back in stock notifications
if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock &&
product.BackorderMode == BackorderMode.NoBackorders &&
product.AllowBackInStockSubscriptions &&
product.GetTotalStockQuantity() > 0 &&
prevStockQuantity <= 0 &&
product.Published &&
!product.Deleted)
{
_backInStockSubscriptionService.SendNotificationsToSubscribers(product);
}
//.........这里部分代码省略.........
示例9: CopyProduct
//.........这里部分代码省略.........
_urlRecordService.SaveSlug(productCopy, productCopy.ValidateSeName("", name, false), lang.Id);
}
//product tags
foreach (var productTag in product.ProductTags)
{
productCopy.ProductTags.Add(productTag);
}
_productService.UpdateProduct(product);
// product pictures
if (copyImages)
{
foreach (var productPicture in product.ProductPictures)
{
var picture = productPicture.Picture;
var pictureCopy = _pictureService.InsertPicture(
_pictureService.LoadPictureBinary(picture),
picture.MimeType,
_pictureService.GetPictureSeName(newName),
true);
_productService.InsertProductPicture(new ProductPicture()
{
ProductId = productCopy.Id,
PictureId = pictureCopy.Id,
DisplayOrder = productPicture.DisplayOrder
});
}
}
// product <-> categories mappings
foreach (var productCategory in product.ProductCategories)
{
var productCategoryCopy = new ProductCategory()
{
ProductId = productCopy.Id,
CategoryId = productCategory.CategoryId,
IsFeaturedProduct = productCategory.IsFeaturedProduct,
DisplayOrder = productCategory.DisplayOrder
};
_categoryService.InsertProductCategory(productCategoryCopy);
}
// product <-> manufacturers mappings
foreach (var productManufacturers in product.ProductManufacturers)
{
var productManufacturerCopy = new ProductManufacturer()
{
ProductId = productCopy.Id,
ManufacturerId = productManufacturers.ManufacturerId,
IsFeaturedProduct = productManufacturers.IsFeaturedProduct,
DisplayOrder = productManufacturers.DisplayOrder
};
_manufacturerService.InsertProductManufacturer(productManufacturerCopy);
}
// product <-> releated products mappings
foreach (var relatedProduct in _productService.GetRelatedProductsByProductId1(product.Id, true))
{
_productService.InsertRelatedProduct(
new RelatedProduct()
{
ProductId1 = productCopy.Id,
ProductId2 = relatedProduct.ProductId2,
示例10: ResolveProductCategories
private void ResolveProductCategories(ProductResolveInput input, Product product)
{
List<Category> categories = ResolveCategories(input);
IEnumerable<Category> filteredCategories = categories.Any(x => x.ParentCategoryId != 0)
? categories.Where(x => x.ParentCategoryId != 0)
: categories;
foreach (Category category in filteredCategories)
{
if (product.ProductCategories.FirstOrDefault(x => x.CategoryId == category.Id) == null)
{
var productCategory = new ProductCategory
{
ProductId = product.Id,
CategoryId = category.Id,
IsFeaturedProduct = false,
DisplayOrder = 1,
};
_categoryService.InsertProductCategory(productCategory);
}
}
}
示例11: UpdateProductCategory
/// <summary>
/// Updates the product category mapping
/// </summary>
/// <param name="productCategory">>Product category mapping</param>
public virtual void UpdateProductCategory(ProductCategory productCategory)
{
if (productCategory == null)
throw new ArgumentNullException("productCategory");
//_productCategoryRepository.Update(productCategory);
var builder = Builders<Product>.Filter;
var filter = builder.Eq(x => x.Id, productCategory.ProductId);
filter = filter & builder.Where(x => x.ProductCategories.Any(y => y.Id == productCategory.Id));
var update = Builders<Product>.Update
.Set(x => x.ProductCategories.ElementAt(-1).CategoryId, productCategory.CategoryId)
.Set(x => x.ProductCategories.ElementAt(-1).IsFeaturedProduct, productCategory.IsFeaturedProduct)
.Set(x => x.ProductCategories.ElementAt(-1).DisplayOrder, productCategory.DisplayOrder);
var result = _productRepository.Collection.UpdateManyAsync(filter, update).Result;
//var result = collectionProduct.UpdateManyAsync(filter, update).Result;
//cache
_cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY);
_cacheManager.RemoveByPattern(string.Format(PRODUCTS_BY_ID_KEY, productCategory.ProductId));
//event notification
_eventPublisher.EntityUpdated(productCategory);
}
示例12: InsertProductCategory
/// <summary>
/// Inserts a product category mapping
/// </summary>
/// <param name="productCategory">>Product category mapping</param>
public virtual void InsertProductCategory(ProductCategory productCategory)
{
if (productCategory == null)
throw new ArgumentNullException("productCategory");
var updatebuilder = Builders<Product>.Update;
var update = updatebuilder.AddToSet(p => p.ProductCategories, productCategory);
_productRepository.Collection.UpdateOneAsync(new BsonDocument("Id", productCategory.ProductId), update);
//cache
_cacheManager.RemoveByPattern(CATEGORIES_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTCATEGORIES_PATTERN_KEY);
_cacheManager.RemoveByPattern(string.Format(PRODUCTS_BY_ID_KEY, productCategory.ProductId));
//event notification
_eventPublisher.EntityInserted(productCategory);
}
示例13: ImportPhilatelicProductsFromXlsx
//.........这里部分代码省略.........
lot.LastBidAmt = 0; //do this to ensure nulls don't sneak in as used to determine if bids entered
lot.BidPostDateTime = new DateTime(1970, 01, 01);
_consignorService.InsertLot(lot);
}
else
{
lot.UpdatedByUsername = CurrentCustomer.Username;
lot.UpdatedOnDateTime = System.DateTime.UtcNow;
//keep as little time between operations as possible
_productService.UpdateProduct(product);
//TODO: Make AULotRecord a view model so not constantly stuffing consignmentid
lot.ConsignmentID = ConsignmentId;
_consignorService.UpdateLot(lot);
}
//search engine name
_urlRecordService.SaveSlug(product, product.ValidateSeName(seName, product.Name, true), 0);
//category mappings
if (!String.IsNullOrEmpty(categoryIds))
{
foreach (var id in categoryIds.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (product.ProductCategories.FirstOrDefault(x => x.CategoryId == id) == null)
{
//ensure that category exists
var category = _categoryService.GetCategoryById(id);
if (category != null)
{
var productCategory = new ProductCategory
{
ProductId = product.Id,
CategoryId = category.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_categoryService.InsertProductCategory(productCategory);
}
else
{
logError = string.Format("Lot Import: Category ID not found but storing lot anyway row#{0}/Id:{1}.", iRow, id);
_logger.InsertLog(LogLevel.Information, logError);
}
}
}
}
//manufacturer mappings
if (!String.IsNullOrEmpty(manufacturerIds))
{
foreach (var id in manufacturerIds.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (product.ProductManufacturers.FirstOrDefault(x => x.ManufacturerId == id) == null)
{
//ensure that manufacturer exists
var manufacturer = _manufacturerService.GetManufacturerById(id);
if (manufacturer != null)
{
var productManufacturer = new ProductManufacturer
{
ProductId = product.Id,
ManufacturerId = manufacturer.Id,
示例14: ImportProductsFromXlsx
//.........这里部分代码省略.........
var manufacturerIds = worksheet.Cells[endRow, manufacturerCellNum].Value.Return(p => p.ToString(), string.Empty);
if (!manufacturerIds.IsEmpty())
allManufacturersNames.AddRange(manufacturerIds.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()));
}
endRow++;
}
//performance optimization, the check for the existence of the categories in one SQL request
var notExistingCategories = _categoryService.GetNotExistingCategories(allCategoriesNames.ToArray());
if (notExistingCategories.Any())
{
throw new ArgumentException(string.Format("The following category name(s) don't exist - {0}", string.Join(", ", notExistingCategories)));
}
//performance optimization, the check for the existence of the manufacturers in one SQL request
var notExistingManufacturers = _manufacturerService.GetNotExistingManufacturers(allManufacturersNames.ToArray());
if (notExistingManufacturers.Any())
{
throw new ArgumentException(string.Format("The following manufacturer name(s) don't exist - {0}", string.Join(", ", notExistingManufacturers)));
}
//performance optimization, the check for the existence of the product attributes in one SQL request
var notExistingProductAttributes = _productAttributeService.GetNotExistingAttributes(allAttributeIds.ToArray());
if (notExistingProductAttributes.Any())
{
throw new ArgumentException(string.Format("The following product attribute ID(s) don't exist - {0}", string.Join(", ", notExistingProductAttributes)));
}
//performance optimization, load all products by SKU in one SQL request
var allProductsBySku = _productService.GetProductsBySku(allSku.ToArray());
//performance optimization, load all categories IDs for products in one SQL request
var allProductsCategoryIds = _categoryService.GetProductCategoryIds(allProductsBySku.Select(p => p.Id).ToArray());
//performance optimization, load all categories in one SQL request
var allCategories = _categoryService.GetAllCategories(showHidden: true);
//performance optimization, load all manufacturers IDs for products in one SQL request
var allProductsManufacturerIds = _manufacturerService.GetProductManufacturerIds(allProductsBySku.Select(p => p.Id).ToArray());
//performance optimization, load all manufacturers in one SQL request
var allManufacturers = _manufacturerService.GetAllManufacturers(showHidden: true);
//product to import images
var productPictureMetadata = new List<ProductPictureMetadata>();
Product lastLoadedProduct = null;
for (var iRow = 2; iRow < endRow; iRow++)
{
//imports product attributes
if (worksheet.Row(iRow).OutlineLevel != 0)
{
if (_catalogSettings.ExportImportProductAttributes)
{
managerProductAttribute.ReadFromXlsx(worksheet, iRow,
ExportProductAttribute.ProducAttributeCellOffset);
if (lastLoadedProduct == null || managerProductAttribute.IsCaption)
continue;
var productAttributeId = managerProductAttribute.GetProperty("AttributeId").IntValue;
var attributeControlTypeId = managerProductAttribute.GetProperty("AttributeControlType").IntValue;
var productAttributeValueId = managerProductAttribute.GetProperty("ProductAttributeValueId").IntValue;
var associatedProductId = managerProductAttribute.GetProperty("AssociatedProductId").IntValue;
示例15: CreateIB
public ActionResult CreateIB(ProductModel model)
{
bool continueEditing = true;
if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
model.ProductTypeId = 5;
model.ProductTemplateId = 1;
model.Published = true;
model.VisibleIndividually = true;
int minDisplayOrder = 999999;
if (ModelState.IsValid)
{
//a vendor should have access only to his products
if (_workContext.CurrentVendor != null)
{
model.VendorId = _workContext.CurrentVendor.Id;
minDisplayOrder = _productService.GetMinDisplayOrder(model.VendorId);
}
model.ShowOnHomePage = true;
//product
var catId = model.CategoryId;
var product = model.ToEntity();
product.CreatedOnUtc = DateTime.UtcNow;
product.UpdatedOnUtc = DateTime.UtcNow;
product.DisplayOrder = minDisplayOrder - 1;
_productService.InsertProduct(product);
//search engine name
model.SeName = product.ValidateSeName(model.SeName, product.Name, true);
_urlRecordService.SaveSlug(product, model.SeName, 0);
//locales
UpdateLocales(product, model);
//ACL (customer roles)
SaveProductAcl(product, model);
//Stores
SaveStoreMappings(product, model);
//tags
SaveProductTags(product, ParseProductTags(model.ProductTags));
//warehouses
SaveProductWarehouseInventory(product, model);
//discounts
// category
if(catId > 0)
{
var categoryMapping = new ProductCategory();
categoryMapping.CategoryId = catId;
categoryMapping.ProductId = product.Id;
categoryMapping.DisplayOrder = 1;
_categoryService.InsertProductCategory(categoryMapping);
}
var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToSkus, showHidden: true);
foreach (var discount in allDiscounts)
{
if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
product.AppliedDiscounts.Add(discount);
}
_productService.UpdateProduct(product);
_productService.UpdateHasDiscountsApplied(product);
// attributes
//var attributes = _productAttributeService.GetAllProductAttributes();
//var attribute = attributes.FirstOrDefault(a => a.Name == "Circa Date");
//if (attribute != null && model.CircaDate.Year != 1)
// SaveAttribute(model, attribute);
//attribute = attributes.FirstOrDefault(a => a.Name == "Materials");
//if (attribute != null &&!string.IsNullOrWhiteSpace(model.Material))
// SaveAttribute(model, attribute);
//attribute = attributes.FirstOrDefault(a => a.Name == "Country");
//if (attribute != null && !string.IsNullOrWhiteSpace(model.Country))
// SaveAttribute(model, attribute);
//attribute = attributes.FirstOrDefault(a => a.Name == "DesignBy");
//if (attribute != null && !string.IsNullOrWhiteSpace(model.DesignBy))
// SaveAttribute(model, attribute);
//attribute = attributes.FirstOrDefault(a => a.Name == "TermsCondtion");
//if (attribute != null )
// SaveAttribute(model, attribute);
//attribute = attributes.FirstOrDefault(a => a.Name == "Color");
//if (attribute != null && !string.IsNullOrWhiteSpace(model.Color))
// SaveAttribute(model, attribute);
//activity log
_customerActivityService.InsertActivity("AddNewProduct", _localizationService.GetResource("ActivityLog.AddNewProduct"), product.Name);
SuccessNotification(_localizationService.GetResource("Admin.Catalog.Products.Added"));
if (_workContext.CurrentVendor != null)
{
//return RedirectToAction("myhome", "vendor", new { id = _workContext.CurrentVendor.Id });
return RedirectToAction("EditIB", new { id = product.Id });
}
//.........这里部分代码省略.........