コード例 #1
0
        public void RunAddToProduct(ShopifyAddVariantImportContext context)
        {
            if (MonsterConfig.Settings.DisableShopifyPut)
            {
                _logService.Log(LogBuilder.ShopifyPutDisabled());
                return;
            }

            // Attempt to auto-match Item Ids SKU's that exists
            //
            AutomatchExistingSkus(context);

            // Creates payload for Shopify API only including valid Variants not in Shopify
            //
            var createVariantList    = CleanAndBuildVariantPayload(context.AcumaticaItemIds);
            var shopifyProductRecord = _syncInventoryRepository.RetrieveProduct(context.ShopifyProductId);

            // Add Variants thru Shopify API
            //
            foreach (var createVariant in createVariantList)
            {
                _logService.Log(LogBuilder.CreatingShopifyVariant(createVariant));

                // Invoke Shopify API and create new Variant
                //
                var json = new { variant = createVariant }.SerializeToJson();
                var resultJson = _productApi.AddVariant(context.ShopifyProductId, json);
                var result     = resultJson.DeserializeFromJson <VariantParent>();

                // Create Variant Record and Sync
                //
                var variantRecord =
                    _shopifyInventoryGet.CreateNewVariantRecord(shopifyProductRecord.MonsterId, result.variant);
                CreateSyncRecord(createVariant.sku.StandardizedSku(), variantRecord);
            }

            // Need to refresh local cache of Product, so Inventory Levels records reflect current state
            //
            _shopifyInventoryGet.Run(context.ShopifyProductId);

            foreach (var stockItemId in context.AcumaticaItemIds)
            {
                // Update the Inventory data
                //
                RunInventoryUpdate(stockItemId);
            }
        }