freakdesign / shopify-code-snippets Goto Github PK
View Code? Open in Web Editor NEWShopify code examples and tips
License: Other
Shopify code examples and tips
License: Other
Hi Jason, the snippet has been working all year long! But today, something has been weird.
I have several pages, let's imagine them like this:
https://www.mystore.com/pages/repair?p=item1&cache=false
https://www.mystore.com/pages/repair?p=item2&cache=false
https://www.mystore.com/pages/repair?p=item3&cache=false
If I visit the repair page with item1, the pageurl will be correct and everything will work properly.
Now my hope is that when I visit item2, the pageurl will also reflect p=item2, but it doesn't. It remains with item1. The same result as if I visited item3, the pageurl will contain item1.
Note the real URL will say https://www.mystore.com/pages/repair?p=item2&cache=false
or https://www.mystore.com/pages/repair?p=item3&cache=false. But the content_for_header pageurl: will reflect the first visited https://www.mystore.com/pages/repair?p=item1&cache=false. It looks like content_for_header isn't updating the pageurl?
Would love to get some help on this, as I haven't modified any code since it's always been working.
Thanks for the good work :)
{%- comment -%}
{%- render 'date_translator', date: date, format: format -%}
{%- endcomment -%}
{% liquid
assign datesSupported = 'en,no,fr,es,de' | split:','
assign dateFormat = format | default: '%A %B %d, %Y'
assign dateString = date | date: dateFormat
if datesSupported contains localization.language.iso_code and dateString != blank
assign daysen = 'Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday' | split:','
assign monthsen = 'January,February,March,April,May,June,July,August,September,October,November,December' | split:','
assign daysno = 'Mandag,Tirsdag,Onsdag,Torsdag,Fredag,Lørdag,Søndag' | split:','
assign monthsno = 'Januar,Februar,Mars,April,Mai,Juni,Juli,August,September,Oktober,November,Desember' | split:','
assign daysfr = 'Lundi,Mardi,Mercredi,Jeudi,Vendredi,Samedi,Dimanche' | split:','
assign monthsfr = 'Janvier,Février,Mars,Avril,Mai,juin,Juillet,Août,Septembre,Octobre,Novembre,Décembre' | split:','
assign dayses = 'Lunes,Martes,Miércoles,Jueves,Viernes,Sábado,Domingo' | split:','
assign monthses = 'Enero,Febrero,Marzo,Abril,Mayo,Junio,Julio,Agosto,Septiembre,Octubre,Noviembre,Diciembre' | split:','
assign daysde = 'Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag,Sonntag' | split:','
assign monthsde = 'Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember' | split:','
assign currentDays = 'days' | append: localization.language.iso_code
assign currentMonths = 'months' | append: localization.language.iso_code
assign currentDaysArray = [currentDays]
assign currentMonthsArray = [currentMonths]
assign shortSlice = 3
for i in (0..11)
if i < 7
assign shortDateFormatEnglish = daysen[i] | slice:0,shortSlice
assign shortDateFormatCurrent = currentDaysArray[i] | slice:0,shortSlice
assign dateString = dateString | replace:daysen[i],currentDaysArray[i] | replace:shortDateFormatEnglish, shortDateFormatCurrent
endif
assign shortMonthFormatEnglish = monthsen[i] | slice:0,shortSlice
assign shortMonthFormatCurrent = currentMonthsArray[i] | slice:0,shortSlice
assign dateString = dateString | replace:monthsen[i],currentMonthsArray[i] | replace:shortMonthFormatEnglish, shortMonthFormatCurrent
endfor
echo dateString
endif
%}
To note, the example doesn't work:
https://jasons-experiments.myshopify.com/search?type=product&q=sku:23200&view=sku
This does though:
https://jasons-experiments.myshopify.com/search?type=product&q=23200&view=sku
Is there any official documentation on these JSONP endpoints?
In Shopify forums someone even claims that "the Shopify API doesn't support JSONP requests" – https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/front-end-api-call-cors-issue-413232.
I need access to check if the product only has a default variant. I noticed it wasn't included in your example, but no problem, I figured I would just add it in within the items loop but for some reason, it always returns null.
I did a test and output the cartJson
variable you create based on the native cart
object and within that, all of the values are correct for that product_only_has_default_variant
variable, but when I try to manually create that variable while building the template JSON, it returns null. What am I missing here?
This is what I added to the items loop...
"product_has_only_default_variant": {{ item.product_has_only_default_variant | json }},
I’m using “Get Shopify cart data with JSONP“. Since a couple of days ago the request returns empty carts. Anyone else experiencing the same?
I make sure the Shopify store has items in the cart, but when getting the cart via Jsonp from another domain the cart response is without any cart items. Did Shopify change it’s api in some way?
Using the starts-with example, I tried to detect if the current page URL matches a certain page:
{% assign stringToCheck = page.url %}
{% assign startsWith = '/about/' %}
{% assign checkArray = stringToCheck | split:startsWith %}
{% if checkArray[0] == blank %}
The string {{ stringToCheck }} does start with {{ startsWith }}.
{% else %}
The string {{ stringToCheck }} does NOT start with {{ startsWith }}.
{% endif %}
However, with that snippet, I get this on the page:
The string /about/ does NOT start with /about/.
Though, this works for me:
{% assign stringToCheck = page.url %}
{% assign startsWith = '/about/' %}
{% assign checkArray = stringToCheck | split:startsWith %}
{% assign checkSlice = stringToCheck | slice: 0, stringToCheck.size %}
{% if checkSlice == startsWith %}
The string {{ stringToCheck }} does start with {{ startsWith }}.
{% else %}
The string {{ stringToCheck }} does NOT start with {{ startsWith }}.
{% endif %}
Which, as I implied, outputs:
The string /about/ does start with /about/.
Hi, I am having hard time using this snippet on my shopify store. I copied the code and added hmac but it's not working. It's not even sending the request. See Here
Create a test account it's fine, I console logged customer ID and cookie but to no avail. Thanks, hope we can fix this.
Hi, you have gone so far with this and that is awesome. It would be helpful if you gave users a full solution by simply showing which folder they should be creating this file in
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.