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 PortItemsAsync(string locationId)
        {
            V1Fee tax = await CreateTaxV1(locationId);

            string discoutId = await CreateDiscount(locationId);

            List <ShopifySharp.Product> products = await Shopify.GetProductsAsync();

            V1ItemsApi v1 = new V1ItemsApi();

            foreach (ShopifySharp.Product prod in products)
            {
                System.Console.WriteLine(prod.Title);
                V1Item item = new V1Item(
                    Name: prod.Title,
                    Type: "NORMAL",
                    Visibility: "PUBLIC",
                    AvailableOnline: true,
                    Variations: new List <V1Variation>(),
                    Taxable: true,
                    Fees: new List <V1Fee>()
                {
                    tax
                }
                    );
                foreach (ShopifySharp.ProductVariant variant in prod.Variants)
                {
                    V1Variation vari = new V1Variation
                                       (
                        Name: variant.Title,
                        PricingType: "FIXEDPRICING",
                        PriceMoney: new V1Money(
                            Amount: variant.Price.HasValue ? ((int?)(variant.Price.Value * 100L)) : null,
                            CurrencyCode: "USD"
                            ),
                        TrackInventory: true,
                        UserData: variant.Id.ToString()
                                       );
                    item.Variations.Add(vari);
                }
                V1Item item2 = await v1.CreateItemAsync(locationId, item);

                ShopifySharp.ProductImage image = prod.Images.FirstOrDefault();
                if (image != null)
                {
                    await ImageUploader.PortImage(locationId, item2.Id, prod.Images.First().Src);
                }
            }
//			await SetInventory(products);
            await FixBarCodes(products);
            await FixLocations();
        }
Esempio n. 3
0
        static public async Task <string> CreateDiscount(string locationId)
        {
            V1ItemsApi v1   = new V1ItemsApi();
            V1Discount body = new V1Discount(
                null,
                "Employee",
                "0.40",
                null,
                "FIXED",
                false,
                "B21212");
            V1Discount resp = await v1.CreateDiscountAsync(locationId, body);

            return(resp.Id);
        }
Esempio n. 4
0
        static public async Task <V1Fee> CreateTaxV1(string locationId)
        {
            V1ItemsApi v1    = new V1ItemsApi();
            V1Fee      v1Fee = new V1Fee(
                null,
                "Sales Tax",
                ".089",
                "FEESUBTOTALPHASE",
                "TAX",
                true,
                true,
                "ADDITIVE",
                "USSALESTAX");
            V1Fee resp = await v1.CreateFeeAsync(locationId, v1Fee);

            return(resp);
        }
 public void Init()
 {
     instance = new V1ItemsApi();
 }