ba_spree_loyalty_points 1.0.0 → 1.0.2

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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +688 -1
  3. data/README.md +1 -1
  4. data/app/controllers/spree/admin/loyalty_points_transactions_controller.rb +5 -1
  5. data/app/controllers/spree/admin/resource_controller_decorator.rb +4 -0
  6. data/app/controllers/spree/admin/return_authorizations_controller_decorator.rb +10 -2
  7. data/app/controllers/spree/loyalty_points_controller.rb +1 -1
  8. data/app/controllers/{spree → spree_loyalty_points}/checkout_controller_decorator.rb +5 -3
  9. data/app/models/concerns/spree/loyalty_points.rb +3 -3
  10. data/app/models/concerns/spree/order/loyalty_points.rb +1 -1
  11. data/app/models/concerns/spree/payment/loyalty_points.rb +27 -27
  12. data/app/models/spree/loyalty_points_transaction.rb +12 -1
  13. data/app/models/{spree → spree_loyalty_points}/order_decorator.rb +2 -2
  14. data/app/models/{spree → spree_loyalty_points}/payment_decorator.rb +5 -2
  15. data/app/models/{spree → spree_loyalty_points}/payment_method_decorator.rb +2 -2
  16. data/app/models/spree_loyalty_points/store_decorator.rb +13 -0
  17. data/app/overrides/add_loyalty_points_debiting_to_return_authorization_page.rb +6 -6
  18. data/app/overrides/add_loyalty_points_to_account_nav.rb +13 -0
  19. data/app/overrides/add_loyalty_points_to_admin_user_show_page.rb +12 -10
  20. data/app/overrides/add_loyalty_points_to_cart_page.rb +9 -5
  21. data/app/overrides/add_loyalty_points_to_order_checkout_page.rb +11 -7
  22. data/app/overrides/add_loyalty_points_to_return_authorization_index_page.rb +24 -10
  23. data/app/overrides/add_loyalty_points_transaction_table_to_return_authorization_form.rb +13 -3
  24. data/app/overrides/spree/admin/stores/add_loyalty_points_settings.rb +5 -2
  25. data/app/views/spree/admin/loyalty_points_transactions/new.html.erb +6 -10
  26. data/app/views/spree/admin/stores/_loyalty_points_settings.html.erb +21 -21
  27. data/app/views/spree/checkout/payment/_loyaltypoints.html.erb +3 -3
  28. data/app/views/spree/loyalty_points/_transaction_table.html.erb +2 -2
  29. data/db/migrate/20140116090042_add_loyalty_points_balance_to_spree_user.rb +1 -1
  30. data/db/migrate/20140116110437_create_loyalty_points_transactions.rb +1 -1
  31. data/db/migrate/20140117062720_add_timestamps_to_loyalty_points_transaction.rb +1 -1
  32. data/db/migrate/20140117065314_add_fields_to_spree_loyalty_points_transaction.rb +1 -1
  33. data/db/migrate/20140122084005_add_comment_to_spree_loyalty_points_transaction.rb +1 -1
  34. data/db/migrate/20140123092709_add_paid_at_to_spree_order.rb +1 -1
  35. data/db/migrate/20140123120355_add_loyalty_points_to_spree_return_authorization.rb +1 -1
  36. data/db/migrate/20140124121728_add_loyalty_points_awarded_to_spree_order.rb +1 -1
  37. data/db/migrate/20140130131957_rename_fields_in_spree_loyalty_points_transaction.rb +1 -1
  38. data/db/migrate/20140131072702_remove_loyalty_points_awarded_from_spree_order.rb +1 -1
  39. data/db/migrate/20140203063433_add_indexing_to_spree_loyalty_points_transaction.rb +1 -1
  40. data/db/migrate/20140205111553_add_transaction_id_to_spree_loyalty_points_transactions.rb +1 -1
  41. data/db/migrate/20140207055836_add_lock_version_to_spree_user.rb +1 -1
  42. data/db/migrate/20251210070500_remove_lock_version_from_spree_user.rb +11 -0
  43. data/lib/ba_spree_loyalty_points.rb +1 -0
  44. data/lib/spree_loyalty_points/engine.rb +3 -2
  45. data/lib/spree_loyalty_points/version.rb +1 -1
  46. metadata +64 -24
  47. data/app/models/spree/store_decorator.rb +0 -23
  48. data/app/overrides/add_condition_to_amount_on_return_authorization_page.rb +0 -8
  49. data/app/overrides/add_loyalty_points_balance_to_account_page.rb +0 -9
  50. data/lib/spree_loyalty_points/factories.rb +0 -84
data/README.md CHANGED
@@ -14,7 +14,7 @@ This extension allows only Loyalty Points payment method for making a purchase a
14
14
 
15
15
  * Supports Ruby 3.1
16
16
  * Supports Rails 7.1
17
- * Supports Spree 4.10
17
+ * Supports Spree 5.3
18
18
  * Japanese translations included
19
19
  * Actively maintained with contributions back to the original project
20
20
 
@@ -40,6 +40,10 @@ module Spree
40
40
  params.require(:loyalty_points_transaction).permit(:loyalty_points, :type, :comment, :source_id, :source_type)
41
41
  end
42
42
 
43
+ def permitted_resource_params
44
+ loyalty_points_transaction_params
45
+ end
46
+
43
47
  def build_resource
44
48
  if params[:loyalty_points_transaction].present? && params[:loyalty_points_transaction][:type].present?
45
49
  parent.send(association_name(params[:loyalty_points_transaction][:type])).build
@@ -63,7 +67,7 @@ module Spree
63
67
  def set_ordered_transactions
64
68
  @loyalty_points_transactions = @loyalty_points_transactions.order(updated_at: :desc).
65
69
  page(params[:page]).
66
- per(params[:per_page] || Spree::Backend::Config[:admin_orders_per_page])
70
+ per(params[:per_page] || 25)
67
71
  end
68
72
  end
69
73
  end
@@ -3,6 +3,8 @@ module Spree
3
3
  module ResourceControllerDecorator
4
4
  protected
5
5
 
6
+ # @gem-override spree_admin-5.3.6/app/controllers/spree/admin/resource_controller.rb#parent
7
+ # @see https://github.com/be-agile/giga-repeat/commit/7c6b01c098e0003527926b1c221d4a586fe76a23
6
8
  def parent
7
9
  if parent_data.is_a?(Hash) && parent_data[:model_class].present?
8
10
  @parent ||= parent_data[:model_class].send("find_by_#{parent_data[:find_by]}", params["#{resource.model_name}_id"])
@@ -13,6 +15,8 @@ module Spree
13
15
  end
14
16
  end
15
17
 
18
+ # @gem-override spree_admin-5.3.6/app/controllers/spree/admin/resource_controller.rb#resource_not_found
19
+ # @see https://github.com/be-agile/giga-repeat/commit/7c6b01c098e0003527926b1c221d4a586fe76a23
16
20
  def resource_not_found
17
21
  flash[:error] = flash_message_for(model_class.new, :not_found)
18
22
  flash[:error] = flash_message_for(parent_data[:model_class].new, :not_found) if parent_data.present? && @parent.nil?
@@ -8,9 +8,17 @@ module Spree
8
8
  private
9
9
 
10
10
  def set_loyalty_points_transactions
11
- @loyalty_points_transactions = @return_authorization.order.loyalty_points_transactions.
11
+ # new アクションでは @return_authorization がまだ build されておらず、
12
+ # 親注文の instance var もこの before_action 時点では未設定
13
+ # (Spree 5.3.6 の load_resource は member_action 以外で resource を組み立てない)。
14
+ # ネストルートの :order_id (注文番号) から注文を解決してフォールバックする (#1253)。
15
+ order = @return_authorization&.order ||
16
+ (params[:order_id].present? && Spree::Order.find_by(number: params[:order_id]))
17
+ return if order.blank?
18
+
19
+ @loyalty_points_transactions = order.loyalty_points_transactions.
12
20
  page(params[:page]).
13
- per(params[:per_page] || Spree::Backend::Config[:admin_orders_per_page])
21
+ per(params[:per_page] || 25)
14
22
  end
15
23
  end
16
24
  end
@@ -4,7 +4,7 @@ module Spree
4
4
  def index
5
5
  @loyalty_points_transactions = spree_current_user.loyalty_points_transactions.includes(:source).order(updated_at: :desc).
6
6
  page(params[:page]).
7
- per(params[:per_page] || Spree::Backend::Config[:admin_orders_per_page])
7
+ per(params[:per_page] || 25)
8
8
  end
9
9
 
10
10
  end
@@ -1,4 +1,4 @@
1
- module Spree
1
+ module SpreeLoyaltyPoints
2
2
  module CheckoutControllerDecorator
3
3
  def self.prepended(base)
4
4
  base.before_action :sufficient_loyalty_points, only: [:update], if: -> { params[:state] == 'payment' }
@@ -12,10 +12,12 @@ module Spree
12
12
  end
13
13
  if Spree::PaymentMethod.loyalty_points_id_included?(payment_method_ids) && !@order.user.has_sufficient_loyalty_points?(@order)
14
14
  flash[:error] = Spree.t(:insufficient_loyalty_points)
15
- redirect_to spree.checkout_state_path(@order.state)
15
+ redirect_to Spree::Core::Engine.routes.url_helpers.checkout_state_path(@order.token, @order.state)
16
16
  end
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
- Spree::CheckoutController.prepend Spree::CheckoutControllerDecorator if Spree::CheckoutController.included_modules.exclude?(Spree::CheckoutControllerDecorator)
21
+ if Spree::CheckoutController.included_modules.exclude?(SpreeLoyaltyPoints::CheckoutControllerDecorator)
22
+ Spree::CheckoutController.prepend SpreeLoyaltyPoints::CheckoutControllerDecorator
23
+ end
@@ -6,16 +6,16 @@ module Spree
6
6
 
7
7
  def loyalty_points_for(amount, purpose = 'award')
8
8
  loyalty_points = if purpose == 'award' && eligible_for_loyalty_points?(amount)
9
- (amount * Spree::Store.default.loyalty_points_awarding_unit).floor
9
+ (amount * Spree::Store.default.preferred_loyalty_points_awarding_unit).floor
10
10
  elsif purpose == 'redeem'
11
- (amount / Spree::Store.default.loyalty_points_conversion_rate).ceil
11
+ (amount / Spree::Store.default.preferred_loyalty_points_conversion_rate).ceil
12
12
  else
13
13
  0
14
14
  end
15
15
  end
16
16
 
17
17
  def eligible_for_loyalty_points?(amount)
18
- amount >= Spree::Store.default.min_amount_required_to_get_loyalty_points
18
+ amount >= Spree::Store.default.preferred_min_amount_required_to_get_loyalty_points
19
19
  end
20
20
 
21
21
  end
@@ -27,7 +27,7 @@ module Spree
27
27
  module ClassMethods
28
28
 
29
29
  def credit_loyalty_points_to_user
30
- points_award_period = Spree::Store.default.loyalty_points_award_period
30
+ points_award_period = Spree::Store.default.preferred_loyalty_points_award_period
31
31
  uncredited_orders = Spree::Order.with_uncredited_loyalty_points(points_award_period)
32
32
  uncredited_orders.each do |order|
33
33
  order.award_loyalty_points
@@ -6,43 +6,43 @@ module Spree
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- scope :by_loyalty_points, -> { joins(:payment_method).readonly(false).where(spree_payment_methods: { type: 'Spree::PaymentMethod::LoyaltyPoints'}) }
9
+ scope :by_loyalty_points, -> { joins(:payment_method).readonly(false).where(spree_payment_methods: { type: 'Spree::PaymentMethod::LoyaltyPoints' }) }
10
10
  end
11
11
 
12
- module ClassMethods
13
-
14
- def any_with_loyalty_points?
15
- by_loyalty_points.size != 0
16
- end
12
+ module ClassMethods
13
+ def any_with_loyalty_points?
14
+ by_loyalty_points.size != 0
17
15
  end
16
+ end
18
17
 
19
18
  private
20
19
 
21
- def redeem_loyalty_points
22
- loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
23
- order.create_debit_transaction(loyalty_points_redeemed)
24
- end
20
+ def redeem_loyalty_points
21
+ loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
22
+ order.create_debit_transaction(loyalty_points_redeemed)
23
+ end
25
24
 
26
- def return_loyalty_points
27
- loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
28
- order.create_credit_transaction(loyalty_points_redeemed)
29
- end
25
+ def return_loyalty_points
26
+ loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
27
+ order.create_credit_transaction(loyalty_points_redeemed)
28
+ end
30
29
 
31
- def by_loyalty_points?
32
- payment_method.type == "Spree::PaymentMethod::LoyaltyPoints"
33
- end
30
+ def by_loyalty_points?
31
+ payment_method&.type == "Spree::PaymentMethod::LoyaltyPoints"
32
+ end
34
33
 
35
- def redeemable_loyalty_points_balance?
36
- order.user.loyalty_points_balance >= Spree::Store.default.loyalty_points_redeeming_balance
37
- end
34
+ def redeemable_loyalty_points_balance?
35
+ order.user.loyalty_points_balance >= Spree::Store.default.preferred_loyalty_points_redeeming_balance
36
+ end
38
37
 
39
- def redeemable_user_balance
40
- unless redeemable_loyalty_points_balance?
41
- min_balance = Spree::Store.default.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
+ def redeemable_user_balance
39
+ if order&.user.blank?
40
+ errors.add :loyalty_points_balance, " not available for guest user"
41
+ elsif !redeemable_loyalty_points_balance?
42
+ min_balance = Spree::Store.default.preferred_loyalty_points_redeeming_balance
43
+ errors.add :loyalty_points_balance, "should be at least #{min_balance.to_s + " " + "point".pluralize(min_balance)} for redeeming Loyalty Points"
44
44
  end
45
-
45
+ end
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -4,7 +4,7 @@ module Spree
4
4
  TRANSACTION_TYPES = ['Spree::LoyaltyPointsCreditTransaction', 'Spree::LoyaltyPointsDebitTransaction']
5
5
  CLASS_TO_TRANSACTION_TYPE = { 'Spree::LoyaltyPointsCreditTransaction' => 'Credit', 'Spree::LoyaltyPointsDebitTransaction' => 'Debit'}
6
6
  belongs_to :user, class_name: "::#{Spree.user_class}"
7
- belongs_to :source, polymorphic: true
7
+ belongs_to :source, polymorphic: true, optional: true
8
8
 
9
9
  validates :loyalty_points, numericality: { only_integer: true, message: Spree.t('validation.must_be_int'), greater_than: 0 }
10
10
  validates :type, inclusion: { in: TRANSACTION_TYPES }
@@ -16,6 +16,17 @@ module Spree
16
16
 
17
17
  before_create :generate_transaction_id
18
18
 
19
+ # Spree 5.2(Ransack 4.x)は検索・ソート対象を明示的に allowlist することを要求する。
20
+ # ActiveRecord::Base 継承で Spree::Core::Ransackable を含まないため、Ransack 標準の
21
+ # ransackable_attributes / ransackable_associations をオーバーライドして許可する。
22
+ def self.ransackable_attributes(_auth_object = nil)
23
+ %w[id loyalty_points type user_id source_id source_type balance comment transaction_id created_at updated_at]
24
+ end
25
+
26
+ def self.ransackable_associations(_auth_object = nil)
27
+ %w[user source]
28
+ end
29
+
19
30
  def transaction_type
20
31
  CLASS_TO_TRANSACTION_TYPE[type]
21
32
  end
@@ -1,4 +1,4 @@
1
- module Spree
1
+ module SpreeLoyaltyPoints
2
2
  module OrderDecorator
3
3
  def self.prepended(base)
4
4
  base.include Spree::LoyaltyPoints
@@ -30,4 +30,4 @@ module Spree
30
30
  end
31
31
  end
32
32
 
33
- Spree::Order.prepend(Spree::OrderDecorator)
33
+ Spree::Order.prepend(SpreeLoyaltyPoints::OrderDecorator)
@@ -1,4 +1,4 @@
1
- module Spree
1
+ module SpreeLoyaltyPoints
2
2
  module PaymentDecorator
3
3
  def self.prepended(base)
4
4
  base.include Spree::LoyaltyPoints
@@ -16,6 +16,9 @@ module Spree
16
16
 
17
17
  private
18
18
 
19
+ # @gem-override spree_core-5.3.6/app/models/spree/payment.rb#invalidate_old_payments
20
+ # @see https://github.com/be-agile/giga-repeat/commit/7c6b01c098e0003527926b1c221d4a586fe76a23
21
+ # ロイヤリティポイント決済を無効化対象から除外する。
19
22
  def invalidate_old_payments
20
23
  return if store_credit? || by_loyalty_points?
21
24
  order.payments.with_state('checkout').where("id != ?", self.id).each do |payment|
@@ -35,4 +38,4 @@ module Spree
35
38
  end
36
39
  end
37
40
 
38
- Spree::Payment.prepend Spree::PaymentDecorator if Spree::Payment.included_modules.exclude?(Spree::PaymentDecorator)
41
+ Spree::Payment.prepend SpreeLoyaltyPoints::PaymentDecorator
@@ -1,4 +1,4 @@
1
- module Spree
1
+ module SpreeLoyaltyPoints
2
2
  module PaymentMethodDecorator
3
3
  def self.prepended(base)
4
4
  base.scope :loyalty_points_type, -> { where(type: 'Spree::PaymentMethod::LoyaltyPoints') }
@@ -13,4 +13,4 @@ module Spree
13
13
  end
14
14
  end
15
15
 
16
- Spree::PaymentMethod.prepend(Spree::PaymentMethodDecorator)
16
+ Spree::PaymentMethod.prepend(SpreeLoyaltyPoints::PaymentMethodDecorator)
@@ -0,0 +1,13 @@
1
+ module SpreeLoyaltyPoints
2
+ module StoreDecorator
3
+ def self.prepended(base)
4
+ base.preference :loyalty_points_awarding_unit, :decimal, default: 0.01
5
+ base.preference :loyalty_points_redeeming_balance, :decimal, default: 0.0
6
+ base.preference :loyalty_points_conversion_rate, :decimal, default: 1.0
7
+ base.preference :loyalty_points_award_period, :integer, default: 12
8
+ base.preference :min_amount_required_to_get_loyalty_points, :decimal, default: 0.0
9
+ end
10
+ end
11
+ end
12
+
13
+ Spree::Store.prepend SpreeLoyaltyPoints::StoreDecorator
@@ -1,9 +1,9 @@
1
- Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
1
+ Deface::Override.new(virtual_path: 'spree/admin/orders/return_authorizations/_form',
2
2
  name: 'add_loyalty_points_to_return_authorization_page',
3
- insert_before: "erb[loud]:contains('field_container :reason')",
3
+ insert_before: "erb[loud]:contains('spree_select :return_authorization_reason_id')",
4
4
  text: "
5
5
  <% if !@order.loyalty_points_used? && @order.eligible_for_loyalty_points?(@order.item_total) %>
6
- <%= f.field_container :loyalty_points do %>
6
+ <div class='form-group'>
7
7
  <%= label :loyalty_points, Spree.t(:loyalty_points_debit) %> <span class='required'>*</span><br />
8
8
  <% if @return_authorization.received? %>
9
9
  <%= @return_authorization.loyalty_points %> points Debited <br />
@@ -12,9 +12,9 @@ Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
12
12
  <%= f.hidden_field :loyalty_points_transaction_type, { value: :Debit } %>
13
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
14
  <% end %>
15
- <% end %>
15
+ </div>
16
16
  <% elsif @order.loyalty_points_used? %>
17
- <%= f.field_container :loyalty_points do %>
17
+ <div class='form-group'>
18
18
  <br /><%= label :loyalty_points, Spree.t(:loyalty_points_credit) %> <span class='required'>*</span><br />
19
19
  <% if @return_authorization.received? %>
20
20
  <%= @return_authorization.loyalty_points %> points Credited <br />
@@ -23,6 +23,6 @@ Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
23
23
  <%= f.hidden_field :loyalty_points_transaction_type, { value: :Credit } %>
24
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
25
  <% end %>
26
- <% end %>
26
+ </div>
27
27
  <% end %>
28
28
  ")
@@ -0,0 +1,13 @@
1
+ Deface::Override.new(
2
+ virtual_path: "spree/account/_account_nav",
3
+ name: "add_loyalty_points_to_account_nav",
4
+ insert_after: "erb[loud]:contains('account_wishlist_path')",
5
+ text: <<-HTML
6
+ <% if LoyaltyPointsService.enabled? %>
7
+ <%= link_to Spree.t(:loyalty_points), spree.loyalty_points_path,
8
+ data: { active: current == "loyalty_points" },
9
+ class: "shrink-0 block lg:px-4 lg:py-3 px-3 py-4 border-b lg:border-b-0 text-neutral-700 hover:border-accent-100 hover:bg-accent-100 hover:text-black \#{current == "loyalty_points" ? "lg:bg-accent border-text lg:border-b-0 lg:border-l-[1.5px]" : "border-accrent lg:border-l"}"
10
+ %>
11
+ <% end %>
12
+ HTML
13
+ )
@@ -1,15 +1,17 @@
1
- Deface::Override.new(virtual_path: 'spree/admin/users/edit',
1
+ Deface::Override.new(
2
+ virtual_path: 'spree/admin/users/_form',
2
3
  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>
4
+ insert_bottom: "div.card-body",
5
+ text: <<-HTML
6
+ <div class="form-group">
7
+ <%= f.label :loyalty_points_balance, Spree.t(:loyalty_points_balance) %>
8
+ <div>
8
9
  <% if @user.loyalty_points_balance.present? %>
9
- <%= link_to @user.loyalty_points_balance, spree.admin_user_loyalty_points_path(@user) %>
10
+ <%= link_to @user.loyalty_points_balance, spree.admin_user_loyalty_points_path(@user), class: 'btn btn-sm btn-outline-secondary' %>
10
11
  <% else %>
11
- <%= 'No loyalty points yet' %>
12
- <% end %
12
+ <%= Spree.t(:no_loyalty_points_yet) %>
13
+ <% end %>
13
14
  </div>
14
15
  </div>
15
- ")
16
+ HTML
17
+ )
@@ -1,8 +1,12 @@
1
- Deface::Override.new(virtual_path: 'spree/orders/edit',
1
+ Deface::Override.new(
2
+ virtual_path: 'spree/orders/_summary',
2
3
  name: 'add_loyalty_points_to_cart_page',
3
- insert_before: ".shopping-cart-buttons",
4
+ insert_before: "erb[loud]:contains('link_to Spree.t(:checkout)')",
4
5
  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>
6
+ <% if LoyaltyPointsService.enabled? && order.loyalty_points_for(order.item_total) > 0 %>
7
+ <div class='text-center lg:text-right my-4 text-sm'>
8
+ <%= Spree.t(:loyalty_points_earnable, quantity: \"<span class='font-medium'>\#{order.loyalty_points_for(order.item_total)}</span>\").html_safe %>
9
+ </div>
7
10
  <% end %>
8
- ")
11
+ "
12
+ )
@@ -1,12 +1,16 @@
1
- Deface::Override.new(virtual_path: 'spree/shared/_order_details',
1
+ Deface::Override.new(
2
+ virtual_path: 'spree/shared/_order_details',
2
3
  name: 'add_loyalty_points_to_order_checkout_page',
3
- insert_after: "#checkout-summary",
4
+ insert_bottom: "div.bg-accent.mb-24",
4
5
  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>
6
+ <% if LoyaltyPointsService.enabled? %>
7
+ <div class='p-4 lg:p-6 text-sm border-t border-default'>
8
+ <% if order.loyalty_points_awarded? %>
9
+ <span class='font-medium'><%= order.loyalty_points_for(order.item_total) %></span> <b><%= Spree.t(:loyalty_points) %></b> <%= Spree.t('loyalty_points.have_been_credited') %>
8
10
  <% else %>
9
- <span><%= @order.loyalty_points_for(@order.item_total) %></span> <b><%= Spree.t(:loyalty_points) %> will be credited to your account soon.</b>
11
+ <span class='font-medium'><%= order.loyalty_points_for(order.item_total) %></span> <b><%= Spree.t(:loyalty_points) %></b> <%= Spree.t('loyalty_points.will_be_credited_soon') %>
10
12
  <% end %>
11
13
  </div>
12
- ")
14
+ <% end %>
15
+ "
16
+ )
@@ -1,13 +1,27 @@
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')",
1
+ # Spree 5.2.0: return_authorizations/index now uses _table_header and _table_row partials
2
+ Deface::Override.new(
3
+ virtual_path: 'spree/admin/return_authorizations/_table_header',
4
+ name: 'add_loyalty_points_to_return_authorization_table_header',
5
+ insert_before: "th:contains('Spree.t(:status)')",
4
6
  text: "
5
- <th><%= Spree.t(:loyalty_points) %></th>
6
- ")
7
+ <th scope=\"col\"><%= Spree.t(:loyalty_points) %></th>
8
+ "
9
+ )
7
10
 
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
+ Deface::Override.new(
12
+ virtual_path: 'spree/admin/return_authorizations/_table_row',
13
+ name: 'add_loyalty_points_to_return_authorization_table_row',
14
+ insert_before: "td:contains('return_authorization.state')",
11
15
  text: "
12
- <td><%= return_authorization.loyalty_points %> pts <%= return_authorization.loyalty_points_transaction_type %></td>
13
- ")
16
+ <td data-action=\"click->row-link#openLink\">
17
+ <% if return_authorization.loyalty_points.present? %>
18
+ <%= return_authorization.loyalty_points %> pts
19
+ <% if return_authorization.loyalty_points_transaction_type.present? %>
20
+ (<%= return_authorization.loyalty_points_transaction_type %>)
21
+ <% end %>
22
+ <% else %>
23
+ -
24
+ <% end %>
25
+ </td>
26
+ "
27
+ )
@@ -1,6 +1,16 @@
1
- Deface::Override.new(virtual_path: 'spree/admin/return_authorizations/_form',
1
+ Deface::Override.new(virtual_path: 'spree/admin/orders/return_authorizations/_form',
2
2
  name: 'add_loyalty_points_transaction_table_to_return_authorization_form',
3
- insert_after: "div[data-hook='admin_return_authorization_form_fields']",
3
+ insert_after: "div.card.mb-6:contains('spree_text_area :memo')",
4
4
  text: "
5
- <%= render partial: 'spree/loyalty_points/transaction_table' %>
5
+
6
+ <div class=\"card mb-6\">
7
+ <div class=\"card-header\">
8
+ <h5 class=\"card-title\">
9
+ <%= Spree.t(:loyalty_points_transactions) %>
10
+ </h5>
11
+ </div>
12
+ <div class=\"card-body\">
13
+ <%= render partial: 'spree/loyalty_points/transaction_table' %>
14
+ </div>
15
+ </div>
6
16
  ")
@@ -1,6 +1,9 @@
1
+ # Updated for Spree 5.2.0 - form split into multiple partials
2
+ # Now targeting spree/admin/stores/form/_basic instead of _form
3
+ # Using render_admin_partials hook for reliable insertion
1
4
  Deface::Override.new(
2
- virtual_path: "spree/admin/stores/_form",
5
+ virtual_path: "spree/admin/stores/form/_basic",
3
6
  name: "add_loyalty_points_settings",
4
- insert_bottom: "[data-hook='admin_store_form_fields']",
7
+ insert_before: "erb[loud]:contains('render_admin_partials')",
5
8
  partial: "spree/admin/stores/loyalty_points_settings"
6
9
  )
@@ -19,11 +19,9 @@
19
19
  <div data-hook="update_loyalty_points_attrs" class="row">
20
20
 
21
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 %>
22
+ <%= f.label :loyalty_points, Spree.t(:loyalty_points) %> <span class="required">*</span><br />
23
+ <%= f.text_field :loyalty_points, class: 'fullwidth title form-control' %>
24
+ <%= f.error_message_on :loyalty_points %>
27
25
  </div>
28
26
 
29
27
  <div class="field col-md-4">
@@ -43,11 +41,9 @@
43
41
  <div data-hook="comment_row" class="row">
44
42
 
45
43
  <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 %>
44
+ <%= f.label :comment, Spree.t(:comment) %> <span class="required">*</span><br />
45
+ <%= f.text_area :comment, class: 'fullwidth form-control', rows: '3' %>
46
+ <%= f.error_message_on :comment %>
51
47
  </div>
52
48
 
53
49
  </div>
@@ -7,39 +7,39 @@
7
7
  <div class="card-body">
8
8
  <div class="row">
9
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 %>
10
+ <div class="form-group">
11
+ <%= f.label :preferred_loyalty_points_awarding_unit, Spree.t('admin.store.loyalty_points_awarding_unit') %>
12
+ <%= f.number_field :preferred_loyalty_points_awarding_unit, class: 'form-control', min: 0, step: 0.01 %>
13
+ </div>
14
14
  </div>
15
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 %>
16
+ <div class="form-group">
17
+ <%= f.label :preferred_loyalty_points_redeeming_balance, Spree.t('admin.store.loyalty_points_redeeming_balance') %>
18
+ <%= f.number_field :preferred_loyalty_points_redeeming_balance, class: 'form-control', min: 0, step: 0.01 %>
19
+ </div>
20
20
  </div>
21
21
  </div>
22
22
  <div class="row mt-3">
23
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 %>
24
+ <div class="form-group">
25
+ <%= f.label :preferred_loyalty_points_conversion_rate, Spree.t('admin.store.loyalty_points_conversion_rate') %>
26
+ <%= f.number_field :preferred_loyalty_points_conversion_rate, class: 'form-control', min: 0, step: 0.01 %>
27
+ </div>
28
28
  </div>
29
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 %>
30
+ <div class="form-group">
31
+ <%= f.label :preferred_loyalty_points_award_period, Spree.t('admin.store.loyalty_points_award_period') %>
32
+ <%= f.number_field :preferred_loyalty_points_award_period, class: 'form-control', min: 0 %>
33
+ </div>
34
34
  </div>
35
35
  </div>
36
36
  <div class="row mt-3">
37
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 %>
38
+ <div class="form-group">
39
+ <%= f.label :preferred_min_amount_required_to_get_loyalty_points, Spree.t('admin.store.min_amount_required_to_get_loyalty_points') %>
40
+ <%= f.number_field :preferred_min_amount_required_to_get_loyalty_points, class: 'form-control', min: 0, step: 0.01 %>
41
+ </div>
42
42
  </div>
43
43
  </div>
44
44
  </div>
45
- </div>
45
+ </div>
@@ -1,8 +1,8 @@
1
- <%- lp_balance = spree_current_user.loyalty_points_balance %>
2
- <%- equivalent_currency_balance = spree_current_user.loyalty_points_equivalent_currency %>
1
+ <%- lp_balance = spree_current_user&.loyalty_points_balance %>
2
+ <%- equivalent_currency_balance = spree_current_user&.loyalty_points_equivalent_currency %>
3
3
  Loyalty Points Balance: <%= lp_balance %><%= "($" + equivalent_currency_balance.to_s + ")" %>
4
4
  <%- lp_needed = @order.loyalty_points_for(@order.total, 'redeem') %>
5
5
  <br/>Loyalty Points Needed: <%= lp_needed %>
6
- <% if lp_needed > lp_balance %>
6
+ <% if lp_balance.nil? || lp_needed > lp_balance %>
7
7
  <br/><b>Insufficient Balance!</b>
8
8
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= paginate @loyalty_points_transactions %>
1
+ <%= paginate @loyalty_points_transactions if @loyalty_points_transactions.respond_to?(:total_pages) %>
2
2
 
3
3
  <% if @loyalty_points_transactions.present? %>
4
4
  <table class="loyalty-points-summary table table-striped table-hover">
@@ -41,4 +41,4 @@
41
41
  <p><%= Spree.t(:you_have_not_earned_any_loyalty_points_yet) %></p>
42
42
  <% end %>
43
43
 
44
- <%= paginate @loyalty_points_transactions %>
44
+ <%= paginate @loyalty_points_transactions if @loyalty_points_transactions.respond_to?(:total_pages) %>
@@ -1,4 +1,4 @@
1
- class AddLoyaltyPointsBalanceToSpreeUser < ActiveRecord::Migration[7.1]
1
+ class AddLoyaltyPointsBalanceToSpreeUser < ActiveRecord::Migration[8.0]
2
2
  def change
3
3
  users_table_name = Spree.user_class.present? ? Spree.user_class.table_name : :spree_users
4
4
  add_column users_table_name, :loyalty_points_balance, :integer, default: 0, null: false
@@ -1,4 +1,4 @@
1
- class CreateLoyaltyPointsTransactions < ActiveRecord::Migration[7.1]
1
+ class CreateLoyaltyPointsTransactions < ActiveRecord::Migration[8.0]
2
2
  def change
3
3
  create_table :spree_loyalty_points_transactions do |t|
4
4
  t.integer :loyalty_points