Skip to content

Commit

Permalink
Merge pull request #2 from BKWLD/adding-collections
Browse files Browse the repository at this point in the history
Adding collections
  • Loading branch information
isaazgarcia authored Apr 11, 2022
2 parents 1d9b4df + 6af101f commit 8cc82ec
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ Set up FeedMe to query either of the following routes. We're only exposing a mi
},
]
```

#### Collections

`https://cms-domain.com/actions/importable-shopify-feeds/feeds/collections`

```json
[
{
"title": "Collection Title",
"handle": "collection-title"
},
]
```
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "bkwld/craft-importable-shopify-feeds",
"description": "A Craft plugin that maps Shopify data into feeds that are more easily consumed by FeedMe.",
"type": "craft-plugin",
"version": "1.2.0",
"license": "MIT",
"authors": [
{
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/FeedsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,14 @@ public function actionVariants(): Response
return $this->asJson($variants);
}

/**
* Get all collections
*/
public function actionCollections(): Response
{
$collections = Plugin::getInstance()->shopifyAdminApi->getCollections();
return $this->asJson($collections);
}


}
20 changes: 20 additions & 0 deletions src/services/ShopifyAdminApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ public function getVariants()
}, $variants);
}

/**
* Get all collections
*/
public function getCollections()
{
$response = $this->execute([
'query' => '{
collections(first:250) {
edges {
node {
title
handle
}
}
}
}'
]);
return $this->flattenEdges($response)['collections'];
}

/**
* Flatten edges arrays
*/
Expand Down

0 comments on commit 8cc82ec

Please sign in to comment.