public AmazonListing UpdateAmazonListing(AmazonListing amazonListing)
        {
            var productVariant = _productVariantService.GetProductVariantBySKU(amazonListing.ProductVariant.SKU);

            amazonListing.ProductVariant = productVariant;
            amazonListing.Brand = productVariant.Product.BrandPage != null ? productVariant.Product.BrandPage.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.BrandPage != null ? productVariant.Product.BrandPage.Name : String.Empty;
            amazonListing.MfrPartNumber = productVariant.ManufacturerPartNumber;
            amazonListing.Quantity = productVariant.TrackingPolicy == TrackingPolicy.Track
                                          ? _getStockRemainingQuantity.Get(productVariant)
                                          : 1000;
            amazonListing.Price = productVariant.Price;
            amazonListing.SellerSKU = productVariant.SKU;
            amazonListing.Title = productVariant.DisplayName;
            amazonListing.StandardProductIDType = _amazonSellerSettings.BarcodeIsOfType;
            amazonListing.StandardProductId = productVariant.Barcode.Trim();

            amazonListing.FulfillmentChannel = amazonListing.AmazonListingGroup.FulfillmentChannel ?? AmazonFulfillmentChannel.MFN;

            _amazonListingService.Save(amazonListing);

            return amazonListing;
        }
        public void AmazonGenerateFeedService_GetProduct_ShouldSetValues()
        {
            var listing = new AmazonListing()
            {
                SellerSKU = "S1",
                Manafacturer = "M",
                Brand = "B",
                StandardProductId = "SP",
                StandardProductIDType = StandardProductIDType.EAN,
                Condition = ConditionType.New,
                ConditionNote = "CN",
                Title = "T",
                ReleaseDate = CurrentRequestData.Now,
                MfrPartNumber = "MPN1"
            };
            var results = _amazonGenerateFeedService.GetProduct(listing);

            results.As<Product>().Condition.ConditionType.Should().Be(listing.Condition);
            results.As<Product>().Condition.ConditionNote.Should().Be(listing.ConditionNote);
            results.As<Product>().SKU.Should().Be(listing.SellerSKU);
            results.As<Product>().StandardProductID.Type.Should().Be(listing.StandardProductIDType);
            results.As<Product>().StandardProductID.Value.Should().Be(listing.StandardProductId);
            results.As<Product>().DescriptionData.Brand.Should().Be(listing.Brand);
            results.As<Product>().DescriptionData.Title.Should().Be(listing.Title);
            results.As<Product>().DescriptionData.Manufacturer.Should().Be(listing.Manafacturer);
            results.As<Product>().DescriptionData.MfrPartNumber.Should().Be(listing.MfrPartNumber);
            results.As<Product>().ReleaseDate.Should().Be(listing.ReleaseDate.Value);
        }
Ejemplo n.º 3
0
 public void Save(AmazonListing item)
 {
     var id = item.Id;
     _session.Transact(session => session.SaveOrUpdate(item));
     _amazonLogService.Add(AmazonLogType.Listings, id > 0 ? AmazonLogStatus.Update : AmazonLogStatus.Insert,
                           null, null, null, null, null, item, null);
 }
Ejemplo n.º 4
0
        public AmazonLog Add(AmazonLogType type, AmazonLogStatus status, Exception elmahError, MarketplaceWebService.Model.Error amazonError,
            AmazonApiSection? apiSection, string apiOperation, AmazonOrder amazonOrder, AmazonListing amazonListing, AmazonListingGroup amazonListingGroup,
            string message = "", string details = "")
        {
            var log = new AmazonLog
                          {
                              LogType = type,
                              LogStatus = status,
                              AmazonOrder = amazonOrder,
                              ApiSection = apiSection,
                              ApiOperation = !String.IsNullOrWhiteSpace(apiOperation) ? apiOperation : null,
                              AmazonListing = amazonListing,
                              AmazonListingGroup = amazonListingGroup,
                              Message = !String.IsNullOrWhiteSpace(message) ? message : null,
                              Detail = !String.IsNullOrWhiteSpace(details) ? details : null,
                              Site = CurrentRequestData.CurrentSite
                          };
            log.SetGuid(Guid.NewGuid());
            if (elmahError != null)
            {
                log.Message = elmahError.Message;
                log.Detail = elmahError.StackTrace;
            }
            if (amazonError != null)
            {
                log.ErrorCode = amazonError.Code;
                log.ErrorType = amazonError.Type;
                log.Message = amazonError.Message;
                log.Detail = amazonError.Detail.ToString();
            }

            return Save(log);
        }
        public void AmazonListingSyncManager_GetAmazonSyncModel_ShouldReturnAmazonSyncModelTypeSecondMethod()
        {
            var model = new AmazonListing();

            var results = _amazonListingSyncManager.GetAmazonSyncModel(model);

            results.Should().BeOfType<AmazonSyncModel>();
        }
Ejemplo n.º 6
0
        public void CloseAmazonListing(AmazonSyncModel syncModel, AmazonListing amazonListing)
        {
            var feedContent = _amazonFeedsApiService.GetSingleProductDeleteFeed(amazonListing);

            var submissionId = _amazonRequestService.SubmitCloseRequest(syncModel, feedContent);

            _amazonRequestService.CheckIfDeleteRequestWasProcessed(syncModel, amazonListing, submissionId);
        }
Ejemplo n.º 7
0
        public void SubmitSingleProductFeed(AmazonSyncModel model, AmazonListing item)
        {
            var feeds = _amazonFeedsApiService.GetSingleProductMainFeeds(item);

            var submissionIds = _amazonRequestService.SubmitMainFeeds(model, feeds);

            _amazonRequestService.CheckIfRequestWasProcessed(model, item, submissionIds);
        }
Ejemplo n.º 8
0
 public void UpdateAmazonListingStatus(AmazonListing item)
 {
     var amazonProduct = _amazonProductsApiService.GetMatchingProductForId(item.SellerSKU);
     if (amazonProduct == null && !String.IsNullOrWhiteSpace(item.ASIN))
         item.Status = AmazonListingStatus.Inactive;
     else
         item.Status = AmazonListingStatus.Active;
     Save(item);
 }
Ejemplo n.º 9
0
        public void AmazonListingService_Delete_ShouldRemoveItemFromTheSession()
        {
            var item = new AmazonListing();
            Session.Transact(session => session.Save(item));

            _amazonListingService.Delete(item);

            Session.QueryOver<AmazonListing>().RowCount().Should().Be(0);
        }
Ejemplo n.º 10
0
        public void AmazonListingService_Save_ShouldCallAddLog()
        {
            var item = new AmazonListing();

            _amazonListingService.Save(item);

            A.CallTo(() => _amazonLogService.Add(AmazonLogType.Listings, AmazonLogStatus.Insert,
                                  null, null, null, null, null, item, null, string.Empty, string.Empty)).MustHaveHappened();
        }
Ejemplo n.º 11
0
        public void AmazonListingService_GetByProductVariantSku_ShouldReturnPersistedEntryFromSession()
        {
            var item = new AmazonListing() { SellerSKU = "T1"};
            Session.Transact(session => session.Save(item));

            var results = _amazonListingService.GetByProductVariantSku("T1");

            results.As<AmazonListing>().Id.Should().Be(1);
        }
Ejemplo n.º 12
0
        public void AmazonListingService_Get_ShouldReturnPersistedEntryFromSession()
        {
            var item = new AmazonListing();
            Session.Transact(session => session.Save(item));

            var results=_amazonListingService.Get(1);

            results.As<AmazonListing>().Id.Should().Be(1);
        }
        public void AmazonGenerateFeedService_GetProduct_ShouldReturnProductType()
        {
            var model = new AmazonListing()
                {
                    SellerSKU = "S1"
                };
            var results = _amazonGenerateFeedService.GetProduct(model);

            results.Should().BeOfType<Product>();
        }
Ejemplo n.º 14
0
        public void AmazonListingService_Save_ShouldUpdateInSession()
        {
            var item = new AmazonListing();
            Session.Transact(session => session.Save(item));
            item.SellerSKU = "T1";

            _amazonListingService.Save(item);
            Session.Evict(item);

            Session.Get<AmazonListing>(1).SellerSKU.Should().Be("T1");
        }
Ejemplo n.º 15
0
        public AmazonListingModel()
        {
            Listing = new AmazonListing();

            Name = String.Empty;
            Page = 1;
            PageSize = 10;

            CategoryId = 0;
            Categories = new List<SelectListItem>();
            ProductVariants = new PagedList<ProductVariant>(new List<ProductVariant>(), Page, PageSize);
        }
        public void AmazonGenerateFeedService_GetProductPrice_ShouldReturnPriceType()
        {
            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());

            var model = new AmazonListing()
            {
                SellerSKU = "S1"
            };
            var results = _amazonGenerateFeedService.GetProductPrice(model);

            results.Should().BeOfType<Price>();
        }
Ejemplo n.º 17
0
        public void UpdateAmazonListingStatusAndAsin(AmazonListing item, Product amazonProduct)
        {
            if (amazonProduct == null)
                amazonProduct = _amazonProductsApiService.GetMatchingProductForId(item.SellerSKU);

            if (amazonProduct != null && amazonProduct.Identifiers.MarketplaceASIN != null)
            {
                    item.Status = AmazonListingStatus.Active;
                    item.ASIN = amazonProduct.Identifiers.MarketplaceASIN.ASIN;
            }
            else
            {
                item.Status = String.IsNullOrWhiteSpace(item.ASIN)
                                  ? AmazonListingStatus.NotOnAmazon
                                  : AmazonListingStatus.Inactive;
            }
            Save(item);
        }
        public void PrepareForSyncAmazonListingService_UpdateAmazonListing_ShouldReturnAmazonListingType()
        {
            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());

            var product = new Product();
            var productVariant = new ProductVariant() { Product = product, SKU = "S1", Barcode = "" };
            var model = new AmazonListing() { ProductVariant = productVariant, AmazonListingGroup = new AmazonListingGroup()
                {
                    FulfillmentChannel = AmazonFulfillmentChannel.MFN
                }};

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(model.ProductVariant.SKU)).Returns(productVariant);

            var results = _prepareForSyncAmazonListingService.UpdateAmazonListing(model);

            results.Should().BeOfType<AmazonListing>();
        }
        public void PrepareForSyncAmazonListingService_UpdateAmazonListing_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 model = new AmazonListing()
            {
                ProductVariant = productVariant,
                StandardProductId = "1P",
                StandardProductIDType = StandardProductIDType.EAN,
                AmazonListingGroup = new AmazonListingGroup()
                {
                    FulfillmentChannel = AmazonFulfillmentChannel.MFN
                }
            };

            A.CallTo(() => _productVariantService.GetProductVariantBySKU(model.ProductVariant.SKU)).Returns(productVariant);

            var results = _prepareForSyncAmazonListingService.UpdateAmazonListing(model);

            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);
        }
        public void PrepareForSyncAmazonListingService_InitAmazonListingFromProductVariant_ShouldCallSave()
        {
            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);

            A.CallTo(() =>  _amazonListingGroupService.Save(amazonListingGroup)).MustHaveHappened();
        }
        public void PrepareForSyncAmazonListingService_InitAmazonListingFromProductVariant_ShouldReturnAmazonListingType()
        {
            var mockingKernel = new MockingKernel();
            MrCMSKernel.OverrideKernel(mockingKernel);
            mockingKernel.Bind<ISession>().ToMethod(context => A.Fake<ISession>());

            var model = new AmazonListing();

            var results = _prepareForSyncAmazonListingService.InitAmazonListingFromProductVariant(model,"S1",1);

            results.Should().BeOfType<AmazonListing>();
        }
Ejemplo n.º 22
0
 public AmazonSyncModel GetAmazonSyncModel(AmazonListing amazonListing)
 {
     return new AmazonSyncModel()
     {
         Id = amazonListing.Id,
         Title = amazonListing.Title,
         Description = amazonListing.ASIN,
         AmazonListingGroup = amazonListing.AmazonListingGroup
     };
 }
Ejemplo n.º 23
0
        public void ListingController_DeletePOST_ShouldCallDelete()
        {
            var model = new AmazonListing()
                {
                    AmazonListingGroup = new AmazonListingGroup() { Id = 1 }
                };

            var result = _listingController.Delete_POST(model);

            A.CallTo(() => _amazonListingService.Delete(model)).MustHaveHappened();
        }
Ejemplo n.º 24
0
        public void ListingController_DeletePOST_ReturnsRedirectToEdit()
        {
            var model = new AmazonListing()
            {
                AmazonListingGroup = new AmazonListingGroup() { Id = 1 }
            };

            var result = _listingController.Delete_POST(model);

            result.As<RedirectToRouteResult>().RouteValues["action"].Should().Be("Edit");
        }
Ejemplo n.º 25
0
        public void ListingController_CloseOne_ShouldCallGetAmazonCloseModel()
        {
            var model = new AmazonListing();

            var result = _listingController.CloseOne(model);

            A.CallTo(() => _amazonListingSyncManager.GetAmazonSyncModel(model)).MustHaveHappened();
        }
Ejemplo n.º 26
0
        public void ListingController_CloseOne_ShouldCallUpdateAmazonListing()
        {
            var listing = new AmazonListing();

            var result = _listingController.CloseOne(listing);

            A.CallTo(() => _prepareForSyncAmazonListingService.UpdateAmazonListing(listing)).MustHaveHappened();
        }
Ejemplo n.º 27
0
        public void ListingController_AddManyPOST_ShouldRedirectToSyncOneIfValuesProvided()
        {
            var listing = new AmazonListing();

            var result = _listingController.AddOne_POST(listing);

            result.As<RedirectToRouteResult>().RouteValues["action"].Should().Be("SyncOne");
        }
Ejemplo n.º 28
0
        public void ListingController_AddOnePOST_ShouldCallSave()
        {
            var listing = new AmazonListing();

            var result = _listingController.AddOne_POST(listing);

            A.CallTo(() => _amazonListingService.Save(listing)).MustHaveHappened();
        }
Ejemplo n.º 29
0
        public void CheckIfDeleteRequestWasProcessed(AmazonSyncModel model, AmazonListing amazonListing, string submissionId)
        {
            var uploadSuccess = false;
            var retryCount = 0;

            while (!uploadSuccess)
            {
                retryCount++;
                if (retryCount == 3)
                {
                    AmazonProgressBarHelper.Update(model.Task, "Error",
                                                  "Request timed out. Please check logs for potential errors and try again later.", 100,
                                                  100);
                    break;
                }

                try
                {
                    AmazonProgressBarHelper.Update(model.Task, "Push", "Checking if request was processed...", 100, 75);
                    if (_amazonFeedsApiService.GetFeedSubmissionList(submissionId).FeedProcessingStatus == "_DONE_")
                    {
                        AmazonProgressBarHelper.Update(model.Task, "Push", "Request was processed", 100, 75);
                        AmazonProgressBarHelper.Update(model.Task, "Push",
                                                       "Updating local status of Amazon Listing with SKU:" + amazonListing.SellerSKU,
                                                       100, 85);
                        _amazonListingService.UpdateAmazonListingStatus(amazonListing);

                        uploadSuccess = true;
                    }
                    else
                    {
                        AmazonProgressBarHelper.Update(model.Task, "Push",
                                                       "Nothing yet, we will wait 2 min. more and try again...", 100, 75);
                        Thread.Sleep(120000);
                    }
                }
                catch (Exception ex)
                {
                    _amazonLogService.Add(AmazonLogType.Listings, AmazonLogStatus.Error, ex, null,
                                          AmazonApiSection.Feeds, null, null, amazonListing, null);

                    AmazonProgressBarHelper.Update(model.Task, "Push",
                                                   "Amazon Api is busy, we will need to wait additional 2 min. and try again",
                                                   100, 75);
                    Thread.Sleep(120000);
                }
            }
        }
Ejemplo n.º 30
0
        public void CheckIfRequestWasProcessed(AmazonSyncModel model, AmazonListing amazonListing, List<string> submissionIds)
        {
            var uploadSuccess = false;
            var retryCount = 0;

            var feedContent = _amazonFeedsApiService.GetSingleProductImageFeed(amazonListing);
            while (!uploadSuccess)
            {
                retryCount++;
                if (retryCount == 3)
                {
                    AmazonProgressBarHelper.Update(model.Task, "Error",
                                                  "Request timed out. Please check logs for potential errors and try again later.", 100,
                                                  100);
                    break;
                }

                try
                {
                    AmazonProgressBarHelper.Update(model.Task, "Push", "Checking if request was processed...", 100, 75);
                    var amazonProduct = _amazonProductsApiService.GetMatchingProductForId(amazonListing.SellerSKU);
                    if (amazonProduct != null)
                    {
                        AmazonProgressBarHelper.Update(model.Task, "Push", "Request was processed", 100, 75);
                        AmazonProgressBarHelper.Update(model.Task, "Push", "Updating local status of Amazon Listing with SKU:" + amazonListing.SellerSKU, 100, 85);
                        _amazonListingService.UpdateAmazonListingStatusAndAsin(amazonListing, amazonProduct);

                        if (feedContent != null)
                        {
                            SubmitProductImageFeed(model, feedContent, ref submissionIds);
                        }

                        uploadSuccess = true;
                    }
                    else
                    {
                        AmazonProgressBarHelper.Update(model.Task, "Push",
                                                       "Nothing yet, we will wait 2 min. more and try again...", 100, 75);
                        Thread.Sleep(120000);
                    }
                }
                catch (Exception ex)
                {
                    CurrentRequestData.ErrorSignal.Raise(ex);

                    AmazonProgressBarHelper.Update(model.Task, "Push",
                                                   "Amazon Api is busy, we will wait additional 2 min. and try again...", 100,
                                                   75);
                    Thread.Sleep(120000);
                }
            }
        }