// ready for potential use in Product upload private static void GetAndSaveProductImages(SKUTreeNode product, string imageUrl, string thumbnailUrl) { var library = new MediaLibrary { SiteId = product.NodeSiteID, LibraryName = "ProductImages", LibraryFolder = "Products", LibraryDescription = "Media library for storing product images" }; var libraryImageUrl = library.DownloadImageToMedialibrary(imageUrl, $"Image{product.SKU.SKUNumber}", $"Product image for SKU {product.SKU.SKUNumber}"); product.RemoveImage(); product.SetImage(libraryImageUrl); RemoveTumbnail(product); AttachThumbnail(product, thumbnailUrl); }
private static void AssignImage(SKUTreeNode product, string mediaLibraryName, string imagePath) { var library = MediaLibraryInfoProvider.GetMediaLibraryInfo(mediaLibraryName, SiteContext.CurrentSiteName); if (library == null) { throw new KeyNotFoundException($"Unable to assign image to SKU '{product.SKU.SKUNumber}'. Media library '{mediaLibraryName}' not found."); } var image = MediaFileInfoProvider.GetMediaFileInfo(library.LibraryID, imagePath); if (image == null) { throw new KeyNotFoundException($"Unable to assign image to SKU '{product.SKU.SKUNumber}'. File '{imagePath}' not found."); } product.RemoveImage(); product.SetImage(image); }
private static void RemoveProductImages(SKUTreeNode product) { product.RemoveImage(); RemoveTumbnail(product); }
private SKUTreeNode AppendProduct(TreeNode parent, ProductDto product, SKUInfo sku, int siteId) { if (parent == null || product == null) { return(null); } TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); SKUTreeNode existingProduct = (SKUTreeNode)parent.Children.FirstOrDefault(c => c.NodeSKUID == sku.SKUID); SKUTreeNode newProduct = existingProduct ?? (SKUTreeNode)TreeNode.New("KDA.Product", tree); newProduct.DocumentName = product.ProductName; newProduct.DocumentSKUName = product.ProductName; newProduct.NodeSKUID = sku.SKUID; newProduct.NodeName = product.ProductName; newProduct.DocumentCulture = _culture; newProduct.SetValue("ProductType", product.ProductType); newProduct.SetValue("ProductSKUWeight", Convert.ToDecimal(product.PackageWeight)); newProduct.SetValue("ProductNumberOfItemsInPackage", Convert.ToInt32(product.ItemsInPackage)); newProduct.SetValue("ProductChiliTemplateID", product.ChiliTemplateID ?? string.Empty); newProduct.SetValue("ProductChiliWorkgroupID", product.ChiliWorkgroupID ?? string.Empty); newProduct.SetValue("ProductChiliPdfGeneratorSettingsId", product.ChiliPdfGeneratorSettingsID ?? string.Empty); newProduct.SetValue("ProductSKUNeedsShipping", (product.NeedsShipping?.ToLower() ?? string.Empty) == "true"); newProduct.SetValue("ProductChili3dEnabled", (product.Chili3DEnabled?.ToLower() ?? string.Empty) == "true"); newProduct.SetValue("ProductDynamicPricing", GetDynamicPricingJson(product.DynamicPriceMinItems, product.DynamicPriceMaxItems, product.DynamicPrice)); newProduct.SetValue("ProductCustomerReferenceNumber", product.CustomerReferenceNumber); newProduct.SetValue("ProductMachineType", product.MachineType); newProduct.SetValue("ProductColor", product.Color); newProduct.SetValue("ProductPaper", product.Paper); newProduct.SetValue("ProductProductionTime", product.ProductionTime); newProduct.SetValue("ProductShipTime", product.ShipTime); newProduct.SetValue("ProductShippingCost", product.ShippingCost); newProduct.SetValue("ProductSheetSize", product.SheetSize); newProduct.SetValue("ProductTrimSize", product.TrimSize); newProduct.SetValue("ProductFinishedSize", product.FinishedSize); newProduct.SetValue("ProductBindery", product.Bindery); if (DateTime.TryParse(product.PublishFrom, out DateTime publishFrom)) { newProduct.DocumentPublishFrom = publishFrom; } if (DateTime.TryParse(product.PublishTo, out DateTime publishTo)) { newProduct.DocumentPublishTo = publishTo; } SetPageTemplate(newProduct, "_Kadena_Product_Detail"); if (existingProduct == null) { newProduct.Insert(parent); } if (!string.IsNullOrEmpty(product.ImageMediaLibraryName) && !string.IsNullOrEmpty(product.ImagePath)) { AssignImage(newProduct, product.ImageMediaLibraryName, product.ImagePath); } else { newProduct.RemoveImage(); } newProduct.Update(); return(newProduct); }