Can't Access Some Methods Of Shopify Order API
This is my first time attempting to create a Shopify App; all I'm trying to do is query my store for order details.
After having completed the tutorials: https://www.youtube.com/watch?v=DB48N8rRHFw and the Shopify_app on Github, I have an app that I can install to a development store and test. I switched out the default Products query and have attempted to replace it with a query on Orders instead.
The current code is as follows:
class HomeController < ShopifyApp::AuthenticatedController def index @orders = ShopifyAPI::Order.find(:all) end end
The thing that I do not for the life of me understand is how I can be completely successful getting the values such as the creation date, total cost, tax, etc. but I run into massive issues when it comes to getting the values from the properties that are hashes. Having been using https://help.shopify.com/api/reference/order as my API reference, I know that they exist, however when I run the app, I get the following from the Heroku logs:
2016-06-27T22:47:02.298067+00:00 app[web.1]: Processing by HomeController#index as HTML 2016-06-27T22:47:02.512071+00:00 app[web.1]: Rendered home/index.html.erb within layouts/embedded_app (2.1ms) 2016-06-27T22:47:02.513471+00:00 app[web.1]: 32: <td>cust</td> 2016-06-27T22:47:02.513473+00:00 app[web.1]: 36: <td><%= order.subtotal_price %></td> 2016-06-27T22:47:02.513470+00:00 app[web.1]: 31: <td><%= order.order_number %></td> 2016-06-27T22:47:02.513468+00:00 app[web.1]: ActionView::Template::Error (undefined method `shipping_address' for #<ShopifyAPI::Order:0x007f27612d5660>): 2016-06-27T22:47:02.513464+00:00 app[web.1]: 2016-06-27T22:47:02.513469+00:00 app[web.1]: 30: <tr> 2016-06-27T22:47:02.513471+00:00 app[web.1]: 33: <td><%= order.shipping_address %></td> 2016-06-27T22:47:02.513472+00:00 app[web.1]: 34: <td>total</td> 2016-06-27T22:47:02.513473+00:00 app[web.1]: 35: <td><%= order.created_at %></td> 2016-06-27T22:47:02.513474+00:00 app[web.1]: app/views/home/index.html.erb:33:in `block in _app_views_home_index_html_erb__4133370917654343554_69903554858260' 2016-06-27T22:47:02.513475+00:00 app[web.1]: app/views/home/index.html.erb:29:in `_app_views_home_index_html_erb__4133370917654343554_69903554858260'
Obviously, I'm not understanding something probably very fundamental about this. If there didn't exist a shipping address, I'd still get back "nil" or something; it's so weird that the error is that the method doesn't exist.
Edit: I should probably note gem versions in case that is the cause. shopify_api (4.2.2), shopify_app (7.0.7), json (1.8.3), and using ruby 2.3.0p0. If there's another gem that might be the cause, just tell me and I'll look into it.
My first test order that I had created lacked a customer outright, meaning no shipping address to pull. I must have simply overlooked the field the first time, and never noticed after. It wasn't that it was returning nil or any such thing, the field just never existed to begin with; that was my problem.
Once I removed the order and tested with ones that had the information of interest, order.shipping_address.city was successful.
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How can I add a featured image from a blog post to my homepage on shopify
- → Need "add to cart" button price to update with correct amount depending on what checkbox is checked
- → GET /admin/webhooks.json returns an empty array