Store a variable from URL to use in theme

Hi All

We sell our products combined with software from other companies. If someone visits our site, they see our product and get to choose from 6 different software choices that will come with it. That part works perfectly.

ie. The customer can choose from:

Our Product + Software 1

Our Product + Software 2

Our Product + Software 3

etc…

However, the software providers are competitors, so if one refers customers to our site, they don’t want them to see their competitors options.

So I’m trying to figure out how we can give them a URL, which will essentially hide the other choices. The technicality of doing that are easy, but the problem I face is getting a variable to work with.

So far I’ve tried:

Option 1:

{% assign pageurl = content_for_header | split: '"pageurl":"' | last | split:'"' | first %}
{% if pageurl contains "?" %}
        {% assign parameters = pageurl | split: "?" | last | split: "\u0026" %}
        {% for parameter in parameters %}
                {% assign setting = parameter | split: "=" | first %}
                {% assign value = parameter | split: "=" | last %}
                {% if setting == "partner" %}
                        {% if value == "Software 1" or value == "Software 2">
                                {% assign partner = value %}
                                {% assign partnerurl = "?partner=" | append: parner %}
                        {% endif %}
                {% endif %}
        {% endfor %}
{% endif %}

This works, but only for the page they initially come to. As soon as they click on another page, the URL variable is lost. I could append every single link with {{ partnerurl }}, but that seems overcomplicated and error prone.

Option 2:

I’m getting the “partner” attribute, either using JQuery (splitting the last ‘/’) or Liquid (same method as above)

$(document).ready(function () {
        $.post('/cart.js', {
                attributes: {
                        'Partner': '{{ partner }}'
                }

        }).done(function () {

        });
});

However, the cart attribute seems to only stay that for a mere moment, and then disappears.

So my question is, is there a more elegant way of doing this? And if not, how does one permanently store a cart attribute?

Thanks in advance

What browser are you developing in?

Try the /cart/update.js endpoint instead to see if behavior changes.

Also there is a typo? in the liquid

{% assign partnerurl = “?partner=” | append: parner %}

{% assign partnerurl = “?partner=” | append: partner %}

Unconfirmed I think there are oddities when there’s no items in the cart new tokens get set , this behavior should change when there is an item in the cart.

Thank you very much! The /cart/update.js seems to handle it fine (even with no items in the cart).