How to get the URL for any product in Shopify Shop given that its pattern varies if it belongs to a collection?

Nihal Sharma

For a product which does not belong to any collection we can have url defined as - <shop-url>/products/< product.handle >. In case a product belongs to a collection it changes to - <shop-url>/collections/<collection-name>/products/< product.handle >. Is there any third case also?

How to handle these cases. Also, I do not get the collection name attached to the product when I make an api call so that I may build upon the url myself. Is there a generic way to get the product url when fetching product via api call?

I wonder why shopify does not provide with the product url straightways! Is there any reason?

EDIT:

I just realized that even if a product is associated with a collection we can have its url as <shop-url>/products/< product.handle >; and <shop-url>/collections/<collection-name>/products/< product.handle > are same thing. Two different url but same page?

Steph Sharp

In liquid you can access a product's URL with product.url, which outputs /products/handle. It doesn't look like the URL is available via the API, but you could easily build the URL with the product's handle (which you can get via the API).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

On Shopify, check if a given product is not on any collection

How to get URL of shop in Shopify embeded app?

Shopify Schema - Get Collection URL

How to remove /shop or /product in URL WooCommerce

How to grab what collection a product belongs to?

How to Select Collection using its name on Shopify

How to get all the distinct options of all the products in Shopify Shop?

How to get Shopify order data to product page

How to make dynamic Product URL key in phtml file for magento shop

How to get duration of an audio file given only its url

How to determine if a product is part of a hidden collection in Shopify liquid templates?

How to add "you added this" bellow the product in the collection SHOPIFY

Shopify - If item in cart belongs to a specific collection

How can I make an SVG pattern vary its repetition count as container dimension varies?

Shopify - Get shop domain inside a app

How to bundle product in shopify?

Shopify: how to retrieve shop level metafield in the cartpage?

How to get the java Class to which a method belongs given the method signature?

How can I get 'online store' Sales channels product in shopify?

How to get all product id from Shopify Python API

How to get particular product image in shopify liquid file?

how to get the url only in javascript shopify

Get Shipping rates for a product - Shopify

How to get model and product collection in magento 2

How to get Collection object in Shopify when selected from customize window

How to get an Agent when given its name?

Given a Python method, how to get its class?

How to handle a in the views a model that belongs to another and given its ID the view should display different info?

Get product given date