【发布时间】:2012-08-07 11:02:59
【问题描述】:
我检查了 Shopify 产品 API,但结果似乎没有返回产品页面 URL。 URL 看起来像是在对标题进行一些转换后产生的。是否有可靠的、明确定义的逻辑来获取产品页面 URL?
【问题讨论】:
标签: shopify
我检查了 Shopify 产品 API,但结果似乎没有返回产品页面 URL。 URL 看起来像是在对标题进行一些转换后产生的。是否有可靠的、明确定义的逻辑来获取产品页面 URL?
【问题讨论】:
标签: shopify
您可以将其作为“产品/
【讨论】:
product.handle 是 URL 中使用的产品标题的 URL 安全版本。
products/< product.handle > 时才有效,否则失败。一些商店已配置为使用类似collections/accessories/<product.handle>
products/< product.handle >,但有些主题使用 within: 帮助器作为产品 URL,因此产品页面上的面包屑可以出现显示用户来自的集合,但这始终是可选的。用户可能来自任何集合,没有与产品关联的主要集合。
我通常在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
【讨论】:
为了完成 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)
【讨论】:
这是相当老的帖子,也许 api 已经升级,因为有 def。其他 url 结构,例如 collections/collection-name/products/product-name。
仍在寻找是否有办法获得唯一的产品 URI
【讨论】: