public AmazonListing InitAmazonListingFromProductVariant(AmazonListing amazonListing, string productVariantSku, int amazonListingGroupId) { var productVariant = _productVariantService.GetProductVariantBySKU(productVariantSku); var amazonListingGroup = _amazonListingGroupService.Get(amazonListingGroupId); if (amazonListing == null) { amazonListing = new AmazonListing() { Status = AmazonListingStatus.NotOnAmazon } } ; amazonListing.AmazonListingGroup = amazonListingGroup; amazonListing.ProductVariant = productVariant; amazonListing.Brand = productVariant.Product.Brand != null ? productVariant.Product.Brand.Name : String.Empty; amazonListing.Condition = ConditionType.New; var currency = _ecommerceSettings.Currency(); amazonListing.Currency = (currency != null && !String.IsNullOrWhiteSpace(currency.Code)) ? currency.Code : CurrencyCode.GBP.GetDescription(); amazonListing.Manafacturer = productVariant.Product.Brand != null ? productVariant.Product.Brand.Name : String.Empty; amazonListing.MfrPartNumber = productVariant.ManufacturerPartNumber; amazonListing.Quantity = productVariant.TrackingPolicy == TrackingPolicy.Track ? _getStockRemainingQuantity.Get(productVariant) : 1000; amazonListing.Price = _productPricingMethod.GetUnitPrice(productVariant, 0m, 0m); amazonListing.SellerSKU = productVariant.SKU; amazonListing.Title = productVariant.DisplayName; amazonListing.StandardProductIDType = _amazonSellerSettings.BarcodeIsOfType; amazonListing.StandardProductId = (string.IsNullOrWhiteSpace(productVariant.Barcode) ? "":productVariant.Barcode.Trim()); amazonListing.FulfillmentChannel = amazonListing.AmazonListingGroup.FulfillmentChannel ?? AmazonFulfillmentChannel.MFN; amazonListingGroup.Items.Add(amazonListing); _amazonListingGroupService.Save(amazonListingGroup); return(amazonListing); } }
public void PrepareForSyncAmazonListingService_InitAmazonListingFromProductVariant_ShouldSetValues() { var item = new Currency() { Code = "GBP", Id = 1 }; Session.Transact(session => session.Save(item)); var mockingKernel = new MockingKernel(); MrCMSKernel.OverrideKernel(mockingKernel); mockingKernel.Bind <ISession>().ToMethod(context => A.Fake <ISession>()); mockingKernel.Bind <EcommerceSettings>().ToMethod(context => new EcommerceSettings() { CurrencyId = 1 }); var product = new Product() { BrandPage = new Brand() { Name = "B" } }; var productVariant = new ProductVariant() { Product = product, SKU = "S1", BasePrice = 1, StockRemaining = 2, Name = "P", ManufacturerPartNumber = "MPN1", Barcode = "" }; var amazonListingGroup = new AmazonListingGroup() { Id = 1, FulfillmentChannel = AmazonFulfillmentChannel.MFN }; var model = new AmazonListing() { ProductVariant = productVariant, StandardProductId = "1P", StandardProductIDType = StandardProductIDType.EAN, AmazonListingGroup = amazonListingGroup }; A.CallTo(() => _amazonListingGroupService.Get(amazonListingGroup.Id)).Returns(amazonListingGroup); A.CallTo(() => _productVariantService.GetProductVariantBySKU(model.ProductVariant.SKU)).Returns(productVariant); var results = _prepareForSyncAmazonListingService.InitAmazonListingFromProductVariant(model, model.ProductVariant.SKU, amazonListingGroup.Id); results.As <AmazonListing>().Condition.Should().Be(ConditionType.New); results.As <AmazonListing>().Currency.Should().Be("GBP"); results.As <AmazonListing>().Manafacturer.Should().Be("B"); results.As <AmazonListing>().Brand.Should().Be("B"); results.As <AmazonListing>().MfrPartNumber.Should().Be("MPN1"); results.As <AmazonListing>().Price.Should().Be(1); results.As <AmazonListing>().Quantity.Should().Be(2); results.As <AmazonListing>().Title.Should().Be("P"); results.As <AmazonListing>().StandardProductIDType.Should().Be(_amazonSellerSettings.BarcodeIsOfType); results.As <AmazonListing>().StandardProductId.Should().Be(model.StandardProductId); results.As <AmazonListing>().FulfillmentChannel.Should().Be(AmazonFulfillmentChannel.MFN); }