コード例 #1
0
        static public async Task FixLocations()
        {
            CatalogApi api    = new CatalogApi();
            string     cursor = null;

            string[] types = { "MODIFIER_LIST", "ITEM", "MODIFIER", "CATEGORY", "DISCOUNT", "TAX", "ITEM_VARIATION" };
            foreach (string type in types)
            {
                List <CatalogObjectBatch> batches = new List <CatalogObjectBatch>();
                CatalogObjectBatch        batch   = new CatalogObjectBatch
                {
                    Objects = new List <CatalogObject>()
                };
                batches.Add(batch);
                do
                {
                    ListCatalogResponse resp = await api.ListCatalogAsync(cursor, type);

                    if (resp.Objects != null && resp.Objects.Count > 0)
                    {
                        batch.Objects.AddRange(resp.Objects.Where(o => o.PresentAtAllLocations == false));
                    }
                    cursor = resp.Cursor;
                } while (cursor != null);

                foreach (CatalogObject obj in batch.Objects)
                {
                    obj.PresentAtAllLocations = true;
                }
                BatchUpsertCatalogObjectsRequest  body     = new BatchUpsertCatalogObjectsRequest(Guid.NewGuid().ToString(), batches);
                BatchUpsertCatalogObjectsResponse response = await api.BatchUpsertCatalogObjectsAsync(body);
            }
        }
コード例 #2
0
        static public async Task SetInventory(List <ShopifySharp.Product> products)
        {
            CatalogApi api    = new CatalogApi();
            V1ItemsApi v1api  = new V1ItemsApi();
            string     cursor = null;

            do
            {
                ListCatalogResponse resp = await api.ListCatalogAsync(cursor, "ITEM_VARIATION");

                foreach (CatalogObject obj in resp.Objects)
                {
                    long id = long.Parse(obj.ItemVariationData.UserData);
                    ShopifySharp.Product        prod    = products.FirstOrDefault(p => p.Variants.Any(v => v.Id == id));
                    ShopifySharp.ProductVariant variant = prod.Variants.FirstOrDefault(v => v.Id == id);
                    V1AdjustInventoryRequest    body    = new V1AdjustInventoryRequest(variant.InventoryQuantity, "MANUALADJUST", "From Shopify");
                    try
                    {
                        await v1api.AdjustInventoryAsync(obj.CatalogV1Ids[0].LocationId, obj.CatalogV1Ids[0]._CatalogV1Id, body);
                    }
                    catch (Exception)
                    {
                    }
                    //				obj.PresentAtAllLocations = true;
                }

                cursor = resp.Cursor;
            } while (cursor != null);
        }
コード例 #3
0
        public RestaurantFullMenu getInventory()
        {
            RestaurantFullMenu retMenu = new RestaurantFullMenu();

            Configuration.Default.AccessToken = "sq0atp-ck43ZyjwVgVq8ZnmW98QNw";
            int categorynumber = 0;

            var apiInstance = new CatalogApi();

            try
            {
                // ListCatalog
                ListCatalogResponse result = apiInstance.ListCatalog(null, null);
                IDictionary <string, RestaurantItem>     items     = new Dictionary <string, RestaurantItem>();
                IDictionary <string, RestaurantCategory> categorys = new Dictionary <string, RestaurantCategory>();

                foreach (var restObj in result.Objects)
                {
                    switch (restObj.Type)
                    {
                    case Square.Connect.Model.CatalogObject.TypeEnum.ITEM:
                        if (restObj.ItemData.CategoryId == "CC523COHULAO3I5DAZRPCNKB")
                        {
                            items.Add(restObj.ItemData.Name, new RestaurantItem()
                            {
                                ItemName        = restObj.ItemData.Name,
                                ItemDescription = restObj.ItemData.Description,
                                ItemPrice       = "$12"
                            });
                        }
                        break;

                    case Square.Connect.Model.CatalogObject.TypeEnum.CATEGORY:
                        categorynumber = categorynumber + 1;
                        categorys.Add(restObj.CategoryData.Name, new RestaurantCategory()
                        {
                            CategoryName   = restObj.CategoryData.Name,
                            CategoryNumber = categorynumber.ToString()
                        });
                        break;

                    default:
                        break;
                    }
                }

                retMenu.items     = items;
                retMenu.categorys = categorys;
            }
            catch (Exception e)
            {
                //Debug.Print("Exception when calling CatalogApi.ListCatalog: " + e.Message);
            }

            return(retMenu);
        }
コード例 #4
0
        static public async Task GetProductsAsync()
        {
            CatalogApi api    = new CatalogApi();
            string     cursor = null;
//			string[] types = { "ITEM_VARIATION", "MODIFIER_LIST", "ITEM", "MODIFIER", "CATEGORY", "DISCOUNT", "TAX" };
//			foreach (string type in types)
            {
                do
                {
                    ListCatalogResponse resp = await api.ListCatalogAsync(cursor, "ITEM");

                    if (resp.Objects != null && resp.Objects.Count > 0)
                    {
                    }
                    cursor = resp.Cursor;
                } while (cursor != null);
            }
        }
コード例 #5
0
        static public async Task DeleteProducts()
        {
            CatalogApi api    = new CatalogApi();
            string     cursor = null;

            string[] types = { "ITEM_VARIATION", "MODIFIER_LIST", "ITEM", "MODIFIER", "CATEGORY", "DISCOUNT", "TAX" };
            foreach (string type in types)
            {
                do
                {
                    ListCatalogResponse resp = await api.ListCatalogAsync(cursor, type);

                    if (resp.Objects != null && resp.Objects.Count > 0)
                    {
                        BatchDeleteCatalogObjectsRequest  body    = new BatchDeleteCatalogObjectsRequest(resp.Objects.Select(s => s.Id).ToList());
                        BatchDeleteCatalogObjectsResponse delResp = await api.BatchDeleteCatalogObjectsAsync(body);
                    }
                    cursor = resp.Cursor;
                } while (cursor != null);
            }
        }
コード例 #6
0
        static public async Task FixBarCodes(List <ShopifySharp.Product> products)
        {
            CatalogApi api    = new CatalogApi();
            string     cursor = null;
            List <CatalogObjectBatch> batches = new List <CatalogObjectBatch>();
            CatalogObjectBatch        batch   = new CatalogObjectBatch
            {
                Objects = new List <CatalogObject>()
            };

            batches.Add(batch);

            do
            {
                ListCatalogResponse resp = await api.ListCatalogAsync(cursor, "ITEM_VARIATION");

                if (resp.Objects != null && resp.Objects.Count > 0)
                {
                    batch.Objects.AddRange(resp.Objects);
                }
                cursor = resp.Cursor;
            } while (cursor != null);

            foreach (CatalogObject obj in batch.Objects)
            {
                long id = long.Parse(obj.ItemVariationData.UserData);
                ShopifySharp.Product        prod    = products.FirstOrDefault(p => p.Variants.Any(v => v.Id == id));
                ShopifySharp.ProductVariant variant = prod.Variants.FirstOrDefault(v => v.Id == id);

//				ShopifySharp.ProductVariant variant = products.Select(p => p.Variants.First(v => v.Id.ToString() == obj.ItemVariationData.UserData)).First();
                obj.ItemVariationData.Upc = variant.Barcode;
                obj.ItemVariationData.Sku = variant.Barcode;
//				obj.PresentAtAllLocations = true;
            }

            BatchUpsertCatalogObjectsRequest  body     = new BatchUpsertCatalogObjectsRequest(Guid.NewGuid().ToString(), batches);
            BatchUpsertCatalogObjectsResponse response = await api.BatchUpsertCatalogObjectsAsync(body);
        }