solidus_virtual_gift_card 1.2.0 → 1.3.0
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 +5 -5
- data/.circleci/config.yml +35 -0
- data/Gemfile +20 -6
- data/README.md +4 -3
- data/Rakefile +2 -2
- data/app/controllers/spree/admin/gift_cards_controller.rb +14 -14
- data/app/controllers/spree/api/gift_cards_controller.rb +2 -2
- data/app/decorators/models/solidus_virtual_gift_card/spree/inventory_unit_decorator.rb +13 -0
- data/app/decorators/models/solidus_virtual_gift_card/spree/line_item_decorator.rb +24 -0
- data/app/{models/concerns/spree/gift_cards/order_contents_concerns.rb → decorators/models/solidus_virtual_gift_card/spree/order_contents_decorator.rb} +14 -20
- data/app/{models/concerns/spree/gift_cards/order_concerns.rb → decorators/models/solidus_virtual_gift_card/spree/order_decorator.rb} +14 -14
- data/app/{models → decorators/models/solidus_virtual_gift_card}/spree/store_credit_category_decorator.rb +1 -1
- data/app/mailers/spree/gift_card_mailer.rb +5 -2
- data/app/models/spree/gift_cards/gift_card_date_format_error.rb +6 -0
- data/app/models/{concerns/spree → spree}/redemption_code_generator.rb +0 -0
- data/app/models/spree/virtual_gift_card.rb +19 -16
- data/app/overrides/admin_gift_card_order_confirmation.rb +4 -4
- data/app/overrides/admin_item_view_gift_card_codes.rb +12 -12
- data/app/overrides/admin_user_sidebar_store_credits.rb +3 -3
- data/app/overrides/admin_user_sub_menu.rb +2 -2
- data/app/views/spree/admin/gift_cards/_lookup_form.html.erb +2 -2
- data/app/views/spree/admin/gift_cards/_redemption_form.html.erb +1 -1
- data/app/views/spree/admin/gift_cards/edit.html.erb +5 -5
- data/app/views/spree/admin/gift_cards/index.html.erb +1 -1
- data/app/views/spree/admin/gift_cards/lookup.html.erb +1 -1
- data/app/views/spree/admin/orders/_confirmation_gift_card_details.html.erb +9 -9
- data/app/views/spree/admin/orders/_gift_card_details.html.erb +2 -2
- data/app/views/spree/admin/users/_gift_card_sidebar.html.erb +2 -2
- data/app/views/spree/gift_card_mailer/gift_card_email.text.erb +3 -3
- data/config/initializers/line_item_controller_gift_card_details.rb +1 -1
- data/db/migrate/20140623152903_create_virtual_gift_card.rb +1 -1
- data/db/migrate/20140624175113_seed_gift_card_category.rb +1 -1
- data/db/migrate/20140627185148_add_timestamps_to_gift_cards.rb +1 -1
- data/db/migrate/20140702153907_add_gift_card_flag_to_products.rb +1 -1
- data/db/migrate/20140707200431_add_line_item_to_gift_card.rb +1 -1
- data/db/migrate/20151013172931_add_recipient_fields_to_virtual_gift_card.rb +1 -1
- data/db/migrate/20151013210615_add_active_flag_to_virtual_gift_card.rb +1 -1
- data/db/migrate/20151013214647_set_redeemable_true_on_virtual_gift_cards.rb +2 -2
- data/db/migrate/20151019190731_add_email_send_time_to_virtual_gift_card.rb +1 -1
- data/db/migrate/20151109202300_add_deactivated_at_to_gift_card.rb +1 -1
- data/db/migrate/20151110202752_add_inventory_unit_to_gift_card.rb +1 -1
- data/db/migrate/20151111211220_backfill_inventory_units_on_gift_card.rb +2 -2
- data/lib/generators/solidus_virtual_gift_card/install/install_generator.rb +1 -1
- data/lib/solidus_virtual_gift_card.rb +1 -0
- data/lib/spree_virtual_gift_card/engine.rb +3 -3
- data/lib/spree_virtual_gift_card/factories.rb +7 -7
- data/lib/tasks/send_gift_card_emails.rake +1 -1
- data/solidus_virtual_gift_card.gemspec +23 -21
- data/spec/controllers/spree/admin/gift_cards_controller_spec.rb +33 -34
- data/spec/controllers/spree/api/gift_cards_controller_spec.rb +12 -13
- data/spec/features/admin/gift_cards_spec.rb +19 -17
- data/spec/features/admin/products_card_spec.rb +3 -3
- data/spec/lib/tasks/send_gift_card_emails_spec.rb +12 -12
- data/spec/mailers/spree/gift_card_mailer_spec.rb +4 -4
- data/spec/models/concerns/spree/redemption_code_generator_spec.rb +5 -5
- data/spec/models/spree/line_item_spec.rb +2 -2
- data/spec/models/spree/order_contents_spec.rb +82 -82
- data/spec/models/spree/order_spec.rb +13 -13
- data/spec/models/spree/permission_sets/virtual_gift_card_display_spec.rb +2 -2
- data/spec/models/spree/permission_sets/virtual_gift_card_management_spec.rb +2 -2
- data/spec/models/spree/store_credit_category_spec.rb +6 -6
- data/spec/models/spree/virtual_gift_card_spec.rb +23 -23
- data/spec/spec_helper.rb +13 -74
- data/spec/support/cancan.rb +3 -0
- metadata +56 -25
- data/.travis.yml +0 -8
- data/app/models/concerns/spree/gift_cards/inventory_unit_concerns.rb +0 -10
- data/app/models/concerns/spree/gift_cards/line_item_concerns.rb +0 -22
- data/app/models/spree/inventory_unit_decorator.rb +0 -1
- data/app/models/spree/line_item_decorator.rb +0 -1
- data/app/models/spree/order_contents_decorator.rb +0 -1
- data/app/models/spree/order_decorator.rb +0 -1
- data/circle.yml +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cd464b35ade1d8c367f28771b22632bf2dfbd1bffb6ab56b1e4893b40cf74ce2
|
|
4
|
+
data.tar.gz: 41c2ac487d74730c650e4636dd115bb307a3ad065fc900bae37a9453afca7060
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa2b39045ef1ba5f6d7de759bd523fa5787a2709f3a5bd85950ce8578befc490b5f9c68866517b154a371fdffd4fadfd58b942a2a7b46b2caf4425ddc758555f
|
|
7
|
+
data.tar.gz: 71c837556620b2aaf272a3236f56813f99da6ae48214b725453493b778a80e320c27a5a932ead827b3ca07b4114c96f1f971b15ad22bfc5209e7ee1516fc0f8a
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
orbs:
|
|
4
|
+
# Always take the latest version of the orb, this allows us to
|
|
5
|
+
# run specs against Solidus supported versions only without the need
|
|
6
|
+
# to change this configuration every time a Solidus version is released
|
|
7
|
+
# or goes EOL.
|
|
8
|
+
solidusio_extensions: solidusio/extensions@volatile
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
run-specs-with-postgres:
|
|
12
|
+
executor: solidusio_extensions/postgres
|
|
13
|
+
steps:
|
|
14
|
+
- solidusio_extensions/run-tests
|
|
15
|
+
run-specs-with-mysql:
|
|
16
|
+
executor: solidusio_extensions/mysql
|
|
17
|
+
steps:
|
|
18
|
+
- solidusio_extensions/run-tests
|
|
19
|
+
|
|
20
|
+
workflows:
|
|
21
|
+
"Run specs on supported Solidus versions":
|
|
22
|
+
jobs:
|
|
23
|
+
- run-specs-with-postgres
|
|
24
|
+
- run-specs-with-mysql
|
|
25
|
+
"Weekly run specs against master":
|
|
26
|
+
triggers:
|
|
27
|
+
- schedule:
|
|
28
|
+
cron: "0 0 * * 4" # every Thursday
|
|
29
|
+
filters:
|
|
30
|
+
branches:
|
|
31
|
+
only:
|
|
32
|
+
- master
|
|
33
|
+
jobs:
|
|
34
|
+
- run-specs-with-postgres
|
|
35
|
+
- run-specs-with-mysql
|
data/Gemfile
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
source
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
3
|
branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
|
|
4
|
-
gem
|
|
5
|
-
gem
|
|
4
|
+
gem 'solidus', github: 'solidusio/solidus', branch: branch
|
|
5
|
+
gem 'solidus_auth_devise'
|
|
6
6
|
|
|
7
|
-
gem '
|
|
8
|
-
gem 'mysql2'
|
|
7
|
+
gem 'rails-controller-testing', group: :test
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
case ENV['DB']
|
|
10
|
+
when 'postgres'
|
|
11
|
+
gem 'pg'
|
|
12
|
+
when 'mysql'
|
|
13
|
+
gem 'mysql2'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Needed to help Bundler figure out how to resolve dependencies, otherwise it takes forever to
|
|
17
|
+
# resolve them
|
|
18
|
+
if branch == 'master' || Gem::Version.new(branch[1..-1]) >= Gem::Version.new('2.10.0')
|
|
19
|
+
gem 'rails', '~> 6.0'
|
|
20
|
+
else
|
|
21
|
+
gem 'rails', '~> 5.0'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
group :development, :test do
|
|
11
25
|
gem 'pry-rails'
|
|
12
26
|
end
|
|
13
27
|
|
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
Solidus - Virtual Gift Card
|
|
2
2
|
===========================
|
|
3
|
+
|
|
4
|
+
[](https://circleci.com/gh/solidusio-contrib/solidus_virtual_gift_card)
|
|
5
|
+
|
|
3
6
|
A virtual gift card implementation for Solidus.
|
|
4
7
|
|
|
5
8
|
* Allows setup of virtual gift card products that get unique codes upon
|
|
@@ -7,8 +10,6 @@ A virtual gift card implementation for Solidus.
|
|
|
7
10
|
* The virtual gift card codes can be used to add store credit to a user's
|
|
8
11
|
account.
|
|
9
12
|
|
|
10
|
-
[](https://travis-ci.org/solidusio/solidus_virtual_gift_card)
|
|
11
|
-
|
|
12
13
|
Installation
|
|
13
14
|
------------
|
|
14
15
|
|
|
@@ -44,7 +45,7 @@ bundle
|
|
|
44
45
|
bundle exec rake
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
When testing your
|
|
48
|
+
When testing your application's integration with this extension you may use its
|
|
48
49
|
factories. Simply add this require statement to your spec_helper:
|
|
49
50
|
|
|
50
51
|
```ruby
|
data/Rakefile
CHANGED
|
@@ -7,9 +7,9 @@ require 'spree/testing_support/extension_rake'
|
|
|
7
7
|
RSpec::Core::RakeTask.new
|
|
8
8
|
|
|
9
9
|
task :default do
|
|
10
|
-
if Dir[
|
|
10
|
+
if Dir['spec/dummy'].empty?
|
|
11
11
|
Rake::Task[:test_app].invoke
|
|
12
|
-
Dir.chdir(
|
|
12
|
+
Dir.chdir('../../')
|
|
13
13
|
end
|
|
14
14
|
Rake::Task[:spec].invoke
|
|
15
15
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
class Spree::Admin::GiftCardsController < Spree::Admin::BaseController
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
before_action :load_user, only: [:lookup, :redeem]
|
|
3
|
+
before_action :load_gift_card_for_redemption, only: [:redeem]
|
|
4
|
+
before_action :load_gift_card_by_id, only: [:edit, :update, :send_email, :deactivate]
|
|
5
|
+
before_action :load_order, only: [:edit, :update, :deactivate]
|
|
6
6
|
|
|
7
7
|
def index
|
|
8
|
-
@search = Spree::VirtualGiftCard.purchased.
|
|
8
|
+
@search = Spree::VirtualGiftCard.purchased.ransack(params[:q])
|
|
9
9
|
@gift_cards = @search.result.page(params[:page]).per(params[:per_page])
|
|
10
10
|
end
|
|
11
11
|
|
|
@@ -16,35 +16,35 @@ class Spree::Admin::GiftCardsController < Spree::Admin::BaseController
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def update
|
|
19
|
-
if @gift_card.
|
|
20
|
-
flash[:success] =
|
|
19
|
+
if @gift_card.update(gift_card_params)
|
|
20
|
+
flash[:success] = I18n.t('spree.admin.gift_cards.gift_card_updated')
|
|
21
21
|
redirect_to edit_admin_order_path(@order)
|
|
22
22
|
else
|
|
23
|
-
flash[:error] = @gift_card.errors.full_messages.join(
|
|
23
|
+
flash[:error] = @gift_card.errors.full_messages.join(', ')
|
|
24
24
|
redirect_to :back
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def redeem
|
|
29
29
|
if @gift_card.redeem(@user)
|
|
30
|
-
flash[:success] =
|
|
30
|
+
flash[:success] = I18n.t('spree.admin.gift_cards.redeemed_gift_card')
|
|
31
31
|
redirect_to admin_user_store_credits_path(@user)
|
|
32
32
|
else
|
|
33
|
-
flash[:error] =
|
|
33
|
+
flash[:error] = I18n.t('spree.admin.gift_cards.errors.unable_to_redeem_gift_card')
|
|
34
34
|
render :lookup
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def deactivate
|
|
39
39
|
if @gift_card.deactivate
|
|
40
|
-
flash[:success] =
|
|
40
|
+
flash[:success] = I18n.t('spree.admin.gift_cards.deactivated_gift_card')
|
|
41
41
|
redirect_to edit_admin_order_path(@order)
|
|
42
42
|
else
|
|
43
|
-
flash[:error] = @gift_card.errors.full_messages.join(
|
|
43
|
+
flash[:error] = @gift_card.errors.full_messages.join(', ').presence || I18n.t('spree.admin.gift_cards.errors.unable_to_reimburse_gift_card')
|
|
44
44
|
redirect_to edit_admin_order_gift_card_path(@order, @gift_card)
|
|
45
45
|
end
|
|
46
46
|
rescue Spree::Reimbursement::IncompleteReimbursementError
|
|
47
|
-
flash[:error] =
|
|
47
|
+
flash[:error] = I18n.t('spree.admin.gift_cards.errors.unable_to_reimburse_gift_card')
|
|
48
48
|
redirect_to edit_admin_order_gift_card_path(@order, @gift_card)
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -60,7 +60,7 @@ class Spree::Admin::GiftCardsController < Spree::Admin::BaseController
|
|
|
60
60
|
@gift_card = Spree::VirtualGiftCard.active_by_redemption_code(redemption_code)
|
|
61
61
|
|
|
62
62
|
if @gift_card.blank?
|
|
63
|
-
flash[:error] =
|
|
63
|
+
flash[:error] = I18n.t('spree.admin.gift_cards.errors.not_found')
|
|
64
64
|
render :lookup
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class Spree::Api::GiftCardsController < Spree::Api::BaseController
|
|
2
2
|
|
|
3
3
|
def redeem
|
|
4
|
-
redemption_code = Spree::RedemptionCodeGenerator.format_redemption_code_for_lookup(params[:redemption_code] ||
|
|
4
|
+
redemption_code = Spree::RedemptionCodeGenerator.format_redemption_code_for_lookup(params[:redemption_code] || '')
|
|
5
5
|
@gift_card = Spree::VirtualGiftCard.active_by_redemption_code(redemption_code)
|
|
6
6
|
|
|
7
7
|
if !@gift_card
|
|
@@ -17,7 +17,7 @@ class Spree::Api::GiftCardsController < Spree::Api::BaseController
|
|
|
17
17
|
|
|
18
18
|
def redeem_fail_response
|
|
19
19
|
{
|
|
20
|
-
error_message: "#{
|
|
20
|
+
error_message: "#{I18n.t('spree.admin.gift_cards.errors.not_found')}. #{I18n.t('spree.admin.gift_cards.errors.please_try_again')}"
|
|
21
21
|
}
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SolidusVirtualGiftCard
|
|
2
|
+
module Spree
|
|
3
|
+
module InventoryUnitDecorator
|
|
4
|
+
def self.prepended(base)
|
|
5
|
+
base.class_eval do
|
|
6
|
+
has_one :gift_card, class_name: 'Spree::VirtualGiftCard'
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
::Spree::InventoryUnit.prepend self
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module SolidusVirtualGiftCard
|
|
2
|
+
module Spree
|
|
3
|
+
module LineItemDecorator
|
|
4
|
+
def self.prepended(base)
|
|
5
|
+
base.class_eval do
|
|
6
|
+
has_many :gift_cards, class_name: 'Spree::VirtualGiftCard', dependent: :destroy
|
|
7
|
+
delegate :gift_card?, :gift_card, to: :product
|
|
8
|
+
|
|
9
|
+
self.whitelisted_ransackable_associations += %w[order]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def redemption_codes
|
|
14
|
+
gift_cards.map {|gc| {amount: gc.formatted_amount, redemption_code: gc.formatted_redemption_code}}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def gift_card_details
|
|
18
|
+
gift_cards.map(&:details)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
::Spree::LineItem.prepend self
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
class GiftCardDateFormatError < StandardError; end
|
|
5
|
-
|
|
6
|
-
included do
|
|
7
|
-
prepend(InstanceMethods)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
module InstanceMethods
|
|
1
|
+
module SolidusVirtualGiftCard
|
|
2
|
+
module Spree
|
|
3
|
+
module OrderContentsDecorator
|
|
11
4
|
def add(variant, quantity = 1, options = {})
|
|
12
5
|
line_item = super
|
|
13
|
-
create_gift_cards(line_item, quantity, options[
|
|
6
|
+
create_gift_cards(line_item, quantity, options['gift_card_details'] || {})
|
|
14
7
|
line_item
|
|
15
8
|
end
|
|
16
9
|
|
|
@@ -24,7 +17,7 @@ module Spree
|
|
|
24
17
|
update_success = super(params)
|
|
25
18
|
|
|
26
19
|
if update_success && params[:line_items_attributes]
|
|
27
|
-
line_item = Spree::LineItem.find_by(id: params[:line_items_attributes][:id])
|
|
20
|
+
line_item = ::Spree::LineItem.find_by(id: params[:line_items_attributes][:id])
|
|
28
21
|
new_quantity = params[:line_items_attributes][:quantity].to_i
|
|
29
22
|
update_gift_cards(line_item, new_quantity)
|
|
30
23
|
end
|
|
@@ -37,15 +30,15 @@ module Spree
|
|
|
37
30
|
def create_gift_cards(line_item, quantity_diff, gift_card_details = {})
|
|
38
31
|
if line_item.gift_card?
|
|
39
32
|
quantity_diff.to_i.times do
|
|
40
|
-
Spree::VirtualGiftCard.create!(
|
|
33
|
+
::Spree::VirtualGiftCard.create!(
|
|
41
34
|
amount: line_item.price,
|
|
42
35
|
currency: line_item.currency,
|
|
43
36
|
line_item: line_item,
|
|
44
|
-
recipient_name: gift_card_details[
|
|
45
|
-
recipient_email: gift_card_details[
|
|
46
|
-
purchaser_name: gift_card_details[
|
|
47
|
-
gift_message: gift_card_details[
|
|
48
|
-
send_email_at: format_date(gift_card_details[
|
|
37
|
+
recipient_name: gift_card_details['recipient_name'],
|
|
38
|
+
recipient_email: gift_card_details['recipient_email'],
|
|
39
|
+
purchaser_name: gift_card_details['purchaser_name'],
|
|
40
|
+
gift_message: gift_card_details['gift_message'],
|
|
41
|
+
send_email_at: format_date(gift_card_details['send_email_at'])
|
|
49
42
|
)
|
|
50
43
|
end
|
|
51
44
|
end
|
|
@@ -75,10 +68,11 @@ module Spree
|
|
|
75
68
|
begin
|
|
76
69
|
Date.parse(date)
|
|
77
70
|
rescue ArgumentError
|
|
78
|
-
raise GiftCardDateFormatError
|
|
71
|
+
raise ::Spree::GiftCards::GiftCardDateFormatError
|
|
79
72
|
end
|
|
80
73
|
end
|
|
74
|
+
|
|
75
|
+
::Spree::OrderContents.prepend self
|
|
81
76
|
end
|
|
82
77
|
end
|
|
83
78
|
end
|
|
84
|
-
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
module
|
|
2
|
-
module
|
|
3
|
-
|
|
1
|
+
module SolidusVirtualGiftCard
|
|
2
|
+
module Spree
|
|
3
|
+
module OrderDecorator
|
|
4
|
+
def self.prepended(base)
|
|
5
|
+
base.class_eval do
|
|
6
|
+
state_machine.after_transition to: :complete, do: :send_gift_card_emails
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
has_many :gift_cards, through: :line_items
|
|
9
|
-
|
|
10
|
-
prepend(InstanceMethods)
|
|
11
|
-
end
|
|
8
|
+
has_many :gift_cards, through: :line_items
|
|
9
|
+
end
|
|
10
|
+
end
|
|
12
11
|
|
|
13
|
-
module InstanceMethods
|
|
14
12
|
def gift_card_match(line_item, options)
|
|
15
13
|
return true unless line_item.gift_card?
|
|
16
|
-
return true unless options[
|
|
14
|
+
return true unless options['gift_card_details']
|
|
17
15
|
line_item.gift_cards.any? do |gift_card|
|
|
18
|
-
gc_detail_set = gift_card.details.stringify_keys.except(
|
|
19
|
-
options_set = options[
|
|
16
|
+
gc_detail_set = gift_card.details.stringify_keys.except('send_email_at').to_set
|
|
17
|
+
options_set = options['gift_card_details'].except('send_email_at').to_set
|
|
20
18
|
gc_detail_set.superset?(options_set)
|
|
21
19
|
end
|
|
22
20
|
end
|
|
@@ -36,6 +34,8 @@ module Spree
|
|
|
36
34
|
end
|
|
37
35
|
end
|
|
38
36
|
end
|
|
37
|
+
|
|
38
|
+
::Spree::Order.prepend self
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
end
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Spree::StoreCreditCategory::GIFT_CARD_CATEGORY_NAME =
|
|
1
|
+
Spree::StoreCreditCategory::GIFT_CARD_CATEGORY_NAME = 'Gift Card'.freeze
|
|
2
2
|
Spree::StoreCreditCategory.non_expiring_credit_types |= [Spree::StoreCreditCategory::GIFT_CARD_CATEGORY_NAME]
|
|
@@ -2,8 +2,11 @@ class Spree::GiftCardMailer < Spree::BaseMailer
|
|
|
2
2
|
def gift_card_email(gift_card)
|
|
3
3
|
@gift_card = gift_card.respond_to?(:id) ? gift_card : Spree::VirtualGiftCard.find(gift_card)
|
|
4
4
|
@order = @gift_card.line_item.order
|
|
5
|
+
|
|
6
|
+
store = @order.store
|
|
5
7
|
send_to_address = @gift_card.recipient_email.presence || @order.email
|
|
6
|
-
subject = "#{
|
|
7
|
-
|
|
8
|
+
subject = "#{store} #{I18n.t('spree.gift_card_mailer.gift_card_email.subject')}"
|
|
9
|
+
|
|
10
|
+
mail(to: send_to_address, from: from_address(store), subject: subject)
|
|
8
11
|
end
|
|
9
12
|
end
|
|
File without changes
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
class Spree::VirtualGiftCard <
|
|
1
|
+
class Spree::VirtualGiftCard < Spree::Base
|
|
2
2
|
include ActionView::Helpers::NumberHelper
|
|
3
3
|
|
|
4
|
-
belongs_to :store_credit, class_name: 'Spree::StoreCredit'
|
|
5
|
-
belongs_to :purchaser, class_name: 'Spree::User'
|
|
6
|
-
belongs_to :redeemer, class_name: 'Spree::User'
|
|
7
|
-
belongs_to :line_item, class_name: 'Spree::LineItem'
|
|
8
|
-
belongs_to :inventory_unit, class_name: 'Spree::InventoryUnit'
|
|
4
|
+
belongs_to :store_credit, class_name: 'Spree::StoreCredit', optional: true
|
|
5
|
+
belongs_to :purchaser, class_name: 'Spree::User', optional: true
|
|
6
|
+
belongs_to :redeemer, class_name: 'Spree::User', optional: true
|
|
7
|
+
belongs_to :line_item, class_name: 'Spree::LineItem', optional: true
|
|
8
|
+
belongs_to :inventory_unit, class_name: 'Spree::InventoryUnit', optional: true
|
|
9
9
|
has_one :order, through: :line_item
|
|
10
10
|
|
|
11
11
|
validates :amount, numericality: { greater_than: 0 }
|
|
@@ -16,6 +16,9 @@ class Spree::VirtualGiftCard < ActiveRecord::Base
|
|
|
16
16
|
scope :by_redemption_code, -> (redemption_code) { where(redemption_code: redemption_code) }
|
|
17
17
|
scope :purchased, -> { where(redeemable: true) }
|
|
18
18
|
|
|
19
|
+
self.whitelisted_ransackable_associations = %w[line_item order]
|
|
20
|
+
self.whitelisted_ransackable_attributes = %w[redemption_code recipient_email sent_at send_email_at]
|
|
21
|
+
|
|
19
22
|
ransacker :sent_at do
|
|
20
23
|
Arel.sql('date(sent_at)')
|
|
21
24
|
end
|
|
@@ -39,15 +42,15 @@ class Spree::VirtualGiftCard < ActiveRecord::Base
|
|
|
39
42
|
action_originator: self,
|
|
40
43
|
category: store_credit_category,
|
|
41
44
|
})
|
|
42
|
-
self.
|
|
45
|
+
self.update( redeemed_at: Time.now, redeemer: redeemer )
|
|
43
46
|
end
|
|
44
47
|
|
|
45
48
|
def make_redeemable!(purchaser:, inventory_unit:)
|
|
46
|
-
|
|
49
|
+
update!(redeemable: true, purchaser: purchaser, inventory_unit: inventory_unit, redemption_code: (self.redemption_code || generate_unique_redemption_code))
|
|
47
50
|
end
|
|
48
51
|
|
|
49
52
|
def deactivate
|
|
50
|
-
|
|
53
|
+
update(redeemable: false, deactivated_at: Time.now) &&
|
|
51
54
|
cancel_and_reimburse_inventory_unit
|
|
52
55
|
end
|
|
53
56
|
|
|
@@ -73,7 +76,7 @@ class Spree::VirtualGiftCard < ActiveRecord::Base
|
|
|
73
76
|
end
|
|
74
77
|
|
|
75
78
|
def formatted_redemption_code
|
|
76
|
-
redemption_code.present? ? redemption_code.scan(/.{4}/).join('-') :
|
|
79
|
+
redemption_code.present? ? redemption_code.scan(/.{4}/).join('-') : ''
|
|
77
80
|
end
|
|
78
81
|
|
|
79
82
|
def formatted_amount
|
|
@@ -81,23 +84,23 @@ class Spree::VirtualGiftCard < ActiveRecord::Base
|
|
|
81
84
|
end
|
|
82
85
|
|
|
83
86
|
def formatted_send_email_at
|
|
84
|
-
send_email_at.strftime(
|
|
87
|
+
send_email_at.strftime('%-m/%-d/%y') if send_email_at
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
def formatted_sent_at
|
|
88
|
-
sent_at.strftime(
|
|
91
|
+
sent_at.strftime('%-m/%-d/%y') if sent_at
|
|
89
92
|
end
|
|
90
93
|
|
|
91
94
|
def formatted_created_at
|
|
92
|
-
created_at.localtime.strftime(
|
|
95
|
+
created_at.localtime.strftime('%F %I:%M%p')
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
def formatted_redeemed_at
|
|
96
|
-
redeemed_at.localtime.strftime(
|
|
99
|
+
redeemed_at.localtime.strftime('%F %I:%M%p') if redeemed_at
|
|
97
100
|
end
|
|
98
101
|
|
|
99
102
|
def formatted_deactivated_at
|
|
100
|
-
deactivated_at.localtime.strftime(
|
|
103
|
+
deactivated_at.localtime.strftime('%F %I:%M%p') if deactivated_at
|
|
101
104
|
end
|
|
102
105
|
|
|
103
106
|
def store_credit_category
|
|
@@ -110,7 +113,7 @@ class Spree::VirtualGiftCard < ActiveRecord::Base
|
|
|
110
113
|
|
|
111
114
|
def send_email
|
|
112
115
|
Spree::GiftCardMailer.gift_card_email(self).deliver_later
|
|
113
|
-
|
|
116
|
+
update!(sent_at: DateTime.now)
|
|
114
117
|
end
|
|
115
118
|
|
|
116
119
|
private
|