コード例 #1
0
 public AjaxModel(ShoperItem _sku, string isSet)
 {
     success     = true;
     sku         = _sku.Sku;
     inventoryId = _sku.InventoryId;
     this.isSet  = isSet;
 }
コード例 #2
0
        public static async Task <List <ShoperItem> > GetListAsync(string token, string shopUrl, string skuSet, List <Inventory> inventories)
        {
            //zapętl aby uzyskać wszystkie przedmioty
            ShoperProductResponse shoperProductResponse = new ShoperProductResponse();
            int page = 0;

            do
            {
                RestClient  client  = new RestClient(@"https://" + shopUrl + "/");
                RestRequest request = new RestRequest("webapi/rest/products?filters={\"stock.code\":{\"IN\":[" + skuSet + "]}}", Method.GET);
                request.AddHeader("Authorization", "Bearer " + token);
                request.AddParameter("limit", "50");
                var response = await client.ExecuteAsync(request);

                ShoperProductResponse _response = JsonConvert.DeserializeObject <ShoperProductResponse>(response.Content);
                if (page == 0)
                {
                    shoperProductResponse = _response;
                }
                else
                {
                    shoperProductResponse.list.AddRange(_response.list);
                }
                page += 1;
            } while (page != Int32.Parse(shoperProductResponse.pages));

            List <ShoperItem> shoperItems = new List <ShoperItem>();

            foreach (Inventory inventory in inventories)
            {
                ShoperProduct product    = shoperProductResponse.list.Find(x => x.stock.Code.ToLower() == inventory.Sku.ToLower());
                ShoperItem    shoperItem = new ShoperItem();
                if (product == null)
                {
                    shoperItem.Sku           = inventory.Sku;
                    shoperItem.Stock         = inventory.Counter;
                    shoperItem.ExpectedStock = 0;
                    shoperItem.InventoryId   = inventory.InventoryId.ToString();
                    shoperItem.Name          = "Brak produktu w sklepie shoper";
                    shoperItem.Price         = "0";
                    shoperItem.Product_id    = "";
                }
                else
                {
                    shoperItem.Sku           = inventory.Sku;
                    shoperItem.Stock         = inventory.Counter;
                    shoperItem.ExpectedStock = Int32.Parse(product.stock.stock);
                    shoperItem.InventoryId   = inventory.InventoryId.ToString();
                    shoperItem.Name          = product.translations.pl_PL.name;
                    shoperItem.Price         = product.stock.price;
                    shoperItem.Product_id    = product.product_id;
                }
                shoperItems.Add(shoperItem);
            }

            return(shoperItems);
        }
コード例 #3
0
        public static async Task <ShoperItem> GetAsync(string token, string shopUrl, string sku, int counter)
        {
            RestClient  client  = new RestClient(@"https://" + shopUrl + "/");
            RestRequest request = new RestRequest("webapi/rest/products", Method.GET);

            request.AddParameter("filters", "{\"stock.code\":{\"=\":\"" + sku + "\"}}");
            request.AddHeader("Authorization", "Bearer " + token);
            var response = await client.ExecuteAsync(request);

            ShoperProductResponse shoperProductResponse = JsonConvert.DeserializeObject <ShoperProductResponse>(response.Content);
            ShoperItem            shoperItem            = new ShoperItem();

            if (shoperProductResponse.list.Count > 0)
            {
                shoperItem.Sku           = shoperProductResponse.list[0].stock.Code;
                shoperItem.ExpectedStock = Int32.Parse(shoperProductResponse.list[0].stock.stock);
                shoperItem.Name          = shoperProductResponse.list[0].translations.pl_PL.name;
                shoperItem.Price         = shoperProductResponse.list[0].stock.price;
                shoperItem.Product_id    = shoperProductResponse.list[0].product_id;
                shoperItem.Stock         = counter;
            }
            return(shoperItem);
        }