Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variant inventory quantity #802

Merged
merged 10 commits into from
Dec 8, 2020
7 changes: 3 additions & 4 deletions lib/shopify_api/resources/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ def old_inventory_quantity=(new_value)
super
end

def serializable_hash(options = {})
super(options).tap do |resource|
(resource['variant'] || resource).except!('inventory_quantity', 'old_inventory_quantity')
end
def save
attributes.except!('inventory_quantity', 'old_inventory_quantity')
super
mllemango marked this conversation as resolved.
Show resolved Hide resolved
end

private
Expand Down
4 changes: 2 additions & 2 deletions test/product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ def test_price_range_when_has_different_price
assert_equal('100.00 - 199.00', @product.price_range)
end

def test_read_only_variant_inventory_fields_not_present_in_2020_01
def test_read_only_variant_inventory_fields_not_removed_in_2020_01
ShopifyAPI::Base.api_version = '2020-01'
refresh_product(api_version: ShopifyAPI::Base.api_version)

variant = @product.variants.first
refute(variant.as_json.include?('inventory_quantity'))
assert(10, variant.inventory_quantity)
end

def test_deprecated_inventory_fields_are_removed_in_2020_01
Expand Down
3 changes: 1 addition & 2 deletions test/variant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def test_delete_variant
def test_read_only_inventory_quantity
ShopifyAPI::Base.api_version = '2020-01'
refresh_variant(api_version: ShopifyAPI::Base.api_version)
assert(@variant.inventory_quantity, 10)
refute(@variant.as_json.include?('inventory_quantity'))
assert(10, @variant.inventory_quantity)
mllemango marked this conversation as resolved.
Show resolved Hide resolved
end

def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api
Expand Down