/// <summary> /// Update variant (price) and check Ids (update them in SAP). Use checkIdInventoryUpdateQueue, should check <see cref=ProductExport.variantDone></cref> before running /// </summary> static public void CheckIdInventoryUpdateThread() { while (!inventoryUpdateDone || NotFoundIdInventoryUpdateQueue.Count > 0) { InventoryLevel p = null; // SQLDone can become true whithout adding anything to Queue if (NotFoundIdInventoryUpdateQueue.TryDequeue(out p)) { try { if (GeneralAdapter.FindIdFromSku(p)) { var result = Task.Run(() => { return(updateInventoryService.SetAsync(p)); }).Result; } else { GeneralAdapter.OutputString($"Couldn't find the SKU: {p.SKU}"); } } catch { GeneralAdapter.OutputErrorString($"Couldn't resolve the inventory {p.Id} SKU: {p.SKU}"); } } } checkIdInventoryDone = true; GeneralAdapter.OutputString("checkIdInventoryDone Done."); }
static public async Task NotFoundIdInventoryUpdateAsync() { while (!inventoryUpdateDone || NotFoundIdInventoryUpdateQueue.Count > 0) { if (NotFoundIdVariantUpdateQueue.Count == 0) { await Task.Delay(500); } InventoryLevel p = null; // SQLDone can become true whithout adding anything to Queue if (NotFoundIdInventoryUpdateQueue.TryDequeue(out p)) { try { if (GeneralAdapter.FindIdFromSku(p)) { await updateInventoryService.SetAsync(p); } else { GeneralAdapter.OutputString($"Couldn't find the SKU: {p.SKU}"); } } catch { GeneralAdapter.OutputString($"Couldn't resolve the inventory {p.Id} SKU: {p.SKU}"); } } } checkIdInventoryDone = true; GeneralAdapter.OutputString("checkIdInventoryDone Done."); }
public int DetermineNeed(InventoryLevel inventoryLevel) { if (inventoryLevel.Quantity > inventoryLevel.Par) { return 0; } int quantityNeeded = inventoryLevel.Maximum - inventoryLevel.Quantity; int packagesNeeded = quantityNeeded / inventoryLevel.PackageSize; return packagesNeeded; }
public static bool FindIdFromSku(InventoryLevel il, List <ProductVariant> list) { ProductVariant vit = list.Find(e => e.SKU == il.SKU); if (vit != null) { if (vit.Id == null || vit.InventoryItemId == null) { OutputErrorString($"Couldn't find Id From Sku in Shopify. SKU in SAP: {il.SKU} SKU in Shopify: {il.SKU}"); } OutputFoundVariantId(vit); il.Id = vit.Id; il.InventoryItemId = vit.InventoryItemId; return(true); } return(false); }
// 武器孔数修正 static int GetHoleCount(InventoryLevel level) { switch (level) { case InventoryLevel.White: return(0); case InventoryLevel.Green: return(UnityEngine.Random.Range(0, 100) % 2); case InventoryLevel.Blue: return(UnityEngine.Random.Range(0, 100) % 2 + 1); case InventoryLevel.Purple: case InventoryLevel.Special: return(2); default: return(0); } }
private void UpdateInventoryLevel(AcumaticaStockItem stockItem, ShopifyInventoryLevel level) { var location = _syncInventoryRepository.RetrieveLocation(level.ShopifyLocationId); var warehouseIds = location.MatchedWarehouseIds(); var warehouseDetails = stockItem.Inventory(warehouseIds); var available = (int)warehouseDetails.Sum(x => x.AcumaticaAvailQty); var sku = level.ShopifyVariant.ShopifySku; var levelDto = new InventoryLevel { inventory_item_id = level.ShopifyInventoryItemId, available = available, location_id = location.ShopifyLocationId, }; var levelJson = levelDto.SerializeToJson(); _inventoryApi.SetInventoryLevels(levelJson); using (var transaction = _syncInventoryRepository.BeginTransaction()) { var log = $"Updated Shopify Variant {sku} " + $"in Location {location.ShopifyLocationName} to Available Qty {available}"; _executionLogService.Log(log); warehouseDetails.ForEach(x => x.IsInventorySynced = true); // Update Shopify Inventory Level records // level.ShopifyAvailableQuantity = available; level.LastUpdated = DateTime.UtcNow; _inventoryRepository.SaveChanges(); transaction.Commit(); } }
private static async Task ImportNewProductsAsync(Shop2 shop, List <Models.Product> products, bool willPublishProducts) { Console.WriteLine(); WriteInfo("Importing products to {0}...", _myShopifyUrl); for (int i = 0; i < products.Count; i++) { var product = products[i]; var productVariant = new ProductVariant { SKU = product.Sku, Title = product.Title, Price = product.Price, InventoryManagement = "shopify", CompareAtPrice = product.PriceBeforeSale }; Console.WriteLine("{0}/{1}\t\t{2} ({3})", i + 1, products.Count, product.Title, product.Sku); Product existingProduct = null; var productService = new ProductService(_myShopifyUrl, _shopAccessToken); if (i == 0) { // HACK: API CALL var existingProducts = await productService.ListAsync(new ProductFilter { Title = product.Title, Limit = 1 }); existingProduct = existingProducts.FirstOrDefault(); } if (existingProduct == null) { var productImages = new List <ProductImage> { new ProductImage { Attachment = product.Image } }; existingProduct = new Product { Title = product.Title, BodyHtml = string.Format("<strong>{0}</strong>", product.Description), ProductType = "", Images = productImages, Tags = product.Category.Replace("/", ","), Variants = new List <ProductVariant> { productVariant } }; // HACK: API CALL existingProduct = await productService .CreateAsync(existingProduct, new ProductCreateOptions { Published = willPublishProducts }); WriteInfoWithTime("✓ Product added"); } else { WriteInfoWithTime("- Product ALREADY added"); } productVariant = existingProduct.Variants.First(); var inventoryLevelService = new InventoryLevelService(_myShopifyUrl, _shopAccessToken); var inventoryLevel = new InventoryLevel { InventoryItemId = productVariant.InventoryItemId, LocationId = shop.PrimaryLocationId, Available = product.Quantity, }; // HACK: API CALL await inventoryLevelService.SetAsync(inventoryLevel); WriteInfoWithTime("✓ Inventory label has been set"); using (var c = new ServerConnection(_connectionString)) { var command = c.SetStatement(@"INSERT INTO [SeparatedTable](Id) VALUES (@id)"); command.AddParameter("@id", System.Data.SqlDbType.Int, product.Id); await command.ExecuteNonQueryAsync(); WriteInfoWithTime("✓ Added to database"); } Console.WriteLine(); } WriteInfoWithTime("DONE Importing products to {0}", _myShopifyUrl); }
public static bool FindIdFromSku(InventoryLevel il) { return(FindIdFromSku(il, ProductExport.variantList)); }