variant.rb 1.2 KB

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