Shopify API how to do a search query with like

白昼怎懂夜的黑 提交于 2021-01-27 22:23:06

问题


Hey guys I try to do some searching functions but it is not possible with shopifyAPI gem

ShopifyAPI::Product.find(:all, conditions: ["title LIKE ?", "%#search%"], params: {limit: 20, page: 1}) 

With this function I got all products.

ShopifyAPI::Product.find(:all, conditions: ["title LIKE ?", "%#search%"])

The same I got all products

ShopifyAPI::Product.search(parameters)

I found this function in this example but it is not a function anymore => ecommerce.shopify.com/c/shopify-apis-and-technology/t/ruby-shopifyapi-find-customer-by-email-215330

ShopifyAPI::Product.where({ "title LIKE ?" =>"%#{search}%" })

With this one I got all products, again

This is the shopify_api gem => help.shopify.com/api/reference/product.
This is the shopify_api => help.shopify.com/api/reference/product


回答1:


It doesn't look to me like the Shopify API supports this. What you're trying to do looks like ActiveRecord querying, but this gem only provides an Active Record-like syntax.

The API does support searching based on product title, so perhaps you may be able to specify a single word or two from the product name it and it will match those?




回答2:


You can use direct fields to search like:

ShopifyAPI::Product.find(:all, params: { limit: 10, 
                                         title: params[:title],               
                                         page: params[:page] })


来源:https://stackoverflow.com/questions/41539936/shopify-api-how-to-do-a-search-query-with-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!