Last active
December 17, 2015 21:39
-
-
Save dabit/5675927 to your computer and use it in GitHub Desktop.
AASC Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "acts_as_shopping_cart" | |
gem "sqlite3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
activemodel (3.2.13) | |
activesupport (= 3.2.13) | |
builder (~> 3.0.0) | |
activerecord (3.2.13) | |
activemodel (= 3.2.13) | |
activesupport (= 3.2.13) | |
arel (~> 3.0.2) | |
tzinfo (~> 0.3.29) | |
activesupport (3.2.13) | |
i18n (= 0.6.1) | |
multi_json (~> 1.0) | |
acts_as_shopping_cart (0.1.6) | |
activerecord (~> 3.0) | |
arel (3.0.2) | |
builder (3.0.4) | |
i18n (0.6.1) | |
multi_json (1.7.4) | |
sqlite3 (1.3.7) | |
tzinfo (0.3.37) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
acts_as_shopping_cart | |
sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler' | |
Bundler.setup | |
require 'active_record' | |
require 'acts_as_shopping_cart' | |
ActiveRecord::Migration.verbose = false | |
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") | |
ActiveRecord::Schema.define(:version => 1) do | |
create_table :shopping_carts | |
create_table :shopping_cart_items do |t| | |
t.shopping_cart_item_fields | |
end | |
create_table :products do |t| | |
t.string :name | |
end | |
end | |
class Product < ActiveRecord::Base | |
end | |
class ShoppingCart < ActiveRecord::Base | |
acts_as_shopping_cart | |
def taxes | |
0 | |
end | |
end | |
class ShoppingCartItem < ActiveRecord::Base | |
acts_as_shopping_cart_item | |
end | |
@cart = ShoppingCart.create | |
@product = Product.new | |
@cart.add @product, 1000 | |
@cart.add @product, 1000 | |
puts "Total Unique items: #{@cart.total_unique_items}" | |
puts "Total: #{@cart.total}" | |
puts "Qty in Item object: #{@cart.shopping_cart_items.last.quantity}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment