Esempio n. 1
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);
        }
Esempio n. 2
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);
        }