/// <summary> /// Gets a product manufacturer mapping /// </summary> /// <param name="ProductManufacturerID">Product manufacturer mapping identifier</param> /// <returns>Product manufacturer mapping</returns> public static ProductManufacturer GetProductManufacturerByID(int ProductManufacturerID) { if (ProductManufacturerID == 0) { return(null); } string key = string.Format(PRODUCTMANUFACTURERS_BY_ID_KEY, ProductManufacturerID); object obj2 = NopCache.Get(key); if (ManufacturerManager.MappingsCacheEnabled && (obj2 != null)) { return((ProductManufacturer)obj2); } DBProductManufacturer dbItem = DBProviderManager <DBManufacturerProvider> .Provider.GetProductManufacturerByID(ProductManufacturerID); ProductManufacturer productManufacturer = DBMapping(dbItem); if (ManufacturerManager.MappingsCacheEnabled) { NopCache.Max(key, productManufacturer); } return(productManufacturer); }
/// <summary> /// Updates the product manufacturer mapping /// </summary> /// <param name="ProductManufacturerID">Product manufacturer mapping identifier</param> /// <param name="ProductID">Product identifier</param> /// <param name="ManufacturerID">Manufacturer identifier</param> /// <param name="IsFeaturedProduct">A value indicating whether the product is featured</param> /// <param name="DisplayOrder">The display order</param> /// <returns>Product manufacturer mapping </returns> public static ProductManufacturer UpdateProductManufacturer(int ProductManufacturerID, int ProductID, int ManufacturerID, bool IsFeaturedProduct, int DisplayOrder) { DBProductManufacturer dbItem = DBProviderManager <DBManufacturerProvider> .Provider.UpdateProductManufacturer(ProductManufacturerID, ProductID, ManufacturerID, IsFeaturedProduct, DisplayOrder); ProductManufacturer productManufacturer = DBMapping(dbItem); if (ManufacturerManager.ManufacturersCacheEnabled || ManufacturerManager.MappingsCacheEnabled) { NopCache.RemoveByPattern(MANUFACTURERS_PATTERN_KEY); NopCache.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY); } return(productManufacturer); }
private static ProductManufacturerCollection DBMapping(DBProductManufacturerCollection dbCollection) { if (dbCollection == null) { return(null); } ProductManufacturerCollection collection = new ProductManufacturerCollection(); foreach (DBProductManufacturer dbItem in dbCollection) { ProductManufacturer item = DBMapping(dbItem); collection.Add(item); } return(collection); }
private static ProductManufacturer DBMapping(DBProductManufacturer dbItem) { if (dbItem == null) { return(null); } ProductManufacturer item = new ProductManufacturer(); item.ProductManufacturerID = dbItem.ProductManufacturerID; item.ProductID = dbItem.ProductID; item.ManufacturerID = dbItem.ManufacturerID; item.IsFeaturedProduct = dbItem.IsFeaturedProduct; item.DisplayOrder = dbItem.DisplayOrder; return(item); }
/// <summary> /// Inserts a product manufacturer mapping /// </summary> /// <param name="productManufacturer">Product manufacturer mapping</param> public void InsertProductManufacturer(ProductManufacturer productManufacturer) { if (productManufacturer == null) { throw new ArgumentNullException("productManufacturer"); } _context.ProductManufacturers.AddObject(productManufacturer); _context.SaveChanges(); if (this.ManufacturersCacheEnabled || this.MappingsCacheEnabled) { _cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY); _cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY); } }
/// <summary> /// Creates a copy of product with all depended data /// </summary> /// <param name="productId">The product identifier</param> /// <param name="name">The name of product duplicate</param> /// <param name="isPublished">A value indicating whether the product duplicate should be published</param> /// <param name="copyImages">A value indicating whether the product images should be copied</param> /// <returns>Product entity</returns> public Product DuplicateProduct(int productId, string name, bool isPublished, bool copyImages) { var product = GetProductById(productId); if (product == null) return null; Product productCopy = null; //uncomment this line to support transactions //using (var scope = new System.Transactions.TransactionScope()) { // product productCopy = new Product() { Name = name, ShortDescription = product.ShortDescription, FullDescription = product.FullDescription, AdminComment = product.AdminComment, TemplateId = product.TemplateId, ShowOnHomePage = product.ShowOnHomePage, MetaKeywords = product.MetaKeywords, MetaDescription = product.MetaDescription, MetaTitle = product.MetaTitle, SEName = product.SEName, AllowCustomerReviews = product.AllowCustomerReviews, AllowCustomerRatings = product.AllowCustomerRatings, Published = isPublished, Deleted = product.Deleted, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; InsertProduct(productCopy); if (productCopy == null) return null; var languages = IoC.Resolve<ILanguageService>().GetAllLanguages(true); //localization foreach (var lang in languages) { var productLocalized = GetProductLocalizedByProductIdAndLanguageId(product.ProductId, lang.LanguageId); if (productLocalized != null) { var productLocalizedCopy = new ProductLocalized() { ProductId = productCopy.ProductId, LanguageId = productLocalized.LanguageId, Name = productLocalized.Name, ShortDescription = productLocalized.ShortDescription, FullDescription = productLocalized.FullDescription, MetaKeywords = productLocalized.MetaKeywords, MetaDescription = productLocalized.MetaDescription, MetaTitle = productLocalized.MetaTitle, SEName = productLocalized.SEName }; InsertProductLocalized(productLocalizedCopy); } } // product pictures if (copyImages) { foreach (var productPicture in product.ProductPictures) { var picture = productPicture.Picture; var pictureCopy = IoC.Resolve<IPictureService>().InsertPicture(picture.PictureBinary, picture.MimeType, picture.IsNew); InsertProductPicture(new ProductPicture() { ProductId = productCopy.ProductId, PictureId = pictureCopy.PictureId, DisplayOrder = productPicture.DisplayOrder }); } } // product <-> categories mappings foreach (var productCategory in product.ProductCategories) { var productCategoryCopy = new ProductCategory() { ProductId = productCopy.ProductId, CategoryId = productCategory.CategoryId, IsFeaturedProduct = productCategory.IsFeaturedProduct, DisplayOrder = productCategory.DisplayOrder }; IoC.Resolve<ICategoryService>().InsertProductCategory(productCategoryCopy); } // product <-> manufacturers mappings foreach (var productManufacturers in product.ProductManufacturers) { var productManufacturerCopy = new ProductManufacturer() { ProductId = productCopy.ProductId, ManufacturerId = productManufacturers.ManufacturerId, IsFeaturedProduct = productManufacturers.IsFeaturedProduct, DisplayOrder = productManufacturers.DisplayOrder }; IoC.Resolve<IManufacturerService>().InsertProductManufacturer(productManufacturerCopy); } // product <-> releated products mappings foreach (var relatedProduct in product.RelatedProducts) { InsertRelatedProduct( new RelatedProduct() { ProductId1 = productCopy.ProductId, ProductId2 = relatedProduct.ProductId2, DisplayOrder = relatedProduct.DisplayOrder }); } // product specifications foreach (var productSpecificationAttribute in IoC.Resolve<ISpecificationAttributeService>().GetProductSpecificationAttributesByProductId(product.ProductId)) { var psaCopy = new ProductSpecificationAttribute() { ProductId = productCopy.ProductId, SpecificationAttributeOptionId = productSpecificationAttribute.SpecificationAttributeOptionId, AllowFiltering = productSpecificationAttribute.AllowFiltering, ShowOnProductPage = productSpecificationAttribute.ShowOnProductPage, DisplayOrder = productSpecificationAttribute.DisplayOrder }; IoC.Resolve<ISpecificationAttributeService>().InsertProductSpecificationAttribute(psaCopy); } // product variants var productVariants = GetProductVariantsByProductId(product.ProductId, true); foreach (var productVariant in productVariants) { // product variant picture int pictureId = 0; if (copyImages) { var picture = productVariant.Picture; if (picture != null) { var pictureCopy = IoC.Resolve<IPictureService>().InsertPicture(picture.PictureBinary, picture.MimeType, picture.IsNew); pictureId = pictureCopy.PictureId; } } // product variant download & sample download int downloadId = productVariant.DownloadId; int sampleDownloadId = productVariant.SampleDownloadId; if (productVariant.IsDownload) { var download = productVariant.Download; if (download != null) { var downloadCopy = new Download() { UseDownloadUrl = download.UseDownloadUrl, DownloadUrl = download.DownloadUrl, DownloadBinary = download.DownloadBinary, ContentType = download.ContentType, Filename = download.Filename, Extension = download.Extension, IsNew = download.IsNew }; IoC.Resolve<IDownloadService>().InsertDownload(downloadCopy); downloadId = downloadCopy.DownloadId; } if (productVariant.HasSampleDownload) { var sampleDownload = productVariant.SampleDownload; if (sampleDownload != null) { var sampleDownloadCopy = new Download() { UseDownloadUrl = sampleDownload.UseDownloadUrl, DownloadUrl = sampleDownload.DownloadUrl, DownloadBinary = sampleDownload.DownloadBinary, ContentType = sampleDownload.ContentType, Filename = sampleDownload.Filename, Extension = sampleDownload.Extension, IsNew = sampleDownload.IsNew }; IoC.Resolve<IDownloadService>().InsertDownload(sampleDownloadCopy); sampleDownloadId = sampleDownloadCopy.DownloadId; } } } // product variant var productVariantCopy = new ProductVariant() { ProductId = productCopy.ProductId, Name = productVariant.Name, SKU = productVariant.SKU, Description = productVariant.Description, AdminComment = productVariant.AdminComment, ManufacturerPartNumber = productVariant.ManufacturerPartNumber, IsGiftCard = productVariant.IsGiftCard, GiftCardType = productVariant.GiftCardType, IsDownload = productVariant.IsDownload, DownloadId = downloadId, UnlimitedDownloads = productVariant.UnlimitedDownloads, MaxNumberOfDownloads = productVariant.MaxNumberOfDownloads, DownloadExpirationDays = productVariant.DownloadExpirationDays, DownloadActivationType = productVariant.DownloadActivationType, HasSampleDownload = productVariant.HasSampleDownload, SampleDownloadId = sampleDownloadId, HasUserAgreement = productVariant.HasUserAgreement, UserAgreementText = productVariant.UserAgreementText, IsRecurring = productVariant.IsRecurring, CycleLength = productVariant.CycleLength, CyclePeriod = productVariant.CyclePeriod, TotalCycles = productVariant.TotalCycles, IsShipEnabled = productVariant.IsShipEnabled, IsFreeShipping = productVariant.IsFreeShipping, AdditionalShippingCharge = productVariant.AdditionalShippingCharge, IsTaxExempt = productVariant.IsTaxExempt, TaxCategoryId = productVariant.TaxCategoryId, ManageInventory = productVariant.ManageInventory, StockQuantity = productVariant.StockQuantity, DisplayStockAvailability = productVariant.DisplayStockAvailability, DisplayStockQuantity = productVariant.DisplayStockQuantity, MinStockQuantity = productVariant.MinStockQuantity, LowStockActivityId = productVariant.LowStockActivityId, NotifyAdminForQuantityBelow = productVariant.NotifyAdminForQuantityBelow, Backorders = productVariant.Backorders, OrderMinimumQuantity = productVariant.OrderMinimumQuantity, OrderMaximumQuantity = productVariant.OrderMaximumQuantity, WarehouseId = productVariant.WarehouseId, DisableBuyButton = productVariant.DisableBuyButton, CallForPrice = productVariant.CallForPrice, Price = productVariant.Price, OldPrice = productVariant.OldPrice, ProductCost = productVariant.ProductCost, CustomerEntersPrice = productVariant.CustomerEntersPrice, MinimumCustomerEnteredPrice = productVariant.MinimumCustomerEnteredPrice, MaximumCustomerEnteredPrice = productVariant.MaximumCustomerEnteredPrice, Weight = productVariant.Weight, Length = productVariant.Length, Width = productVariant.Width, Height = productVariant.Height, PictureId = pictureId, AvailableStartDateTime = productVariant.AvailableStartDateTime, AvailableEndDateTime = productVariant.AvailableEndDateTime, Published = productVariant.Published, Deleted = productVariant.Deleted, DisplayOrder = productVariant.DisplayOrder, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; InsertProductVariant(productVariantCopy); //localization foreach (var lang in languages) { var productVariantLocalized = GetProductVariantLocalizedByProductVariantIdAndLanguageId(productVariant.ProductVariantId, lang.LanguageId); if (productVariantLocalized != null) { var productVariantLocalizedCopy = new ProductVariantLocalized() { ProductVariantId = productVariantCopy.ProductVariantId, LanguageId = productVariantLocalized.LanguageId, Name = productVariantLocalized.Name, Description = productVariantLocalized.Description }; InsertProductVariantLocalized(productVariantLocalizedCopy); } } // product variant <-> attributes mappings foreach (var productVariantAttribute in IoC.Resolve<IProductAttributeService>().GetProductVariantAttributesByProductVariantId(productVariant.ProductVariantId)) { var productVariantAttributeCopy = new ProductVariantAttribute() { ProductVariantId = productVariantCopy.ProductVariantId, ProductAttributeId = productVariantAttribute.ProductAttributeId, TextPrompt = productVariantAttribute.TextPrompt, IsRequired = productVariantAttribute.IsRequired, AttributeControlTypeId = productVariantAttribute.AttributeControlTypeId, DisplayOrder = productVariantAttribute.DisplayOrder }; IoC.Resolve<IProductAttributeService>().InsertProductVariantAttribute(productVariantAttributeCopy); // product variant attribute values var productVariantAttributeValues = IoC.Resolve<IProductAttributeService>().GetProductVariantAttributeValues(productVariantAttribute.ProductVariantAttributeId); foreach (var productVariantAttributeValue in productVariantAttributeValues) { var pvavCopy = new ProductVariantAttributeValue() { ProductVariantAttributeId = productVariantAttributeCopy.ProductVariantAttributeId, Name = productVariantAttributeValue.Name, PriceAdjustment = productVariantAttributeValue.PriceAdjustment, WeightAdjustment = productVariantAttributeValue.WeightAdjustment, IsPreSelected = productVariantAttributeValue.IsPreSelected, DisplayOrder = productVariantAttributeValue.DisplayOrder }; IoC.Resolve<IProductAttributeService>().InsertProductVariantAttributeValue(pvavCopy); //localization foreach (var lang in languages) { var pvavLocalized = IoC.Resolve<IProductAttributeService>().GetProductVariantAttributeValueLocalizedByProductVariantAttributeValueIdAndLanguageId(productVariantAttributeValue.ProductVariantAttributeValueId, lang.LanguageId); if (pvavLocalized != null) { var pvavLocalizedCopy = new ProductVariantAttributeValueLocalized() { ProductVariantAttributeValueId = pvavCopy.ProductVariantAttributeValueId, LanguageId = pvavLocalized.LanguageId, Name = pvavLocalized.Name }; IoC.Resolve<IProductAttributeService>().InsertProductVariantAttributeValueLocalized(pvavLocalizedCopy); } } } } foreach (var combination in IoC.Resolve<IProductAttributeService>().GetAllProductVariantAttributeCombinations(productVariant.ProductVariantId)) { var combinationCopy = new ProductVariantAttributeCombination() { ProductVariantId = productVariantCopy.ProductVariantId, AttributesXml = combination.AttributesXml, StockQuantity = combination.StockQuantity, AllowOutOfStockOrders = combination.AllowOutOfStockOrders }; IoC.Resolve<IProductAttributeService>().InsertProductVariantAttributeCombination(combinationCopy); } // product variant tier prices foreach (var tierPrice in productVariant.TierPrices) { InsertTierPrice( new TierPrice() { ProductVariantId = productVariantCopy.ProductVariantId, Quantity = tierPrice.Quantity, Price = tierPrice.Price }); } // product variant <-> discounts mapping foreach (var discount in productVariant.AllDiscounts) { IoC.Resolve<IDiscountService>().AddDiscountToProductVariant(productVariantCopy.ProductVariantId, discount.DiscountId); } // prices by customer role foreach (var crpp in productVariant.CustomerRoleProductPrices) { this.InsertCustomerRoleProductPrice( new CustomerRoleProductPrice() { CustomerRoleId = crpp.CustomerRoleId, ProductVariantId = productVariantCopy.ProductVariantId, Price = crpp.Price } ); } } //uncomment this line to support transactions //scope.Complete(); } return productCopy; }
private static ProductManufacturer DBMapping(DBProductManufacturer dbItem) { if (dbItem == null) return null; ProductManufacturer item = new ProductManufacturer(); item.ProductManufacturerID = dbItem.ProductManufacturerID; item.ProductID = dbItem.ProductID; item.ManufacturerID = dbItem.ManufacturerID; item.IsFeaturedProduct = dbItem.IsFeaturedProduct; item.DisplayOrder = dbItem.DisplayOrder; return item; }
public void SaveInfo(int prodId) { Product product = this.ProductService.GetProductById(prodId); if (product != null) { foreach (var item in this.GridState.Values) { if (item.ProductManufacturerId > 0 && !item.IsMapped) this.ManufacturerService.DeleteProductManufacturer(item.ProductManufacturerId); if (item.ProductManufacturerId > 0 && item.IsMapped) { ProductManufacturer pm = this.ManufacturerService.GetProductManufacturerById(item.ProductManufacturerId); if (pm != null) { pm.ProductId = product.ProductId; pm.ManufacturerId = item.ManufacturerId; pm.IsFeaturedProduct = item.IsFeatured; pm.DisplayOrder = item.DisplayOrder; this.ManufacturerService.UpdateProductManufacturer(pm); } } if (item.ProductManufacturerId == 0 && item.IsMapped) { var pm = new ProductManufacturer() { ProductId = product.ProductId, ManufacturerId = item.ManufacturerId, IsFeaturedProduct = item.IsFeatured, DisplayOrder = item.DisplayOrder }; this.ManufacturerService.InsertProductManufacturer(pm); } } } }
protected void btnSave_Click(object sender, EventArgs e) { Manufacturer manufacturer = this.ManufacturerService.GetManufacturerById(this.ManufacturerId); if (manufacturer != null) { var existingProductManufacturers = manufacturer.ProductManufacturers; foreach (GridViewRow row in gvProducts.Rows) { try { CheckBox cbProductInfo = row.FindControl("cbProductInfo") as CheckBox; HiddenField hfProductId = row.FindControl("hfProductId") as HiddenField; NumericTextBox txtRowDisplayOrder = row.FindControl("txtDisplayOrder") as NumericTextBox; int productId = int.Parse(hfProductId.Value); int displayOrder = txtRowDisplayOrder.Value; if (cbProductInfo.Checked) { if (existingProductManufacturers.FindProductManufacturer(productId, this.ManufacturerId) == null) { var pm = new ProductManufacturer() { ProductId = productId, ManufacturerId = this.ManufacturerId, IsFeaturedProduct = false, DisplayOrder = displayOrder }; this.ManufacturerService.InsertProductManufacturer(pm); } } } catch (Exception exc) { ProcessException(exc); } } } this.Page.ClientScript.RegisterStartupScript(typeof(ManufacturerProductAddControl), "closerefresh", "<script language=javascript>try {window.opener.document.forms[0]." + this.BtnId + ".click();}catch (e){} window.close();</script>"); }
/// <summary> /// Updates the product manufacturer mapping /// </summary> /// <param name="productManufacturer">Product manufacturer mapping</param> public void UpdateProductManufacturer(ProductManufacturer productManufacturer) { if (productManufacturer == null) throw new ArgumentNullException("productManufacturer"); if (!_context.IsAttached(productManufacturer)) _context.ProductManufacturers.Attach(productManufacturer); _context.SaveChanges(); if (this.ManufacturersCacheEnabled || this.MappingsCacheEnabled) { _cacheManager.RemoveByPattern(MANUFACTURERS_PATTERN_KEY); _cacheManager.RemoveByPattern(PRODUCTMANUFACTURERS_PATTERN_KEY); } }