diff --git a/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee b/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee index 7576baf59d..315e0edb98 100644 --- a/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee +++ b/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee @@ -23,8 +23,6 @@ angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, $fil preferred_customer_tags: (tag.text for tag in tagGroup.tags).join(",") type: "TagRule::#{ruleType}" switch ruleType - when "DiscountOrder" - newRule.calculator = { preferred_flat_percent: 0 } when "FilterShippingMethods" newRule.peferred_shipping_method_tags = [] newRule.preferred_matched_shipping_methods_visibility = "visible" diff --git a/app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee b/app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee index 8ac7cfb68c..85af4bca7a 100644 --- a/app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee +++ b/app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee @@ -8,7 +8,6 @@ angular.module("admin.tagRules").directive 'newTagRuleDialog', ($compile, $templ template = $compile($templateCache.get('admin/new_tag_rule_dialog.html'))(scope) scope.ruleTypes = [ - # { id: "DiscountOrder", name: 'Apply a discount to orders' } { id: "FilterProducts", name: t('js.tag_rules.show_hide_variants') } { id: "FilterShippingMethods", name: t('js.tag_rules.show_hide_shipping') } { id: "FilterPaymentMethods", name: t('js.tag_rules.show_hide_payment') } diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 6dd9631ced..6ad2785f9e 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -212,7 +212,6 @@ module Admin tag_rules_attributes.select{ |_i, attrs| attrs[:type].present? }.each do |_i, attrs| rule = @object.tag_rules.find_by(id: attrs.delete(:id)) || attrs[:type].constantize.new(enterprise: @object) - create_calculator_for(rule, attrs) if rule.type == "TagRule::DiscountOrder" && rule.calculator.nil? rule.update(attrs.permit(PermittedAttributes::TagRules.attributes)) end diff --git a/app/models/tag_rule/discount_order.rb b/app/models/tag_rule/discount_order.rb deleted file mode 100644 index 5f9ca44b2f..0000000000 --- a/app/models/tag_rule/discount_order.rb +++ /dev/null @@ -1,24 +0,0 @@ -class TagRule::DiscountOrder < TagRule - include Spree::Core::CalculatedAdjustments - - private - - # Warning: this should only EVER be called via TagRule#apply - def apply! - create_adjustment(I18n.t("discount"), subject, subject) - end - - def subject_class_matches? - subject.class == Spree::Order - end - - def additional_requirements_met? - return false if already_applied? - - true - end - - def already_applied? - subject.adjustments.where(originator_id: id, originator_type: "TagRule").any? - end -end diff --git a/app/serializers/api/admin/tag_rule_serializer.rb b/app/serializers/api/admin/tag_rule_serializer.rb index 0f96f2a5ee..0a64f74c8b 100644 --- a/app/serializers/api/admin/tag_rule_serializer.rb +++ b/app/serializers/api/admin/tag_rule_serializer.rb @@ -19,10 +19,6 @@ module Api attributes :id, :enterprise_id, :type, :is_default, :preferred_customer_tags end - class DiscountOrderSerializer < BaseSerializer - has_one :calculator, serializer: Api::Admin::Calculator::FlatPercentItemTotalSerializer - end - class FilterShippingMethodsSerializer < BaseSerializer attributes :preferred_matched_shipping_methods_visibility, :preferred_shipping_method_tags, :shipping_method_tags diff --git a/spec/features/admin/tag_rules_spec.rb b/spec/features/admin/tag_rules_spec.rb index b1ee2bedb6..e29f180ee9 100644 --- a/spec/features/admin/tag_rules_spec.rb +++ b/spec/features/admin/tag_rules_spec.rb @@ -66,18 +66,8 @@ feature 'Tag Rules', js: true do expect(page).to have_content "not visible" end - # New DiscountOrder Rule - # click_button '+ Add A New Rule' - # select2_select 'Apply a discount to orders', from: 'rule_type_selector' - # click_button "Add Rule" - # fill_in "enterprise_tag_rules_attributes_1_calculator_attributes_preferred_flat_percent", with: 22 - click_button 'Update' - # tag_rule = TagRule::DiscountOrder.last - # expect(tag_rule.preferred_customer_tags).to eq "volunteer" - # expect(tag_rule.calculator.preferred_flat_percent).to eq -22 - tag_rule = TagRule::FilterShippingMethods.last expect(tag_rule.preferred_customer_tags).to eq "volunteer" expect(tag_rule.preferred_shipping_method_tags).to eq "volunteers-only" @@ -111,7 +101,6 @@ feature 'Tag Rules', js: true do let!(:fpm_tag_rule) { create(:filter_payment_methods_tag_rule, enterprise: enterprise, preferred_matched_payment_methods_visibility: "hidden", preferred_customer_tags: "trusted", preferred_payment_method_tags: "trusted" ) } let!(:foc_tag_rule) { create(:filter_order_cycles_tag_rule, enterprise: enterprise, preferred_matched_order_cycles_visibility: "visible", preferred_customer_tags: "wholesale", preferred_exchange_tags: "wholesale" ) } let!(:fsm_tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: enterprise, preferred_matched_shipping_methods_visibility: "hidden", preferred_customer_tags: "local", preferred_shipping_method_tags: "local" ) } - # let!(:do_tag_rule) { create(:tag_rule, enterprise: enterprise, preferred_customer_tags: "member" ) } before do visit_tag_rules @@ -171,12 +160,6 @@ feature 'Tag Rules', js: true do # Moving the Shipping Methods to top priority find(".customer_tag#tg_4 .header", ).drag_to find(".customer_tag#tg_1 .header") - # # DiscountOrder rule - # within "#tr_2" do - # expect(page).to have_field "enterprise_tag_rules_attributes_2_calculator_attributes_preferred_flat_percent", with: '0' - # fill_in "enterprise_tag_rules_attributes_2_calculator_attributes_preferred_flat_percent", with: 45 - # end - click_button 'Update' # DEFAULT FilterShippingMethods rule @@ -207,10 +190,6 @@ feature 'Tag Rules', js: true do expect(foc_tag_rule.preferred_customer_tags).to eq "volunteer" expect(foc_tag_rule.preferred_exchange_tags).to eq "volunteers-only3" expect(foc_tag_rule.preferred_matched_order_cycles_visibility).to eq "hidden" - - # DiscountOrder rule - # expect(do_tag_rule.preferred_customer_tags).to eq "member,volunteer" - # expect(do_tag_rule.calculator.preferred_flat_percent).to eq -45 end end diff --git a/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee b/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee index 280ef457b7..4758d4222e 100644 --- a/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee @@ -25,11 +25,11 @@ describe "TagRulesCtrl", -> describe "adding a new tag group", -> beforeEach -> - scope.addNewRuleTo(scope.tagGroups[0], "DiscountOrder") + scope.addNewRuleTo(scope.tagGroups[0], "FilterOrderCycles") it "adds a new rule of the specified type to the rules array for the tagGroup", -> expect(scope.tagGroups[0].rules.length).toEqual 3 - expect(scope.tagGroups[0].rules[2].type).toEqual "TagRule::DiscountOrder" + expect(scope.tagGroups[0].rules[2].type).toEqual "TagRule::FilterOrderCycles" it "updates tagGroup start indices", -> expect(scope.tagGroups[0].startIndex).toEqual 1 diff --git a/spec/models/tag_rule/discount_order_spec.rb b/spec/models/tag_rule/discount_order_spec.rb deleted file mode 100644 index 1da5635c5e..0000000000 --- a/spec/models/tag_rule/discount_order_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe TagRule::DiscountOrder, type: :model do - let!(:tag_rule) { create(:tag_rule) } - - pending "determining relevance based on additional requirements" do - let(:subject) { double(:subject) } - - before do - tag_rule.context = { subject: subject } - allow(tag_rule).to receive(:customer_tags_match?) { true } - allow(subject).to receive(:class) { Spree::Order } - end - - context "when already_applied? returns false" do - before { expect(tag_rule).to receive(:already_applied?) { false } } - - it "returns true" do - expect(tag_rule.send(:relevant?)).to be true - end - end - - context "when already_applied? returns true" do - before { expect(tag_rule).to receive(:already_applied?) { true } } - - it "returns false immediately" do - expect(tag_rule.send(:relevant?)).to be false - end - end - end - - pending "determining whether a the rule has already been applied to an order" do - let!(:order) { create(:order) } - let!(:adjustment) { order.adjustments.create({ amount: 12.34, source: order, originator: tag_rule, label: 'discount' }) } - - before do - tag_rule.context = { subject: order } - end - - context "where adjustments originating from the rule already exist" do - it { expect(tag_rule.send(:already_applied?)).to be true } - end - - context "where existing adjustments originate from other rules" do - before { adjustment.update_attribute(:originator_id, create(:tag_rule).id) } - it { expect(tag_rule.send(:already_applied?)).to be false } - end - end - - pending "applying the rule" do - # Assume that all validation is done by the TagRule base class - - let!(:line_item) { create(:line_item, price: 100.00) } - let!(:order) { line_item.order } - - before do - order.recreate_all_fees! - tag_rule.calculator.update_attribute(:preferred_flat_percent, -10.00) - tag_rule.context = { subject: order } - end - - context "in a simple scenario" do - let(:adjustment) { order.reload.adjustments.where(originator_id: tag_rule, originator_type: "TagRule").first } - - it "creates a new adjustment on the order" do - tag_rule.send(:apply!) - expect(adjustment).to be_a Spree::Adjustment - expect(adjustment.amount).to eq(-10.00) - expect(adjustment.label).to eq "Discount" - expect(order.adjustment_total).to eq(-10.00) - expect(order.total).to eq 90.00 - end - end - - context "when shipping charges apply" do - let!(:shipping_method) { create(:shipping_method, calculator: Calculator::FlatRate.new( preferred_amount: 25.00 ) ) } - before do - shipping_method.create_adjustment("Shipping", order, order, true) - end - - let(:adjustment) { order.reload.adjustments.where(originator_id: tag_rule, originator_type: "TagRule").first } - - it "the adjustment is made on line item total, ie. ignores the shipping amount" do - tag_rule.send(:apply!) - expect(adjustment).to be_a Spree::Adjustment - expect(adjustment.amount).to eq(-10.00) - expect(adjustment.label).to eq "Discount" - expect(order.adjustment_total).to eq 15.00 - expect(order.total).to eq 115.00 - end - end - end -end