another_cart
Yet another implementation for shopping cart, really simple and easy to use.
Installation
- Add
gem "kart"to Gemfile - Run
bundle install
Usage
Make sure to create [User] and [Product] model beforehand
rails generate cart [User] [Product]\ example:rails g cart Member Bookwill create a cart contains books selected by a member.rails db:migratethese files created by this command are self-explanatory.- insert
selecting :productto [User] andselected_by :userto [Product].
Export methods
selecting_products: list of products are selected by current usershow_cart: list of product id and quantity in cart of current useradd_to_cart (Product): add 1 product to cartremove_from_cart (Product): remove 1 product from cartremove_all_from_cart: remove all products from cart (when checking out successfully)add_multiple_to_cart (Product,number): add multiple products to cart
Handling exception
- Kart::UserNotDefined: insert
selected_byinto Product model - Kart::ProductNotDefined: insert
selectinginto User model - Kart::ItemNotFound: item need to be added to cart before removed