shopify-gold 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/gold/admin/referrals_controller.rb +13 -1
- data/app/controllers/gold/billing_controller.rb +24 -11
- data/app/controllers/gold/referrals_controller.rb +1 -1
- data/app/models/gold/referral.rb +1 -1
- data/app/views/gold/admin/referrals/_card.erb +29 -0
- data/config/routes.rb +4 -3
- data/lib/gold/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80643acee44a7474c72b7286d4875e30a6a15d2dfc7755e69b06d1efdf71ebd9
|
4
|
+
data.tar.gz: d33356b33692267a6c29ea31554f5c99a11a5c01fe8504a291e2a94485a52e30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffd0c44af7c2b7dbab2e9f79b19ede308fa0e30cab8e0e7c1317e27c48ad8b241898797c645e026d17a6ef17c4ab48d3d030ab5dfdd943305563a68390f48f00
|
7
|
+
data.tar.gz: 7e5e8038e53f66fdeb7fc88b977e9834044df9fce4243f4b77ffe9e15937646462237ec10f88b0cf2416e02f9f97fab77eea0fbed6079a7765e26bd63c6e0e8c
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Gold
|
2
2
|
module Admin
|
3
|
+
# Controller for referrals
|
3
4
|
class ReferralsController < AdminController
|
4
5
|
def create
|
5
6
|
referral = Referral.new(referral_params)
|
@@ -11,7 +12,7 @@ module Gold
|
|
11
12
|
flash[:danger] = "Failed to create, #{message}"
|
12
13
|
end
|
13
14
|
|
14
|
-
redirect_to
|
15
|
+
redirect_to "#{request.path}/#{referral.id}"
|
15
16
|
end
|
16
17
|
|
17
18
|
def update
|
@@ -37,6 +38,17 @@ module Gold
|
|
37
38
|
redirect_to gold_admin_engine.referrals_path
|
38
39
|
end
|
39
40
|
|
41
|
+
def add_billing
|
42
|
+
referral = Referral.find_by(id: params[:referral_id])
|
43
|
+
billing = Billing.find(params[:id])
|
44
|
+
|
45
|
+
billing.update(referral: referral)
|
46
|
+
|
47
|
+
flash[:success] = "Updated referral"
|
48
|
+
|
49
|
+
redirect_back(fallback_location: "/admin")
|
50
|
+
end
|
51
|
+
|
40
52
|
private
|
41
53
|
|
42
54
|
def referral_params
|
@@ -42,17 +42,7 @@ module Gold
|
|
42
42
|
def tier
|
43
43
|
billing # Expose the @billing variable to the view
|
44
44
|
|
45
|
-
|
46
|
-
if !billing.referral && session[:gold_referral_id]
|
47
|
-
referral = Gold::Referral.find_by(id: session[:gold_referral_id])
|
48
|
-
|
49
|
-
if referral
|
50
|
-
billing.referral = referral
|
51
|
-
billing.update(
|
52
|
-
discount_percentage: referral.discount_percentage || 0
|
53
|
-
)
|
54
|
-
end
|
55
|
-
end
|
45
|
+
apply_referral_cookie
|
56
46
|
|
57
47
|
@tiers = Tier.visible
|
58
48
|
end
|
@@ -204,6 +194,29 @@ module Gold
|
|
204
194
|
end
|
205
195
|
end
|
206
196
|
|
197
|
+
def apply_referral_cookie
|
198
|
+
reference_id = :gold_referral_id
|
199
|
+
referral_tracking = cookies[reference_id]
|
200
|
+
|
201
|
+
# Remove the cookie for future use
|
202
|
+
cookies.delete(reference_id)
|
203
|
+
|
204
|
+
# Don't continue if billing already has a referral or there's no tracking code
|
205
|
+
return if billing.referral || !referral_tracking
|
206
|
+
|
207
|
+
# Find the referral by ID
|
208
|
+
referral = Gold::Referral.find_by(id: referral_tracking)
|
209
|
+
|
210
|
+
# Don't continue if that referral code wasn't found
|
211
|
+
return unless referral
|
212
|
+
|
213
|
+
# Apply the referral to the billing object
|
214
|
+
billing.referral = referral
|
215
|
+
billing.update(
|
216
|
+
discount_percentage: referral.discount_percentage || 0
|
217
|
+
)
|
218
|
+
end
|
219
|
+
|
207
220
|
# Ensure that the current merchant is in one of the provided states or
|
208
221
|
# redirect to the app's root URL.
|
209
222
|
def ensure_billing_is(*states)
|
@@ -4,7 +4,7 @@ module Gold
|
|
4
4
|
def track
|
5
5
|
referral = Referral.find_by(code: params[:code])
|
6
6
|
|
7
|
-
|
7
|
+
cookies[:gold_referral_id] = { value: referral.id, expires: 30.days } if referral
|
8
8
|
|
9
9
|
redirect_to Gold.configuration.referral_redirect_url
|
10
10
|
end
|
data/app/models/gold/referral.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
<div class="card mb-3">
|
2
|
+
<div class="card-header">
|
3
|
+
<strong>Referral</strong>
|
4
|
+
</div>
|
5
|
+
<div class="card-body">
|
6
|
+
<aside class="float-right">
|
7
|
+
<a data-toggle="collapse" href="#collapseReferral">Change</a>
|
8
|
+
|
9
|
+
<div id="collapseReferral" class="collapse mt-3">
|
10
|
+
<%= form_tag(gold_admin_engine.add_billing_referral_path) do %>
|
11
|
+
<select name="referral_id">
|
12
|
+
<option value="">None</option>
|
13
|
+
<%= Gold::Referral.all.each do |referral| %>
|
14
|
+
<option value="<%= referral.id %>" <% if billing.referral&.id == referral.id %>selected<% end %>><%= referral.code %></option>
|
15
|
+
<% end %>
|
16
|
+
</select>
|
17
|
+
|
18
|
+
<input type="submit" class="btn btn-primary btn-sm" value="Update">
|
19
|
+
<% end %>
|
20
|
+
</div>
|
21
|
+
</aside>
|
22
|
+
|
23
|
+
<% if billing.referral %>
|
24
|
+
<%= link_to(@shop.billing.referral.code, admin_referral_path(@shop.billing.referral)) %>
|
25
|
+
<% else %>
|
26
|
+
<p>No referral</p>
|
27
|
+
<% end %>
|
28
|
+
</div>
|
29
|
+
</div>
|
data/config/routes.rb
CHANGED
@@ -34,8 +34,9 @@ Gold::AdminEngine.routes.draw do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
scope :referrals do
|
37
|
-
post
|
38
|
-
patch
|
39
|
-
|
37
|
+
post "/", to: "admin/referrals#create", as: "referrals"
|
38
|
+
patch "/:id", to: "admin/referrals#update", as: "referral"
|
39
|
+
post "/:id/billings", to: "admin/referrals#add_billing", as: "add_billing_referral"
|
40
|
+
delete "/:id", to: "admin/referrals#delete", as: "delete_referral"
|
40
41
|
end
|
41
42
|
end
|
data/lib/gold/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify-gold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Smith
|
@@ -259,6 +259,7 @@ files:
|
|
259
259
|
- app/views/gold/admin/billing/_tier.erb
|
260
260
|
- app/views/gold/admin/billing/_trial_days.erb
|
261
261
|
- app/views/gold/admin/referrals/_billings.erb
|
262
|
+
- app/views/gold/admin/referrals/_card.erb
|
262
263
|
- app/views/gold/admin/referrals/_delete.erb
|
263
264
|
- app/views/gold/admin/referrals/_form.erb
|
264
265
|
- app/views/gold/billing/_inner_head.html.erb
|