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.
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.
What do you think?