You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️🚨⚠️ Project/labels may still need to be added ⚠️🚨⚠️
Summary
Courtney reached out to the team for help with a plus merchant who had issues previewing newly created draft products after moving to Hydrogen.
Natalie explained that the issue arose because the active products were being redirected to the Hydrogen storefront, which couldn't find the draft products since they were only published to Hydrogen and not the online store.
Natalie recommended that the merchant complete the configuration for their Hydrogen storefront and provided a guide for them to follow.
She also identified a potential edge case for draft product preview in the JavaScript redirect and shared a workaround for this.
Natalie later noticed a bug in the code she had provided and shared a corrected version. Courtney thanked Natalie for her help and said she would share the new script with the merchant.
Hello friends :wave-frog: I hope your Fri-yay is going well so far. I have a plus merchant who just moved to Hydrogen yesterday. They noticed with newly created draft products when selecting preview. Just wanted to confirm with Headless stores if this is expected behavior and if the product even as active will not be able to be previewed as well.
Internal: [removed]
Product example
Video Recording
👤
<@>
2023‑09‑15 18:13
Hi @courlavigne 👋 Thanks for getting in touch! Please let us know how urgent your request is:
👤
<@>
2023‑09‑15 18:13
In order to resolve your request as quickly as possible, please help us out with the following info, and then press 'Done!'.
👤
<@>
2023‑09‑15 18:22
@natalieoldroyd will help you out with your request today. Please wait while they check over your request.
Hi @courlavigne Their active products (published to both Hydrogen and Online store) are first redirected to Hydrogen storefront from the my-shopify URL they've set up as the online store's primary domain. For the draft products they're […]not Online store so when that redirect happens the product can't be found. They should complete configuration for their Hydrogen storefront. We have a guide they can follow _BUT_ I think we have an edge case for draft product preview in our js redirect shown in those docs. When I tested in my hydrogen store choosing to preview a draft product which is published to both online store and to Hydrogen changed my URL changed to
The js redirect assigns the custom storefront primary domain leaving me with https://staffshopnat.com/products_preview which doesn't exist in my Hydrogen store and gives me a 404. This changing URL structure is default not just for headless storefronts. I also tested this in my pure liquid storefront :thinking_face:
I was playing with the js redirect in another hydrogen storefront and edited the js redirect to skip the reassignment of domain if "preview" is detected.
function getCookie(name) {
name = name + '=';
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.indexOf(name) == 0) {
return cookie.substring(name.length, cookie.length);
}
}
}
// Redirect + handle discount codes
var discountCode = getCookie('discount_code');
if (!window.location.href.includes("/products_preview") {
if (discountCode) {
window.location.replace(<code>{{new_website}}/discount/${discountCode}?redirect=${window.location.pathname}</code>);
} else {
window.location.replace(<code>{{new_website}}${window.location.pathname}</code>);
}
}
So in my 2nd hydrogen storefront when I preview a draft product that's published to both hydrogen and online store the redirect doesn't happen and I get to see my product on online storefront. I'll bring this up internally as I'm not sure we ever considered this edge case.
For the merchant, they should follow that guide, switch any draft products they want to view in the browser to be available for both channels and if they want to view them in the browser they can use the redirect above.
In terms of active products (not set to draft) as long as they are set to published to both hydrogen and online store channels they will preview fine. The js redirect for active products (not in draft) will redirect to Hydrogen without error. The edited version I gave above handles the draft product preview scenario. I've just edited this line from just "preview" no way a merchant gonna name their product handle that on purpose:fingers_crossed:
<code> if (!window.location.href.includes("/products_preview")</code>
✅ @natalieoldroyd has marked your request as resolved. If require any further assistance, please post a new request thread.
👤
<@>
2023‑09‑15 19:51
Hi @courlavigne! We would greatly appreciate if you could take a moment of your time to fill out a feedback form regarding this interaction :thank-you4:
Hi @courlavigne I missed a bug with that code I sent, 😬
Here is a new script which I've tested on standard redirect checkout.myshop.com and on live products which are active and on products which are just draft. The defer attribute stops a brief flash before the redirect takes place
Here's the full code
{% assign new_website = '<a href="https://headless-website.com">https://headless-website.com</a>' %}
<code><@></code>
function getCookie(name) {
name = name + '=';
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.indexOf(name) == 0) {
return cookie.substring(name.length, cookie.length);
}
}
}
// Redirect + handle discount codes
var discountCode = getCookie('discount_code');
var originalURL = window.location.pathname;
if (!originalURL.includes('/products_preview')) {
//If originalURL detected we're going to skip making any changes.
if (discountCode) {
window.location.replace(<code>{{new_website}}/discount/${discountCode}?redirect=${originalURL}</code>);
} else {
window.location.replace(<code>{{new_website}}${originalURL}</code>);
}
}
{{content_for_header}}
{{content_for_layout}}
Summary
This summary was generated using OpenAI's gpt-4 with a temperature of 0.5.
🧵 Slack Thread
2023‑09‑15 18:13
2023‑09‑15 18:13
2023‑09‑15 18:13
2023‑09‑15 18:22
2023‑09‑15 19:27
https://[…]28fc059261151713cd2ad7acfccc3491
The js redirect assigns the custom storefront primary domain leaving me with https://staffshopnat.com/products_preview which doesn't exist in my Hydrogen store and gives me a 404. This changing URL structure is default not just for headless storefronts. I also tested this in my pure liquid storefront :thinking_face:
I was playing with the js redirect in another hydrogen storefront and edited the js redirect to skip the reassignment of domain if "preview" is detected.
So in my 2nd hydrogen storefront when I preview a draft product that's published to both hydrogen and online store the redirect doesn't happen and I get to see my product on online storefront. I'll bring this up internally as I'm not sure we ever considered this edge case.
For the merchant, they should follow that guide, switch any draft products they want to view in the browser to be available for both channels and if they want to view them in the browser they can use the redirect above.
2023‑09‑15 19:31
2023‑09‑15 19:45
<code> if (!window.location.href.includes("/products_preview")</code>
2023‑09‑15 19:50
2023‑09‑15 19:50
2023‑09‑15 19:51
2023‑09‑15 19:51
@courlavigne completed Support Feedback
2023‑09‑15 19:56
2023‑09‑18 13:58
Here is a new script which I've tested on standard redirect checkout.myshop.com and on live products which are active and on products which are just draft. The defer attribute stops a brief flash before the redirect takes place
Here's the full code
2023‑09‑18 15:26
Natalie Oldroyd archived this conversation from
headless-support
at 2023‑09‑18 17:31.All times are in UTC.
The text was updated successfully, but these errors were encountered: