Shopify / shopify-api-ruby

ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services.
MIT License
1.06k stars 473 forks source link

Wrong type for InventoryItem's harmonized_system_code #1256

Closed weizheheng closed 11 months ago

weizheheng commented 11 months ago

Issue summary

This gem declare the harmonized_system_code as T.nilable(Integer), however, when I try to add the HS code using Shopify dashboard, it seems to be saved in String instead of Integer.

This raises type error when I try to get the hs code using using inventory_item.hs_code

CleanShot 2023-12-14 at 12 19 31@2x

For now I have to monkey patched it in order to retrieve the hs code

def harmonized_system_code
  value = get_property("harmonized_system_code")

  return value if value.nil?

  value.to_s
end

So, I am wondering what is the correct type for harmonized_system_code? If it's a String, I am happy to open a PR to change the type declaration.

Expected behavior

I am not sure if it's intended to be an Integer or it's a wrong type in the first place. But if the harmonized system code is indeed supposed to be an Integer, then I am expecting the harmonized system code should be saved as Integer.

Actual behavior

The harmonized system code is saved as String.

Steps to reproduce the problem

  1. Create a new product with default variant on Shopify dashboard and set the HS Code
  2. Get the inventory_item record using this gem
    product = ShopifyAPI::Product.find(id: the_product_id)
    inventory_item_id = product.variants.last.inventory_item_id
    inventory_item = ShopifyAPI::InventoryItem.find(id: inventory_item_id)
  3. Try calling inventory_item.harmonized_system_code, the type error like below should be raised CleanShot 2023-12-14 at 12 19 31@2x
weizheheng commented 11 months ago

related issue https://github.com/Shopify/shopify-api-ruby/issues/1087

lizkenyon commented 11 months ago

Hi 👋

Please see this comment on this PR for our plan for this.