locomotive_ecommerce_plugin 1.0.1 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/controllers/locomotive/ecommerce/cart_controller.rb +12 -12
- data/app/controllers/locomotive/ecommerce/purchase_controller.rb +5 -28
- data/app/helpers/locomotive/ecommerce/ecommerce_cart_helper.rb +9 -9
- data/app/models/locomotive/ecommerce/cart.rb +2 -2
- data/app/models/locomotive/ecommerce/order.rb +20 -10
- data/app/models/locomotive/ecommerce/purchase.rb +48 -15
- data/config/initializers/stripe_setup.rb +6 -5
- data/lib/locomotive/ecommerce/plugin/config.html +11 -6
- data/lib/locomotive/ecommerce/plugin/ecommerce_filters.rb +2 -2
- data/lib/locomotive/ecommerce/plugin/ecommerce_tags.rb +7 -5
- data/lib/locomotive/ecommerce/plugin/engine.rb +3 -3
- data/lib/locomotive/ecommerce/plugin/inventory_interface.rb +15 -15
- data/lib/locomotive/ecommerce/plugin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWU3NmY0NDM0ZTBlZDcyNTJmZDM1NDllNmY1MTc0NGIzNzFkNmE1Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWJhMTcxMTEyYTAzZTcyZDIyMDI1MTgyZjdhZWIzZmY5ZmM0Y2NjZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODBlZjBiYzdiYmZmOTkyZTI3NzU4YWZlODZhNTJjNzA0OGMwM2JkZTg3YmUx
|
10
|
+
NTMyMDEyYTE3YWQ3MjUxNTJhZGIxMWNkMWEzNDFmZTVkM2QxOTg3MDhiNjU0
|
11
|
+
MTI2YzA5OTQxNDE1OGMzMmJjZWY5MTQ5YjMyOTI3YWY2Y2Y5M2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjZmOGM4OTJjNzNkYjQ1OThiODc5NDZjNzg1MDViMjI3YTQ0YjIxNmU2MWEy
|
14
|
+
ODVjYWI5MjU3OWIyZDYzM2JkZjBhNTU2YzYzMjI0MGY3MTE0NmM5YTI0ZDhj
|
15
|
+
ZjkyNTY4YmZmNTBjYzE1YTJmMjZhMTY3MGZmN2E0MzhhNTVjZGI=
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module Locomotive
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
1
|
+
module Locomotive
|
2
|
+
module Ecommerce
|
3
|
+
class CartController < ::Locomotive::Ecommerce::ApplicationController
|
4
|
+
def update
|
5
|
+
@cart = Cart.find(params[:id])
|
6
|
+
@cart.update_from_params(params)
|
7
|
+
flash[:success] = 'Updated cart'
|
8
|
+
redirect_to cart_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -3,7 +3,7 @@ require 'stripe'
|
|
3
3
|
module Locomotive
|
4
4
|
module Ecommerce
|
5
5
|
class PurchaseController < ::Locomotive::Ecommerce::ApplicationController
|
6
|
-
before_filter :
|
6
|
+
before_filter :do_authorize, except: [:do_new_purchase]
|
7
7
|
|
8
8
|
def create
|
9
9
|
@purchase = current_user_cart(self).purchase
|
@@ -21,35 +21,12 @@ module Locomotive
|
|
21
21
|
redirect_to checkout_path
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.complete(purchase_id, user, cart, stripeToken)
|
25
|
-
purchase = Purchase.where(_id: purchase_id).first
|
26
|
-
|
27
|
-
#Reset user cart
|
28
|
-
purchase.cart.user_id = nil
|
29
|
-
purchase.cart.save!
|
30
|
-
new_cart = Cart.create
|
31
|
-
new_cart.user_id = user.id
|
32
|
-
new_cart.save!
|
33
|
-
|
34
|
-
#complete purchase
|
35
|
-
purchase.stripe_token = stripeToken
|
36
|
-
purchase.complete
|
37
|
-
purchase.completed = true
|
38
|
-
purchase.user_id = user.id
|
39
|
-
purchase.save!
|
40
|
-
PurchaseMailer.purchase_confirmation(user, purchase).deliver
|
41
|
-
after_purchase_hook(purchase, user)
|
42
|
-
end
|
43
|
-
|
44
24
|
private
|
45
25
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
cxt['user'] = user
|
51
|
-
cxt['purchase'] = purchase
|
52
|
-
last = cxt.eval(Engine.config_or_default('after_purchase_hook'))
|
26
|
+
def do_authorize
|
27
|
+
if Engine.config_or_default('require_user')
|
28
|
+
authenticate_user!
|
29
|
+
end
|
53
30
|
end
|
54
31
|
end
|
55
32
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Locomotive
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
module Ecommerce
|
3
|
+
module EcommerceCartHelper
|
4
|
+
def current_user_cart(controller)
|
5
|
+
user = current_user(controller)
|
6
|
+
id = user == nil ? nil : user.id
|
7
|
+
Cart.find_or_create(id, controller.session)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
11
|
end
|
@@ -44,7 +44,7 @@ module Locomotive
|
|
44
44
|
ext = Engine.config_or_default('edit_extra')
|
45
45
|
return nil unless ext
|
46
46
|
site = Thread.current[:site]
|
47
|
-
cxt = site.plugin_object_for_id('
|
47
|
+
cxt = site.plugin_object_for_id('ecommerce').js3_context
|
48
48
|
cxt['purchase_total'] = purchase_total
|
49
49
|
cxt['orders'] = orders
|
50
50
|
js = cxt.eval(ext)
|
@@ -159,4 +159,4 @@ module Locomotive
|
|
159
159
|
attr_accessor :source
|
160
160
|
end
|
161
161
|
end
|
162
|
-
end
|
162
|
+
end
|
@@ -23,11 +23,11 @@ module Locomotive
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def price
|
26
|
-
quantity * product_price
|
26
|
+
quantity * product_price.to_i
|
27
27
|
end
|
28
28
|
|
29
29
|
def out_of_stock?
|
30
|
-
quantity > product_quantity
|
30
|
+
quantity > product_quantity
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.id_to_sku(id)
|
@@ -36,14 +36,20 @@ module Locomotive
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def product
|
39
|
-
self.class.product_class
|
39
|
+
klass = self.class.product_class
|
40
|
+
|
41
|
+
if klass.respond_to?(:find_by_sku)
|
42
|
+
klass.find_by_sku(sku)
|
43
|
+
else
|
44
|
+
klass.where(sku: sku).first
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
[:size, :color, :quantity, :price, :name].each do |method|
|
43
49
|
defined = "product_#{method}".to_sym
|
44
50
|
default = [:quantity, :price].include?(method)? 0 : ''
|
45
51
|
method = :description if method == :name
|
46
|
-
define_method(defined) do
|
52
|
+
define_method(defined) do
|
47
53
|
i = product
|
48
54
|
if i == nil
|
49
55
|
default
|
@@ -90,18 +96,22 @@ module Locomotive
|
|
90
96
|
"%0.2f" % @source.price.round(2)
|
91
97
|
end
|
92
98
|
|
93
|
-
|
99
|
+
def product_price
|
100
|
+
"%0.2f" % @source.product_price.round(2)
|
101
|
+
end
|
102
|
+
|
103
|
+
[:size, :color, :name].each do |method|
|
94
104
|
defined = "product_#{method}".to_sym
|
95
105
|
define_method(method) do
|
96
|
-
@source.send(defined
|
106
|
+
@source.send(defined)
|
97
107
|
end
|
98
|
-
end
|
108
|
+
end
|
99
109
|
|
100
|
-
delegate :sku, :product, :out_of_stock?, :product_quantity, :cart, to: :@source
|
110
|
+
delegate :sku, :product, :quantity, :out_of_stock?, :product_quantity, :cart, to: :@source
|
101
111
|
|
102
112
|
protected
|
103
113
|
|
104
|
-
attr_accessor :source
|
114
|
+
attr_accessor :source
|
105
115
|
end
|
106
116
|
end
|
107
|
-
end
|
117
|
+
end
|
@@ -11,6 +11,29 @@ module Locomotive
|
|
11
11
|
field :stripe_token, :type => String
|
12
12
|
has_one :cart, :class_name => "::Locomotive::Ecommerce::Cart"
|
13
13
|
|
14
|
+
def self.complete(purchase_id, user, cart, stripeToken, session)
|
15
|
+
purchase = Purchase.where(_id: purchase_id).first
|
16
|
+
|
17
|
+
#Reset user cart
|
18
|
+
purchase.cart.user_id = nil
|
19
|
+
purchase.cart.save!
|
20
|
+
new_cart = Cart.create
|
21
|
+
new_cart.user_id = user.id if user
|
22
|
+
new_cart.save!
|
23
|
+
session[:cart_id] = new_cart.id
|
24
|
+
|
25
|
+
#complete purchase
|
26
|
+
purchase.stripe_token = stripeToken
|
27
|
+
purchase.complete
|
28
|
+
purchase.completed = true
|
29
|
+
purchase.user_id = user.id if user
|
30
|
+
purchase.save!
|
31
|
+
if user
|
32
|
+
PurchaseMailer.purchase_confirmation(user, purchase).deliver
|
33
|
+
end
|
34
|
+
after_purchase_hook(purchase, user)
|
35
|
+
end
|
36
|
+
|
14
37
|
def complete
|
15
38
|
cart.orders.each { |order| order.product_quantity -= order.quantity }
|
16
39
|
end
|
@@ -43,42 +66,42 @@ module Locomotive
|
|
43
66
|
end
|
44
67
|
|
45
68
|
def tax
|
46
|
-
if precent =
|
69
|
+
if precent = tax_percentage
|
47
70
|
cart.purchase_total * (precent.to_f/100)
|
48
71
|
else
|
49
72
|
-1
|
50
73
|
end
|
51
74
|
end
|
52
75
|
|
53
|
-
def
|
54
|
-
unless @
|
76
|
+
def tax_percentage
|
77
|
+
unless @tax_percentage
|
55
78
|
ct = Thread.current[:site].content_types.where(slug: Engine.config_or_default('tax_model')).first
|
56
79
|
if ct
|
57
80
|
query_hash = {}
|
58
81
|
country_field = Engine.config_or_default('country_slug').to_sym
|
59
82
|
province_field = Engine.config_or_default('province_slug').to_sym
|
60
|
-
|
83
|
+
percentage_field = Engine.config_or_default('percentage_slug').to_sym
|
61
84
|
query_hash[country_field] = /#{shipping_info[country_field.to_s]}/i
|
62
85
|
query = ct.entries.where(query_hash)
|
63
86
|
if query.count == 1
|
64
|
-
@
|
87
|
+
@tax_percentage = query.first.send(percentage_field)
|
65
88
|
elsif query.count > 0
|
66
89
|
query_hash = {}
|
67
90
|
query_hash[province_field] = /#{shipping_info[province_field.to_s]}/i
|
68
91
|
query = query.and(query_hash)
|
69
92
|
if query.count > 0
|
70
|
-
@
|
93
|
+
@tax_percentage = query.first.send(percentage_field)
|
71
94
|
else
|
72
|
-
@
|
95
|
+
@tax_percentage = nil
|
73
96
|
end
|
74
97
|
else
|
75
|
-
@
|
98
|
+
@tax_percentage = nil
|
76
99
|
end
|
77
100
|
else
|
78
|
-
@
|
101
|
+
@tax_percentage = nil
|
79
102
|
end
|
80
103
|
end
|
81
|
-
@
|
104
|
+
@tax_percentage
|
82
105
|
end
|
83
106
|
|
84
107
|
def shipping
|
@@ -92,9 +115,9 @@ module Locomotive
|
|
92
115
|
query_hash = {}
|
93
116
|
query_hash[name_field] = self.shipping_method
|
94
117
|
method = ct.entries.where(query_hash).first
|
95
|
-
if self.cart.purchase_total > price_break
|
118
|
+
if method && self.cart.purchase_total > price_break
|
96
119
|
@shipping = method.send(over_field).to_f
|
97
|
-
|
120
|
+
elsif method
|
98
121
|
@shipping = method.send(under_field).to_f
|
99
122
|
end
|
100
123
|
end
|
@@ -110,6 +133,16 @@ module Locomotive
|
|
110
133
|
end
|
111
134
|
end
|
112
135
|
|
136
|
+
protected
|
137
|
+
|
138
|
+
def self.after_purchase_hook(purchase, user)
|
139
|
+
|
140
|
+
site = Thread.current[:site]
|
141
|
+
cxt = site.plugin_object_for_id('ecommerce').js3_context
|
142
|
+
cxt['user'] = user
|
143
|
+
cxt['purchase'] = purchase
|
144
|
+
last = cxt.eval(Engine.config_or_default('after_purchase_hook'))
|
145
|
+
end
|
113
146
|
end
|
114
147
|
|
115
148
|
class PurchaseDrop < ::Liquid::Drop
|
@@ -126,9 +159,9 @@ module Locomotive
|
|
126
159
|
end
|
127
160
|
|
128
161
|
[:subtotal_est_tax, :shipping_estimate, :subtotal_est_shipping,
|
129
|
-
:shipping, :tax, :
|
162
|
+
:shipping, :tax, :tax_percentage, :total].each do |method|
|
130
163
|
define_method("#{method.to_s}_value".to_sym) {@source.send(method).round(2)}
|
131
|
-
define_method(method) {"%0.2f" % @source.send(method).round(2)}
|
164
|
+
define_method(method) {"%0.2f" % @source.send(method).round(2) if @source.send(method)}
|
132
165
|
end
|
133
166
|
|
134
167
|
delegate :cart, :stripe_token, :completed, :shipping_info, to: :@source
|
@@ -145,4 +178,4 @@ module Locomotive
|
|
145
178
|
attr_accessor :source
|
146
179
|
end
|
147
180
|
end
|
148
|
-
end
|
181
|
+
end
|
@@ -24,10 +24,11 @@ module Locomotive
|
|
24
24
|
|
25
25
|
success_proc = lambda do |controller, token, stripe|
|
26
26
|
purchase = Purchase.where(_id: token).first
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
Purchase.complete(token,
|
28
|
+
helper.current_user(controller),
|
29
|
+
helper.current_user_cart(controller),
|
30
|
+
stripe,
|
31
|
+
controller.session)
|
31
32
|
controller.flash[:notice] = "Thank you for your purchase."
|
32
33
|
helper.post_checkout_path
|
33
34
|
end
|
@@ -37,4 +38,4 @@ module Locomotive
|
|
37
38
|
config.charge_success = success_proc
|
38
39
|
end
|
39
40
|
end
|
40
|
-
end
|
41
|
+
end
|
@@ -16,6 +16,11 @@
|
|
16
16
|
<input type="text" name="checkout_url" />
|
17
17
|
</li>
|
18
18
|
|
19
|
+
<li>
|
20
|
+
<label name="confirm_order_url">Confirm Order URL:</label>
|
21
|
+
<input type="text" name="confirm_order_url" />
|
22
|
+
</li>
|
23
|
+
|
19
24
|
<li>
|
20
25
|
<label name="new_checkout_url">Post Checkout URL:</label>
|
21
26
|
<input type="text" name="post_checkout_url" />
|
@@ -24,10 +29,6 @@
|
|
24
29
|
<label name="purchases_url">Purchases URL:</label>
|
25
30
|
<input type="text" name="purchases_url" />
|
26
31
|
</li>
|
27
|
-
<li>
|
28
|
-
<label name="with_quantity">Only in Stock Items:</label>
|
29
|
-
<input type="checkbox" name="with_quantity" />
|
30
|
-
</li>
|
31
32
|
<li>
|
32
33
|
<label name="purchases_url">Estimated Tax Rate (in percent):</label>
|
33
34
|
<input type="text" name="estimated_tax_rate" />
|
@@ -51,8 +52,8 @@
|
|
51
52
|
<input type="text" name="province_slug" />
|
52
53
|
</li>
|
53
54
|
<li>
|
54
|
-
<label name="
|
55
|
-
<input type="text" name="
|
55
|
+
<label name="percentage_slug">Precentage Slug:</label>
|
56
|
+
<input type="text" name="percentage_slug" />
|
56
57
|
</li>
|
57
58
|
<li>
|
58
59
|
<label name="shipping_model">Shipping Model:</label>
|
@@ -109,3 +110,7 @@
|
|
109
110
|
<label name="contact">Contact</label>
|
110
111
|
<input type="text" name="contact" />
|
111
112
|
</li>
|
113
|
+
<li>
|
114
|
+
<label name="require_user">Require User?</label>
|
115
|
+
<input type="checkbox" name="require_user" />
|
116
|
+
</li>
|
@@ -7,9 +7,9 @@ module Locomotive
|
|
7
7
|
"#{stem}cart/#{cart.id}"
|
8
8
|
end
|
9
9
|
|
10
|
-
def add_to_cart_path(
|
10
|
+
def add_to_cart_path(product_sku)
|
11
11
|
stem = @context.registers[:plugin_object].path
|
12
|
-
"#{stem}add_to_cart/#{
|
12
|
+
"#{stem}add_to_cart/#{product_sku}"
|
13
13
|
end
|
14
14
|
|
15
15
|
def remove_from_cart_path(product_sku)
|
@@ -12,10 +12,12 @@ module Locomotive
|
|
12
12
|
super
|
13
13
|
session = context.registers[:controller].session
|
14
14
|
site = Thread.current[:site]
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
id = nil
|
16
|
+
if session[:user_id]
|
17
|
+
user_from_plugin = site.plugin_object_for_id('identity_plugin').js3_context['identity_plugin_users']
|
18
|
+
user = user_from_plugin.find(session[:user_id])
|
19
|
+
id = user == nil ? nil : user.id
|
20
|
+
end
|
19
21
|
cart = Cart.find_or_create(id, session)
|
20
22
|
@purchase = cart.purchase
|
21
23
|
context.registers[:controller].render_cell 'stripe_helper/stripe', :show,
|
@@ -28,4 +30,4 @@ module Locomotive
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
31
|
-
end
|
33
|
+
end
|
@@ -24,15 +24,15 @@ module Locomotive
|
|
24
24
|
'estimated_tax_rate' => '15',
|
25
25
|
'country_slug' => 'country',
|
26
26
|
'province_slug' => 'province',
|
27
|
-
'
|
27
|
+
'percentage_slug' => 'percentage',
|
28
28
|
'shipping_name_slug' => 'name',
|
29
29
|
'shipping_over_slug' => 'over',
|
30
30
|
'shipping_under_slug' => 'under',
|
31
31
|
'price_break' => '100',
|
32
|
-
'edit_extra' => 'add extras through JS',
|
33
32
|
'shop_name' => "<insert name>",
|
34
33
|
'shop_inventory' => "inventory_itemsUpdate",
|
35
|
-
'contact' => "fake@email.com"
|
34
|
+
'contact' => "fake@email.com",
|
35
|
+
'require_user' => false
|
36
36
|
}
|
37
37
|
hash = defaults.merge(config_hash)
|
38
38
|
hash[key]
|
@@ -2,21 +2,21 @@ module Locomotive
|
|
2
2
|
module Ecommerce
|
3
3
|
module InventoryInterface
|
4
4
|
# Inventory
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def self.included(base)
|
6
|
+
base.send :extend, Methods
|
7
|
+
base.send :include, Methods
|
8
|
+
end
|
9
|
+
module Methods
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def inventory_items
|
12
|
+
site = Thread.current[:site]
|
13
|
+
site.plugin_object_for_id('ecommerce').js3_context.eval(Engine.config_or_default('shop_inventory_update'))
|
14
|
+
end
|
15
|
+
def inventory_items_class
|
16
|
+
site = Thread.current[:site]
|
17
|
+
site.plugin_object_for_id('ecommerce').js3_context.eval(Engine.config_or_default('shop_inventory_items'))
|
18
|
+
end
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotive_ecommerce_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colibri Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|