Ad

How To Get All Product Tags For Specifi Collection With Single Request Using Shopify?

- 1 answer

Hi i am developing ios app using storefront api's in shopify now i need fetch all the product tags of specific collection but in document i can nt found can any one suggest me is it possible or not?

Ad

Answer

Please try with this way:

Step 1: create the template for searching tags like:

{% layout none %}
{% capture output %}
{% for collection in collections %} 
        {% if forloop.index == 1 %}""{% endif %}
        {% if collection.all_tags.size > 0 %}
            {% for tag in collection.all_tags %}

                {% if output contains tag %}
                {% else %}
                    ,"{{tag}}"
                {% endif %}

            {% endfor %}  
        {% endif %}     
   {% endfor %}
{% endcapture %}
{{ output | strip_newlines | prepend: '[' | append: ']' }}

Step 2: PHP Sample Code

function pullJson( $url ) {
     $curl = curl_init();
     curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $url,
        CURLOPT_USERAGENT => 'agent-sark'
    ));

    $resp = curl_exec($curl);
    curl_close($curl);
  return json_decode( $resp, true );
  }
 $storeUrl = "http://". { your store } .".myshopify.com";
 /* this will gets you all the tags ( of course with duplicate ) */
 $pTags = array_unique( pullJson( $storeUrl ."/search?view=tags" ) )

source :here

if it's still not help, please let me know.

Ad
source: stackoverflow.com
Ad