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

Why does ShopifyAPI::Variant#to_hash exclude inventory_quantity ? #930

Closed
koshigoe opened this issue Apr 12, 2022 · 1 comment
Closed

Why does ShopifyAPI::Variant#to_hash exclude inventory_quantity ? #930

koshigoe opened this issue Apr 12, 2022 · 1 comment

Comments

@koshigoe
Copy link

Issue summary

I try to get variant's inventory_quantity via ShopiryAPI::Product#to_hash.
But inventory_quantity did not exist in Hash object.

> ShopifyAPI::Auth::Session.temp(shop: 'test.myshopify.com', access_token: 'token') do |session|
  variant = ShopifyAPI::Variant.create_instance(session: session, data: { inventory_item_id: 1234, inventory_quantity: 10 })
  pp variant.inventory_quantity
  pp variant.to_hash
end

10
{"inventory_item_id"=>1234}
=> {"inventory_item_id"=>1234}

Expected behavior

I hope ShopifyAPI::Variant#to_hash include all API properties.

Actual behavior

Some properties exclude?

Specifications

  • shopify_api version: 10.0.2
  • Shopify API version used 2022-01
@paulomarg
Copy link
Contributor

Hey @koshigoe, thanks for reporting this! The inventory_quantity field can't be sent when saving, so we started filtering it out when we call to_hash (because that is the method we use to serialize the object for saving). In your case, we shouldn't be ignoring that field.

We'll add a parameter to to_hash to make that behaviour optional. That way, when you call the method you'll get all the data.

mkevinosullivan added a commit that referenced this issue Apr 22, 2022
Adds parameter to `to_hash` so that default behaviour includes readonly
attributes; setting the parameter to `true` indicates that `to_hash` is
being used to serialize the object for saving (and thus excludes
readonly attributes).

Fixes issue #930
mkevinosullivan added a commit that referenced this issue Apr 22, 2022
Adds parameter to `to_hash` so that default behaviour includes readonly
attributes; setting the parameter to `true` indicates that `to_hash` is
being used to serialize the object for saving (and thus excludes
readonly attributes).

Fixes issue #930
mkevinosullivan added a commit that referenced this issue Apr 25, 2022
Adds parameter to `to_hash` so that default behaviour includes readonly
attributes; setting the parameter to `true` indicates that `to_hash` is
being used to serialize the object for saving (and thus excludes
readonly attributes).

Fixes issue #930
mkevinosullivan added a commit that referenced this issue Apr 26, 2022
Adds parameter to `to_hash` so that default behaviour includes readonly
attributes; setting the parameter to `true` indicates that `to_hash` is
being used to serialize the object for saving (and thus excludes
readonly attributes).

Fixes issue #930
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants