tb_checkout 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +162 -0
- data/Rakefile +24 -0
- data/app/assets/images/tb_checkout/admin/shopping_carts.png +0 -0
- data/app/assets/images/tb_checkout/admin/transactions.png +0 -0
- data/app/assets/javascripts/tb_checkout/admin/carts.js +2 -0
- data/app/assets/javascripts/tb_checkout/admin/transactions.js +2 -0
- data/app/assets/javascripts/tb_checkout/application.js +13 -0
- data/app/assets/javascripts/tb_checkout/cart_items.js +2 -0
- data/app/assets/javascripts/tb_checkout/carts.js +2 -0
- data/app/assets/javascripts/tb_checkout/transactions.js +2 -0
- data/app/assets/stylesheets/tb_checkout/admin/carts.css +4 -0
- data/app/assets/stylesheets/tb_checkout/admin/transactions.css +4 -0
- data/app/assets/stylesheets/tb_checkout/application.css +15 -0
- data/app/assets/stylesheets/tb_checkout/cart_items.css +4 -0
- data/app/assets/stylesheets/tb_checkout/carts.css +4 -0
- data/app/assets/stylesheets/tb_checkout/transactions.css +4 -0
- data/app/controllers/concerns/tb_checkout/controller_helpers.rb +16 -0
- data/app/controllers/tb_checkout/admin/carts_controller.rb +39 -0
- data/app/controllers/tb_checkout/admin/transactions_controller.rb +26 -0
- data/app/controllers/tb_checkout/application_controller.rb +6 -0
- data/app/controllers/tb_checkout/cart_items_controller.rb +63 -0
- data/app/controllers/tb_checkout/carts_controller.rb +8 -0
- data/app/controllers/tb_checkout/transactions_controller.rb +87 -0
- data/app/helpers/tb_checkout/admin/carts_helper.rb +13 -0
- data/app/helpers/tb_checkout/admin/transactions_helper.rb +16 -0
- data/app/helpers/tb_checkout/application_helper.rb +138 -0
- data/app/helpers/tb_checkout/transactions_helper.rb +2 -0
- data/app/models/concerns/tb_checkout/belongs_to_user_session.rb +15 -0
- data/app/models/concerns/tb_checkout/purchasable.rb +81 -0
- data/app/models/tb_checkout/basic_product.rb +6 -0
- data/app/models/tb_checkout/cart.rb +56 -0
- data/app/models/tb_checkout/cart_item.rb +48 -0
- data/app/models/tb_checkout/transaction.rb +253 -0
- data/app/views/tb_checkout/admin/carts/index.html.erb +54 -0
- data/app/views/tb_checkout/admin/carts/show.html.erb +45 -0
- data/app/views/tb_checkout/admin/transactions/_table.html.erb +24 -0
- data/app/views/tb_checkout/admin/transactions/index.html.erb +7 -0
- data/app/views/tb_checkout/admin/transactions/show.html.erb +70 -0
- data/app/views/tb_checkout/cart_items/create.html.erb +2 -0
- data/app/views/tb_checkout/cart_items/destroy.html.erb +2 -0
- data/app/views/tb_checkout/cart_items/update.html.erb +2 -0
- data/app/views/tb_checkout/carts/_cart.html.erb +65 -0
- data/app/views/tb_checkout/carts/show.html.erb +10 -0
- data/app/views/tb_checkout/transactions/_details.html.erb +17 -0
- data/app/views/tb_checkout/transactions/confirm.html.erb +11 -0
- data/app/views/tb_checkout/transactions/index.html.erb +29 -0
- data/app/views/tb_checkout/transactions/new.html.erb +90 -0
- data/app/views/tb_checkout/transactions/show.html.erb +14 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +20 -0
- data/db/migrate/20140703185256_create_tb_checkout_carts.rb +12 -0
- data/db/migrate/20140703185258_create_tb_checkout_cart_items.rb +15 -0
- data/db/migrate/20140703185259_create_tb_checkout_transactions.rb +23 -0
- data/db/migrate/20140707142350_create_tb_checkout_basic_products.rb +8 -0
- data/db/migrate/20140915202848_add_spud_user_and_session_id_to_transactions.rb +10 -0
- data/lib/tasks/tb_checkout_tasks.rake +19 -0
- data/lib/tb_checkout.rb +4 -0
- data/lib/tb_checkout/configuration.rb +8 -0
- data/lib/tb_checkout/engine.rb +36 -0
- data/lib/tb_checkout/schema.rb +51 -0
- data/lib/tb_checkout/version.rb +3 -0
- data/spec/controllers/tb_checkout/carts_controller_spec.rb +11 -0
- data/spec/controllers/tb_checkout/transactions_controller_spec.rb +110 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +13 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20140915202259_create_spud_admin_permissions.tb_core.rb +12 -0
- data/spec/dummy/db/migrate/20140915202260_create_spud_users.tb_core.rb +30 -0
- data/spec/dummy/db/migrate/20140915202261_add_time_zone_to_spud_user.tb_core.rb +7 -0
- data/spec/dummy/db/migrate/20140915202262_add_scope_to_spud_admin_permissions.tb_core.rb +7 -0
- data/spec/dummy/db/migrate/20140915202263_create_spud_user_settings.tb_core.rb +12 -0
- data/spec/dummy/db/migrate/20140915202264_create_spud_roles.tb_core.rb +11 -0
- data/spec/dummy/db/migrate/20140915202265_create_spud_permissions.tb_core.rb +11 -0
- data/spec/dummy/db/migrate/20140915202266_create_spud_role_permissions.tb_core.rb +12 -0
- data/spec/dummy/db/migrate/20140915202267_drop_spud_admin_permissions.tb_core.rb +16 -0
- data/spec/dummy/db/migrate/20140915202268_create_tb_checkout_carts.tb_checkout_engine.rb +13 -0
- data/spec/dummy/db/migrate/20140915202269_create_tb_checkout_cart_items.tb_checkout_engine.rb +16 -0
- data/spec/dummy/db/migrate/20140915202270_create_tb_checkout_transactions.tb_checkout_engine.rb +24 -0
- data/spec/dummy/db/migrate/20140915202271_create_tb_checkout_basic_products.tb_checkout_engine.rb +9 -0
- data/spec/dummy/db/migrate/20140915234534_add_spud_user_and_session_id_to_transactions.tb_checkout_engine.rb +11 -0
- data/spec/dummy/db/schema.rb +135 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/spud_users.rb +16 -0
- data/spec/factories/tb_checkout_basic_products.rb +8 -0
- data/spec/factories/tb_checkout_cart_items.rb +11 -0
- data/spec/factories/tb_checkout_carts.rb +14 -0
- data/spec/factories/tb_checkout_transactions.rb +37 -0
- data/spec/models/tb_checkout/transaction_spec.rb +5 -0
- data/spec/rails_helper.rb +73 -0
- data/spec/spec_helper.rb +85 -0
- metadata +335 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6855d03966c3d9e13b133132baca368f57f4ed50
|
|
4
|
+
data.tar.gz: 810740b48a84765bfc42e5be5ca3e14d95506ed1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8cb3dc92f75a684adf1902102b471be4d4339c127ff7247f4467ad381e39d0c032199e5d87fc36bf03ca8e7a071ce255f375e25aae102db57476dfc3ce7a25e8
|
|
7
|
+
data.tar.gz: afaf30847266b291b4d6b6007f2f4154fadd0472e005625e0650f7a5cc8561a0bcfc3525d6433c5bd4f935f2b110be3a86391259a93bfecda4f33e25e33b5a7b
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2014 YOURNAME
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# TB Checkout
|
|
2
|
+
|
|
3
|
+
TB Checkout is a shopping cart engine intended for use with Rails and [Twice Baked](https://bitbucket.org/westlakedesign/tb_core/). The goal of this engine is to make a drop-in tool for shopping carts and transaction management to your existing product database.
|
|
4
|
+
|
|
5
|
+
TB Checkout is **not** a full-fledged product management system. Instead, our goal is to make it easy for any of your existing ActiveRecord models to fit into the shopping cart and facilite transactions through a payment gateway.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
Checkout requires at minimum the following gems:
|
|
10
|
+
|
|
11
|
+
- Rails 4
|
|
12
|
+
- TB Core 1.2
|
|
13
|
+
- Active Merchant 1.43
|
|
14
|
+
|
|
15
|
+
## Payment Gateways
|
|
16
|
+
|
|
17
|
+
Those familiar with [Active Merchant](http://activemerchant.org) will know that it supports a wide variety of payment gateways. However, it should be noted that TB Checkout is currently being built and tested against [Authorize.net](authorize.net).
|
|
18
|
+
|
|
19
|
+
More gateways may be added in the future, but we do not intend to cover them all. Pull requests adding support for a particular gateway are welcome.
|
|
20
|
+
|
|
21
|
+
## Installation & Usage
|
|
22
|
+
|
|
23
|
+
First, it is recommended you run the steps listed in the "Installation/Usage" section of the [TB Core](https://bitbucket.org/westlakedesign/tb_core/) README file. Then, perform the following steps:
|
|
24
|
+
|
|
25
|
+
1. Add the following to your Gemfile
|
|
26
|
+
|
|
27
|
+
gem 'tb_checkout'
|
|
28
|
+
|
|
29
|
+
2. Run bundle install
|
|
30
|
+
3. Copy in database migrations to your new rails project
|
|
31
|
+
|
|
32
|
+
bundle exec rake railties:install:migrations
|
|
33
|
+
rake db:migrate
|
|
34
|
+
|
|
35
|
+
4. Restart your application
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
TB Checkout accepts the following configuration options.
|
|
40
|
+
|
|
41
|
+
TbCheckout.configure do |config|
|
|
42
|
+
config.gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new({ ... })
|
|
43
|
+
config.card_types = [:visa, :master, :discover, :american_express]
|
|
44
|
+
config.layout = 'application'
|
|
45
|
+
config.canada_is_real = true
|
|
46
|
+
config.cart_lifespan = 3.days
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
#### gateway
|
|
50
|
+
|
|
51
|
+
An `ActiveMerchant` gateway. See the [Active Merchant](http://activemerchant.org) documentation for help creating a payment gateway.
|
|
52
|
+
|
|
53
|
+
#### card_types
|
|
54
|
+
|
|
55
|
+
An array of acceptable credit card types. Remove any types you do not wish to see in the payment form.
|
|
56
|
+
|
|
57
|
+
#### layout
|
|
58
|
+
|
|
59
|
+
The base view layout to be used for all user-facing views. The default value will inherit from your base `ApplicationController` configuration.
|
|
60
|
+
|
|
61
|
+
#### canada_is_real
|
|
62
|
+
|
|
63
|
+
Set to true or false in order to show/hide Canadian provinces in the billing address section of the payment form. Defaults true.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#### cart_lifespan
|
|
67
|
+
|
|
68
|
+
Configures how long a cart lives until it is marked as abandoned. **NOTE:** Carts are not actually marked as abandoned until
|
|
69
|
+
|
|
70
|
+
## Purchasable Models
|
|
71
|
+
|
|
72
|
+
As stated earlier, TB Checkout is not a product management system. You are expected to build your own library of products, categorizations, and so on. Once you have a product model, making it eligible for the shopping cart is easy.
|
|
73
|
+
|
|
74
|
+
At minimum, a product must have a `price` decimal attribute and a `description` string attribute. You can add these columns to your model using the built-in migration method `add_tb_checkout_purchasable`. Or you could treat these as virtual attributes using instance methods.
|
|
75
|
+
|
|
76
|
+
class AddPurchasableToProducts < ActiveRecord::Migration
|
|
77
|
+
def change
|
|
78
|
+
add_tb_checkout_purchasable :products
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
And in your model you should include the `TbCheckout::Purchasable` concern.
|
|
83
|
+
|
|
84
|
+
class Product < ActiveRecord::Base
|
|
85
|
+
include TbCheckout::Purchasable
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
### Model Configuration
|
|
89
|
+
|
|
90
|
+
The `TbCheckout::Purchasable` concern also addes a couple class methods for optional configuration.
|
|
91
|
+
|
|
92
|
+
class Product < ActiveRecord::Base
|
|
93
|
+
include TbCheckout::Purchasable
|
|
94
|
+
|
|
95
|
+
# Disable the quanitity picker in the shopping cart
|
|
96
|
+
tb_checkout_quantity_is_editable false
|
|
97
|
+
|
|
98
|
+
# Run this block after a transaction is captured
|
|
99
|
+
tb_checkout_after_capture ->(instance){
|
|
100
|
+
logger.debug 'My transaction was completed!'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# Alternatively, pass a method name as a symbol
|
|
104
|
+
tb_checkout_after_capture :after_capture
|
|
105
|
+
|
|
106
|
+
def after_capture(instance)
|
|
107
|
+
logger.debug 'My transaction was completed!'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Delete this object if it is removed from the shopping cart
|
|
111
|
+
tb_checkout_delete_on_removal true
|
|
112
|
+
|
|
113
|
+
# Use this helper method to generate a product page url
|
|
114
|
+
tb_checkout_url_builder ->(instance, view){
|
|
115
|
+
view.product_path(product)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# Configure a partial that you want to render in the shopping cart
|
|
119
|
+
tb_checkout_cart_detail_view '/products/cart_view'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
#### tb_checkout_quantity_is_editable
|
|
123
|
+
|
|
124
|
+
Pass false to remove the ability to modify quantities in the shopping cart. This is useful in situations where it only makes sense to purchase 1 quantity of something, i.e., making a donation.
|
|
125
|
+
|
|
126
|
+
#### tb_checkout_after_capture
|
|
127
|
+
|
|
128
|
+
Pass a lambda literal, or a symbol naming the method you wish to call. This hook will be called after a successful transation.
|
|
129
|
+
|
|
130
|
+
#### tb_checkout_delete_on_removal
|
|
131
|
+
|
|
132
|
+
Set to `true` if the object should be permanently deleted when it is removed from the shopping cart. This might make sense in a scenario where your purchasable objects are one-time use records, but not if your purchasable objects are reused across many carts. Defaults to `false`.
|
|
133
|
+
|
|
134
|
+
#### tb_checkout_url_builder
|
|
135
|
+
|
|
136
|
+
Pass a lambda literal, or a symbol naming the method you wish to call. This method will be called whenever we want to generate a URL to your product.
|
|
137
|
+
|
|
138
|
+
#### tb_checkout_cart_detail_view
|
|
139
|
+
|
|
140
|
+
Sometimes you want to render some custom HTML in the row of a shopping cart. This configuration allows you to point to a partial view file in your project. This partial will be passed an `item` local variable.
|
|
141
|
+
|
|
142
|
+
**NOTE:** This partial will only be rendered after a succesful checkout. In-progress carts will only render the product description.
|
|
143
|
+
|
|
144
|
+
## View Helpers
|
|
145
|
+
|
|
146
|
+
The following helper methods are provided for convenience. See the Rdocs for the most up to date information regarding arguments and return values.
|
|
147
|
+
|
|
148
|
+
#### tb_checkout_current_cart
|
|
149
|
+
|
|
150
|
+
Returns the currently active shopping cart or nil if no cart is active.
|
|
151
|
+
|
|
152
|
+
#### tb_checkout_cart_link
|
|
153
|
+
|
|
154
|
+
<%= tb_checkout_cart_link() %>
|
|
155
|
+
|
|
156
|
+
Returns a link to the shopping cart.
|
|
157
|
+
|
|
158
|
+
#### tb_checkout_add_to_cart
|
|
159
|
+
|
|
160
|
+
<%= tb_checkout_add_to_cart(my_product) %>
|
|
161
|
+
|
|
162
|
+
Returns a button that, when clicked, adds a product to the shopping cart.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'TbCheckout'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
rdoc.rdoc_files.include('app/**/*.rb')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
19
|
+
load 'rails/tasks/engine.rake'
|
|
20
|
+
|
|
21
|
+
Bundler::GemHelper.install_tasks
|
|
22
|
+
|
|
23
|
+
require 'rspec/core'
|
|
24
|
+
require 'rspec/core/rake_task'
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module TbCheckout::ControllerHelpers
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
helper_method :tb_checkout_current_cart
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def tb_checkout_current_cart
|
|
9
|
+
return TbCheckout::Cart.find_or_create_by({
|
|
10
|
+
:session_id => session.id,
|
|
11
|
+
:spud_user_id => current_user.try(:id),
|
|
12
|
+
:is_completed => false
|
|
13
|
+
})
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class TbCheckout::Admin::CartsController < Spud::Admin::ApplicationController
|
|
2
|
+
belongs_to_spud_app :shopping_carts
|
|
3
|
+
before_action :setup_breadcrumb
|
|
4
|
+
before_action :load_cart, :only => :show
|
|
5
|
+
|
|
6
|
+
def index
|
|
7
|
+
@carts = TbCheckout::Cart.order('created_at desc').includes(:cart_items).paginate(:page => params[:page])
|
|
8
|
+
if params[:status]
|
|
9
|
+
if params[:status] == 'completed'
|
|
10
|
+
@carts = @carts.completed()
|
|
11
|
+
elsif params[:status] == 'in-progress'
|
|
12
|
+
@carts = @carts.in_progress()
|
|
13
|
+
elsif params[:status] == 'abandoned'
|
|
14
|
+
@carts = @carts.abandoned()
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
respond_with @carts
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def show
|
|
21
|
+
respond_with @cart
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def setup_breadcrumb
|
|
27
|
+
add_breadcrumb 'Shopping Carts', tb_checkout_admin_carts_path(:status => params[:status])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def load_cart
|
|
31
|
+
@cart = TbCheckout::Cart.where(:id => params[:id]).first
|
|
32
|
+
if @cart.blank?
|
|
33
|
+
flash[:error] = "Could not find the requested Shopping Cart"
|
|
34
|
+
redirect_to tb_checkout_admin_carts_path
|
|
35
|
+
return false
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class TbCheckout::Admin::TransactionsController < Spud::Admin::ApplicationController
|
|
2
|
+
belongs_to_spud_app :transactions
|
|
3
|
+
add_breadcrumb 'Transactions', :tb_checkout_admin_transactions_path
|
|
4
|
+
before_action :load_transaction, :only => :show
|
|
5
|
+
|
|
6
|
+
def index
|
|
7
|
+
@transactions = TbCheckout::Transaction.order('created_at desc').paginate(:page => params[:page])
|
|
8
|
+
respond_with @transactions
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
respond_with @transaction
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def load_transaction
|
|
18
|
+
@transaction = TbCheckout::Transaction.where(:id => params[:id]).first
|
|
19
|
+
if @transaction.blank?
|
|
20
|
+
flash[:error] = 'Could not find the requested Transaction'
|
|
21
|
+
redirect_to tb_checkout_admin_transactions_path
|
|
22
|
+
return false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
class TbCheckout::CartItemsController < TbCheckout::ApplicationController
|
|
2
|
+
|
|
3
|
+
before_action :load_cart
|
|
4
|
+
before_action :load_cart_item, :only => [:update, :destroy]
|
|
5
|
+
|
|
6
|
+
def create
|
|
7
|
+
@cart_item = @cart.cart_items.create(cart_item_params)
|
|
8
|
+
respond_with @cart_item do |format|
|
|
9
|
+
format.html{
|
|
10
|
+
if @cart_item.errors.any?
|
|
11
|
+
flash[:error] = "An error occurred: \"#{@cart_item.errors.full_messages.first}\""
|
|
12
|
+
redirect_to :back
|
|
13
|
+
else
|
|
14
|
+
flash[:notice] = "Added \"#{@cart_item.item_description}\" to your cart"
|
|
15
|
+
redirect_to tb_checkout_cart_path
|
|
16
|
+
end
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update
|
|
22
|
+
@cart_item.update_attributes(cart_item_params)
|
|
23
|
+
respond_with @cart_item do |format|
|
|
24
|
+
format.html{
|
|
25
|
+
if @cart_item.errors.any?
|
|
26
|
+
flash[:error] = "An error occurred: \"#{@cart_item.errors.full_messages.first}\""
|
|
27
|
+
redirect_to :back
|
|
28
|
+
else
|
|
29
|
+
flash[:notice] = "Updated \"#{@cart_item.item_description}\" in your cart"
|
|
30
|
+
redirect_to tb_checkout_cart_path
|
|
31
|
+
end
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def destroy
|
|
37
|
+
@cart_item.destroy()
|
|
38
|
+
respond_with @cart_item do |format|
|
|
39
|
+
format.html{
|
|
40
|
+
flash[:notice] = "Removed \"#{@cart_item.item_description}\" from your cart"
|
|
41
|
+
redirect_to tb_checkout_cart_path
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def load_cart
|
|
49
|
+
@cart = tb_checkout_current_cart
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def load_cart_item
|
|
53
|
+
@cart_item = @cart.cart_items.where(:id => params[:id]).first
|
|
54
|
+
if @cart_item.blank?
|
|
55
|
+
raise Spud::NotFoundError('Cart Item')
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def cart_item_params
|
|
60
|
+
params.require(:tb_checkout_cart_item).permit(:item_type, :item_id, :quantity)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|