public void UpdateInventoryLevels(AcumaticaStockItem stockItem) { if (MonsterConfig.Settings.DisableShopifyPut) { _executionLogService.Log(LogBuilder.ShopifyPutDisabled()); return; } var variant = _inventoryRepository .RetrieveVariant(stockItem.MatchedVariant().ShopifyVariantId); if (variant.IsMissing) { _logger.Debug( $"Skipping Inventory Update for " + $"Variant {variant.ShopifySku} ({variant.ShopifyVariantId}) " + $"StockItem {stockItem} - reason: Missing Variant"); return; } if (variant.ShopifyProduct.IsDeleted) { _logger.Debug( $"Skipping Inventory Update for " + $"Variant {variant.ShopifySku} ({variant.ShopifyVariantId}) " + $"StockItem {stockItem} - reason: Deleted Parent Product"); return; } foreach (var level in variant.ShopifyInventoryLevels) { UpdateInventoryLevel(stockItem, level); } }
private InventorySyncStatus MakeSyncStatus(AcumaticaStockItem input) { var settings = _settingsRepository.RetrieveSettings(); var output = new InventorySyncStatus(); output.StockItemId = input.ItemId; output.TaxCategoryId = input.AcumaticaTaxCategory; output.IsStockItemPriceSynced = input.IsVariantSynced; output.IsStockItemInventorySynced = input.AcumaticaInventories.All(x => x.IsInventorySynced); output.IsTaxCategoryValid = input.IsValidTaxCategory(settings); if (input.IsMatched()) { var variant = input.MatchedVariant(); output.ShopifyVariantId = variant.ShopifyVariantId; output.ShopifyVariantSku = variant.ShopifySku; output.IsShopifyVariantMissing = variant.IsMissing; output.ShopifyInventoryIsTracked = variant.ShopifyIsTracked; } else { output.IsShopifyVariantMissing = true; } return(output); }
private void UpdateShopifyVariant(AcumaticaStockItem stockItemRecord, bool setTracking) { var settings = _settingsRepository.RetrieveSettings(); var variantRecord = stockItemRecord.MatchedVariant(); var stockItemObj = _acumaticaJsonService.RetrieveStockItem(stockItemRecord.ItemId); // Build the Shopify DTO // var variantShopifyId = variantRecord.ShopifyVariantId; var variantSku = variantRecord.ShopifySku; // Push the update via Variant API // var id = variantShopifyId; var taxable = stockItemRecord.IsTaxable(settings).Value; var price = settings.InventorySyncPrice ? (decimal)stockItemObj.DefaultPrice.value : (decimal?)null; var grams = settings.InventorySyncWeight ? stockItemObj.DimensionWeight.value.ToShopifyGrams() : (int?)null; string json = VariantUpdate.Make(id, taxable, price, grams); _productApi.UpdateVariantPrice(variantShopifyId, json); using (var transaction = _syncInventoryRepository.BeginTransaction()) { var log = LogBuilder.UpdateShopifyVariantPrice(variantSku, taxable, price, grams); _executionLogService.Log(log); // Update Stock Item record // stockItemRecord.IsVariantSynced = true; stockItemRecord.LastUpdated = DateTime.UtcNow; // Update Variant record // variantRecord.ShopifyIsTaxable = taxable; if (price.HasValue) { variantRecord.ShopifyPrice = price.Value; } if (setTracking) { variantRecord.ShopifyIsTracked = true; } _syncInventoryRepository.SaveChanges(); transaction.Commit(); } }
private void UpdateVariantCostOfGoods(AcumaticaStockItem stockItemRecord, bool setTracking) { var variantRecord = stockItemRecord.MatchedVariant(); var costOfGoods = stockItemRecord.AcumaticaLastCost; // Push the cost of goods via Inventory API // string content; if (setTracking) { var inventoryItem = new InventoryItem(); inventoryItem.id = variantRecord.ShopifyInventoryItemId; inventoryItem.cost = costOfGoods; inventoryItem.tracked = true; content = new { inventory_item = inventoryItem }.SerializeToJson(); } else { var inventoryItem = new InventoryItemUpdate(); inventoryItem.id = variantRecord.ShopifyInventoryItemId; inventoryItem.cost = costOfGoods; content = new { inventory_item = inventoryItem }.SerializeToJson(); } _inventoryApi.SetInventoryCost(variantRecord.ShopifyInventoryItemId, content); using (var transaction = _syncInventoryRepository.BeginTransaction()) { var log = LogBuilder.UpdateShopifyVariantCogsOfGoods(variantRecord.ShopifySku, costOfGoods); _executionLogService.Log(log); variantRecord.ShopifyCost = costOfGoods; _syncInventoryRepository.SaveChanges(); transaction.Commit(); } }