-
Notifications
You must be signed in to change notification settings - Fork 478
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
Add support Collection#products endpoint #609
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module ShopifyAPI | ||
class Collection < Base | ||
include Events | ||
include Metafields | ||
|
||
def products(options = {}) | ||
Product.find(:all, from: "#{self.class.prefix}collections/#{id}/products.json", params: options) | ||
siddhantbajaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'test_helper' | ||
|
||
class CollectionTest < Test::Unit::TestCase | ||
test "Collection get products gets all products in a collection" do | ||
unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: :unstable) | ||
ShopifyAPI::Base.activate_session(unstable_version) | ||
|
||
fake( | ||
'collections', | ||
url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1.json', | ||
method: :get, | ||
status: 200, | ||
body: load_fixture('collection'), | ||
extension: false | ||
) | ||
|
||
collection = ShopifyAPI::Collection.find(1) | ||
|
||
fake( | ||
'products', | ||
url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1/products.json', | ||
method: :get, | ||
status: 200, | ||
body: load_fixture('collection_products'), | ||
extension: false | ||
) | ||
assert_equal [632910392, 921728736], collection.products.map(&:id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"collection": { | ||
"id": 1, | ||
"handle": "test-collection", | ||
"title": "test-collection", | ||
"updated_at": "2016-03-17T16:58:37-04:00", | ||
"body_html": null, | ||
"published_at": "2016-03-17T16:58:37-04:00", | ||
"sort_order": "alpha-asc", | ||
"template_suffix": null, | ||
"published_scope": "global", | ||
"image": { | ||
"created_at": "2016-03-17T16:58:37-04:00", | ||
"src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/collections\/fd43f2c8883f6e9b680e3295fd990d2c.gif?v=1458248317" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"products": [ | ||
{ | ||
"product_type": "Cult Products", | ||
"handle": "ipod-nano", | ||
"created_at": "2011-10-20T14:05:13-04:00", | ||
"body_html": "<p>It's the small iPod with one very big idea: Video. Now the world's most popular music player, available in 4GB and 8GB models, lets you enjoy TV shows, movies, video podcasts, and more. The larger, brighter display means amazing picture quality. In six eye-catching colors, iPod nano is stunning all around. And with models starting at just $149, little speaks volumes.</p>", | ||
"title": "IPod Nano - 8GB", | ||
"template_suffix": null, | ||
"updated_at": "2011-10-20T14:05:13-04:00", | ||
"id": 632910392, | ||
"tags": "Emotive, Flash Memory, MP3, Music", | ||
"images": [ | ||
{ | ||
"position": 1, | ||
"created_at": "2011-10-20T14:05:13-04:00", | ||
"product_id": 632910392, | ||
"updated_at": "2011-10-20T14:05:13-04:00", | ||
"src": "http://static.shopify.com/s/files/1/6909/3384/products/ipod-nano.png?0", | ||
"id": 850703190 | ||
} | ||
], | ||
"vendor": "Apple", | ||
"published_at": "2007-12-31T19:00:00-05:00", | ||
"manually_sorted": true, | ||
"options": [ | ||
{ | ||
"name": "Title" | ||
} | ||
] | ||
}, | ||
{ | ||
"product_type": "Cult Products", | ||
"handle": "ipod-touch", | ||
"created_at": "2018-09-26T14:05:13-04:00", | ||
"body_html": "<p>The iPod Touch has the iPhone's multi-touch interface, with a physical home button off the touch screen. The home screen has a list of buttons for the available applications.</p>", | ||
"title": "IPod Touch 8GB", | ||
"template_suffix": null, | ||
"updated_at": "2018-09-26T14:05:13-04:00", | ||
"id": 921728736, | ||
"tags": null, | ||
"vendor": "Apple", | ||
"published_at": "2018-09-26T14:05:13-04:00", | ||
"manually_sorted": true | ||
} | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to include
Events
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yes, we do need to keep support for
Events
. We will also have to create PR inShopify/shopify
to add support forCollection.events
.