What is the correct syntax for accessing translations in app blocks / theme app extensions in Shopify? - shopify

This link here mentions how to access translations for your app blocks but the example doesn't seem to work and seems to be for regular sections instead of app blocks:
https://shopify.dev/themes/architecture/sections/section-schema#locales
My locales section looks like the following:
"locales": {
"en": {
"title": "Slideshow"
},
"fr": {
"title": "Diaporama"
}
}
I've tried a bunch of different permutations using the name of my section and the name of the file but nothing works. According to the documentation the below should work:
sections.[section-name].[translation-description]
I've also tried the two below which both don't work:
blocks.[section-name].[translation-description]
block.[section-name].[translation-description]
Something tells me I'm doing something wrong or Shopify's documentation is lacking.
Any help on this would be much appreciated!

You can check Shopify's example theme extension app https://github.com/Shopify/product-reviews-sample-app/tree/main/theme-app-extension/locales
basically, you need this format
{ "blocks": { "average-rating": { "name": "Average Review Score",
"settings": { "stars_fill_color": {
"label": "Stars color" }
} } }}
for accesing a label you should do "t:blocks.average-rating.settings.stars_fill_color.label"

Related

Shopify - Modify Page Template & Sections Reference For Custom Page

I am attempting to modify a specific route/template in my Shopify theme, however nothing from examples I have seen or the documentation seems to take.
Currently I have created a page in the Shopify Admin team which is auto assigned to the route /pages/team-page.
In my templates directory I have tried creating different variations as to assign it a custom section such as
team.json
team_page.json
page.team.json
page.team_page.json
And within those json files referenced to my sections directory liquid file custom.liquid with the following:
{
"sections": {
"custom": {
"type": "custom",
"settings": {}
},
"order": [ "custom" ]
}
But to no avail it always references back to the template index.json which renders main.liquid from sections.
Attempting to print out the page.handle returns team-page, while page.template_suffx seems to return nothing.

How to add liquid file URL in theme using assets API shopify theme

Hey anyone can help me how do i add liquid file using URL. I am trying this but this is not working
let add_assets_asset = {
"asset": {
"key": "layout/alternate.liquid",
"src": "https://digitalcodingkloud.000webhostapp.com/new.liquid"
}
};
You should use the value attribute and pass the content itself (not URLs).
let add_assets_asset = {
"asset": {
"key": "layout/alternate.liquid",
"value": "Your liquid content goes here..."
}
};
src attribute can only be used to pass image URLs, not liquid files.

Add Product Images with Shopify API

We have a bunch of disassociated product images in our Shopify store that support could not re-associate. I set up a Postman collection runner to update all these missing images, and it seems to be working in our test environment....
Except, the API call is replacing the default product image with a new image rather than adding the image. I'm using a standard PUT request to the API using the example in their API docs:
PUT /admin/api/2019-04/products/#{product_id}.json
{
"product": {
"id": 632910392,
"images": [
{
"src": "http://example.com/rails_logo.gif"
}
]
}
}
I get that it's an array I'm sending in, so I'm thinking it's overwriting the array each time rather than adding a new element. I tried using a single element variable of "image" in the JSON but that didn't work.
Any ideas?
If you want to add the image use ProductImage resource instead of Product resource.
Product Image Documentation
POST /admin/api/2019-04/products/#{product_id}/images.json
{
"image": {
"src": "http://example.com/rails_logo.gif"
}
}

Creating a shopify template with unique content blocks

I have an ecommerce site, and I'm trying to create a "Lookbook" template. I want my client to be able to create a new lookbook (just as a simple page with a template of "page.lookbook" or similar), then be able to go into the page admin and select and upload images, links, descriptions etc.
So far I have:
page.lookbook.liquid -> calls in the section, lookbook-template.liquid
lookbook-template.liquid has an HTML template
It also has this schema:
{% schema %}
{
"name": "Lookbook",
"blocks": [
{
"type": "Image",
"name": "Lookbook image",
"settings":[
{
"type": "image_picker",
"id": "img",
"label": "Image"
},
{
"type": "text",
"id": "description",
"label": "Description",
"default": "<p>You can write <em>html</em> in here!</p>"
}
]
}
]
}
{% endschema %}
This way, my client can use the simple admin tools to add a new image block. Very nice!
However, this method means that every single lookbook gets the SAME image data as whatever I apply to the lookbook-template.liquid, and this isn't ideal at all.
What am I doing wrong here, and what's the right solution? I want one template that the client choose to attach to a page, and then for each template to have a unique set of images, links and descriptions that the client creates.
Unfortunately, section won't work to get some different content for each page with lookbook.page template.
A solution would be to install (or create) an app to manage metafields attached to pages. Then you can use metafields in your template.
Metafields is a way to add some extra fields in database:
https://help.shopify.com/themes/liquid/objects/metafield

Check whether facebook user likes my app

I've read several sources now but did not find a solution: I'm using Facebook C# SDK with ASP.net 4 and VB.net 2010. I have a Facebook Canvas application. I'm using Canvas Auth.Authorize and it works fine. Now I want to know whether the currently logged in user already likes my app. How could I do that?
'SignedRequest' does not seem to work because according to Facebook Documentation "This field is only present if your app is being loaded within a Page Tab".
graph/user/likes is also not an option because I don't want to ask the user to grant access for my app to all his likes.
But the Facebook Plugin is able to differ whether the current user likes my app or not, so I'm quite optimistic that there is a way which I just did not find yet.
Many thanks!
You can use the graph API to call the users likes. Instead of requesting all of the likes simply request the single one you want.
https://graph.facebook.com/userId/likes/appId
If you the user has liked the page the result will return details about the page. For example:
{
"data": [
{
"name": "Microsoft Office Web Apps",
"category": "Software",
"id": "121883824529155",
"created_time": "2012-03-14T06:48:47+0000"
}
],
"paging": {
"next": "https://graph.facebook.com/me/likes/121883824529155?format=json&limit=5000&offset=5000&__after_id=121883824529155"
}
}
If the user has not liked the page you will receive empty data.
{
"data": [
]
}
With the Facebook C# SDK you would make this request as follows:
var client = FacebookClient("access_token_here");
dynamic result = client.Get('/me/appId');
if (result.data.Length == 1) {
// User has liked page
}