summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluca-landa <lucalanda@hotmail.it>2021-03-19 18:31:51 +0100
committerluca-landa <lucalanda@hotmail.it>2021-03-19 18:31:51 +0100
commit57a0e3d10363323269700d58c18359939f745759 (patch)
tree625c03bd3f67265becbe2a330888f08e2b496006
parent19fcbb18387dd6a2d28d386fd5510203d6f18a77 (diff)
Set promotion rules model paths similar to Solidus
This allows for naming the models in a way more consistent to Solidus (which doesn't include "PromotionRule" in the name of the class). Also, it easily allows for the promotion rules to be displayed with a better name in the admin panel (which just uses the promotions model name humanized).
-rw-r--r--app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb44
-rw-r--r--app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb31
-rw-r--r--app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb40
-rw-r--r--app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb27
-rw-r--r--app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb (renamed from app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb)0
-rw-r--r--app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb (renamed from app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb)0
-rw-r--r--lib/solidus_subscriptions/engine.rb4
-rw-r--r--spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb (renamed from spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb)2
-rw-r--r--spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb (renamed from spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb)2
9 files changed, 79 insertions, 71 deletions
diff --git a/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb b/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb
new file mode 100644
index 0000000..1b44125
--- /dev/null
+++ b/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+module SolidusSubscriptions
+ module Promotion
+ module Rules
+ class SubscriptionCreationOrder < ::Spree::PromotionRule
+ # Promotion can be applied to an entire order. Will only be true
+ # for Spree::Order
+ #
+ # @param promotable [Object] Any object which could have this
+ # promotion rule applied to it.
+ #
+ # @return [Boolean]
+ def applicable?(promotable)
+ promotable.is_a? ::Spree::Order
+ end
+
+ # An order is eligible if it contains a line item with an associates
+ # subscription_line_item. This rule applies to order and so its eligibility
+ # will always be considered against an order. Will only return true for
+ # orders containing Spree::Line item with associated subscription_line_items
+ #
+ # @param order [Spree::Order] The order which could have this rule applied
+ # to it.
+ #
+ # @return [Boolean]
+ def eligible?(order, **_options)
+ order.subscription_line_items.any?
+ end
+
+ # Certain actions create adjustments on line items. In this case, only
+ # line items with associated subscription_line_items are eligible to be
+ # adjusted. Will only return true # if :line_item has an associated
+ # subscription.
+ #
+ # @param line_item [Spree::LineItem] The line item which could be adjusted
+ # by the promotion.
+ def actionable?(line_item)
+ line_item.subscription_line_items.present?
+ end
+ end
+ end
+ end
+end
diff --git a/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb b/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb
new file mode 100644
index 0000000..455825d
--- /dev/null
+++ b/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module SolidusSubscriptions
+ module Promotion
+ module Rules
+ class SubscriptionInstallmentOrder < ::Spree::PromotionRule
+ # Promotion can be applied to an entire order. Will only be true
+ # for Spree::Order
+ #
+ # @param promotable [Object] Any object which could have this
+ # promotion rule applied to it.
+ #
+ # @return [Boolean]
+ def applicable?(promotable)
+ promotable.is_a? ::Spree::Order
+ end
+
+ # An order is eligible if it fulfills a subscription Installment. Will only
+ # return true if the order fulfills one or more Installments
+ #
+ # @param order [Spree::Order] The order which could have this rule applied
+ # to it.
+ #
+ # @return [Boolean]
+ def eligible?(order, **_options)
+ order.subscription_order?
+ end
+ end
+ end
+ end
+end
diff --git a/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb
deleted file mode 100644
index 9b5d465..0000000
--- a/app/models/solidus_subscriptions/subscription_creation_order_promotion_rule.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-module SolidusSubscriptions
- class SubscriptionCreationOrderPromotionRule < ::Spree::PromotionRule
- # Promotion can be applied to an entire order. Will only be true
- # for Spree::Order
- #
- # @param promotable [Object] Any object which could have this
- # promotion rule applied to it.
- #
- # @return [Boolean]
- def applicable?(promotable)
- promotable.is_a? ::Spree::Order
- end
-
- # An order is eligible if it contains a line item with an associates
- # subscription_line_item. This rule applies to order and so its eligibility
- # will always be considered against an order. Will only return true for
- # orders containing Spree::Line item with associated subscription_line_items
- #
- # @param order [Spree::Order] The order which could have this rule applied
- # to it.
- #
- # @return [Boolean]
- def eligible?(order, **_options)
- order.subscription_line_items.any?
- end
-
- # Certain actions create adjustments on line items. In this case, only
- # line items with associated subscription_line_items are eligible to be
- # adjusted. Will only return true # if :line_item has an associated
- # subscription.
- #
- # @param line_item [Spree::LineItem] The line item which could be adjusted
- # by the promotion.
- def actionable?(line_item)
- line_item.subscription_line_items.present?
- end
- end
-end
diff --git a/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb
deleted file mode 100644
index 5714bb8..0000000
--- a/app/models/solidus_subscriptions/subscription_installment_order_promotion_rule.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-module SolidusSubscriptions
- class SubscriptionInstallmentOrderPromotionRule < ::Spree::PromotionRule
- # Promotion can be applied to an entire order. Will only be true
- # for Spree::Order
- #
- # @param promotable [Object] Any object which could have this
- # promotion rule applied to it.
- #
- # @return [Boolean]
- def applicable?(promotable)
- promotable.is_a? ::Spree::Order
- end
-
- # An order is eligible if it fulfills a subscription Installment. Will only
- # return true if the order fulfills one or more Installments
- #
- # @param order [Spree::Order] The order which could have this rule applied
- # to it.
- #
- # @return [Boolean]
- def eligible?(order, **_options)
- order.subscription_order?
- end
- end
-end
diff --git a/app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb
index e69de29..e69de29 100644
--- a/app/views/spree/admin/promotions/rules/_subscription_creation_order_promotion_rule.html.erb
+++ b/app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb
diff --git a/app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb b/app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb
index e69de29..e69de29 100644
--- a/app/views/spree/admin/promotions/rules/_subscription_installment_order_promotion_rule.html.erb
+++ b/app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb
diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb
index 4c3661a..0f274d8 100644
--- a/lib/solidus_subscriptions/engine.rb
+++ b/lib/solidus_subscriptions/engine.rb
@@ -31,8 +31,8 @@ module SolidusSubscriptions
end
initializer 'solidus_subscriptions.register_promotion_rules', after: 'spree.promo.register.promotion.rules' do |app|
- app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionCreationOrderPromotionRule'
- app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionInstallmentOrderPromotionRule'
+ app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder'
+ app.config.spree.promotions.rules << 'SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder'
end
initializer 'solidus_subscriptions.configure_backend' do
diff --git a/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb
index 651c678..f7975f1 100644
--- a/spec/lib/solidus_subscriptions/subscription_creation_order_promotion_rule_spec.rb
+++ b/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-RSpec.describe SolidusSubscriptions::SubscriptionCreationOrderPromotionRule do
+RSpec.describe SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder do
let(:rule) { described_class.new }
describe '#applicable' do
diff --git a/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb b/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb
index 2e0019c..d17fa61 100644
--- a/spec/lib/solidus_subscriptions/subscription_installment_order_promotion_rule_spec.rb
+++ b/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-RSpec.describe SolidusSubscriptions::SubscriptionInstallmentOrderPromotionRule do
+RSpec.describe SolidusSubscriptions::Promotion::Rules::SubscriptionInstallmentOrder do
let(:rule) { described_class.new }
describe '#applicable' do