ba_spree_loyalty_points 1.0.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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +26 -0
  3. data/README.md +77 -0
  4. data/app/assets/javascripts/spree/backend/spree_loyalty_points.js +81 -0
  5. data/app/assets/javascripts/spree/frontend/spree_loyalty_points.js +0 -0
  6. data/app/assets/stylesheets/spree/backend/spree_loyalty_points.css +0 -0
  7. data/app/assets/stylesheets/spree/frontend/spree_loyalty_points.css +10 -0
  8. data/app/controllers/spree/admin/loyalty_points_transactions_controller.rb +70 -0
  9. data/app/controllers/spree/admin/resource_controller_decorator.rb +25 -0
  10. data/app/controllers/spree/admin/return_authorizations_controller_decorator.rb +19 -0
  11. data/app/controllers/spree/checkout_controller_decorator.rb +21 -0
  12. data/app/controllers/spree/loyalty_points_controller.rb +11 -0
  13. data/app/models/concerns/spree/loyalty_points.rb +22 -0
  14. data/app/models/concerns/spree/order/loyalty_points.rb +55 -0
  15. data/app/models/concerns/spree/payment/loyalty_points.rb +48 -0
  16. data/app/models/concerns/spree/transactions_total_validation.rb +25 -0
  17. data/app/models/spree/loyalty_points_credit_transaction.rb +18 -0
  18. data/app/models/spree/loyalty_points_debit_transaction.rb +18 -0
  19. data/app/models/spree/loyalty_points_transaction.rb +42 -0
  20. data/app/models/spree/order_decorator.rb +33 -0
  21. data/app/models/spree/payment_decorator.rb +38 -0
  22. data/app/models/spree/payment_method/loyalty_points.rb +37 -0
  23. data/app/models/spree/payment_method_decorator.rb +16 -0
  24. data/app/models/spree/return_authorization_decorator.rb +29 -0
  25. data/app/models/spree/store_decorator.rb +23 -0
  26. data/app/overrides/add_condition_to_amount_on_return_authorization_page.rb +8 -0
  27. data/app/overrides/add_loyalty_points_balance_to_account_page.rb +9 -0
  28. data/app/overrides/add_loyalty_points_debiting_to_return_authorization_page.rb +28 -0
  29. data/app/overrides/add_loyalty_points_to_admin_user_show_page.rb +15 -0
  30. data/app/overrides/add_loyalty_points_to_cart_page.rb +8 -0
  31. data/app/overrides/add_loyalty_points_to_order_checkout_page.rb +12 -0
  32. data/app/overrides/add_loyalty_points_to_return_authorization_index_page.rb +13 -0
  33. data/app/overrides/add_loyalty_points_transaction_table_to_return_authorization_form.rb +6 -0
  34. data/app/overrides/spree/admin/stores/add_loyalty_points_settings.rb +6 -0
  35. data/app/views/spree/admin/loyalty_points_transactions/index.html.erb +12 -0
  36. data/app/views/spree/admin/loyalty_points_transactions/new.html.erb +62 -0
  37. data/app/views/spree/admin/loyalty_points_transactions/order_transactions.rabl +5 -0
  38. data/app/views/spree/admin/payments/source_forms/_loyaltypoints.html.erb +0 -0
  39. data/app/views/spree/admin/payments/source_views/_loyaltypoints.html.erb +0 -0
  40. data/app/views/spree/admin/stores/_loyalty_points_settings.html.erb +45 -0
  41. data/app/views/spree/checkout/payment/_loyaltypoints.html.erb +8 -0
  42. data/app/views/spree/loyalty_points/_transaction_table.html.erb +44 -0
  43. data/app/views/spree/loyalty_points/index.html.erb +4 -0
  44. data/config/initializers/spree_permitted_attributes.rb +13 -0
  45. data/config/locales/en.yml +27 -0
  46. data/config/locales/ja.yml +27 -0
  47. data/config/routes.rb +14 -0
  48. data/db/migrate/20140116090042_add_loyalty_points_balance_to_spree_user.rb +6 -0
  49. data/db/migrate/20140116110437_create_loyalty_points_transactions.rb +10 -0
  50. data/db/migrate/20140117062720_add_timestamps_to_loyalty_points_transaction.rb +7 -0
  51. data/db/migrate/20140117065314_add_fields_to_spree_loyalty_points_transaction.rb +7 -0
  52. data/db/migrate/20140122084005_add_comment_to_spree_loyalty_points_transaction.rb +5 -0
  53. data/db/migrate/20140123092709_add_paid_at_to_spree_order.rb +5 -0
  54. data/db/migrate/20140123120355_add_loyalty_points_to_spree_return_authorization.rb +6 -0
  55. data/db/migrate/20140124121728_add_loyalty_points_awarded_to_spree_order.rb +5 -0
  56. data/db/migrate/20140130131957_rename_fields_in_spree_loyalty_points_transaction.rb +6 -0
  57. data/db/migrate/20140131072702_remove_loyalty_points_awarded_from_spree_order.rb +5 -0
  58. data/db/migrate/20140203063433_add_indexing_to_spree_loyalty_points_transaction.rb +7 -0
  59. data/db/migrate/20140205111553_add_transaction_id_to_spree_loyalty_points_transactions.rb +5 -0
  60. data/db/migrate/20140207055836_add_lock_version_to_spree_user.rb +6 -0
  61. data/lib/ba_spree_loyalty_points.rb +2 -0
  62. data/lib/generators/spree_loyalty_points/install/install_generator.rb +31 -0
  63. data/lib/spree_loyalty_points/engine.rb +55 -0
  64. data/lib/spree_loyalty_points/factories.rb +84 -0
  65. data/lib/spree_loyalty_points/version.rb +3 -0
  66. data/lib/tasks/loyalty_points/award.rake +8 -0
  67. metadata +320 -0
@@ -0,0 +1,37 @@
1
+ module Spree
2
+ class PaymentMethod::LoyaltyPoints < PaymentMethod
3
+ def actions
4
+ %w{capture void}
5
+ end
6
+
7
+ def can_void?(payment)
8
+ payment.state != 'void'
9
+ end
10
+
11
+ def can_capture?(payment)
12
+ ['checkout', 'pending'].include?(payment.state)
13
+ end
14
+
15
+ def capture(payment, source, gateway)
16
+ ActiveMerchant::Billing::Response.new(true, "", {}, {})
17
+ end
18
+
19
+ def void(source, gateway)
20
+ ActiveMerchant::Billing::Response.new(true, "", {}, {})
21
+ end
22
+
23
+ def source_required?
24
+ false
25
+ end
26
+
27
+ def cancel(*args)
28
+ ActiveMerchant::Billing::Response.new(true, "", {}, {})
29
+ end
30
+
31
+ def credit(credit_cents, transaction_id, options={})
32
+ loyalty_points = options[:originator].reimbursement.return_items.last.return_authorization.loyalty_points
33
+ options[:originator].payment.order.create_credit_transaction(loyalty_points)
34
+ ActiveMerchant::Billing::Response.new(true, "", {}, {})
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ module PaymentMethodDecorator
3
+ def self.prepended(base)
4
+ base.scope :loyalty_points_type, -> { where(type: 'Spree::PaymentMethod::LoyaltyPoints') }
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def loyalty_points_id_included?(method_ids)
10
+ loyalty_points_type.where(id: method_ids).size != 0
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ Spree::PaymentMethod.prepend(Spree::PaymentMethodDecorator)
@@ -0,0 +1,29 @@
1
+ module Spree
2
+ module ReturnAuthorizationDecorator
3
+ def self.prepended(base)
4
+ base.include Spree::TransactionsTotalValidation
5
+ base.validate :transactions_total_range, if: -> { order.present? && order.loyalty_points_transactions.present? }
6
+
7
+ # State machine modification
8
+ base.state_machine.after_transition to: :received, do: :update_loyalty_points
9
+ end
10
+
11
+ def update_loyalty_points
12
+ if loyalty_points_transaction_type == "Debit"
13
+ loyalty_points_debit_quantity = [order.user.loyalty_points_balance, order.loyalty_points_for(order.item_total), loyalty_points].min
14
+ order.create_debit_transaction(loyalty_points_debit_quantity)
15
+ else
16
+ loyalty_points_credit_quantity = [order.loyalty_points_for(order.total), loyalty_points].min
17
+ order.create_credit_transaction(loyalty_points_credit_quantity)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def transactions_total_range
24
+ validate_transactions_total_range(loyalty_points_transaction_type, order)
25
+ end
26
+ end
27
+ end
28
+
29
+ Spree::ReturnAuthorization.prepend(Spree::ReturnAuthorizationDecorator)
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ module StoreDecorator
3
+ def self.prepended(base)
4
+ existing_settings = base.typed_stores[:settings]&.fields || {}
5
+ base.typed_store :settings, coder: ActiveRecord::TypedStore::IdentityCoder do |s|
6
+ existing_settings.each do |name, field|
7
+ s.send(field.type_sym, name, **field.instance_variables.each_with_object({}) { |var, hash|
8
+ hash[var.to_s.delete("@").to_sym] = field.instance_variable_get(var) unless var == :@type
9
+ })
10
+ end
11
+ unless existing_settings.key?(:loyalty_points_awarding_unit)
12
+ s.decimal :loyalty_points_awarding_unit, default: 0.01, null: false
13
+ s.decimal :loyalty_points_redeeming_balance, default: 0.0, null: false
14
+ s.decimal :loyalty_points_conversion_rate, default: 1.0, null: false
15
+ s.integer :loyalty_points_award_period, default: 12, null: false
16
+ s.decimal :min_amount_required_to_get_loyalty_points, default: 0.0, null: false
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ Spree::Store.prepend Spree::StoreDecorator
@@ -0,0 +1,8 @@
1
+ Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
2
+ name: 'surround_amount_with_condition_in_return_authorization_form',
3
+ surround: "erb[loud]:contains('field_container :amount')",
4
+ text: "
5
+ <% if !@return_authorization.order.loyalty_points_used? %>
6
+ <%= render_original %>
7
+ <% end %>
8
+ ")
@@ -0,0 +1,9 @@
1
+ Deface::Override.new(virtual_path: 'spree/users/show',
2
+ name: 'add_loyalty_points_balance_to_account_page',
3
+ insert_after: ".account-page-user-info-item-store-credits",
4
+ text: "
5
+ <dl id='loyalty-points-info'>
6
+ <dt><%= Spree.t(:loyalty_points_balance) %></dt>
7
+ <dd><%= @user.loyalty_points_balance %> (<%= link_to Spree.t(:details), spree.loyalty_points_path %>)</dd>
8
+ </dl>
9
+ ")
@@ -0,0 +1,28 @@
1
+ Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
2
+ name: 'add_loyalty_points_to_return_authorization_page',
3
+ insert_before: "erb[loud]:contains('field_container :reason')",
4
+ text: "
5
+ <% if !@order.loyalty_points_used? && @order.eligible_for_loyalty_points?(@order.item_total) %>
6
+ <%= f.field_container :loyalty_points do %>
7
+ <%= label :loyalty_points, Spree.t(:loyalty_points_debit) %> <span class='required'>*</span><br />
8
+ <% if @return_authorization.received? %>
9
+ <%= @return_authorization.loyalty_points %> points Debited <br />
10
+ <% else %>
11
+ <%= f.text_field :loyalty_points, {style: 'width:80px;'} %>
12
+ <%= f.hidden_field :loyalty_points_transaction_type, { value: :Debit } %>
13
+ <br /> User's Loyalty Points Balance: <%= @order.user.loyalty_points_balance %> <br /> Net Loyalty Points Credited for this Order: <%= @order.loyalty_points_total %>
14
+ <% end %>
15
+ <% end %>
16
+ <% elsif @order.loyalty_points_used? %>
17
+ <%= f.field_container :loyalty_points do %>
18
+ <br /><%= label :loyalty_points, Spree.t(:loyalty_points_credit) %> <span class='required'>*</span><br />
19
+ <% if @return_authorization.received? %>
20
+ <%= @return_authorization.loyalty_points %> points Credited <br />
21
+ <% else %>
22
+ <%= f.text_field :loyalty_points, {style: 'width:80px;'} %>
23
+ <%= f.hidden_field :loyalty_points_transaction_type, { value: :Credit } %>
24
+ <br /> User's Loyalty Points Balance: <%= @order.user.loyalty_points_balance %> <br /> Net Loyalty Points Debited for this Order: <%= -@order.loyalty_points_total %>
25
+ <% end %>
26
+ <% end %>
27
+ <% end %>
28
+ ")
@@ -0,0 +1,15 @@
1
+ Deface::Override.new(virtual_path: 'spree/admin/users/edit',
2
+ name: 'add_loyalty_points_to_admin_user_show_page',
3
+ insert_after: "[data-hook=admin_user_edit_general_settings]",
4
+ text: "
5
+ <div class='panel panel-default' data-hook='loyalty-points'>
6
+ <div class=panel-heading><%= Spree.t(:loyalty_points_balance) %></div>
7
+ <div class=panel-body>
8
+ <% if @user.loyalty_points_balance.present? %>
9
+ <%= link_to @user.loyalty_points_balance, spree.admin_user_loyalty_points_path(@user) %>
10
+ <% else %>
11
+ <%= 'No loyalty points yet' %>
12
+ <% end %
13
+ </div>
14
+ </div>
15
+ ")
@@ -0,0 +1,8 @@
1
+ Deface::Override.new(virtual_path: 'spree/orders/edit',
2
+ name: 'add_loyalty_points_to_cart_page',
3
+ insert_before: ".shopping-cart-buttons",
4
+ text: "
5
+ <% if @order.loyalty_points_for(@order.item_total) > 0 %>
6
+ <h5><%= Spree.t(:loyalty_points_earnable, quantity: \"<span class='order-total'> \#{@order.loyalty_points_for(@order.item_total)}</span>\").html_safe %></h5>
7
+ <% end %>
8
+ ")
@@ -0,0 +1,12 @@
1
+ Deface::Override.new(virtual_path: 'spree/shared/_order_details',
2
+ name: 'add_loyalty_points_to_order_checkout_page',
3
+ insert_after: "#checkout-summary",
4
+ text: "
5
+ <div class='mt-5'>
6
+ <% if @order.loyalty_points_awarded? %>
7
+ <span><%= @order.loyalty_points_for(@order.item_total) %></span> <b><%= Spree.t(:loyalty_points) %> have been credited to your account.</b>
8
+ <% else %>
9
+ <span><%= @order.loyalty_points_for(@order.item_total) %></span> <b><%= Spree.t(:loyalty_points) %> will be credited to your account soon.</b>
10
+ <% end %>
11
+ </div>
12
+ ")
@@ -0,0 +1,13 @@
1
+ Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/index',
2
+ name: 'add_loyalty_points_to_return_authorization_index_page_head',
3
+ insert_after: "thead[data-hook='rma_header'] th:contains('amount')",
4
+ text: "
5
+ <th><%= Spree.t(:loyalty_points) %></th>
6
+ ")
7
+
8
+ Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/index',
9
+ name: 'add_loyalty_points_to_return_authorization_index_page_row',
10
+ insert_after: "tr[data-hook='rma_row'] td:contains('display_amount')",
11
+ text: "
12
+ <td><%= return_authorization.loyalty_points %> pts <%= return_authorization.loyalty_points_transaction_type %></td>
13
+ ")
@@ -0,0 +1,6 @@
1
+ Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
2
+ name: 'add_loyalty_points_transaction_table_to_return_authorization_form',
3
+ insert_after: "div[data-hook='admin_return_authorization_form_fields']",
4
+ text: "
5
+ <%= render partial: 'spree/loyalty_points/transaction_table' %>
6
+ ")
@@ -0,0 +1,6 @@
1
+ Deface::Override.new(
2
+ virtual_path: "spree/admin/stores/_form",
3
+ name: "add_loyalty_points_settings",
4
+ insert_bottom: "[data-hook='admin_store_form_fields']",
5
+ partial: "spree/admin/stores/loyalty_points_settings"
6
+ )
@@ -0,0 +1,12 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:loyalty_points) %>
3
+ <% end %>
4
+
5
+ <% content_for :page_actions do %>
6
+ <%= button_link_to Spree.t(:back_to_user_profile), :back, icon: 'chevron-left', class: 'btn-primary', id: 'admin_user_link' %>
7
+ <%= button_link_to Spree.t(:update_loyalty_points), spree.new_admin_user_loyalty_point_path(@user), icon: 'plus', class: 'btn-primary', id: 'admin_user_new_loyalty_point_link' %>
8
+ <% end %>
9
+
10
+ <p>Current Balance: <%= @user.loyalty_points_balance %></p>
11
+ <%= render partial: 'spree/loyalty_points/transaction_table' %>
12
+ <br />
@@ -0,0 +1,62 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:loyalty_points) %>
3
+ <% end %>
4
+
5
+ <% content_for :page_actions do %>
6
+ <%= button_link_to Spree.t(:back_to_users_list), spree.admin_users_path, class: 'btn btn-primary', icon: 'chevron-left' %>
7
+ <% end %>
8
+
9
+ <%= render partial: 'spree/shared/error_messages', locals: { target: @loyalty_points_transaction.user } %>
10
+ <%= render partial: 'spree/shared/error_messages', locals: { target: @loyalty_points_transaction } %>
11
+
12
+ <div id='loyalty-points-order-transactions'></div>
13
+
14
+ <%= form_for @loyalty_points_transaction, as: :loyalty_points_transaction, url: spree.admin_user_loyalty_points_path(@user), class: 'form' do |f| %>
15
+ <fieldset data-hook="update_loyalty_points">
16
+
17
+ <legend align="center"><%= Spree.t(:update_loyalty_points) %></legend>
18
+
19
+ <div data-hook="update_loyalty_points_attrs" class="row">
20
+
21
+ <div class="col-md-4 form-group">
22
+ <%= f.field_container :loyalty_points do %>
23
+ <%= f.label :loyalty_points, Spree.t(:loyalty_points) %> <span class="required">*</span><br />
24
+ <%= f.text_field :loyalty_points, class: 'fullwidth title form-control' %>
25
+ <%= f.error_message_on :loyalty_points %>
26
+ <% end %>
27
+ </div>
28
+
29
+ <div class="field col-md-4">
30
+ <%= f.label :type, Spree.t(:transaction_type) %> <span class="required">*</span><br />
31
+ <%= f.select :type, options_for_select(Spree::LoyaltyPointsTransaction::CLASS_TO_TRANSACTION_TYPE.invert), {}, class: 'select2 fullwidth' %>
32
+ <%= f.error_message_on :type %>
33
+ </div>
34
+
35
+ <div class="field col-md-4">
36
+ <%= label_tag nil, Spree.t(:order) %>
37
+ <%= f.select :source_id, @user.orders.collect {|o| [o.number, o.id]}, {include_blank: true}, class: 'select2 fullwidth', :"data-transactions-link" => spree.admin_user_loyalty_points_path(@user) %>
38
+ <%= f.hidden_field :source_type, { value: 'Spree::Order' } %>
39
+ </div>
40
+
41
+ </div>
42
+
43
+ <div data-hook="comment_row" class="row">
44
+
45
+ <div class="col-md-4 form-group">
46
+ <%= f.field_container :comment do %>
47
+ <%= f.label :comment, Spree.t(:comment) %> <span class="required">*</span><br />
48
+ <%= f.text_area :comment, class: 'fullwidth form-control', rows: '3' %>
49
+ <%= f.error_message_on :comment %>
50
+ <% end %>
51
+ </div>
52
+
53
+ </div>
54
+
55
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
56
+ <%= button Spree.t('actions.update'), 'ok' %>
57
+ <span class="or"><%= Spree.t(:or) %></span>
58
+ <%= link_to_with_icon 'remove', Spree.t('actions.cancel'), spree.admin_users_path, class: 'btn btn-primary' %>
59
+ </div>
60
+
61
+ </fieldset>
62
+ <% end %>
@@ -0,0 +1,5 @@
1
+ collection(@loyalty_points_transactions)
2
+ attributes :source_type, :comment, :updated_at, :loyalty_points, :balance, :transaction_type
3
+ child source: :source do
4
+ attributes :id, :number
5
+ end
@@ -0,0 +1,45 @@
1
+ <div class="card mb-4">
2
+ <div class="card-header">
3
+ <h5 class="card-title mb-0 h6">
4
+ <%= Spree.t('admin.store.loyalty_points_settings') %>
5
+ </h5>
6
+ </div>
7
+ <div class="card-body">
8
+ <div class="row">
9
+ <div class="col-12 col-md-6">
10
+ <%= f.field_container :loyalty_points_awarding_unit do %>
11
+ <%= f.label :loyalty_points_awarding_unit, Spree.t('admin.store.loyalty_points_awarding_unit') %>
12
+ <%= f.number_field :loyalty_points_awarding_unit, class: 'form-control', min: 0, step: 0.01 %>
13
+ <% end %>
14
+ </div>
15
+ <div class="col-12 col-md-6">
16
+ <%= f.field_container :loyalty_points_redeeming_balance do %>
17
+ <%= f.label :loyalty_points_redeeming_balance, Spree.t('admin.store.loyalty_points_redeeming_balance') %>
18
+ <%= f.number_field :loyalty_points_redeeming_balance, class: 'form-control', min: 0, step: 0.01 %>
19
+ <% end %>
20
+ </div>
21
+ </div>
22
+ <div class="row mt-3">
23
+ <div class="col-12 col-md-6">
24
+ <%= f.field_container :loyalty_points_conversion_rate do %>
25
+ <%= f.label :loyalty_points_conversion_rate, Spree.t('admin.store.loyalty_points_conversion_rate') %>
26
+ <%= f.number_field :loyalty_points_conversion_rate, class: 'form-control', min: 0, step: 0.01 %>
27
+ <% end %>
28
+ </div>
29
+ <div class="col-12 col-md-6">
30
+ <%= f.field_container :loyalty_points_award_period do %>
31
+ <%= f.label :loyalty_points_award_period, Spree.t('admin.store.loyalty_points_award_period') %>
32
+ <%= f.number_field :loyalty_points_award_period, class: 'form-control', min: 0 %>
33
+ <% end %>
34
+ </div>
35
+ </div>
36
+ <div class="row mt-3">
37
+ <div class="col-12">
38
+ <%= f.field_container :min_amount_required_to_get_loyalty_points do %>
39
+ <%= f.label :min_amount_required_to_get_loyalty_points, Spree.t('admin.store.min_amount_required_to_get_loyalty_points') %>
40
+ <%= f.number_field :min_amount_required_to_get_loyalty_points, class: 'form-control', min: 0, step: 0.01 %>
41
+ <% end %>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </div>
@@ -0,0 +1,8 @@
1
+ <%- lp_balance = spree_current_user.loyalty_points_balance %>
2
+ <%- equivalent_currency_balance = spree_current_user.loyalty_points_equivalent_currency %>
3
+ Loyalty Points Balance: <%= lp_balance %><%= "($" + equivalent_currency_balance.to_s + ")" %>
4
+ <%- lp_needed = @order.loyalty_points_for(@order.total, 'redeem') %>
5
+ <br/>Loyalty Points Needed: <%= lp_needed %>
6
+ <% if lp_needed > lp_balance %>
7
+ <br/><b>Insufficient Balance!</b>
8
+ <% end %>
@@ -0,0 +1,44 @@
1
+ <%= paginate @loyalty_points_transactions %>
2
+
3
+ <% if @loyalty_points_transactions.present? %>
4
+ <table class="loyalty-points-summary table table-striped table-hover">
5
+ <thead class="thead-inverse">
6
+ <tr>
7
+ <th class="loyalty-points-date"><%= Spree.t(:date) %></th>
8
+ <th class="loyalty-points-source"><%= Spree.t(:source) %></th>
9
+ <th class="loyalty-points-source-id"><%= Spree.t(:source_reference) %></th>
10
+ <th class="loyalty-points-comment"><%= Spree.t(:comment) %></th>
11
+ <th class="loyalty-points-type"><%= Spree.t(:transaction_type) %></th>
12
+ <th class="loyalty-points"><%= Spree.t(:loyalty_points) %></th>
13
+ <th class="loyalty-points-balance"><%= Spree.t(:updated_balance) %></th>
14
+ </tr>
15
+ </thead>
16
+ <tbody>
17
+ <% @loyalty_points_transactions.each do |loyalty_point_transaction| %>
18
+ <tr class="<%= cycle('even', 'odd') %>">
19
+ <td class="loyalty-points-date"><%= pretty_time(loyalty_point_transaction.updated_at) %></td>
20
+ <% if loyalty_point_transaction.source.present? %>
21
+ <% transaction_source = loyalty_point_transaction.source_type.gsub('Spree::','') -%>
22
+ <td class="loyalty-points-source"><%= transaction_source %></td>
23
+ <% if transaction_source == "Order" %>
24
+ <td class="loyalty-points-source-id"><%= link_to loyalty_point_transaction.source.number, spree.order_path(loyalty_point_transaction.source) %></td>
25
+ <% else %>
26
+ <td class="loyalty-points-source-id"><%= loyalty_point_transaction.source_id %></td>
27
+ <% end %>
28
+ <% else %>
29
+ <td class="loyalty-points-source"></td>
30
+ <td class="loyalty-points-source-id"></td>
31
+ <% end %>
32
+ <td class="loyalty-points-comment"><%= loyalty_point_transaction.comment %></td>
33
+ <td class="loyalty-points-type"><%= loyalty_point_transaction.transaction_type %></td>
34
+ <td class="loyalty-points"><%= loyalty_point_transaction.loyalty_points %></td>
35
+ <td class="loyalty-points-balance"><%= loyalty_point_transaction.balance %></td>
36
+ </tr>
37
+ <% end %>
38
+ </tbody>
39
+ </table>
40
+ <% else %>
41
+ <p><%= Spree.t(:you_have_not_earned_any_loyalty_points_yet) %></p>
42
+ <% end %>
43
+
44
+ <%= paginate @loyalty_points_transactions %>
@@ -0,0 +1,4 @@
1
+ <h3><%= Spree.t(:loyalty_points) %></h3>
2
+ <p>Current Balance: <%= spree_current_user.loyalty_points_balance %></p>
3
+ <%= render partial: 'spree/loyalty_points/transaction_table' %>
4
+ <br />
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module PermittedAttributes
3
+ mattr_accessor :store_attributes
4
+
5
+ @@store_attributes += [
6
+ :loyalty_points_awarding_unit,
7
+ :loyalty_points_redeeming_balance,
8
+ :loyalty_points_conversion_rate,
9
+ :loyalty_points_award_period,
10
+ :min_amount_required_to_get_loyalty_points
11
+ ]
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ spree:
6
+ loyalty_points_balance: Loyalty Points Balance
7
+ loyalty_points: Loyalty Points
8
+ loyalty_points_debit: Loyalty Points To Be Deducted Against this Return
9
+ loyalty_points_credit: Loyalty Points To Be Awarded Against this Return
10
+ details: Details
11
+ min_amount_required_to_get_loyalty_points: "Minimum amount to be spent per order(item total, excluding shipping and any other charges) to award loyalty points."
12
+ loyalty_points_awarding_unit: "Number of Loyalty Points to be awarded per Unit Amount Spent"
13
+ loyalty_points_redeeming_balance: Minimum Loyalty Points Balance Required for Redeeming
14
+ loyalty_points_conversion_rate: "Loyalty point to amount conversion rate"
15
+ loyalty_points_award_period: Time(in hours) after payment to award loyalty points
16
+ back_to_user_profile: Back to User Profile
17
+ update_loyalty_points: Update Loyalty Points
18
+ loyalty_points_earnable: "%{quantity} Loyalty Points Will Be Awarded for this Order"
19
+ insufficient_loyalty_points: 'You have insufficient Loyalty Points'
20
+ admin:
21
+ store:
22
+ loyalty_points_settings: "Loyalty Points Settings"
23
+ loyalty_points_awarding_unit: "Points Awarding Unit"
24
+ loyalty_points_redeeming_balance: "Minimum Redeemable Balance"
25
+ loyalty_points_conversion_rate: "Points to Currency Conversion Rate"
26
+ loyalty_points_award_period: "Points Award Period (days)"
27
+ min_amount_required_to_get_loyalty_points: "Minimum Purchase Amount for Points"
@@ -0,0 +1,27 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ jp:
5
+ spree:
6
+ loyalty_points_balance: 保有ポイント
7
+ loyalty_points: ポイント
8
+ loyalty_points_debit: ポイント利用
9
+ loyalty_points_credit: ポイント付与
10
+ details: 詳細
11
+ min_amount_required_to_get_loyalty_points: "1回の注文でポイントを獲得するために必要な最低金額(商品価格のみ。配送料やその他の手数料は除く)"
12
+ loyalty_points_awarding_unit: "1ポイントが付与される購入金額"
13
+ loyalty_points_redeeming_balance: ポイントを利用するために必要な最低ポイント数
14
+ loyalty_points_conversion_rate: "ポイントを金額に換算する比率"
15
+ loyalty_points_award_period: 支払い後ポイントが付与されるまでの時間
16
+ back_to_user_profile: マイページに戻る
17
+ update_loyalty_points: ポイントを更新する
18
+ loyalty_points_earnable: "本注文に対して%{quantity}ポイントが付与されます"
19
+ insufficient_loyalty_points: 'ポイントが不足しています'
20
+ admin:
21
+ store:
22
+ loyalty_points_settings: "ポイント設定"
23
+ loyalty_points_awarding_unit: "1ポイントが付与される購入金額"
24
+ loyalty_points_redeeming_balance: "ポイント利用に必要な最小保有ポイント"
25
+ loyalty_points_conversion_rate: "ポイントを金額に換算する比率"
26
+ loyalty_points_award_period: "支払い後ポイントが付与されるまでの時間"
27
+ min_amount_required_to_get_loyalty_points: "ポイント付与に必要な最低注文金額"
data/config/routes.rb ADDED
@@ -0,0 +1,14 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ # Add your extension routes here
3
+
4
+ resources :loyalty_points, only: [:index]
5
+
6
+ namespace :admin do
7
+ resources :users do
8
+ resources :loyalty_points, only: [:index, :new, :create], controller: 'loyalty_points_transactions' do
9
+ get 'order_transactions/:order_id', action: :order_transactions, on: :collection
10
+ end
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,6 @@
1
+ class AddLoyaltyPointsBalanceToSpreeUser < ActiveRecord::Migration[7.1]
2
+ def change
3
+ users_table_name = Spree.user_class.present? ? Spree.user_class.table_name : :spree_users
4
+ add_column users_table_name, :loyalty_points_balance, :integer, default: 0, null: false
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class CreateLoyaltyPointsTransactions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :spree_loyalty_points_transactions do |t|
4
+ t.integer :loyalty_points
5
+ t.string :transaction_type
6
+ t.integer :user_id, null: false
7
+ t.integer :order_id
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ class AddTimestampsToLoyaltyPointsTransaction < ActiveRecord::Migration[7.1]
2
+ def change
3
+ change_table :spree_loyalty_points_transactions do |t|
4
+ t.timestamps
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddFieldsToSpreeLoyaltyPointsTransaction < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :spree_loyalty_points_transactions, :source_type, :string
4
+ rename_column :spree_loyalty_points_transactions, :order_id, :source_id
5
+ add_column :spree_loyalty_points_transactions, :updated_balance, :integer, default: 0, null: false
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddCommentToSpreeLoyaltyPointsTransaction < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :spree_loyalty_points_transactions, :comment, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddPaidAtToSpreeOrder < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :spree_orders, :paid_at, :datetime
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddLoyaltyPointsToSpreeReturnAuthorization < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :spree_return_authorizations, :loyalty_points, :integer, default: 0, null: false
4
+ add_column :spree_return_authorizations, :loyalty_points_transaction_type, :string
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddLoyaltyPointsAwardedToSpreeOrder < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :spree_orders, :loyalty_points_awarded, :boolean, default: false, null: false
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class RenameFieldsInSpreeLoyaltyPointsTransaction < ActiveRecord::Migration[7.1]
2
+ def change
3
+ rename_column :spree_loyalty_points_transactions, :updated_balance, :balance
4
+ rename_column :spree_loyalty_points_transactions, :transaction_type, :type
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveLoyaltyPointsAwardedFromSpreeOrder < ActiveRecord::Migration[7.1]
2
+ def change
3
+ remove_column :spree_orders, :loyalty_points_awarded, :boolean, default: false, null: false
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class AddIndexingToSpreeLoyaltyPointsTransaction < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_index :spree_loyalty_points_transactions, [:source_type, :source_id], name: 'by_source'
4
+ add_index :spree_loyalty_points_transactions, :user_id
5
+ add_index :spree_loyalty_points_transactions, :type
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddTransactionIdToSpreeLoyaltyPointsTransactions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :spree_loyalty_points_transactions, :transaction_id, :string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddLockVersionToSpreeUser < ActiveRecord::Migration[7.1]
2
+ def change
3
+ users_table_name = Spree.user_class.present? ? Spree.user_class.table_name : :spree_users
4
+ add_column users_table_name, :lock_version, :integer, default: 0, null: false unless column_exists?(users_table_name, :lock_version)
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ require 'spree_core'
2
+ require 'spree_loyalty_points/engine'