variant.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. module ShopifyAPI
  2. class Variant < Base
  3. include Metafields
  4. include DisablePrefixCheck
  5. conditional_prefix :product
  6. def initialize(*)
  7. super
  8. unless allow_inventory_params?
  9. attributes.except!('inventory_quantity_adjustment', 'inventory_quantity', 'old_inventory_quantity')
  10. end
  11. end
  12. def inventory_quantity_adjustment=(new_value)
  13. raise_deprecated_inventory_call('inventory_quantity_adjustment') unless allow_inventory_params?
  14. super
  15. end
  16. def inventory_quantity=(new_value)
  17. raise_deprecated_inventory_call('inventory_quantity') unless allow_inventory_params?
  18. super
  19. end
  20. def old_inventory_quantity=(new_value)
  21. raise_deprecated_inventory_call('old_inventory_quantity') unless allow_inventory_params?
  22. super
  23. end
  24. private
  25. def raise_deprecated_inventory_call(parameter)
  26. raise(
  27. ShopifyAPI::ValidationException,
  28. "'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide",
  29. )
  30. end
  31. def allow_inventory_params?
  32. Base.api_version < ApiVersion.find_version('2019-10')
  33. end
  34. end
  35. end