14

我检查了 Shopify 产品 API,但结果似乎没有返回产品页面 URL。URL 看起来像是在对标题进行一些转换后产生的。是否有可靠的、定义明确的逻辑用于此或任何其他方法来获取产品页面 URL?

4

4 回答 4

23

您可以将其作为“产品/<product.handle >”来执行。我不确定是否有更好的方法,但它确实有效。

于 2012-08-10T07:06:33.230 回答
4

我通常将其添加到config/initializers/shopify_api.rb

module ShopifyAPI
  class Shop
    def store_url_for(entity)
      return "http://#{self.domain}/#{entity.class.element_name}/#{entity.handle}"
    end
  end
end
于 2013-11-04T09:50:18.307 回答
1

为了完成 Michael Johnston 的回答,您需要先调用 ShopifyAPI::Shop.current,然后才能使用 store_url_for(entity)。

例如,要在控制器中获取产品的 url:

product = ShopifyAPI::Product.find(@product_id)
shop = ShopifyAPI::Shop.current
product_url = shop.store_url_for(product)
于 2016-10-28T14:18:15.753 回答
0

这是相当老的帖子,也许 api 已经升级,因为有 def。其他 url 结构,例如 collections/collection-name/products/product-name。

Still looking if there is a way to get unique product URI

于 2017-03-27T13:14:33.073 回答