本文整理汇总了C#中Nop.Core.Domain.Catalog.ProductManufacturer类的典型用法代码示例。如果您正苦于以下问题:C# ProductManufacturer类的具体用法?C# ProductManufacturer怎么用?C# ProductManufacturer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProductManufacturer类属于Nop.Core.Domain.Catalog命名空间,在下文中一共展示了ProductManufacturer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteProductManufacturer
/// <summary>
/// Deletes a product manufacturer mapping
/// </summary>
/// <param name="productManufacturer">Product manufacturer mapping</param>
public virtual void DeleteProductManufacturer(ProductManufacturer productManufacturer)
{
if (productManufacturer == null)
throw new ArgumentNullException("productManufacturer");
_productManufacturerRepository.Delete(productManufacturer);
//cache
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
//event notification
_eventPublisher.EntityDeleted(productManufacturer);
}
示例2: Can_save_and_load_productManufacturer
public void Can_save_and_load_productManufacturer()
{
var productManufacturer = new ProductManufacturer
{
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)
},
Manufacturer = new Manufacturer()
{
Name = "Name",
Description = "Description 1",
MetaKeywords = "Meta keywords",
MetaDescription = "Meta description",
MetaTitle = "Meta title",
SeName = "SE name",
PictureId = 3,
PageSize = 4,
PriceRanges = "1-3;",
Published = true,
Deleted = false,
DisplayOrder = 5,
CreatedOnUtc = new DateTime(2010, 01, 01),
UpdatedOnUtc = new DateTime(2010, 01, 02),
}
};
var fromDb = SaveAndLoadEntity(productManufacturer);
fromDb.ShouldNotBeNull();
fromDb.IsFeaturedProduct.ShouldEqual(true);
fromDb.DisplayOrder.ShouldEqual(1);
fromDb.Product.ShouldNotBeNull();
fromDb.Product.Name.ShouldEqual("Name 1");
fromDb.Manufacturer.ShouldNotBeNull();
fromDb.Manufacturer.Name.ShouldEqual("Name");
}
示例3: ImportProductsFromXlsx
//.........这里部分代码省略.........
//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);
}
}
}
}
//pictures
foreach (var picturePath in new [] { picture1, picture2, picture3 })
{
if (String.IsNullOrEmpty(picturePath))
continue;
var mimeType = GetMimeTypeFromFilePath(picturePath);
var newPictureBinary = File.ReadAllBytes(picturePath);
var pictureAlreadyExists = false;
if (!newProduct)
{
//compare with existing product pictures
var existingPictures = _pictureService.GetPicturesByProductId(product.Id);
foreach (var existingPicture in existingPictures)
示例4: ProductManufacturerInsert
public ActionResult ProductManufacturerInsert(GridCommand command, ProductModel.ProductManufacturerModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
return AccessDeniedView();
var productId = model.ProductId;
var manufacturerId = Int32.Parse(model.Manufacturer); //use Manufacturer property (not ManufacturerId) 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 existingProductmanufacturers = _manufacturerService.GetProductManufacturersByManufacturerId(manufacturerId, 0, int.MaxValue, true);
if (existingProductmanufacturers.FindProductManufacturer(productId, manufacturerId) == null)
{
var productManufacturer = new ProductManufacturer()
{
ProductId = productId,
ManufacturerId = manufacturerId,
DisplayOrder = model.DisplayOrder
};
//a vendor cannot edit "IsFeaturedProduct" property
if (_workContext.CurrentVendor == null)
{
productManufacturer.IsFeaturedProduct = model.IsFeaturedProduct;
}
_manufacturerService.InsertProductManufacturer(productManufacturer);
}
return ProductManufacturerList(command, productId);
}
示例5: CopyProduct
//.........这里部分代码省略.........
{
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,
DisplayOrder = relatedProduct.DisplayOrder
});
}
// product <-> cross sells mappings
foreach (var csProduct in _productService.GetCrossSellProductsByProductId1(product.Id, true))
{
_productService.InsertCrossSellProduct(
new CrossSellProduct()
{
ProductId1 = productCopy.Id,
ProductId2 = csProduct.ProductId2,
示例6: ProductManufacturerInsert
public ActionResult ProductManufacturerInsert(GridCommand command, ProductModel.ProductManufacturerModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
return AccessDeniedView();
var productId = model.ProductId;
var manufacturerId = Int32.Parse(model.Manufacturer); //use Manufacturer property (not ManufacturerId) because appropriate property is stored in it
var existingProductmanufacturers = _manufacturerService.GetProductManufacturersByManufacturerId(manufacturerId, 0, int.MaxValue, true);
if (existingProductmanufacturers.FindProductManufacturer(productId, manufacturerId) == null)
{
var productManufacturer = new ProductManufacturer()
{
ProductId = productId,
ManufacturerId = manufacturerId,
IsFeaturedProduct = model.IsFeaturedProduct,
DisplayOrder = model.DisplayOrder
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}
return ProductManufacturerList(command, productId);
}
示例7: InsertProductManufacturer
/// <summary>
/// Inserts a product manufacturer mapping
/// </summary>
/// <param name="productManufacturer">Product manufacturer mapping</param>
public virtual void InsertProductManufacturer(ProductManufacturer productManufacturer)
{
if (productManufacturer == null)
throw new ArgumentNullException("productManufacturer");
//_productManufacturerRepository.Insert(productManufacturer);
var updatebuilder = Builders<Product>.Update;
var update = updatebuilder.AddToSet(p => p.ProductManufacturers, productManufacturer);
_productRepository.Collection.UpdateOneAsync(new BsonDocument("Id", productManufacturer.ProductId), update);
//cache
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
_cacheManager.RemoveByPattern(string.Format(PRODUCTS_BY_ID_KEY, productManufacturer.ProductId));
//event notification
_eventPublisher.EntityInserted(productManufacturer);
}
示例8: ImportProductsFromXlsx
//.........这里部分代码省略.........
NotifyAdminForQuantityBelow = notifyAdminForQuantityBelow,
BackorderModeId = backorderModeId,
AllowBackInStockSubscriptions = allowBackInStockSubscriptions,
OrderMinimumQuantity = orderMinimumQuantity,
OrderMaximumQuantity = orderMaximumQuantity,
AllowedQuantities = allowedQuantities,
DisableBuyButton = disableBuyButton,
CallForPrice = callForPrice,
Price = price,
OldPrice = oldPrice,
ProductCost = productCost,
SpecialPrice = specialPrice,
SpecialPriceStartDateTimeUtc = specialPriceStartDateTimeUtc,
SpecialPriceEndDateTimeUtc = specialPriceEndDateTimeUtc,
CustomerEntersPrice = customerEntersPrice,
MinimumCustomerEnteredPrice = minimumCustomerEnteredPrice,
MaximumCustomerEnteredPrice = maximumCustomerEnteredPrice,
Weight = weight,
Length = length,
Width = width,
Height = height,
Published = published,
CreatedOnUtc = createdOnUtc,
UpdatedOnUtc = DateTime.UtcNow
};
_productService.InsertProductVariant(productVariant);
}
//category mappings
if (!String.IsNullOrEmpty(categoryIds))
{
foreach (var id in categoryIds.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (productVariant.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 = productVariant.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 char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt32(x.Trim())))
{
if (productVariant.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 = productVariant.Product.Id,
ManufacturerId = manufacturer.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}
}
}
}
//pictures
foreach (var picture in new string[] { picture1, picture2, picture3 })
{
if (String.IsNullOrEmpty(picture))
continue;
productVariant.Product.ProductPictures.Add(new ProductPicture()
{
Picture = _pictureService.InsertPicture(File.ReadAllBytes(picture), "image/jpeg", _pictureService.GetPictureSeName(name), true),
DisplayOrder = 1,
});
_productService.UpdateProduct(productVariant.Product);
}
//update "HasTierPrices" and "HasDiscountsApplied" properties
_productService.UpdateHasTierPricesProperty(productVariant);
_productService.UpdateHasDiscountsApplied(productVariant);
//next product
iRow++;
}
}
}
示例9: ImportPhilatelicProductsFromXlsx
//.........这里部分代码省略.........
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,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}
else
{
logError = string.Format("Lot Import: Manufacturer ID not found but storing lot anyway row#{0}/Id:{1}.", iRow, id);
_logger.InsertLog(LogLevel.Information, logError);
}
}
}
}
//pictures
foreach (var picturePath in new[] { picture1, picture2, picture3 })
{
if (String.IsNullOrEmpty(picturePath))
continue;
var mimeType = GetMimeTypeFromFilePath(picturePath);
var newPictureBinary = File.ReadAllBytes(picturePath);
var pictureAlreadyExists = false;
示例10: ResolveProductBrand
private void ResolveProductBrand(ProductResolveInput input, Product product)
{
Manufacturer brand = ResolveBrand(input.ProductInputRow.Brands.Split('|')[0].Trim());
if (product.ProductManufacturers.FirstOrDefault(x => x.ManufacturerId == brand.Id) == null)
{
var productManufacturer = new ProductManufacturer
{
ProductId = product.Id,
ManufacturerId = brand.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}
}
示例11: ImportProductsFromXlsx
//.........这里部分代码省略.........
}
//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;
var valueName = managerProductAttribute.GetProperty("ValueName").StringValue;
var attributeValueTypeId = managerProductAttribute.GetProperty("AttributeValueType").IntValue;
var colorSquaresRgb = managerProductAttribute.GetProperty("ColorSquaresRgb").StringValue;
var imageSquaresPictureId = managerProductAttribute.GetProperty("ImageSquaresPictureId").IntValue;
var priceAdjustment = managerProductAttribute.GetProperty("PriceAdjustment").DecimalValue;
var weightAdjustment = managerProductAttribute.GetProperty("WeightAdjustment").DecimalValue;
示例12: creerArticle
public static bool creerArticle(int idArticle)
{
//Récupération du produit dans la base
string article = NopService.demandeArticle(idArticle);
XmlDocument xmlArticle = new XmlDocument();
xmlArticle.LoadXml(article);
//Création du produit
Product produit = new Product();
produit.Id= int.Parse(xmlArticle.SelectSingleNode("//ID/text()").ToString());
produit.Name = xmlArticle.SelectSingleNode("//Libelle/text()").ToString();
produit.FullDescription = xmlArticle.SelectSingleNode("//Description/text()").ToString();
produit.VendorId = int.Parse(xmlArticle.SelectSingleNode("//ID_Griffe/text()").ToString());
produit.Sku = xmlArticle.SelectSingleNode("//CodeArticle/text()").ToString();
produit.StockQuantity = int.Parse(xmlArticle.SelectSingleNode("//QteUniteStock/text()").ToString());
produit.Price = decimal.Parse(xmlArticle.SelectSingleNode("//PrixTTC/text()").ToString());
produit.Weight = decimal.Parse(xmlArticle.SelectSingleNode("//PoidsArticle/text()").ToString());
produit.IsDownload = false;
produit.IsRecurring = false;
produit.IsRental = false;
produit.DisableWishlistButton = true;
//produit.ShortDescription
//produit.FullDescription
//produit.VisibleIndividually ?
//produit.Gtin ?
//Mise à jour du fabricant + vérification si marque existe ou pas
var manufacturer = _manufacturerService.GetManufacturerById(produit.VendorId);
if (manufacturer != null)
{
//Mises à jour dans le système de NopCommerce
_productService.InsertProduct(produit);
_urlRecordService.SaveSlug(produit, produit.ValidateSeName(produit.Name, produit.Name, true), 0);
var productManufacturer = new ProductManufacturer
{
ProductId = produit.Id,
ManufacturerId = manufacturer.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
//Mise à jour des catégories, à revoir
/*if (produit.ProductCategories == null)
{
//ensure that category exists
var category = _categoryService.GetCategoryById(produit.VendorId);
if (category != null)
{
var productCategory = new ProductCategory
{
ProductId = produit.Id,
CategoryId = category.Id,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_categoryService.InsertProductCategory(productCategory);
}
}*/
//Mise à jour du systère de réductions
_productService.UpdateHasTierPricesProperty(produit);
_productService.UpdateHasDiscountsApplied(produit);
return true;
}
return false;
}
示例13: UpdateProductManufacturer
/// <summary>
/// Updates the product manufacturer mapping
/// </summary>
/// <param name="productManufacturer">Product manufacturer mapping</param>
public virtual void UpdateProductManufacturer(ProductManufacturer productManufacturer)
{
if (productManufacturer == null)
throw new ArgumentNullException("productManufacturer");
//_productManufacturerRepository.Update(productManufacturer);
var builder = Builders<Product>.Filter;
var filter = builder.Eq(x => x.Id, productManufacturer.ProductId);
filter = filter & builder.Where(x => x.ProductManufacturers.Any(y => y.Id == productManufacturer.Id));
var update = Builders<Product>.Update
.Set(x => x.ProductManufacturers.ElementAt(-1).ManufacturerId, productManufacturer.ManufacturerId)
.Set(x => x.ProductManufacturers.ElementAt(-1).IsFeaturedProduct, productManufacturer.IsFeaturedProduct)
.Set(x => x.ProductManufacturers.ElementAt(-1).DisplayOrder, productManufacturer.DisplayOrder);
var result = _productRepository.Collection.UpdateManyAsync(filter, update).Result;
//cache
_cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY);
_cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY);
_cacheManager.RemoveByPattern(string.Format(PRODUCTS_BY_ID_KEY, productManufacturer.ProductId));
//event notification
_eventPublisher.EntityUpdated(productManufacturer);
}
示例14: ImportProductsFromXlsx
//.........这里部分代码省略.........
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,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}
}
}
}
//pictures
foreach (var picturePath in new[] { picture1, picture2, picture3 })
{
if (String.IsNullOrEmpty(picturePath))
continue;
var mimeType = GetMimeTypeFromFilePath(picturePath);
var newPictureBinary = File.ReadAllBytes(picturePath);
var pictureAlreadyExists = false;
if (!isNew)
{
//compare with existing product pictures
示例15: CopyProduct
//.........这里部分代码省略.........
}
}
// product <-> warehouses mappings
foreach (var pwi in product.ProductWarehouseInventory)
{
var pwiCopy = new ProductWarehouseInventory
{
ProductId = productCopy.Id,
WarehouseId = pwi.WarehouseId,
StockQuantity = pwi.StockQuantity,
ReservedQuantity = 0,
};
productCopy.ProductWarehouseInventory.Add(pwiCopy);
}
_productService.UpdateProduct(productCopy);
// 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,
DisplayOrder = relatedProduct.DisplayOrder
});
}
// product <-> cross sells mappings
foreach (var csProduct in _productService.GetCrossSellProductsByProductId1(product.Id, true))
{
_productService.InsertCrossSellProduct(
new CrossSellProduct
{
ProductId1 = productCopy.Id,
ProductId2 = csProduct.ProductId2,