简体   繁体   English

获取所有供应商的列表?

[英]Getting list of all vendors?

I am doing the following to take the vendor out of the products and using unique to get it to the front end to list each vendor on a store.我正在执行以下操作以将供应商从产品中取出并使用 unique 将其带到前端以列出商店中的每个供应商。

Controller:控制器:

@count = ShopifyAPI::Product.count
@n = 1
@products = ShopifyAPI::Product.find(:all, limit: 250, page: @n)
if (@count > 50) && params[:page_number]
  @page_number = params[:page_number].to_i
  @products = ShopifyAPI::Product.find(:all, params: {page: @page_number})
end

front end:前端:

<% @products.map(&:vendor).uniq.each do |vendor| %>
...
...
<% end %>

<% if (@count > 50) && (@page_number.present? && @page_number > 1) %>
  <%= link_to "<", company_shop_vendors_path(shop_id: @shop.id, page_number: (@page_number - 1)) %> <%= link_to "1", company_shop_vendors_path(shop_id: @shop.id, page_number: 1) %> <%= link_to "#{@page_number + 1} >", company_shop_vendors_path(shop_id: @shop.id, page_number: (@page_number + 1)) %>
<% elsif (@count > 50) %>
  <%= link_to "#{@n+1} >", company_shop_vendors_path(shop_id: @shop.id, page_number: (@n += 1)) %>
<% end %>

This gets me the vendors but not how i would like.这让我找到了供应商,但不是我想要的。

The whole page system is a terrible attempt and I actually use a search form also which is better.整个页面系统是一个糟糕的尝试,我实际上也使用了一个更好的搜索表单。 paginating through the product pages just gets me the unique vendors on each page and when there are hundreds of pages, it's pointless.对产品页面进行分页只会让我在每个页面上找到唯一的供应商,当有数百页时,这毫无意义。

What is the best way to do this?做这个的最好方式是什么?

Is there maybe a way to paginate and throw all of the vendors into memory and THEN display to the front end all of the vendors uniquely?有没有办法对所有供应商进行分页并将所有供应商放入内存中,然后将所有供应商独特地显示到前端?

Aisde from that, the only other option is to store the vendors in the database on a Product API request and then Product create webhook --- instead of using the API directly.此外,唯一的其他选择是将供应商存储在产品 API 请求的数据库中,然后产品创建 webhook ---而不是直接使用 API。

What do you think?你怎么认为?

Creepy Way but might help someone who doesn't want to loop through products and won't able to do through app proxy令人毛骨悚然的方式,但可能会帮助那些不想遍历产品并且无法通过应用代理进行操作的人

  1. Ask Merchant to visit below URL on their store要求商家访问其商店中的以下 URL

https://{{ shop_doamin }}/admin/products/vendors.json https://{{ shop_doamin }}/admin/products/vendors.json

This will list all product vendors in JSON format.这将以 JSON 格式列出所有产品供应商。

  1. Ask them to put this JSON in textbox save this JSON on your local DB and serve from there.要求他们将此 JSON 放入文本框中,将此 JSON 保存在您的本地数据库中并从那里提供服务。

Might break the automate process.可能会破坏自动化过程。 but can be helpful when you don't want to loop through large data.但是当您不想遍历大数据时会很有帮助。

Hope the information will make sense and might help.希望这些信息有意义并可能有所帮助。

You know Shopify has a Liquid construct where they will show you all the vendors of a shop?您知道 Shopify 有一个 Liquid 结构,它们会向您展示商店的所有供应商吗?

https://help.shopify.com/en/themes/liquid/objects/shop#shop-vendors https://help.shopify.com/en/themes/liquid/objects/shop#shop-vendors

So you can easily use that to send your App that listing, using an App Proxy.因此,您可以使用 App 代理轻松地使用它来向您的 App 发送该列表。 Is a heck of a lot more efficient than iterating products, and other hocus pocus.比迭代产品和其他骗局要高效得多。

Instead of using the API to display vendors --- and I am sure there is a way to do this while keeping the results in memory --- I cycle through the products and product pages and store the vendors in my database and display it that way.而不是使用 API 来显示供应商 --- 我确信有一种方法可以做到这一点,同时将结果保存在内存中 --- 我循环浏览产品和产品页面并将供应商存储在我的数据库中并显示它道路。 I allow users to "Sync" their vendors if they add new ones.我允许用户在添加新供应商时“同步”他们的供应商。 I did not implement webhooks just in case someone makes a product with a new vendor that is mispelled or something.我没有实施 webhooks 以防万一有人与拼写错误的新供应商一起生产产品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从货运公司获取所有包裹的清单 - Getting a list of all packages from shipping carriers 当没有路线匹配时,获取所有可用路线的列表; 如何禁用? - When No Route Matches, getting list of all available routes; how to disable? ActionController :: RoutingError:没有路由与{:controller =&gt;“ vendors”,:action =&gt;“ vendors”}匹配? - ActionController::RoutingError: No route matches {:controller=>“vendors”, :action=>“vendors”}? 在rails“获取&#39;vendors / keyword_search&#39;,到:&#39;vendors#keyword_search&#39;”中运行“&#39;vendors#show&#39;” - In rails “get 'vendors/keyword_search', to: 'vendors#keyword_search'” runs “'vendors#show'” 获取所有数据库更改 - Getting all database changes 获取所有评论 - Getting all comments 获取具有那里属性的关注者列表 - Getting the list of followers with there attributes 获取aws区域列表 - Getting the list of aws regions 我想从数据库中列出我的所有用户,我收到一个奇怪的错误 - 未定义的方法 `each&#39;。我该怎么办? - i want to list all my users from the database, i am getting a strange error - undefined method `each'.What should i do? Ubuntu上的Phusion Passenger在vendor目录中未看到插件 - Phusion Passenger on Ubuntu not seeing plugin in vendors directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM