codeindulgence / alacart

Super simple shopping cart interface. Coding challenge. Not for production use.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alacart

Super simple shopping cart interface

Installation

Build & install:

$ gem build alacart.gemspec
$ gem install alacart*.gem

Or just:

require_relative './lib/alacart'

Synopsis

Define your inventory:

inventory = {
  'ipd' => 549.99,
  'mbp' => 1399.99,
  'atv' => 109.50,
  'vga' => 30.00
}

Define discount modifiers:

modifiers = [
  {sku: 'atv', type: :multibuy, params: [3]},
  {sku: 'ipd', type: :bulk, params: [4, 50]},
  {sku: 'mbp', type: :freebie, params: ['vga']}
]

Initialise the cart:

require 'alacart'

cart = Alacart::Cart.new(inventory, modifiers)

Add some items:

cart.add 'ipd'
cart.add 'mbp'
cart.add 'atv'
cart.total # 2059.48

About

Super simple shopping cart interface. Coding challenge. Not for production use.


Languages

Language:Ruby 100.0%