What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Syncing pages with sections

Syncing pages with sections

Chris_Marshall1
Shopify Partner
40 1 11

Hi there,

 

We've been looking at the developer preview and are excited about deploying this on upcoming projects.

 

One of the use cases we're considering is syncing content across multiple plus stores. If a user creates a blog post on one site, we want to copy that to another site using the API.

 

On current non-sectioned pages that would be fairly straightforward, as most of the content would reside in the body_html property. 

 

How could this be approached on sectioned blog posts (assuming the two stores share a common theme)?

 

Any pointers appreciated. Thanks.

Replies 5 (5)

Liam
Community Manager
3108 344 895

Hi there @Chris_Marshall1 

 

Thanks for getting in touch and we're glad to hear you're excited to start using the new theme architecture on your projects. The use-case you've described should be possible, but it will be slightly more complex than how you would presently transfer content like a blog post across different Shopify stores.

 

Since all of the store data (like blog post content) is accessible through the Admin API it will be possible to copy content from one store to another. However, you'll be copying sections_data (instead of body_html) which contains references to resources such as products, collections, etc. by ID, and IDs (unlike handles) cannot be the same across shops. This means that during the process of copying sections_data you'll need to replace the product/etc. IDs of shop A with the IDs of the equivalent product/etc. in shop B.

 

Hope this helps Chris- there's some more info on this on our help docs here

 

Cheers,

 

Liam Griffin

Shopify | Developer Community Manager

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Chris_Marshall1
Shopify Partner
40 1 11

Thanks @Liam - that makes sense, but would require that we maintain some form of mapping of IDs between the sites. This is of course possible, but there's an overhead. We know the handles are going to be the same between the two sites, so if we had the handle we could smooth this.

 

I have an alternative solution which I've tested and appears to work, but would greatly appreciate your thoughts.

 

Taking the 'Featured product' type:

  1. Change the 'static > type' from 'product' to 'custom'
  2. The user can no longer choose a product, so we add a new 'url' field to the schema. Prompt the user to pick a product from this -> this gives us a handle, not an ID.
  3. Filter the url to parse off the handle
  4. Pass the handle to 'all_products' to get the product

This seems to work well, and gives us the handle via the API:

 

{
                    "after": "158486273386377e0b",
                    "section": {
                        "id": "158486465870edce43",
                        "content": {
                            "static": [
                                {
                                    "id": "15848646580031af74",
                                    "type": "custom",
                                    "settings": {}
                                }
                            ],
                            "blocks": []
                        },
                        "settings": {
                            "product_link": {
                                "type": "url",
                                "value": "shopify://products/jumper"
                            },
                            "image_size": {
                                "type": "select",
                                "value": "medium"
                            },

This would work for collections, pages and articles too. 

 

Anything we'd need to consider here?

 

Thanks


Chris

 

 

 

 

Liam
Community Manager
3108 344 895

Hi again @Chris_Marshall1 

 

The process you've described would work but we wouldn't recommend this approach because it leads to bad UX (adopting a URL picker instead of a product picker), and using the custom content type means the content would not be portable across themes.  The lack of portability across themes may not a concern in the short-run, but when you make major redesigns theme portability could be helpful. 

 

Additionally using the all_products global carries the risk of running into the "20 per page" limit described here which makes it likely that pages with a lot of  sections will error out. 

 

Hope this helps Chris!

 

Liam 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Chris_Marshall1
Shopify Partner
40 1 11

Thanks Liam, that's really useful feedback.

 

We could live with the less-than-perfect UX. The all_products limit is a definite blocker tho' - pah!

 

The options to sync content across sites therefore are:

  • do it manually - double/triple enter content
  • maintain an index of product, collection, page and article ids outside of Shopify and lookup/replace these ids when syncing
  • use shogun - might be an option (esp given that the site has to launch this year)

OK thanks - need to do some thinking!

Chris_Marshall1
Shopify Partner
40 1 11

Hi @Liam 

 

Another question on this.  If we were having to sync images - obviously there's no files API. If we were to replace the 'shopify://shop_images/' in the below with the URL/path of the originating site, would this work? Would it reference the original URL or would it import it anew into the CDN?

 

{
                                    "id": "1581529975ac14d4cc",
                                    "type": "image",
                                    "value": "shopify://shop_images/confident-young-woman.jpg",
                                    "settings": {
                                        "width": {
                                            "type": "select",
                                            "value": "50%"
                                        },
                                        "alignment": {
                                            "type": "select",
                                            "value": "middle"
                                        }
                                    }
                                }