instantcommerce / shopify-headless-theme

Liquid theme that automatically redirects customers to your custom storefront.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discount links don't provide a way to pass the code through to the headless store.

benjaminsehl opened this issue · comments

When a shareable discount link evaluates … for example…

theme.com/discount/freeshipping?redirect=/pages/contact

The theme currently would redirect you to … 

headless.com/pages/contact, and there is a cookie for discount_code set to freeshipping but for the domain theme.com.

This is because the client side code isn't executed until the routing is complete — one way to get around this would be to add a search param called discount_code and set it to the value passed above.

e.g.

      const discount_code = getCookie('discount_code');

      function getCookie(name) {
        name = name + '=';
        var decodedCookie = decodeURIComponent(document.cookie);
        var cookies = decodedCookie.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);
          }
        }
      }

      const url = new URL(window.location.href)

      let params = new URLSearchParams(url.search);
      
      params.append("discount_code", discount_code);

      // Continue with existing logic…