craftcms / shopify

Synchronize and extend product data from your Shopify storefront.
MIT License
45 stars 25 forks source link

Collections Documentation #19

Closed bfjare closed 4 years ago

bfjare commented 4 years ago

Looks like Collections only pulls the collection id. Is it possible to give some basic documentation on the best way to pull a list of collections?

Thanks in advance.

nmaier95 commented 4 years ago

@TonyDeStefano or @ryanpcmcquen may you help answering here?

TonyDeStefano commented 4 years ago

@bfjare if you are wanting to pull a list of products by collection, you need to use this Shopify endpoint in your code: /2020-01/products.json?limit=200&collection_id=[collection id]

bfjare commented 4 years ago

Sorry, I guess I'm not fully understanding how this integrates with twig.

nmaier95 commented 4 years ago

I think we actually didn't expose the collection-service-calls to the shopify-twig-variable, did we @TonyDeStefano ? If thats what @bfjare needs...?

bfjare commented 4 years ago

@nmaier95 I'm just hoping to be able to use it to select collections in the fields to build navigation and then create product listing pages for those collections. The documentation isn't very clear how this works in Twig is all. Especially on the collections side. Right now I have some of what I need to be done by creating a simple plugin with variables going directly through the API but it's less than elegant.

Actually would be happy to sponsor some expansion to the plugin. I don't think it needs very much and makes it a better tool for us moving forward.

ryanpcmcquen commented 4 years ago

@bfjare, is there a reason you can't just add a field with the type of 'Shopify Collection'?

Screen Shot 2020-04-22 at 9 26 14 AM
bfjare commented 4 years ago

@ryanpcmcquen That's what I am using but all it produces is the Collection ID number. I cant grab handles, title, etc, or if I can I'm not understanding how it works in Twig other then "use this endpoint". I'm well aware of the fact this is a me problem.

ryanpcmcquen commented 4 years ago

@bfjare, that's all it returns and stores. You will want your front end to fetch any other data from Shopify directly using their API. The advantage here is storing less data inside of Craft itself, and eliminating the issue of data 'freshness' you would hit if you chose to store Shopify data inside of Craft as well.

bfjare commented 4 years ago

@ryanpcmcquen gotcha, That's what I am doing now. I have a separate module I built using simple variables to grab the ID and pull the rest of the data from Shopify with their API. Looks like that is the right way to go as of now.

ryanpcmcquen commented 4 years ago

@bfjare, I'd recommend keeping product data out of Craft. We did that with our catalog and Craft's internal schema did not scale well. Long story short, you end up with millions of rows in your relations table and some tricky puzzles to solve ...

bfjare commented 4 years ago

I wanted to provide more information on this after a full day working on the project. I feel all too often we figure things out (kinda) and then leave them, which I have no judgment on, but wanted to share my experience for anyone fighting this. @ryanpcmcquen is absolutely right on not having Shopify's data within Craft for obvious reasons he explained. This plugin is actually right on for what you need. High-level back-end devs with great experience in plugin development will look at this and the Shopify API and this and say, "cool no big deal". Dev's looking at this with a front end specialty will probably not have the same experience. That being said, even using the simple framework of something like the Business Logic plugin ("I don't know how to set up a plugin, are you crazy!") "shoutout: @lindseydiloreto" could get something working at a pretty high level with a couple of simple variables, basic simple PHP, and an understanding of how twig can loop through generic arrays. My site has a couple thousand SKU's and it seems it be just fine although it's far from an enterprise solution, it works and doesn't take a million years to load with smart, eh... (best I can do) caching. All in all, for a free plug-in I really appreciate everyone involved in it and it makes a client's ability to manage a store pretty easy. I'm thinking of writing a case study for it in the future, although I don't see it happening in the next few weeks. If anyone is looking at this and is interested in how it can be done in a somewhat simple manner (with guidance) please let me know (not a solicitation for work). Pay it forward. Once, again thanks for all of your work everyone, I owe you a beer.