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);
            }
        }
Exemple #2
0
        public void UpsertVariant(long parentProductId, Variant variant)
        {
            var existing = _inventoryRepository.RetrieveVariant(variant.id);

            if (existing == null)
            {
                CreateNewVariantRecord(parentProductId, variant);
            }
            else
            {
                using (var transaction = _inventoryRepository.BeginTransaction())
                {
                    existing.ShopifySku       = variant.sku;
                    existing.ShopifyTitle     = variant.title ?? "";
                    existing.ShopifyIsTaxable = variant.taxable;
                    existing.ShopifyPrice     = (decimal)variant.price;
                    existing.LastUpdated      = DateTime.UtcNow;

                    _shopifyJsonService.Upsert(ShopifyJsonType.Variant, variant.id, variant.SerializeToJson());
                    _inventoryRepository.SaveChanges();
                    transaction.Commit();
                }
            }
        }