public void UpdateAmazonListings(AmazonListingGroup amazonListingGroup)
 {
     foreach (var item in amazonListingGroup.Items)
     {
         UpdateAmazonListing(item);
     }
 }
Exemple #2
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 Save(AmazonListingGroup item)
 {
     var id = item.Id;
     _session.Transact(session => session.SaveOrUpdate(item));
     _amazonLogService.Add(AmazonLogType.ListingGroups, id > 0 ? AmazonLogStatus.Update : AmazonLogStatus.Insert,
         null, null, null, null, null, null, item);
 }
        public void AmazonListingGroupService_Delete_ShouldCallAddLog()
        {
            var item = new AmazonListingGroup();

            _amazonListingGroupService.Delete(item);

            A.CallTo(() => _amazonLogService.Add(AmazonLogType.ListingGroups, AmazonLogStatus.Delete, null, null, null, null, null, null, item, string.Empty, string.Empty)).MustHaveHappened();
        }
        public void SubmitProductFeeds(AmazonSyncModel model, AmazonListingGroup item)
        {
            var feeds = _amazonFeedsApiService.GetProductsMainFeeds(item);

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

            _amazonRequestService.CheckIfRequestsWereProcessed(model, item, submissionIds);
        }
        public void AmazonListingSyncManager_GetAmazonSyncModel_ShouldReturnAmazonSyncModelType()
        {
            var model = new AmazonListingGroup();

            var results = _amazonListingSyncManager.GetAmazonSyncModel(model);

            results.Should().BeOfType<AmazonSyncModel>();
        }
        public void ListingController_ChooseProductVariant_ShouldCallGetAmazonDashboardModel()
        {
            var model = new AmazonListingGroup();

            var result = _listingController.ChooseProductVariant(model);

            A.CallTo(() => _amazonListingService.GetAmazonListingModel(model)).MustHaveHappened();
        }
        public void AmazonListingGroupService_Delete_ShouldRemoveItemFromTheSession()
        {
            var item = new AmazonListingGroup();
            Session.Transact(session => session.Save(item));

            _amazonListingGroupService.Delete(item);

            Session.QueryOver<AmazonListingGroup>().RowCount().Should().Be(0);
        }
        public void AmazonListingGroupService_Get_ShouldReturnPersistedEntryFromSession()
        {
            var item = new AmazonListingGroup();
            Session.Transact(session => session.Save(item));

            var results=_amazonListingGroupService.Get(1);

            results.As<AmazonListingGroup>().Id.Should().Be(1);
        }
        public void AmazonListingGroupService_Save_ShouldUpdateInSession()
        {
            var item = new AmazonListingGroup();
            Session.Transact(session => session.Save(item));
            item.Name = "updated";

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

            Session.Get<AmazonListingGroup>(1).Name.Should().Be("updated");
        }
        public void CheckIfRequestsWereProcessed(AmazonSyncModel model, AmazonListingGroup item, List<string> submissionIds)
        {
            var uploadSuccess = false;
            var retryCount = 0;

            var feedContent = _amazonFeedsApiService.GetProductsImageFeeds(item);
            while (!uploadSuccess)
            {
                retryCount++;
                if (retryCount == 5)
                {
                    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(submissionIds.First()).FeedProcessingStatus ==
                        "_DONE_")
                    {
                        AmazonProgressBarHelper.Update(model.Task, "Push", "Request was processed", 100, 75);
                        foreach (var amazonListing in item.Items)
                        {
                            AmazonProgressBarHelper.Update(model.Task, "Push", "Updating local status of Amazon Listing with SKU:" + amazonListing.SellerSKU, 100, 85);
                            _amazonListingService.UpdateAmazonListingStatusAndAsin(amazonListing, 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);
                }
            }
        }
        public void CloseAmazonListings(AmazonSyncModel model, AmazonListingGroup amazonListingGroup)
        {
            var feedContent = _amazonFeedsApiService.GetProductsDeleteFeeds(amazonListingGroup);

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

            var isUploaded = false;
            var retryCounter = 0;

            while (!isUploaded)
            {
                retryCounter++;
                retryCounter++;
                if (retryCounter == 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, 90);
                        foreach (var amazonListing in amazonListingGroup.Items)
                        {
                            AmazonProgressBarHelper.Update(model.Task, "Push", "Updating local status of Amazon Listing #"+amazonListing.SellerSKU, 100, 90);
                            _amazonListingService.UpdateAmazonListingStatus(amazonListing);
                        }

                        isUploaded = 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,null,null,"Closing Amazon Listings");

                    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);
                }
            }
        }
        public void InitAmazonListingsFromProductVariants(AmazonListingGroup amazonListingGroup, string rawProductVariantsIds)
        {
            try
            {
                var productVariantsIds = rawProductVariantsIds.Trim().Split(',');
                foreach (var item in productVariantsIds)
                {
                    if (String.IsNullOrWhiteSpace(item)) continue;

                    var amazonListing = _amazonListingService.GetByProductVariantSku(item);

                    InitAmazonListingFromProductVariant(amazonListing, item, amazonListingGroup.Id);
                }
            }
            catch (Exception ex)
            {
                CurrentRequestData.ErrorSignal.Raise(ex);
            }
        }
        public void AmazonListingService_GetAmazonListingModel_ShouldReturnAmazonListingModelType()
        {
            var model = new AmazonListingGroup();

            var results = _amazonListingService.GetAmazonListingModel(model);

            results.Should().BeOfType<AmazonListingModel>();
        }
 public FileStream GetProductsImageFeeds(AmazonListingGroup amazonListingGroup)
 {
     var feeds = amazonListingGroup.Items.Where(x => x.Status == AmazonListingStatus.NotOnAmazon
         || x.Status == AmazonListingStatus.Inactive).Select(_amazonGenerateFeedContentService.GetProductImage).ToList();
     return _amazonGenerateFeedContentService.GetFeed(feeds, AmazonEnvelopeMessageType.ProductImage, AmazonEnvelopeMessageOperationType.Update);
 }
        public void Delete(AmazonListingGroup item)
        {
            _amazonLogService.Add(AmazonLogType.ListingGroups, AmazonLogStatus.Delete,null,null,null,null,null,null,item);

            _session.Transact(session => session.Delete(item));
        }
        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);
        }
        public void ListingController_CloseMany_ShouldCallUpdateAmazonListing()
        {
            var model = new AmazonListingGroup();

            var result = _listingController.CloseMany(model);

            A.CallTo(() => _prepareForSyncAmazonListingService.UpdateAmazonListings(model)).MustHaveHappened();
        }
        public void ListingGroupController_DeletePOST_ReturnsRedirectToEdit()
        {
            var model = new AmazonListingGroup() { Id = 1 };

            var result = _listingGroupController.Delete_POST(model);

            result.As<RedirectToRouteResult>().RouteValues["action"].Should().Be("Index");
        }
        public void ListingGroupController_DeletePOST_ShouldCallDelete()
        {
            var model = new AmazonListingGroup() { Id = 1 };

            var result = _listingGroupController.Delete_POST(model);

            A.CallTo(() => _amazonListingGroupService.Delete(model)).MustHaveHappened();
        }
        public void ListingController_CloseMany_ShouldCallGetAmazonSyncModel()
        {
            var model = new AmazonListingGroup();

            var result = _listingController.CloseMany(model);

            A.CallTo(() => _amazonListingSyncManager.GetAmazonSyncModel(model)).MustHaveHappened();
        }
 public AmazonListingModel GetAmazonListingModel(AmazonListingGroup amazonListingGroup)
 {
     return new AmazonListingModel()
     {
         ProductVariants = _productVariantService.GetAllVariants(String.Empty),
         AmazonListingGroup = amazonListingGroup,
         Categories = _optionService.GetCategoryOptions()
     };
 }
 public AmazonSyncModel GetAmazonSyncModel(AmazonListingGroup amazonListingGroup)
 {
     return new AmazonSyncModel()
     {
         Id = amazonListingGroup.Id,
         Title = amazonListingGroup.Name,
         AmazonListingGroup = amazonListingGroup
     };
 }
 public FileStream GetProductsDeleteFeeds(AmazonListingGroup amazonListingGroup)
 {
     var feeds = amazonListingGroup.Items.Where(x=>x.Status==AmazonListingStatus.Active).Select(x=>new Product{SKU = x.SellerSKU }).ToList();
     return _amazonGenerateFeedContentService.GetFeed(feeds, AmazonEnvelopeMessageType.Product, AmazonEnvelopeMessageOperationType.Delete);
 }
        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 List<FileStream> GetProductsMainFeeds(AmazonListingGroup amazonListingGroup)
        {
            var feedCollection = new List<FileStream>();

            var products = amazonListingGroup.Items.Select(_amazonGenerateFeedContentService.GetProduct).ToList();
            feedCollection.Add(_amazonGenerateFeedContentService.GetFeed(products, AmazonEnvelopeMessageType.Product, AmazonEnvelopeMessageOperationType.Update));

            var prices = amazonListingGroup.Items.Select(_amazonGenerateFeedContentService.GetProductPrice).ToList();
            feedCollection.Add(_amazonGenerateFeedContentService.GetFeed(prices, AmazonEnvelopeMessageType.Price, AmazonEnvelopeMessageOperationType.Update));

            var inventories = amazonListingGroup.Items.Select(_amazonGenerateFeedContentService.GetProductInventory).ToList();
            feedCollection.Add(_amazonGenerateFeedContentService.GetFeed(inventories, AmazonEnvelopeMessageType.Inventory, AmazonEnvelopeMessageOperationType.Update));

            return feedCollection;
        }