Build Status

Beecart

Requirement

  • Redis Server

Installation

Adding to your Gemfile

gem "beecart"

Create initializer

# ./config/initializers/beecart.rb

Beecart.configure do |config|

  # Time to expire your cart in seconds
  config.expire_time = 30

  # Redis Information
  config.redis = {
    host: 'localhost',
    port: 5555
  }

  # Default Tax Rate
  config.tax_rate = 0.05

  # Default Preset Info in the cart
  default_cart_info: {
    shipping_address: {},
    billing_address: {},
    credit_card: {},
    shipping_instruction: {},
  }
end

How to use?

# ./app/controllers/application_controller.rb

include Beecart::CurrentCart
# ./app/controllers/your_controller.rb

class YourController < ApplicationController
  def index
    @cart = current_cart
  end

  def add_item
    @cart = current_cart
    @cart.add_item(
      item_id:  1,
      price:    5000,
      quantity: 3,
      any_data: 'you_may_put_any_data',
      ...
    )
  end

  def remove_item
    @cart = current_cart
    @cart.remove_item(params[:key])
  end
end

You may call current_cart method from any controllers you want. This method will return ShoppingCart object which provides functionality to

  • Add Item
  • Remove Item
  • Reset Cart
  • Expiret cart
  • Sum total price in the cart

Detailed definition can be found in the Doc.

Check instance methods here

Saving Data in Cart

You may save any data in the cart along with the item data.

@cart = current_cart
@cart.change_append_transaction_data(:user_data, {
  name: 

TODO

[ ] Customizable Validation [ ] Adding Custom Payment Methods