shopify_app: :order => "created_at DESC" is not a valid parameter for the Order query

In: home_controller.rb Line: 15 https://github.com/Shopify/shopify_app/blob/master/lib/generators/shopify_app/templates/app/controllers/home_controller.rb#L15

The :order => "created_at DESC" parameter is not valid. In other words, it does not work.

This is because the Shopify API is an ActiveResource, the parameter order does not work in the same way that it would with an ActiveRecord model.

limit is one of the end points of Order, so that parameter works. http://docs.shopify.com/api/order#index

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 16 (12 by maintainers)

Most upvoted comments

@yu-coder order_id maybe, but not order_number as that doesn’t exist as a parameter.

As a way of getting around the problem, I have had to use: .sort_by(&:created_at) or .sort_by(&:created_at).reverse

For example:

<% @Products.sort_by(&:created_at).reverse.each do |product| %>
...
<% end %>

Could you indicate what doesn’t work? Because when I run the following queries, it does exactly what I expect:

ShopifyAPI::Order.find(:all, :params => {limit: 5, order: "created_at ASC"}).map(&:created_at)
["2013-10-11T00:23:49-04:00",
 "2013-11-13T16:44:31-05:00",
 "2013-11-13T20:20:13-05:00",
 "2013-11-13T20:23:04-05:00",
 "2013-11-13T20:33:39-05:00"]

ShopifyAPI::Order.find(:all, :params => {limit: 5, order: "created_at DESC"}).map(&:created_at)
["2014-01-09T16:23:24-05:00",
 "2014-01-09T16:16:00-05:00",
 "2013-12-17T10:29:17-05:00",
 "2013-11-14T09:34:53-05:00",
 "2013-11-13T20:50:37-05:00"]

The former shows the first 5, the latter the last 5.