예제 #1
0
        public List <BigCommerceProduct> GetProducts(bool includeExtendInfo)
        {
            var products = new List <BigCommerceProduct>();
            var marker   = this.GetMarker();

            for (var i = 1; i < int.MaxValue; i++)
            {
                var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit));
                endpoint += includeExtendInfo ? ParamsBuilder.GetFieldsForProductSync() : ParamsBuilder.GetFieldsForInventorySync();
                var productsWithinPage = ActionPolicies.Get(marker, endpoint).Get(() =>
                                                                                  this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceProduct> >(BigCommerceCommand.GetProductsV2_OAuth, endpoint, marker));
                this.CreateApiDelay(productsWithinPage.Limits).Wait();                   //API requirement

                if (productsWithinPage.Response == null)
                {
                    break;
                }

                this.FillProductsSkus(productsWithinPage.Response, marker);
                products.AddRange(productsWithinPage.Response);
                if (productsWithinPage.Response.Count < RequestMaxLimit)
                {
                    break;
                }
            }

            if (includeExtendInfo)
            {
                base.FillWeightUnit(products, marker);
                base.FillBrands(products, marker);
            }

            return(products);
        }
예제 #2
0
        private void GetOrdersCoupons(IEnumerable <BigCommerceOrder> orders, string marker)
        {
            foreach (var order in orders)
            {
                if (string.IsNullOrWhiteSpace(order.CouponsReference?.Url))
                {
                    continue;
                }

                for (var i = 1; i < int.MaxValue; i++)
                {
                    var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit));
                    var coupons  = ActionPolicies.Get(marker, endpoint).Get(() =>
                                                                            this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceOrderCoupon> >(order.CouponsReference.Url, endpoint, marker));
                    this.CreateApiDelay(coupons.Limits).Wait();                       //API requirement

                    if (coupons.Response == null)
                    {
                        break;
                    }
                    order.Coupons.AddRange(coupons.Response);
                    if (coupons.Response.Count < RequestMaxLimit)
                    {
                        break;
                    }
                }
            }
        }
예제 #3
0
        public List <BigCommerceOrder> GetOrdersForV3(DateTime dateFrom, DateTime dateTo)
        {
            var mainEndpoint = ParamsBuilder.CreateOrdersParams(dateFrom, dateTo);
            var orders       = new List <BigCommerceOrder>();
            var marker       = this.GetMarker();

            for (var i = 1; i < int.MaxValue; i++)
            {
                var compositeEndpoint = mainEndpoint.ConcatParams(ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)));
                var ordersWithinPage  = ActionPolicies.Get(marker, compositeEndpoint).Get(() =>
                                                                                          this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceOrder> >(BigCommerceCommand.GetOrdersV2_OAuth, compositeEndpoint, marker));
                this.CreateApiDelay(ordersWithinPage.Limits).Wait();                   //API requirement

                if (ordersWithinPage.Response == null)
                {
                    break;
                }

                this.GetOrdersProducts(ordersWithinPage.Response, marker);
                this.GetOrdersCoupons(ordersWithinPage.Response, marker);
                this.GetOrdersShippingAddresses(ordersWithinPage.Response, marker);
                orders.AddRange(ordersWithinPage.Response);
                if (ordersWithinPage.Response.Count < RequestMaxLimit)
                {
                    break;
                }
            }

            return(orders);
        }
        protected override void FillBrands(IEnumerable <BigCommerceProduct> products, string marker)
        {
            var brands = new List <BigCommerceBrand>();

            for (var i = 1; i < int.MaxValue; i++)
            {
                var endpoint         = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit));
                var brandsWithinPage = ActionPolicies.Get(marker, endpoint).Get(() =>
                                                                                this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceBrand> >(BigCommerceCommand.GetBrandsV2, endpoint, marker));
                this.CreateApiDelay(brandsWithinPage.Limits).Wait();                   //API requirement

                if (brandsWithinPage.Response == null)
                {
                    break;
                }

                brands.AddRange(brandsWithinPage.Response);
                if (brandsWithinPage.Response.Count < RequestMaxLimit)
                {
                    break;
                }
            }

            this.FillBrandsForProducts(products, brands);
        }
예제 #5
0
        protected virtual string GetSecureURL(string marker)
        {
            var command = BigCommerceCommand.GetStoreV2_OAuth;
            var store   = ActionPolicies.Get(marker, command.Command).Get(() =>
                                                                          this._webRequestServices.GetResponseByRelativeUrl <BigCommerceStore>(command, string.Empty, marker));

            this.CreateApiDelay(store.Limits).Wait();             //API requirement

            return(store.Response.SecureURL);
        }
        protected override void FillWeightUnit(IEnumerable <BigCommerceProduct> products, string marker)
        {
            var command = BigCommerceCommand.GetStoreV2;
            var store   = ActionPolicies.Get(marker, command.Command).Get(() =>
                                                                          this._webRequestServices.GetResponseByRelativeUrl <BigCommerceStore>(command, string.Empty, marker));

            this.CreateApiDelay(store.Limits).Wait();               //API requirement

            foreach (var product in products)
            {
                product.WeightUnit = store.Response.WeightUnits;
            }
        }
예제 #7
0
        private void GetOrdersShippingAddresses(IEnumerable <BigCommerceOrder> orders, string marker)
        {
            foreach (var order in orders)
            {
                if (string.IsNullOrWhiteSpace(order.ShippingAddressesReference?.Url))
                {
                    continue;
                }

                var addresses = ActionPolicies.Get(marker, order.ShippingAddressesReference.Url).Get(() =>
                                                                                                     this._webRequestServices.GetResponse <List <BigCommerceShippingAddress> >(order.ShippingAddressesReference.Url, marker));
                order.ShippingAddresses = addresses.Response;
                this.CreateApiDelay(addresses.Limits).Wait();                   //API requirement
            }
        }
예제 #8
0
        protected void FillProductsSkus(IEnumerable <BigCommerceProduct> products, string marker)
        {
            foreach (var product in products.Where(product => product.InventoryTracking.Equals(InventoryTrackingEnum.sku)))
            {
                for (var i = 1; i < int.MaxValue; i++)
                {
                    var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit));
                    var options  = ActionPolicies.Get(marker, endpoint).Get(() =>
                                                                            this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceProductOption> >(product.ProductOptionsReference.Url, endpoint, marker));
                    this.CreateApiDelay(options.Limits).Wait();                     //API requirement

                    if (options.Response == null)
                    {
                        break;
                    }
                    product.ProductOptions.AddRange(options.Response);
                    if (options.Response.Count < RequestMaxLimit)
                    {
                        break;
                    }
                }
            }
        }