spree_loyalty_points 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -2
- data/app/assets/javascripts/{admin → spree/backend}/spree_loyalty_points.js +0 -2
- data/app/assets/javascripts/spree/frontend/spree_loyalty_points.js +0 -0
- data/app/assets/stylesheets/spree/backend/spree_loyalty_points.css +0 -0
- data/app/assets/stylesheets/{store → spree/frontend}/spree_loyalty_points.css +0 -3
- data/app/models/concerns/spree/order/loyalty_points.rb +1 -1
- data/app/models/concerns/spree/payment/loyalty_points.rb +6 -11
- data/app/models/spree/payment_decorator.rb +6 -7
- data/db/migrate/20140207055836_add_lock_version_to_spree_user.rb +1 -1
- data/lib/generators/spree_loyalty_points/install/install_generator.rb +4 -4
- metadata +54 -36
- data/app/assets/javascripts/store/spree_loyalty_points.js +0 -1
- data/app/assets/stylesheets/admin/spree_loyalty_points.css +0 -3
data/README.md
CHANGED
@@ -7,10 +7,16 @@ This extension adds Loyalty Points for users.
|
|
7
7
|
Installation
|
8
8
|
------------
|
9
9
|
|
10
|
-
|
10
|
+
In your Gemfile, add:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem 'spree_loyalty_points'
|
13
|
+
gem 'spree_loyalty_points'
|
14
|
+
```
|
15
|
+
|
16
|
+
For Spree 2.1.x:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'spree_loyalty_points', '1.0.2'
|
14
20
|
```
|
15
21
|
|
16
22
|
Bundle your dependencies and run the installation generator:
|
@@ -18,6 +24,7 @@ Bundle your dependencies and run the installation generator:
|
|
18
24
|
```shell
|
19
25
|
bundle
|
20
26
|
bundle exec rails g spree_loyalty_points:install
|
27
|
+
bundle exec rake db:migrate
|
21
28
|
```
|
22
29
|
|
23
30
|
Usage
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
class Payment
|
4
|
+
class Payment < ActiveRecord::Base
|
5
5
|
module LoyaltyPoints
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
@@ -19,8 +19,10 @@ module Spree
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def redeem_loyalty_points
|
22
|
-
loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
|
23
|
-
|
22
|
+
loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
|
23
|
+
if by_loyalty_points? && redeemable_loyalty_points_balance?
|
24
|
+
order.create_debit_transaction(loyalty_points_redeemed)
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
28
|
def return_loyalty_points
|
@@ -33,14 +35,7 @@ module Spree
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def redeemable_loyalty_points_balance?
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def redeemable_user_balance
|
40
|
-
unless redeemable_loyalty_points_balance?
|
41
|
-
min_balance = Spree::Config.loyalty_points_redeeming_balance
|
42
|
-
errors.add :loyalty_points_balance, "should be atleast #{ min_balance.to_s + " " + "point".pluralize(min_balance) } for redeeming Loyalty Points"
|
43
|
-
end
|
38
|
+
amount >= Spree::Config.loyalty_points_redeeming_balance
|
44
39
|
end
|
45
40
|
|
46
41
|
end
|
@@ -4,7 +4,6 @@ Spree::Payment.class_eval do
|
|
4
4
|
include Spree::Payment::LoyaltyPoints
|
5
5
|
|
6
6
|
validates :amount, numericality: { greater_than: 0 }, :if => :by_loyalty_points?
|
7
|
-
validate :redeemable_user_balance, :if => :by_loyalty_points?
|
8
7
|
scope :state_not, ->(s) { where('state != ?', s) }
|
9
8
|
|
10
9
|
fsm = self.state_machines[:state]
|
@@ -13,13 +12,13 @@ Spree::Payment.class_eval do
|
|
13
12
|
fsm.after_transition :from => fsm.states.map(&:name) - [:completed], :to => [:completed], :do => :redeem_loyalty_points, :if => :by_loyalty_points?
|
14
13
|
fsm.after_transition :from => [:completed], :to => fsm.states.map(&:name) - [:completed] , :do => :return_loyalty_points, :if => :by_loyalty_points?
|
15
14
|
|
16
|
-
|
15
|
+
def invalidate_old_payments
|
16
|
+
order.payments.with_state('checkout').where("id != ?", self.id).each do |payment|
|
17
|
+
payment.invalidate!
|
18
|
+
end unless by_loyalty_points?
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
order.payments.with_state('checkout').where("id != ?", self.id).each do |payment|
|
20
|
-
payment.invalidate!
|
21
|
-
end unless by_loyalty_points?
|
22
|
-
end
|
21
|
+
private
|
23
22
|
|
24
23
|
def notify_paid_order
|
25
24
|
if all_payments_completed?
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class AddLockVersionToSpreeUser < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
add_column :spree_users, :lock_version, :integer, default: 0, null: false
|
3
|
+
add_column :spree_users, :lock_version, :integer, default: 0, null: false
|
4
4
|
end
|
5
5
|
end
|
@@ -5,13 +5,13 @@ module SpreeLoyaltyPoints
|
|
5
5
|
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
6
|
|
7
7
|
def add_javascripts
|
8
|
-
append_file '
|
9
|
-
append_file '
|
8
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_loyalty_points\n"
|
9
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_loyalty_points\n"
|
10
10
|
end
|
11
11
|
|
12
12
|
def add_stylesheets
|
13
|
-
inject_into_file '
|
14
|
-
inject_into_file '
|
13
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_loyalty_points\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_loyalty_points\n", :before => /\*\//, :verbose => true
|
15
15
|
end
|
16
16
|
|
17
17
|
def add_migrations
|
metadata
CHANGED
@@ -1,45 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_loyalty_points
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Jatin Baweja
|
9
14
|
- Sushant Mittal
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
|
19
|
+
date: 2014-03-21 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
16
22
|
name: spree_core
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ~>
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2.1'
|
23
|
-
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
25
|
none: false
|
27
|
-
requirements:
|
26
|
+
requirements:
|
28
27
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
version: "2.2"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
31
36
|
description: To award loyalty points and add loyalty points payment method to spree
|
32
37
|
email: info@vinsol.com
|
33
38
|
executables: []
|
39
|
+
|
34
40
|
extensions: []
|
41
|
+
|
35
42
|
extra_rdoc_files: []
|
36
|
-
|
43
|
+
|
44
|
+
files:
|
37
45
|
- LICENSE
|
38
46
|
- README.md
|
39
|
-
- app/assets/javascripts/
|
40
|
-
- app/assets/javascripts/
|
41
|
-
- app/assets/stylesheets/
|
42
|
-
- app/assets/stylesheets/
|
47
|
+
- app/assets/javascripts/spree/backend/spree_loyalty_points.js
|
48
|
+
- app/assets/javascripts/spree/frontend/spree_loyalty_points.js
|
49
|
+
- app/assets/stylesheets/spree/backend/spree_loyalty_points.css
|
50
|
+
- app/assets/stylesheets/spree/frontend/spree_loyalty_points.css
|
43
51
|
- app/controllers/spree/admin/general_settings_controller_decorator.rb
|
44
52
|
- app/controllers/spree/admin/loyalty_points_transactions_controller.rb
|
45
53
|
- app/controllers/spree/admin/resource_controller_decorator.rb
|
@@ -97,29 +105,39 @@ files:
|
|
97
105
|
- db/migrate/20140205111553_add_transaction_id_to_spree_loyalty_points_transactions.rb
|
98
106
|
- db/migrate/20140207055836_add_lock_version_to_spree_user.rb
|
99
107
|
homepage: http://vinsol.com
|
100
|
-
licenses:
|
108
|
+
licenses:
|
101
109
|
- MIT
|
102
110
|
post_install_message:
|
103
111
|
rdoc_options: []
|
104
|
-
|
112
|
+
|
113
|
+
require_paths:
|
105
114
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
116
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 53
|
121
|
+
segments:
|
122
|
+
- 1
|
123
|
+
- 9
|
124
|
+
- 3
|
111
125
|
version: 1.9.3
|
112
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
127
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
-
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirements:
|
119
136
|
- none
|
120
137
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.8.
|
138
|
+
rubygems_version: 1.8.24
|
122
139
|
signing_key:
|
123
140
|
specification_version: 3
|
124
141
|
summary: Add loyalty points to spree
|
125
142
|
test_files: []
|
143
|
+
|
@@ -1 +0,0 @@
|
|
1
|
-
//= require store/spree_frontend
|