How can I access URL search parameters for business operations?

Hi team,

I would like to perform some business operation using URL search parameters. I could saw that earlier in request object, we could able to find the params like below

request.params.variant

Here, I can get the value for the parameter variant. Now I couldn’t able to get this value. Is there any other alternative available since params property is not there for now.

1 Like

Hi @techtinium_dev I think you want to get full url with the parameters value then you can use this below code -

{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
  {%- assign pageUrl = contentForQuerystring
    | split: '"pageurl":"'
    | last
    | split: '"'
    | first
    | split: '.myshopify.com'
    | last
    | replace: '\/', '/'
    | replace: '%20', ' '
    | replace: '\u0026', '&'
  -%}
  {% capture finalurl %}https://{{ pageUrl }}{% endcapture %}
  {{ finalurl }}

How to use this code? for this you can follow and click on it - How to Get/Fetch Full URL in Shopify with Query String or Parameters

2 Likes

Hi @techtinium_dev

I’ve found a very good solution myself for that..

  1. Get URL Param(s) within the URL using JavaScript.

  2. Send this value to the native and global cart attributes from Shopify

  3. Assign the {{ cart.attributes.[value] }} to a custom liquid variable

et voilà! :grinning_face_with_smiling_eyes:

Example:

{% assign selectedAuthor = cart.attributes.selectedAuthor %}

Unfortunately, “pageUrl” does not show the URL consistently on this solution.