Browse Source

Update variant.rb

marschattha 4 years ago
parent
commit
a19caa3945
1 changed files with 37 additions and 0 deletions
  1. 37 0
      lib/shopify_api/resources/variant.rb

+ 37 - 0
lib/shopify_api/resources/variant.rb

@@ -4,5 +4,42 @@ module ShopifyAPI
     include DisablePrefixCheck
 
     conditional_prefix :product
+    
+    def inventory_quantity_adjustment=(new_value)
+      raise_deprecated_inventory_call('inventory_quantity_adjustment') unless allow_inventory_params?
+      super
+    end
+
+    def inventory_quantity=(new_value)
+      raise_deprecated_inventory_call('inventory_quantity') unless allow_inventory_params?
+      super
+    end
+
+    def old_inventory_quantity=(new_value)
+      raise_deprecated_inventory_call('old_inventory_quantity') unless allow_inventory_params?
+      super
+    end
+
+    def serializable_hash(options = {})
+      if allow_inventory_params?
+        super(options)
+      else
+        super(options).tap do |serialized_hash|
+          (serialized_hash['variant'] || serialized_hash).except!('inventory_quantity', 'old_inventory_quantity')
+        end
+      end
+    end
+
+    private
+
+    def raise_deprecated_inventory_call(parameter)
+      raise(ShopifyAPI::ValidationException,
+        "'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide",
+        )
+    end
+
+    def allow_inventory_params?
+      Base.api_version < ApiVersion.find_version('2019-10')
+    end
   end
 end