Shopify [Plus] Liquid to Retrieve Orders & Customers, or Include App Proxy Snippets - shopify

I'm looking for a way in Liquid to retrieve all Customers, or all Orders. I know it's targeted from a Client POV so probably not, but I just wanted to double check if there are any undocumented handles anyone has come across? Its for a protected page for staff user only access.
If the only solution to fetch this data is to use the App Proxy (for API access), is there a tidy way of including the output in a template? I gather there is no way to simply include an App Proxy liquid file into a Page as you can with Snippets, so does that purely leave either having the webpage at a proxy url or to pull in the contents with a jQuery call?

Your question is confusing. If you're on the front-end of a store, using Liquid, it seems pretty obvious you cannot easily access all customers. That would not be a front-end store thing. If you were logged in as a customer, with Liquid you'd have all that customer's order data.
With a clearer question, maybe you might get more help. What are you trying to do, and why?

Related

Changing the URL for blogs on Shopify

I was wondering if it was possible to change the default URL for blogs. Our client has recipes and would like it to be mydomain/recipes instead of the mydomain/blogs
If not, is it possible to copy the blog.liquid template and rework that somehow on its own custom page? Ultimately, is there any way to achieve this behavior without having to move the recipes to some other platform?
You can have /blogs/recipes but you can't have just /recipes.
There is no way in Shopify to change this no matter what you try.
If he is concerned about SEO the /blogs/recipes won't affect it or it least it wont affect it as hard as he think.
The best you can do is generate a proxy page with an App and add the products there, but the URL will be something like /a/recipes, which will be an overkill for just an url.
Shopify does not support URL rewrite rules, so the bottom line is - you can't achieve this with only Shopify.
You can create a separate page that pulls the blogs posts from Shopify if this is really important for your client, but once again - it's an overkill.

Shopify Interact with product page HTML via app

We plan to create a Shopify app but we face some problems to find in documentations how to interact with pages.
I`m not sure we must ask every time users to add codes and etc, so I need to know if I miss something.
I need to interact with the product pages in Shopify from an app.
I search and read all the web for this and everything is how to start but not the actual examples.
I know for the ScriptTags and how to include them but that is.
If someone can give me a simple example of how for example to hide the Buy button and insert something on instead.
I know how to select it with the default theme with JQuery but what about all other themes?
There are two ways to interact with the front page:
1) Inject some code in the page ( the live one )
2) Use ScriptTag as you mentioned.
The code injection script will modify the product template for example and inject your code if you like to do this automatically or you can instruct the user to do so on their own, but if they are not code savvy there might be issues.
In addition this code will live only on the live theme in most cases. And if the user likes to delete your app at a specific time you must be sure to write the logic in such way that it won't affect the site if your app is no longer present ( since it will be really hard to clean up the files once you add the code automatically )
For this approach you will need to use the Asset API.
You will need to get the content of the file with a GET request to the file and make a put request in order to update it.
The better approach is to use ScriptTag API.
This will allow the use of a script file that will be attached on EVERY theme. This will not modify the theme files in any form or shape.
It seems that this is the approach that you are looking for.
Please have in mind that you will be the one hosting the file from your app so pretty much you can write what ever you like there. So if you like to use jQuery you must be sure that the themes have included jQuery or you will have to add the jQuery core code inside your script.
As for how to write a script tag, there is a pretty straightforward documentation here: https://help.shopify.com/en/api/reference/online-store/scripttag#create-2020-01

Is there a way to save search filters between sessions per user account on Shopify?

So (for example) if a user selects their gender and pant size while searching on Shopify store, could those selections be saved and be in place when they visit again?
I'm open to switching to a new Shopify search app that would support this feature.
There a few approaches that you can achieve this.
Using cookies
You can save their choices as cookies and refer to them once they search modifying the search URL before redirecting or appending hidden files in the form so that they submit them as well.
Creating a custom app
You can create a custom app with only one purpose to save the information to the customer metafields or tags.
Once you have this information you will be able to use the same logic as the cookie one but instead of relying on a cookie you will have access to the metafields directly.
App
I don't think that there is an App that meets these criteria, but you can look it up. Yet it may be possible to hack up the Apps in a such way that you may be able to pass this information.

How to create shopify ScriptTag that would be used without asyncLoad wrapper?

Shopify does wrap all scripts added through ScriptTag API into special asyncLoad function. While it makes sense in many circumstances there still situations when you need script tag inserted directly into the header.
For example Optimizely wouldn't work that smooth if there wasn't other way to insert script tag, i.e. somehow theirs script appears in the store front independently, i.e. without asyncLoad function.
How would I do the same?
One option is to parse and then send back current theme, but it looks weird and not quite reliable, and according my research Optimizely does know another approach.
I was able to get in touch with Optimizely, here is their's response:
We actually partnered with Shopify to get our snippet added to the page in this way by default. I don’t think there is a simple way to work around the async limitation otherwise.
and here is Shopify's response:
Unfortunately this was a one-off hack-y fix, and not something that we're open to doing again at this time.
So, for now the only reliable way to work around the async limitation is to instruct users to place the script into current theme as others applications does.

Integrating custom analytics with Shopify

I am developing an analytics product similar to Google Analytics and want to offer an integration for our Shopify users.
I would need to do just two things:
1) Insert our JavaScript snippet into the body of all the shop's pages
2) Insert a second conversion snippet into the body of only the "thank you" page after a purchase to record the sale, passing back the order total and order number
Could you point me in the right direction?
The ScriptTag endpoint looks optimal except that it doesn't seem to provide any way to differentiate between the "thank you" page and other pages, or to pass the order details from the "thank you" page into the script.
It seems like I either need an endpoint that can inject arbitrary code into all pages, or one which lets me alter the theme layout file to add code before the </body> tag.
If I can do that much, it looks like I might be able to use a conditional in the templating language to only show the conversion code if the URL matches the "thank you" page URL, and use {{ total_price }} and {{ order_number }} in that code.
Does the uninstall webhook allow me to make changes before the rights for the app are revoked? It seems like I would need a way to clean up at uninstall to remove my code from the theme, if I'm allowed to edit the layout file.
itThere are two ways you can go about this:
ScriptTags: You're already aware of this method. It's true that the script is loaded into each and every page, but you can look at document.url in your js to figure out which page you're on and conditionally execute code based on that.
Scripts inserted this way are executed during the 'onLoad' event. At that time you have access to the DOM and can do basically whatever you want with the page.
Snippets: Using the Assets endpoint you can make arbitrary changes to the user's theme. Be careful with this power! The recommended way to make complex changes to a page is to create a custom snippet in the theme with your additions and then tell the user to insert an include tag into their code where it needs to appear. This reduces clutter in the main theme files.
I'd recommend using ScriptTags wherever possible. As mentioned below, they don't need cleaning up and remove the need for user interaction when setting up the app.
--
As for the uninstall webhook: It is fired after the app has been uninstalled from the shop, so you no longer have access. It's designed to be used to trigger cleanup on your end (remove db entries, etc.). Note that ScriptTags and Webhook subscriptions are automatically cleaned up, but any changes you've made to the theme aren't
You ask a lot of questions in one posting.
For your #1 and #2 read:
http://api.shopify.com/scripttag.html
Secondly, for your app install/uninstall read:
http://api.shopify.com/webhook.html
Pay attention to the part about app/uninstalled since you're interested in that.
As for knowing when someone installs your App, that is really up to you to figure out. Should not be too hard since you probably read about how to make and App in the first place. Shopify provides lots of boiler plate code on github that can show you almost everything you asked here.