0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Provides shopify_api with pagination support via Kaminari
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 5.0
~> 10.0
~> 0.16
~> 0.9

Runtime

 Project Readme

Shopify::Kaminari

Build Status Coverage Status

Makes the shopify_api gem compatible with the kaminari pagination gem.

Installation

Add this line to your application's Gemfile:

gem 'shopify-kaminari'

And then execute:

$ bundle

Or install it yourself as:

$ gem install shopify-kaminari

Usage

Just require "shopify-kaminari" in your project, and you're good to go! If you're using a Bundler backed project, like Rails, then you don't have to even do that much. Just add the gem to your Gemfile, and all of your Shopify resources will be paginatable with Kaminari.

Example:

ShopifyAPI::Session.temp(domain, token) do
  @products = ShopifyAPI::Product.all(params: { page: 2, limit: 250 })
end

Rails Example

Here's a simplified example of how to paginate a Shopify product in a Rails controller:

class ProductsController < ApplicationController
  around_action :shopify_session

  def index
    @products = ShopifyAPI::Product.all(params: pagination_params)
  end
  
  private

  def current_shop
    @current_shop ||= Shop.find_by(id: session[:shop_id])
  end
  
  def pagination_params
    params.slice(:page, :limit).permit!
  end
  
  def shopify_session(&block)
    ShopifyAPI::Session.temp(current_shop.domain, current_shop.token, &block)
  end
end

Then you could paginate the products in the view as you would with any other model:

<%= paginate(@products) %>

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hi5dev/shopify-kaminari.