private SKUTreeNode AppendProduct(TreeNode parent, CampaignProductDto 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(CampaignsProduct.CLASS_NAME, tree); Program program = GetProgram(product.Campaign, product.ProgramName); ProductCategory productCategory = GetProductCategory(product.ProductCategory); newProduct.DocumentName = product.ProductName; newProduct.DocumentSKUName = product.ProductName; newProduct.NodeSKUID = sku.SKUID; newProduct.NodeName = product.ProductName; newProduct.DocumentCulture = _culture; newProduct.SetValue("ProductName", product.ProductName); newProduct.SetValue("BrandID", GetBrandID(product.Brand)); SetProductItemSpecs(ref newProduct, product); if (program != null) { newProduct.SetValue("ProgramID", program.ProgramID); } if (!string.IsNullOrWhiteSpace(product.AllowedStates)) { newProduct.SetValue("State", GetStatesGroupID(product.AllowedStates)); } if (!string.IsNullOrWhiteSpace(product.EstimatedPrice)) { newProduct.SetValue("EstimatedPrice", product.EstimatedPrice); } if (productCategory != null) { newProduct.SetValue("CategoryID", productCategory.ProductCategoryID); } if (!string.IsNullOrWhiteSpace(product.BundleQuantity)) { newProduct.SetValue("QtyPerPack", product.BundleQuantity); } if (existingProduct == null) { newProduct.Insert(parent); } if (!string.IsNullOrEmpty(product.ImageURL) && !string.IsNullOrEmpty(product.ThumbnailURL)) { GetAndSaveProductImages(newProduct, product.ImageURL, product.ThumbnailURL); } else { RemoveProductImages(newProduct); } newProduct.Update(); return(newProduct); }
private TreeNode GetProductParent(CampaignProductDto campaignProductDto, int siteID) { TreeNode parentDocument = null; SiteInfo site = SiteInfoProvider.GetSiteInfo(siteID); if (string.IsNullOrEmpty(campaignProductDto.Campaign)) { string inventoryProductsAliasPath = SettingsKeyInfoProvider.GetValue("KDA_InventoryProductFolderPath", siteID); parentDocument = DocumentHelper.GetDocument( new NodeSelectionParameters { AliasPath = inventoryProductsAliasPath, SiteName = site.SiteName, CultureCode = site.DefaultVisitorCulture, CombineWithDefaultCulture = false }, new TreeProvider(MembershipContext.AuthenticatedUser) ); } else { parentDocument = GetProgram(campaignProductDto.Campaign, campaignProductDto.ProgramName); } return(parentDocument); }
private void SaveProduct(CampaignProductDto campaignProductDto, int siteID) { TreeNode productParent = GetProductParent(campaignProductDto, siteID); SKUInfo sku = EnsureSKU(campaignProductDto, siteID); AppendProduct(productParent, campaignProductDto, sku, siteID); }
private void SetProductItemSpecs(ref SKUTreeNode newProduct, CampaignProductDto product) { if (!string.IsNullOrWhiteSpace(product.ItemSpecs)) { ProductItemSpecsItem itemSpecs = CustomTableItemProvider.GetItems <ProductItemSpecsItem>().WhereEquals("ItemSpec", product.ItemSpecs); if (itemSpecs != null) { newProduct.SetValue("ItemSpecs", itemSpecs.ItemID); } } if (!string.IsNullOrWhiteSpace(product.CustomItemSpecs)) { newProduct.SetValue("CustomItemSpecs", product.CustomItemSpecs); } }
private static bool ValidateImportItem(CampaignProductDto product, string[] posList, out List <string> validationErrors) { var errorMessageFormat = "field {0} - {1}"; bool isValid = ValidatorHelper.ValidateDto(product, out validationErrors, errorMessageFormat); if (!isValid) { return(false); } if (posList != null && posList.Count() > 0 && !posList.Contains(product.POSNumber)) { isValid = false; validationErrors.Add("Invalid POS Number, POS Number not found"); } return(isValid); }
private static SKUInfo EnsureSKU(CampaignProductDto product, int siteID) { var sku = GetUniqueSKUByPOSNumber(product.POSNumber, siteID) ?? new SKUInfo(); sku.SKUName = product.ProductName; sku.SKUPrice = Convert.ToDouble(product.ActualPrice); sku.SKUSiteID = siteID; sku.SKUNumber = string.IsNullOrWhiteSpace(product.CenveoID) ? "00000" : product.CenveoID; sku.SKUDescription = product.LongDescription; if (product.Status.ToLower().Equals("active")) { sku.SKUEnabled = true; } else { sku.SKUEnabled = false; } if (string.IsNullOrWhiteSpace(product.Campaign)) { sku.SKUTrackInventory = TrackInventoryTypeEnum.ByProduct; } if (!string.IsNullOrWhiteSpace(product.SKUValidUntil)) { sku.SKUValidUntil = ValidationHelper.GetDateTime(product.SKUValidUntil, DateTime.Now); } if (!string.IsNullOrWhiteSpace(product.TotalQuantity)) { sku.SKUAvailableItems = ValidationHelper.GetInteger(product.TotalQuantity, 0); } if (!string.IsNullOrWhiteSpace(product.ProductWeight)) { sku.SKUWeight = ValidationHelper.GetDouble(product.ProductWeight, 0); } sku.SetValue("SKUProductCustomerReferenceNumber", product.POSNumber); SKUInfoProvider.SetSKUInfo(sku); return(sku); }