public static Country TranslateCountry(string connectionString, string countryBvin) { Country result = new Country(); data.BV53Entities db = new data.BV53Entities(connectionString); var old = db.bvc_Country.Where(y => y.bvin == countryBvin).FirstOrDefault(); if (old == null) return Country.FindByISOCode("US"); result = Country.FindByISOCode(old.ISOCode); return result; }
public static string TranslateRegionBvinToAbbreviation(string connString, string regionBvin) { string result = string.Empty; data.BV53Entities db = new data.BV53Entities(connString); var old = db.bvc_Region.Where(y => y.bvin == regionBvin).FirstOrDefault(); if (old == null) return result; result = old.Abbreviation; return result; }
private List<OrderNoteDTO> TranslateNotes(string orderBvin) { List<OrderNoteDTO> result = new List<OrderNoteDTO>(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var old = db.bvc_OrderNote.Where(y => y.OrderId == orderBvin); if (old == null) return result; foreach (data.bvc_OrderNote item in old) { OrderNoteDTO n = new OrderNoteDTO(); n.AuditDate = item.AuditDate; n.IsPublic = item.NoteType == 3; n.LastUpdatedUtc = item.LastUpdated; n.Note = item.Note ?? string.Empty; n.OrderID = orderBvin; result.Add(n); } return result; }
private List<LineItemDTO> TranslateItems(string orderBvin) { List<LineItemDTO> result = new List<LineItemDTO>(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var old = db.bvc_LineItem.Where(y => y.OrderBvin == orderBvin); if (old == null) return result; foreach (data.bvc_LineItem item in old) { LineItemDTO li = new LineItemDTO(); li.BasePricePerItem = item.BasePrice; li.CustomProperties = TranslateOldProperties(item.CustomProperties); li.DiscountDetails = new List<DiscountDetailDTO>(); li.ExtraShipCharge = 0; li.Id = -1; li.LastUpdatedUtc = item.LastUpdated; li.OrderBvin = orderBvin; li.ProductId = item.ProductId; li.ProductName = item.ProductName; li.ProductShortDescription = item.ProductShortDescription; li.ProductSku = item.ProductSku; li.ProductShippingHeight = 0; li.ProductShippingLength = 0; li.ProductShippingWeight = 0; li.ProductShippingWidth = 0; li.Quantity = (int)item.Quantity; li.QuantityReturned = (int)item.QuantityReturned; li.QuantityShipped = (int)item.QuantityShipped; li.SelectionData = new List<OptionSelectionDTO>(); li.ShipFromAddress = new AddressDTO(); li.ShipFromMode = ShippingModeDTO.ShipFromSite; li.ShipFromNotificationId = string.Empty; li.ShippingPortion = 0; li.ShippingSchedule = 0; li.ShipSeparately = false; li.StatusCode = item.StatusCode; li.StatusName = item.StatusName; li.TaxPortion = 0m; li.TaxSchedule = 0; li.VariantId = string.Empty; // Calculate Adjustments and Discounts decimal lineTotal = item.LineTotal; decimal prediscountTotal = (li.BasePricePerItem * (decimal)li.Quantity); decimal allDiscounts = prediscountTotal - lineTotal; if (allDiscounts != 0) { li.DiscountDetails.Add(new DiscountDetailDTO() { Amount = -1 * allDiscounts, Description = "BV5 Discounts", Id = new Guid() }); } result.Add(li); } return result; }
private void ImportRelatedItems() { Header("Importing Related Items"); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var crosses = db.bvc_ProductCrossSell; if (crosses == null) return; foreach (data.bvc_ProductCrossSell x in crosses) { wl("Relating " + x.ProductBvin + " to " + x.CrossSellBvin); proxy.ProductRelationshipsQuickCreate(x.ProductBvin, x.CrossSellBvin, false); } var ups = db.bvc_ProductUpSell; if (ups == null) return; foreach (data.bvc_ProductUpSell up in ups) { wl("Relating Up " + up.ProductBvin + " to " + up.UpSellBvin); proxy.ProductRelationshipsQuickCreate(up.ProductBvin, up.UpSellBvin, true); } }
private void ImportAffiliateReferrals(string bvin, long newId) { wl(" - Migrating Referrals..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var referrals = db.bvc_AffiliateReferral.Where(y => y.affid == bvin); if (referrals == null) return; foreach (data.bvc_AffiliateReferral r in referrals) { AffiliateReferralDTO rnew = new AffiliateReferralDTO(); rnew.AffiliateId = newId; rnew.TimeOfReferralUtc = r.TimeOfReferral; rnew.ReferrerUrl = r.referrerurl; Api bv6proxy = GetBV6Proxy(); var res = bv6proxy.AffiliateReferralsCreate(rnew); } }
private BV5OptionTextSettings GetOptionSettingsText(string bvin) { BV5OptionTextSettings result = new BV5OptionTextSettings(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var componentSettings = db.bvc_ComponentSetting.Where(y => y.ComponentID == bvin).OrderBy(y => y.SettingName); if (componentSettings == null) return result; foreach (data.bvc_ComponentSetting cs in componentSettings) { switch (cs.SettingName.Trim().ToLowerInvariant()) { case "columns": result.Columns = cs.SettingValue; break; case "rows": result.Rows = cs.SettingValue; break; case "displayname": result.DisplayName = cs.SettingValue; break; case "required": result.Required = cs.SettingValue; break; case "wraptext": result.WrapText = cs.SettingValue; break; } } return result; }
public void Migrate(MigrationSettings s) { wl(""); wl("BV Commerce 5 Migrator Started"); wl(""); settings = s; try { oldDatabase = new data.BV53Entities(EFConnString(s.SourceConnectionString())); } catch (Exception ex2) { wl("EXCEPTION While attempting to create old database model!"); wl(ex2.Message); wl(ex2.StackTrace); return; } try { // Clear Products if (s.ClearProducts && s.ImportProductImagesOnly == false) { ClearProducts(); } // Clear Categories if (s.ClearCategories) { ClearCategories(); } // Clear Users if (s.ClearUsers) { ClearUsers(); } // Users if (s.ImportUsers) { //ImportRoles(); ImportPriceGroups(); ImportUsers(); } // Affiliates if (s.ImportAffiliates) { ImportAffiliates(); } // Tax Classes are prerequisite for product import if (s.ImportOtherSettings || (s.ImportProducts && s.SkipProductPrerequisites == false)) { ImportTaxSchedules(); ImportTaxes(); } // Vendors and Manufacturers if ((s.ImportProducts && s.ImportProductImagesOnly == false && s.SkipProductPrerequisites == false) || s.ImportCategories) { ImportVendors(); ImportManufacturers(); } // Product Types if (s.ImportProducts && s.ImportProductImagesOnly == false && s.SkipProductPrerequisites == false) { ImportProductProperties(); ImportProductTypes(); } // Categories if (s.ImportCategories) { ImportCategories(); } if (s.ImportProducts) { if (s.ImportProductImagesOnly == false && s.SkipProductPrerequisites == false) { ImportProductInputs(); ImportProductModifiers(); ImportProductChoices(); } ImportProducts(); MigrateProductFileDownloads(); if (s.ImportProductImagesOnly == false) { ImportRelatedItems(); } } if (s.ImportOrders) { ImportOrders(); } if (s.ImportOtherSettings) { ImportMailingLists(); ImportPolicies(); ImportFraudData(); } } catch (Exception e) { wl("ERROR: " + e.Message); wl(e.StackTrace); } }
private void MigrateProductFileDownloads() { Header("Migrating File Downloads"); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var items = db.bvc_ProductFile; if (items == null) return; foreach (data.bvc_ProductFile old in items) { wl("File: " + old.FileName); string safeFileName = "\\files\\" + old.bvin + "_" + old.FileName + ".config"; byte[] bytes = GetBytesForLocalImage(safeFileName); if (bytes == null) { wl("Missing File: " + old.FileName); continue; } else { wl("Found File: " + old.FileName + " [" + FriendlyFormatBytes(bytes.Length) + "]"); } int totalChunks = 0; byte[] partial = null; if (bytes != null && bytes.Length > 0) { double ChunkCount = 0; ChunkCount = (double)bytes.Length / (double)CHUNKSIZE; ChunkCount = Math.Ceiling(ChunkCount); totalChunks = (int)ChunkCount; if (totalChunks > 0) { partial = GetAChunkFromFullBytes(bytes, 0); } } var res = proxy.ProductFilesDataUploadFirstPart(old.bvin, old.FileName, old.ShortDescription, partial); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } wl("File Created"); if (totalChunks > 1) { wl("Uploading: "); for (int i = 1; i < totalChunks; i++) { partial = GetAChunkFromFullBytes(bytes, i); wl("+ " + old.FileName + " [" + FriendlyFormatBytes(bytes.Length) + "] part " + (i + 1) + " of " + totalChunks.ToString()); var res2 = proxy.ProductFilesDataUploadAdditionalPart(old.bvin, old.FileName, partial); } } wl("File Done Uploading!"); } else { wl("FAILED! EXCEPTION!"); } } var crosses = db.bvc_ProductFileXProduct; if (crosses == null) return; foreach (data.bvc_ProductFileXProduct x in crosses) { wl("Linking Product " + x.ProductId + " to " + x.ProductFileId); var res2 = proxy.ProductFilesAddToProduct(x.ProductId, x.ProductFileId, x.AvailableMinutes, x.MaxDownloads); if (res2 != null) { if (res2.Errors.Count > 0) { DumpErrors(res2.Errors); wl("FAILED"); } else { wl("SUCCESS"); } } else { wl("FAILED! EXCEPTION!"); } } }
private void MigrateProductCategoryLinks(string bvin) { wl(" - Migrating Category Links"); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var items = db.bvc_ProductXCategory.Where(y => y.ProductId == bvin); if (items == null) return; foreach (data.bvc_ProductXCategory item in items) { wl("To Category: " + item.CategoryId); var res = proxy.CategoryProductAssociationsQuickCreate(bvin, item.CategoryId); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } } else { wl("FAILED! EXCEPTION!"); } } }
private void AssignProductPropertyValues(string bvin) { wl(" - Migrating Property Values..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var items = db.bvc_ProductPropertyValue.Where(y => y.ProductBvin == bvin); if (items == null) return; foreach (data.bvc_ProductPropertyValue item in items) { var map = ProductPropertyMapper.Where(y => y.OldBvin == item.PropertyBvin).FirstOrDefault(); if (map == null) { wl("!!Missing Map for old property bvin of " + item.PropertyBvin); continue; } string newPropertyValue = item.PropertyValue; long newChoiceId = -1; switch (map.PropertyType) { case ProductPropertyTypeDTO.MultipleChoiceField: newChoiceId = FindNewChoiceId(map, item.PropertyValue); newPropertyValue = newChoiceId.ToString(); break; default: newPropertyValue = item.PropertyValue; break; } long newId = map.NewBvin; if (newId > 0) { proxy.ProductPropertiesSetValueForProduct(newId, bvin, newPropertyValue, newChoiceId); } } }
private void MigrateProductAdditionalImages(string bvin) { wl(" - Migrating AdditionalImages..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var items = db.bvc_ProductImage.Where(y => y.ProductID == bvin); if (items == null) return; foreach (data.bvc_ProductImage old in items) { ProductImageDTO img = new ProductImageDTO(); img.AlternateText = old.AlternateText; img.Bvin = old.bvin; img.Caption = old.Caption; img.FileName = TextHelper.CleanFileName(System.IO.Path.GetFileName(old.FileName)); img.LastUpdatedUtc = old.LastUpdated; img.ProductId = old.ProductID; img.SortOrder = old.SortOrder; byte[] bytes = GetBytesForLocalImage(old.FileName); if (bytes == null) return; wl("Found Image: " + img.FileName + " [" + bytes.Length + " bytes]"); var res = proxy.ProductImagesCreate(img, bytes); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } } else { wl("FAILED! EXCEPTION!"); } } }
private List<OptionItemDTO> LoadOptionItemsModifier(string bvin) { List<OptionItemDTO> result = new List<OptionItemDTO>(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var items = db.bvc_ProductModifierOption.Where(y => y.ModifierId == bvin) .OrderBy(y => y.Order); if (items == null) return result; foreach (data.bvc_ProductModifierOption item in items) { OptionItemDTO dto = new OptionItemDTO(); dto.Bvin = item.bvin; dto.IsLabel = item.Null; dto.Name = item.Name; dto.OptionBvin = bvin; dto.PriceAdjustment = item.PriceAdjustment; dto.SortOrder = item.Order; dto.WeightAdjustment = item.WeightAdjustment; result.Add(dto); } return result; }
private void AssignOptionsToProduct(string bvin) { wl(" - Migrating Options..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var choices = db.bvc_ProductXChoice.Where(y => y.ProductId == bvin); if (choices == null) return; foreach (data.bvc_ProductXChoice choice in choices) { proxy.ProductOptionsAssignToProduct(choice.ChoiceId, bvin, false); } var modifiers = db.bvc_ProductXModifier.Where(y => y.ProductId == bvin); if (modifiers == null) return; foreach (data.bvc_ProductXModifier mod in modifiers) { proxy.ProductOptionsAssignToProduct(mod.ModifierId, bvin, false); } var inputs = db.bvc_ProductXInput.Where(y => y.ProductId == bvin); if (inputs == null) return; foreach (data.bvc_ProductXInput input in inputs) { proxy.ProductOptionsAssignToProduct(input.InputId, bvin, false); } // Only generate variants after all options are added. Saves Time proxy.ProductOptionsGenerateAllVariants(bvin); }
private List<OrderPackageDTO> TranslatePackages(string orderBvin) { List<OrderPackageDTO> result = new List<OrderPackageDTO>(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var old = db.bvc_OrderPackage.Where(y => y.OrderId == orderBvin); if (old == null) return result; foreach (data.bvc_OrderPackage item in old) { OrderPackageDTO pak = new OrderPackageDTO(); pak.CustomProperties = TranslateOldProperties(item.CustomProperties); pak.Description = item.Description ?? string.Empty; pak.EstimatedShippingCost = item.EstimatedShippingCost; pak.HasShipped = item.HasShipped == 1; pak.Height = item.Height; pak.Items = TranslateOldPackageItems(item.Items); pak.LastUpdatedUtc = item.LastUpdated; pak.Length = item.Length; pak.OrderId = orderBvin; pak.ShipDateUtc = item.ShipDate; pak.ShippingMethodId = string.Empty; pak.ShippingProviderId = item.ShippingProviderId; pak.ShippingProviderServiceCode = item.ShippingProviderServiceCode; pak.SizeUnits = LengthTypeDTO.Inches; if (item.SizeUnits == 2) { pak.SizeUnits = LengthTypeDTO.Centimeters; } pak.TrackingNumber = item.TrackingNumber; pak.Weight = item.Weight; pak.WeightUnits = WeightTypeDTO.Pounds; if (item.WeightUnits == 2) { pak.WeightUnits = WeightTypeDTO.Kilograms; } pak.Width = item.Width; result.Add(pak); } return result; }
private string GetCustomUrlSlug(string oldBvin) { wl(" - Getting Custom Url - "); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var customUrl = db.bvc_CustomUrl.Where(y => y.SystemUrl == 1).Where(y => y.SystemData == oldBvin).FirstOrDefault(); if (customUrl != null) { wl("using URL: " + customUrl.RequestedUrl + " for " + oldBvin); return customUrl.RequestedUrl.TrimStart('/'); } wl("No custom URL Found for " + oldBvin); return string.Empty; }
private void MigrateProductInventory(string bvin) { wl(" - Migrating Inventory..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var old = db.bvc_ProductInventory.Where(y => y.ProductBvin == bvin).FirstOrDefault(); if (old == null) return; ProductInventoryDTO inv = new ProductInventoryDTO(); inv.LowStockPoint = (int)(old.ReorderLevel ?? 0); inv.ProductBvin = bvin; inv.QuantityOnHand = (int)((old.QuantityAvailableForSale ?? 0) + old.QuantityReserved); inv.QuantityReserved = (int)old.QuantityReserved; var res = proxy.ProductInventoryCreate(inv); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } } else { wl("FAILED! EXCEPTION!"); } }
private BV5OptionHtmlSettings GetOptionSettingsHtml(string bvin) { BV5OptionHtmlSettings result = new BV5OptionHtmlSettings(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var componentSettings = db.bvc_ComponentSetting.Where(y => y.ComponentID == bvin).OrderBy(y => y.SettingName); if (componentSettings == null) return result; foreach (data.bvc_ComponentSetting cs in componentSettings) { switch (cs.SettingName.Trim().ToLowerInvariant()) { case "htmldata": result.HtmlData = cs.SettingValue; break; } } return result; }
private void MigrateProductReviews(string bvin) { wl(" - Migrating Reviews..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var items = db.bvc_ProductReview.Where(y => y.ProductBvin == bvin); if (items == null) return; foreach (data.bvc_ProductReview item in items) { ProductReviewDTO r = new ProductReviewDTO(); r.Approved = item.Approved == 1; r.Bvin = item.bvin; r.Description = item.Description; r.Karma = item.Karma; r.ProductBvin = item.ProductBvin; switch (item.Rating) { case 0: r.Rating = ProductReviewRatingDTO.ZeroStars; break; case 1: r.Rating = ProductReviewRatingDTO.OneStar; break; case 2: r.Rating = ProductReviewRatingDTO.TwoStars; break; case 3: r.Rating = ProductReviewRatingDTO.ThreeStars; break; case 4: r.Rating = ProductReviewRatingDTO.FourStars; break; case 5: r.Rating = ProductReviewRatingDTO.FiveStars; break; } r.ReviewDateUtc = item.ReviewDate; r.UserID = item.UserID; wl("Review [" + r.Bvin + "]"); var res = proxy.ProductReviewsCreate(r); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } } else { wl("FAILED! EXCEPTION!"); } } }
private List<ProductPropertyChoiceDTO> GetPropertyChoices(string propertyBvin, PropertyMapperInfo mapInfo) { List<ProductPropertyChoiceDTO> result = new List<ProductPropertyChoiceDTO>(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var choices = db.bvc_ProductPropertyChoice.Where(y => y.PropertyBvin == propertyBvin) .OrderBy(y => y.SortOrder); if (choices == null) return result; foreach (data.bvc_ProductPropertyChoice ppc in choices) { ProductPropertyChoiceDTO dto = new ProductPropertyChoiceDTO(); dto.ChoiceName = ppc.ChoiceName; dto.LastUpdated = ppc.LastUpdated; //dto.PropertyId = ppc.PropertyBvin; dto.SortOrder = ppc.SortOrder; result.Add(dto); PropertyChoiceMapperInfo choiceMapInfo = new PropertyChoiceMapperInfo(); choiceMapInfo.OldBvin = ppc.bvin; choiceMapInfo.SortOrder = ppc.SortOrder; choiceMapInfo.TextValue = ppc.ChoiceName; mapInfo.Choices.Add(choiceMapInfo); } return result; }
private void MigrateProductVolumePrices(string bvin) { wl(" - Migrating Volume Prices..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var items = db.bvc_ProductVolumeDiscounts.Where(y => y.ProductID == bvin); if (items == null) return; foreach (data.bvc_ProductVolumeDiscounts item in items) { ProductVolumeDiscountDTO v = new ProductVolumeDiscountDTO(); v.Amount = item.Amount; v.Bvin = item.bvin; switch (item.DiscountType) { case 1: v.DiscountType = ProductVolumeDiscountTypeDTO.Percentage; break; case 2: v.DiscountType = ProductVolumeDiscountTypeDTO.Amount; break; } v.DiscountType = (ProductVolumeDiscountTypeDTO)item.DiscountType; v.LastUpdated = item.LastUpdated; v.ProductId = item.ProductID; v.Qty = item.Qty; wl("Discount for qty: " + v.Qty + " [" + v.Bvin + "]"); var res = proxy.ProductVolumeDiscountsCreate(v); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED"); } } else { wl("FAILED! EXCEPTION!"); } } }
private void ImportOrderTransactions(string orderBvin, string orderNumber) { wl(" - Transactions for Order " + orderNumber); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var old = db.bvc_OrderPayment.Where(y => y.orderID == orderBvin); if (old == null) return; foreach (data.bvc_OrderPayment item in old) { wl("Transaction: " + item.bvin); bool hasAuth = item.AmountAuthorized != 0; bool hasCharge = item.AmountCharged != 0; bool hasRefund = item.AmountRefunded != 0; Guid AuthTransactionID = new Guid(); Guid ChargeTransactionId = new Guid(); Guid RefundTransactionId = new Guid(); // Get Guids for transactions Guid.TryParse(item.bvin, out ChargeTransactionId); if (hasAuth && (hasCharge == false && hasRefund == false)) { // Auth only, no refund or charge Guid.TryParse(item.bvin, out AuthTransactionID); } if (hasRefund && (hasCharge == false && hasAuth == false)) { // Refund only, no auth or charge Guid.TryParse(item.bvin, out RefundTransactionId); } if (hasAuth) { OrderTransactionDTO opAuth = new OrderTransactionDTO(); opAuth.Id = AuthTransactionID; switch (item.paymentMethodId) { case "4A807645-4B9D-43f1-BC07-9F233B4E713C": // Credit Card opAuth.Action = OrderTransactionActionDTO.CreditCardHold; break; case "9FD35C50-CDCB-42ac-9549-14119BECBD0C": // Telephone opAuth.Action = OrderTransactionActionDTO.OfflinePaymentRequest; break; case "494A61C8-D7E7-457f-B293-4838EF010C32": // Check opAuth.Action = OrderTransactionActionDTO.OfflinePaymentRequest; break; case "7FCC4B3F-6E67-4f58-86B0-25BCCC035A0E": // Cash case "EE171EFD-9E4A-4eda-AD70-4CB99F28E06C": // COD opAuth.Action = OrderTransactionActionDTO.OfflinePaymentRequest; break; case "A0300DBD-39EE-472C-9179-D4B96F27913B": // CredEx opAuth.Action = OrderTransactionActionDTO.CreditCardHold; break; case "26C948F3-22EF-4bcb-9AE9-DEB9839BF4A7": // PO opAuth.Action = OrderTransactionActionDTO.PurchaseOrderInfo; break; case "91a205f1-8c1c-4267-bed0-c8e410e7e680": // Gift Card opAuth.Action = OrderTransactionActionDTO.GiftCardHold; break; case "49de5510-dfe4-4b18-91a6-3dc9925566a1": // Google Checkout opAuth.Action = OrderTransactionActionDTO.CreditCardHold; break; case "33eeba60-e5b7-4864-9b57-3f8d614f8301": // PayPal Express opAuth.Action = OrderTransactionActionDTO.PayPalHold; break; default: opAuth.Action = OrderTransactionActionDTO.CreditCardHold; break; } opAuth.Amount = item.AmountAuthorized; opAuth.CheckNumber = item.checkNumber ?? string.Empty; opAuth.CreditCard = new OrderTransactionCardDataDTO(); opAuth.CreditCard.CardHolderName = item.creditCardHolder ?? string.Empty; opAuth.CreditCard.CardIsEncrypted = true; opAuth.CreditCard.CardNumber = string.Empty; opAuth.CreditCard.ExpirationMonth = item.creditCardExpMonth; opAuth.CreditCard.ExpirationYear = item.creditCardExpYear; opAuth.CreditCard.SecurityCode = string.Empty; opAuth.GiftCardNumber = item.giftCertificateNumber ?? string.Empty; opAuth.LinkedToTransaction = string.Empty; opAuth.Messages = item.note ?? string.Empty; opAuth.OrderId = orderBvin ?? string.Empty; opAuth.OrderNumber = orderNumber ?? string.Empty; opAuth.PurchaseOrderNumber = item.purchaseOrderNumber ?? string.Empty; opAuth.RefNum1 = item.transactionReferenceNumber ?? string.Empty; opAuth.RefNum2 = item.transactionResponseCode ?? string.Empty; opAuth.Success = true; opAuth.TimeStampUtc = item.auditDate; opAuth.Voided = false; var res = proxy.OrderTransactionsCreate(opAuth); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED TRANSACTION: " + item.bvin); } } else { wl("FAILED! EXCEPTION! TRANSACTION: " + item.bvin); } } if (hasCharge) { OrderTransactionDTO opCharge = new OrderTransactionDTO(); opCharge.Id = ChargeTransactionId; switch (item.paymentMethodId) { case "4A807645-4B9D-43f1-BC07-9F233B4E713C": // Credit Card opCharge.Action = OrderTransactionActionDTO.CreditCardCharge; break; case "9FD35C50-CDCB-42ac-9549-14119BECBD0C": // Telephone opCharge.Action = OrderTransactionActionDTO.OfflinePaymentRequest; break; case "494A61C8-D7E7-457f-B293-4838EF010C32": // Check opCharge.Action = OrderTransactionActionDTO.CheckReceived; break; case "7FCC4B3F-6E67-4f58-86B0-25BCCC035A0E": // Cash case "EE171EFD-9E4A-4eda-AD70-4CB99F28E06C": // COD opCharge.Action = OrderTransactionActionDTO.CashReceived; break; case "A0300DBD-39EE-472C-9179-D4B96F27913B": // CredEx opCharge.Action = OrderTransactionActionDTO.CashReceived; break; case "26C948F3-22EF-4bcb-9AE9-DEB9839BF4A7": // PO opCharge.Action = OrderTransactionActionDTO.PurchaseOrderAccepted; break; case "91a205f1-8c1c-4267-bed0-c8e410e7e680": // Gift Card opCharge.Action = OrderTransactionActionDTO.GiftCardCapture; break; case "49de5510-dfe4-4b18-91a6-3dc9925566a1": // Google Checkout opCharge.Action = OrderTransactionActionDTO.CreditCardCharge; break; case "33eeba60-e5b7-4864-9b57-3f8d614f8301": // PayPal Express opCharge.Action = OrderTransactionActionDTO.PayPalCharge; break; default: opCharge.Action = OrderTransactionActionDTO.CreditCardCharge; break; } opCharge.Amount = item.AmountCharged; opCharge.CheckNumber = item.checkNumber ?? string.Empty; opCharge.CreditCard = new OrderTransactionCardDataDTO(); opCharge.CreditCard.CardHolderName = item.creditCardHolder ?? string.Empty; opCharge.CreditCard.CardIsEncrypted = true; opCharge.CreditCard.CardNumber = string.Empty; opCharge.CreditCard.ExpirationMonth = item.creditCardExpMonth; opCharge.CreditCard.ExpirationYear = item.creditCardExpYear; opCharge.CreditCard.SecurityCode = string.Empty; opCharge.GiftCardNumber = item.giftCertificateNumber ?? string.Empty; opCharge.LinkedToTransaction = string.Empty; opCharge.Messages = item.note ?? string.Empty; opCharge.OrderId = orderBvin ?? string.Empty; opCharge.OrderNumber = orderNumber ?? string.Empty; opCharge.PurchaseOrderNumber = item.purchaseOrderNumber ?? string.Empty; opCharge.RefNum1 = item.transactionReferenceNumber ?? string.Empty; opCharge.RefNum2 = item.transactionResponseCode ?? string.Empty; opCharge.Success = true; opCharge.TimeStampUtc = item.auditDate; opCharge.Voided = false; var res = proxy.OrderTransactionsCreate(opCharge); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED TRANSACTION: " + item.bvin); } } else { wl("FAILED! EXCEPTION! TRANSACTION: " + item.bvin); } } if (hasRefund) { OrderTransactionDTO opRefund = new OrderTransactionDTO(); opRefund.Id = RefundTransactionId; switch (item.paymentMethodId) { case "4A807645-4B9D-43f1-BC07-9F233B4E713C": // Credit Card opRefund.Action = OrderTransactionActionDTO.CreditCardRefund; break; case "9FD35C50-CDCB-42ac-9549-14119BECBD0C": // Telephone opRefund.Action = OrderTransactionActionDTO.OfflinePaymentRequest; break; case "494A61C8-D7E7-457f-B293-4838EF010C32": // Check opRefund.Action = OrderTransactionActionDTO.CheckReturned; break; case "7FCC4B3F-6E67-4f58-86B0-25BCCC035A0E": // Cash case "EE171EFD-9E4A-4eda-AD70-4CB99F28E06C": // COD opRefund.Action = OrderTransactionActionDTO.CashReturned; break; case "A0300DBD-39EE-472C-9179-D4B96F27913B": // CredEx opRefund.Action = OrderTransactionActionDTO.CashReturned; break; case "26C948F3-22EF-4bcb-9AE9-DEB9839BF4A7": // PO opRefund.Action = OrderTransactionActionDTO.CashReturned; break; case "91a205f1-8c1c-4267-bed0-c8e410e7e680": // Gift Card opRefund.Action = OrderTransactionActionDTO.GiftCardIncrease; break; case "49de5510-dfe4-4b18-91a6-3dc9925566a1": // Google Checkout opRefund.Action = OrderTransactionActionDTO.CreditCardRefund; break; case "33eeba60-e5b7-4864-9b57-3f8d614f8301": // PayPal Express opRefund.Action = OrderTransactionActionDTO.PayPalRefund; break; default: opRefund.Action = OrderTransactionActionDTO.CreditCardRefund; break; } opRefund.Amount = -1 * item.AmountCharged; opRefund.CheckNumber = item.checkNumber ?? string.Empty; opRefund.CreditCard = new OrderTransactionCardDataDTO(); opRefund.CreditCard.CardHolderName = item.creditCardHolder ?? string.Empty; opRefund.CreditCard.CardIsEncrypted = true; opRefund.CreditCard.CardNumber = string.Empty; opRefund.CreditCard.ExpirationMonth = item.creditCardExpMonth; opRefund.CreditCard.ExpirationYear = item.creditCardExpYear; opRefund.CreditCard.SecurityCode = string.Empty; opRefund.GiftCardNumber = item.giftCertificateNumber ?? string.Empty; opRefund.LinkedToTransaction = string.Empty; opRefund.Messages = item.note ?? string.Empty; opRefund.OrderId = orderBvin ?? string.Empty; opRefund.OrderNumber = orderNumber ?? string.Empty; opRefund.PurchaseOrderNumber = item.purchaseOrderNumber ?? string.Empty; opRefund.RefNum1 = item.transactionReferenceNumber ?? string.Empty; opRefund.RefNum2 = item.transactionResponseCode ?? string.Empty; opRefund.Success = true; opRefund.TimeStampUtc = item.auditDate; opRefund.Voided = false; var res = proxy.OrderTransactionsCreate(opRefund); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); wl("FAILED TRANSACTION: " + item.bvin); } } else { wl("FAILED! EXCEPTION! TRANSACTION: " + item.bvin); } } } }
private void MigratePropertiesForType(string typeBvin) { wl("Migrating Properties to Type..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var crosses = db.bvc_ProductTypeXProductProperty.Where(y => y.ProductTypeBvin == typeBvin); if (crosses == null) return; foreach (data.bvc_ProductTypeXProductProperty cross in crosses) { int sort = cross.SortOrder; string oldPropertyBvin = cross.ProductPropertyBvin; long newId = 0; var map = ProductPropertyMapper.Where(y => y.OldBvin == oldPropertyBvin).FirstOrDefault(); if (map != null) { newId = map.NewBvin; } if (newId <= 0) continue; wl("Mapping " + oldPropertyBvin + " to " + newId.ToString()); Api bv6proxy = GetBV6Proxy(); bv6proxy.ProductTypesAddProperty(typeBvin, newId, sort); } }
private List<OrderCouponDTO> TranslateCoupons(string orderBvin) { List<OrderCouponDTO> result = new List<OrderCouponDTO>(); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); var old = db.bvc_OrderCoupon.Where(y => y.OrderBvin == orderBvin); if (old == null) return result; foreach (data.bvc_OrderCoupon oldCoupon in old) { OrderCouponDTO c = new OrderCouponDTO(); c.CouponCode = oldCoupon.CouponCode ?? string.Empty; c.IsUsed = true; c.OrderBvin = orderBvin ?? string.Empty; result.Add(c); } return result; }
private void AssignOptionsToProduct(string bvin) { wl(" - Migrating Options..."); data.BV53Entities db = new data.BV53Entities(EFConnString(settings.SourceConnectionString())); Api proxy = GetBV6Proxy(); var choices = db.bvc_ProductXChoice.Where(y => y.ProductId == bvin); if (choices == null) return; foreach (data.bvc_ProductXChoice choice in choices) { if (this.EmptyOptions.Contains(choice.ChoiceId)) continue; // Skip already assigned proxy.ProductOptionsAssignToProduct(choice.ChoiceId, bvin, false); } var modifiers = db.bvc_ProductXModifier.Where(y => y.ProductId == bvin); if (modifiers == null) return; foreach (data.bvc_ProductXModifier mod in modifiers) { if (this.EmptyOptions.Contains(mod.ModifierId)) continue; // Skip already assigned proxy.ProductOptionsAssignToProduct(mod.ModifierId, bvin, false); } var inputs = db.bvc_ProductXInput.Where(y => y.ProductId == bvin); if (inputs == null) return; foreach (data.bvc_ProductXInput input in inputs) { proxy.ProductOptionsAssignToProduct(input.InputId, bvin, false); } // Only generate variants after all options are added. Saves Time proxy.ProductOptionsGenerateAllVariants(bvin); // Now Assign Variant Skus var combos = db.bvc_ProductChoiceCombinations.Where(y => y.ParentProductId == bvin).ToList(); if (combos == null) return; if (combos.Count < 1) { wl("No Combos Found."); return; } else { wl(combos.Count + " combos found"); } var children = db.bvc_Product.Where(y => y.ParentID == bvin).ToList(); if (children == null) return; if (children.Count < 1) { wl("No children found."); return; } else { wl(children.Count + " children found to update skus"); } int childCounter = 0; foreach (var child in children) { childCounter++; wl("Updating Child Variant Sku " + childCounter); var dto = new ProductVariantSkuUpdateDTO(); dto.Sku = child.SKU.Trim(); dto.ProductBvin = bvin; if (dto.Sku.Length > 0) { var matchingChoices = combos.Where(y => y.ProductId == child.bvin).ToList(); foreach (var match in matchingChoices) { dto.MatchingOptions.Add(new VariantOptionDataDTO() { ChoiceId = match.ChoiceId, ChoiceItemId = match.ChoiceOptionId }); } } wl("SKU: " + dto.Sku + " of parent " + dto.ProductBvin + " matches "); foreach (var match in dto.MatchingOptions) { wl("Choice: " + match.ChoiceId + " Option:" + match.ChoiceItemId); } proxy.ProductVariantUpdateSku(dto); } }