private void ImportSingleProduct(data.bvc_Product old) { if (old == null) return; wl("Product: " + old.ProductName + " [" + old.ID + "]"); ProductDTO p = new ProductDTO(); p.AllowReviews = true; p.Bvin = old.ID; p.CreationDateUtc = old.CreationDate; p.CustomProperties = new List<CustomPropertyDTO>(); p.Featured = false; p.GiftWrapAllowed = true; p.GiftWrapPrice = 0; p.ImageFileSmall = TextHelper.CleanFileName(System.IO.Path.GetFileName(old.ImageFileMedium)); p.ImageFileSmallAlternateText = old.ProductName; p.InventoryMode = ProductInventoryModeDTO.AlwayInStock; switch (old.InventoryNotAvailableStatus) { case 1: // Ignore Inventory p.InventoryMode = ProductInventoryModeDTO.AlwayInStock; break; case 2: // Allow Backorders p.InventoryMode = ProductInventoryModeDTO.WhenOutOfStockAllowBackorders; break; case 3: // Show, no orders p.InventoryMode = ProductInventoryModeDTO.WhenOutOfStockShow; break; case 0: // Pull from store p.InventoryMode = ProductInventoryModeDTO.WhenOutOfStockHide; break; } p.IsAvailableForSale = true; p.Keywords = string.Empty; p.ListPrice = (decimal)old.ListPrice; p.LongDescription = old.LongDescription; p.ManufacturerId = old.ManufacturerID.ToString(); p.MetaDescription = old.MetaDescription; p.MetaKeywords = old.MetaKeywords; p.MetaTitle = old.MetaTitle; p.MinimumQty = old.MinimumQty; p.PostContentColumnId = string.Empty; p.PreContentColumnId = string.Empty; p.PreTransformLongDescription = string.Empty; p.ProductName = old.ProductName; p.ProductTypeId = old.ProductTypeID.ToString(); p.ShippingDetails = new ShippableItemDTO(); p.ShippingDetails.ExtraShipFee = old.ExtraShipFee; p.ShippingDetails.Height = (decimal)old.ShippingHeight; p.ShippingDetails.IsNonShipping = old.NonShipping == 1; p.ShippingDetails.Length = (decimal)old.ShippingLength; p.ShippingDetails.ShippingScheduleId = 0; p.ShippingDetails.ShipSeparately = old.ShipSeparately == 1; p.ShippingDetails.Weight = (decimal)old.ShippingWeight; p.ShippingDetails.Width = (decimal)old.ShippingWeight; switch (old.DropShipMode) { case 1: p.ShippingMode = ShippingModeDTO.ShipFromSite; break; case 2: p.ShippingMode = ShippingModeDTO.ShipFromVendor; break; case 3: p.ShippingMode = ShippingModeDTO.ShipFromManufacturer; break; default: p.ShippingMode = ShippingModeDTO.ShipFromSite; break; } p.ShortDescription = old.ShortDescription; p.SiteCost = (decimal)old.SiteCost; p.SitePrice = (decimal)old.SitePrice; p.SitePriceOverrideText = string.Empty; p.Sku = old.ID; switch (old.Status) { case 0: p.Status = ProductStatusDTO.Disabled; break; default: p.Status = ProductStatusDTO.Active; break; } p.Tabs = new List<ProductDescriptionTabDTO>(); p.TaxExempt = old.TaxExempt == 1; p.TaxSchedule = 0; if (TaxScheduleMapper.ContainsKey(old.TaxClass)) p.TaxSchedule = TaxScheduleMapper[old.TaxClass]; p.VendorId = old.VendorID.ToString(); byte[] bytes = GetBytesForLocalImage(old.ImageFileMedium); if (bytes != null) { wl("Found Image: " + p.ImageFileSmall + " [" + FriendlyFormatBytes(bytes.Length) + "]"); } else { wl("Missing Image: " + p.ImageFileSmall); bytes = new byte[0]; } Api proxy = GetBV6Proxy(); ApiResponse<ProductDTO> res = null; //if (settings.ImportProductImagesOnly == true) //{ // proxy.ProductsMainImageUpload(old.ID, p.ImageFileSmall, bytes); // res = new ApiResponse<ProductDTO>(); // res.Errors.Clear(); //} //else //{ res = proxy.ProductsCreate(p, bytes); //} if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } else { if (settings.ImportProductImagesOnly == false) { AssignOptionsToProduct(old.ID); AssignProductPropertyValues(old.ID); } wl("SUCCESS"); } } if (settings.ImportProductImagesOnly == false) { // Inventory MigrateProductInventory(old.ID); } // Additional Images MigrateProductAdditionalImages(old.ID); if (settings.ImportProductImagesOnly == false) { // Volume Prices MigrateProductVolumePrices(old.ID); // Reviews MigrateProductReviews(old.ID); // Link to Categories MigrateProductCategoryLinks(old.ID); } // Assign File Downloads AssignFileDownloadsToProduct(old.ID); // Index Product wl("- Building Search Index for Product"); Api bv6proxy = GetBV6Proxy(); bv6proxy.SearchManagerIndexProduct(old.ID); wl("-FINISHED Product: " + old.ProductName + " [" + old.ID + "]"); }
//private List<CustomPropertyDTO> TranslateOldProperties(string oldXml) //{ // List<CustomPropertyDTO> result = new List<CustomPropertyDTO>(); // CustomPropertyCollection props = CustomPropertyCollection.FromXml(oldXml); // if (props != null) // { // foreach (CustomProperty prop in props) // { // result.Add(prop.ToDto()); // } // } // return result; //} private void ImportSingleProduct(ProductDTO p) { wl("Product: " + p.ProductName + " [" + p.Sku + "]"); byte[] bytes = new byte[0]; Api proxy = GetMerchantTribeProxy(); var res = proxy.ProductsCreate(p, bytes); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } else { if (settings.ImportProductImagesOnly == false) { AssignOptionsToProduct(p.Bvin); AssignProductPropertyValues(p.Bvin); } wl("SUCCESS"); } } if (settings.ImportProductImagesOnly == false) { // Inventory MigrateProductInventory(p.Bvin); // File Downloads //MigrateProductFileDownloads(p.Bvin); } // Additional Images MigrateProductAdditionalImages(p.Bvin); if (settings.ImportProductImagesOnly == false) { // Volume Prices MigrateProductVolumePrices(p.Bvin); // Reviews MigrateProductReviews(p.Bvin); // Link to Categories MigrateProductCategoryLinks(p.Bvin); } }
private void ImportSingleProduct(data.bvc_Product old) { if (old == null) return; if (old.ParentID.Trim() != string.Empty) { wl("Skipping product [" + old.SKU + "] because it is a variant"); return; } wl("Product: " + old.ProductName + " [" + old.SKU + "]"); ProductDTO p = new ProductDTO(); p.AllowReviews = true; p.Bvin = old.bvin; p.CreationDateUtc = old.CreationDate; p.CustomProperties = TranslateOldProperties(old.CustomProperties); p.Featured = false; p.GiftWrapAllowed = true; p.GiftWrapPrice = 0; p.ImageFileSmall = TextHelper.CleanFileName(System.IO.Path.GetFileName(old.ImageFileMedium)); p.ImageFileSmallAlternateText = old.MediumImageAlternateText; p.InventoryMode = ProductInventoryModeDTO.AlwayInStock; if (old.TrackInventory == 1) p.InventoryMode = ProductInventoryModeDTO.WhenOutOfStockShow; p.IsAvailableForSale = true; p.Keywords = old.Keywords; p.ListPrice = old.ListPrice; p.LongDescription = old.LongDescription; p.ManufacturerId = old.ManufacturerID; p.MetaDescription = TextHelper.RemoveHtmlTags(old.MetaDescription, " "); p.MetaKeywords = TextHelper.RemoveHtmlTags(old.MetaKeywords, " "); p.MetaTitle = TextHelper.RemoveHtmlTags(old.MetaTitle, " "); p.MinimumQty = old.MinimumQty; p.PostContentColumnId = string.Empty; p.PreContentColumnId = string.Empty; p.PreTransformLongDescription = old.PreTransformLongDescription; p.ProductName = TextHelper.RemoveHtmlTags(old.ProductName, " "); p.ProductTypeId = old.ProductTypeId; p.ShippingDetails = new ShippableItemDTO(); p.ShippingDetails.ExtraShipFee = old.ExtraShipFee; p.ShippingDetails.Height = old.ShippingHeight; p.ShippingDetails.IsNonShipping = old.NonShipping == 1; p.ShippingDetails.Length = old.ShippingLength; p.ShippingDetails.ShippingScheduleId = 0; p.ShippingDetails.ShipSeparately = old.ShipSeparately == 1; p.ShippingDetails.Weight = old.ShippingWeight; p.ShippingDetails.Width = old.ShippingWidth; switch (old.ShippingMode) { case 1: p.ShippingMode = ShippingModeDTO.ShipFromSite; break; case 2: p.ShippingMode = ShippingModeDTO.ShipFromVendor; break; case 3: p.ShippingMode = ShippingModeDTO.ShipFromManufacturer; break; default: p.ShippingMode = ShippingModeDTO.ShipFromSite; break; } p.ShortDescription = old.ShortDescription; p.SiteCost = old.SiteCost; p.SitePrice = old.SitePrice; p.SitePriceOverrideText = old.SitePriceOverrideText; p.Sku = old.SKU; switch (old.Status) { case 0: p.Status = ProductStatusDTO.Disabled; break; default: p.Status = ProductStatusDTO.Active; break; } p.Tabs = new List<ProductDescriptionTabDTO>(); p.TaxExempt = old.TaxExempt == 1; p.TaxSchedule = 0; if (TaxScheduleMapper.ContainsKey(old.TaxClass)) p.TaxSchedule = TaxScheduleMapper[old.TaxClass]; p.VendorId = old.VendorID; p.UrlSlug = GetCustomUrlSlug(old.bvin); byte[] bytes = GetBytesForLocalImage(old.ImageFileMedium); if (bytes != null) { wl("Found Image: " + p.ImageFileSmall + " [" + FriendlyFormatBytes(bytes.Length) + "]"); } else { wl("Missing Image: " + p.ImageFileSmall); bytes = new byte[0]; } Api proxy = GetBV6Proxy(); ApiResponse<ProductDTO> res = null; //if (settings.ImportProductImagesOnly == true) //{ // proxy.ProductsMainImageUpload(old.bvin, p.ImageFileSmall, bytes); // res = new ApiResponse<ProductDTO>(); // res.Errors.Clear(); //} //else //{ res = proxy.ProductsCreate(p, bytes); //} if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } else { if (settings.ImportProductImagesOnly == false) { AssignOptionsToProduct(old.bvin); AssignProductPropertyValues(old.bvin); } wl("SUCCESS"); } } if (settings.ImportProductImagesOnly == false) { // Inventory MigrateProductInventory(old.bvin); } // Additional Images MigrateProductAdditionalImages(old.bvin); if (settings.ImportProductImagesOnly == false) { // Volume Prices MigrateProductVolumePrices(old.bvin); // Reviews MigrateProductReviews(old.bvin); // Link to Categories MigrateProductCategoryLinks(old.bvin); } }
public ApiResponse<ProductDTO> ProductsUpdate(ProductDTO item) { ApiResponse<ProductDTO> result = new ApiResponse<ProductDTO>(); result = RestHelper.PostRequest<ApiResponse<ProductDTO>>(this.fullApiUri + "products/" + Enc(item.Bvin) + "?key=" + Enc(key), MerchantTribe.Web.Json.ObjectToJson(item)); return result; }
public ApiResponse<ProductDTO> ProductsCreate(ProductDTO item, byte[] imageData) { ApiResponse<ProductDTO> result = new ApiResponse<ProductDTO>(); result = RestHelper.PostRequest<ApiResponse<ProductDTO>>(this.fullApiUri + "products/?key=" + Enc(key), MerchantTribe.Web.Json.ObjectToJson(item)); if (result.Content != null) { ProductsMainImageUpload(result.Content.Bvin, result.Content.ImageFileSmall, imageData); } return result; }
private void IndexSingleProduct(ProductDTO p) { if (p == null) return; wl("Indexing: " + p.ProductName + " [" + p.Sku + "]"); Api proxy = GetBV6Proxy(); var result = proxy.SearchManagerIndexProduct(p.Bvin); if (result != null) { if (result.Content == true) { wl("SUCCESS - " + p.ProductName + " [" + p.Sku + "]"); } else { wl("FAIL - " + p.ProductName + " [" + p.Sku + "]"); } } }