Remove TagRule::DiscountOrder

This class was removed from the UI in 2016 and hasn't been used since...
This commit is contained in:
Matt-Yorkley
2021-04-08 12:34:40 +01:00
parent e61fe86d00
commit 80d43c714d
8 changed files with 2 additions and 150 deletions

View File

@@ -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"

View File

@@ -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') }

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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