Adding FilterPaymentMethods rules to tag rule UI

This commit is contained in:
Rob Harrington
2016-04-27 15:33:45 +10:00
parent 3fb6fba0f0
commit e999b5715a
7 changed files with 65 additions and 0 deletions

View File

@@ -26,6 +26,9 @@ angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, ente
when "FilterShippingMethods"
newRule.peferred_shipping_method_tags = []
newRule.preferred_matched_shipping_methods_visibility = "visible"
when "FilterPaymentMethods"
newRule.peferred_payment_method_tags = []
newRule.preferred_matched_payment_methods_visibility = "visible"
when "FilterProducts"
newRule.peferred_variant_tags = []
newRule.preferred_matched_variants_visibility = "visible"

View File

@@ -9,6 +9,7 @@ angular.module("admin.tagRules").directive 'newTagRuleDialog', ($compile, $templ
# { id: "DiscountOrder", name: 'Apply a discount to orders' }
{ id: "FilterProducts", name: 'Show or Hide variants in my shopfront' }
{ id: "FilterShippingMethods", name: 'Show or Hide shipping methods at checkout' }
{ id: "FilterPaymentMethods", name: 'Show or Hide payment methods at checkout' }
]
scope.ruleType = scope.ruleTypes[0].id

View File

@@ -0,0 +1,4 @@
angular.module("admin.tagRules").directive "filterPaymentMethods", ->
restrict: "E"
replace: true
templateUrl: "admin/tag_rules/filter_payment_methods.html"

View File

@@ -0,0 +1,27 @@
%div
%input{ type: "hidden",
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_id",
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][id]",
ng: { value: "rule.id" } }
%input{ type: "hidden",
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_type",
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][type]",
value: "TagRule::FilterPaymentMethods" }
%input{ type: "hidden",
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_customer_tags",
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_customer_tags]",
ng: { value: "rule.preferred_customer_tags" } }
%input{ type: "hidden",
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_payment_method_tags",
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_payment_method_tags]",
ng: { value: "rule.preferred_customer_tags" } }
%span.text-normal {{ $index + 1 }}. Payment methods with matching tags are
%input.light.ofn-select2{ id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_payment_methods_visibility",
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_payment_methods_visibility]",
ng: { model: "rule.preferred_matched_payment_methods_visibility"},
data: 'visibilityOptions', "min-search" => 5 }
-# %tags-with-translation{ object: "rule", "tags-attr" => "payment_method_tags", "tag-list-attr" => "preferred_payment_method_tags" }

View File

@@ -25,6 +25,14 @@ module Api::Admin::TagRule
end
end
class FilterPaymentMethodsSerializer < BaseSerializer
attributes :preferred_matched_payment_methods_visibility, :payment_method_tags
def payment_method_tags
object.preferred_payment_method_tags.split(",")
end
end
class FilterProductsSerializer < BaseSerializer
attributes :preferred_matched_variants_visibility, :variant_tags

View File

@@ -26,6 +26,7 @@
%discount-order{ ng: { if: "::rule.type == 'TagRule::DiscountOrder'" } }
%filter-shipping-methods{ ng: { if: "::rule.type == 'TagRule::FilterShippingMethods'" } }
%filter-products{ ng: { if: "::rule.type == 'TagRule::FilterProducts'" } }
%filter-payment-methods{ ng: { if: "::rule.type == 'TagRule::FilterPaymentMethods'" } }
%td.actions
%a{ ng: { click: "deleteTagRule(tagGroup, rule)" }, :class => "delete-tag-rule icon-trash no-text" }
.add_rule.text-center

View File

@@ -34,6 +34,12 @@ feature 'Tag Rules', js: true do
click_button "Add Rule"
select2_select "VISIBLE", from: "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility"
# New FilterPaymentMethods Rule
click_button '+ Add A New Rule'
select2_select 'Show or Hide payment methods at checkout', from: 'rule_type_selector'
click_button "Add Rule"
select2_select "VISIBLE", from: "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility"
# New DiscountOrder Rule
# click_button '+ Add A New Rule'
# select2_select 'Apply a discount to orders', from: 'rule_type_selector'
@@ -55,6 +61,11 @@ feature 'Tag Rules', js: true do
expect(tag_rule.preferred_customer_tags).to eq "volunteer"
expect(tag_rule.preferred_variant_tags).to eq "volunteer"
expect(tag_rule.preferred_matched_variants_visibility).to eq "visible"
tag_rule = TagRule::FilterPaymentMethods.last
expect(tag_rule.preferred_customer_tags).to eq "volunteer"
expect(tag_rule.preferred_payment_method_tags).to eq "volunteer"
expect(tag_rule.preferred_matched_payment_methods_visibility).to eq "visible"
end
end
@@ -62,6 +73,7 @@ feature 'Tag Rules', js: true do
let!(:do_tag_rule) { create(:tag_rule, enterprise: enterprise, preferred_customer_tags: "member" ) }
let!(:fsm_tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: enterprise, preferred_matched_shipping_methods_visibility: "hidden", preferred_customer_tags: "member" ) }
let!(:fp_tag_rule) { create(:filter_products_tag_rule, enterprise: enterprise, preferred_matched_variants_visibility: "visible", preferred_customer_tags: "member" ) }
let!(:fpm_tag_rule) { create(:filter_payment_methods_tag_rule, enterprise: enterprise, preferred_matched_payment_methods_visibility: "hidden", preferred_customer_tags: "member" ) }
before do
login_to_admin_section
@@ -88,6 +100,10 @@ feature 'Tag Rules', js: true do
expect(page).to have_select2 "enterprise_tag_rules_attributes_2_preferred_matched_variants_visibility", selected: 'VISIBLE'
select2_select 'NOT VISIBLE', from: "enterprise_tag_rules_attributes_2_preferred_matched_variants_visibility"
# FilterPaymentMethods rule
expect(page).to have_select2 "enterprise_tag_rules_attributes_3_preferred_matched_payment_methods_visibility", selected: 'NOT VISIBLE'
select2_select 'VISIBLE', from: "enterprise_tag_rules_attributes_3_preferred_matched_payment_methods_visibility"
click_button 'Update'
# DiscountOrder rule
@@ -103,6 +119,11 @@ feature 'Tag Rules', js: true do
expect(fp_tag_rule.preferred_customer_tags).to eq "member,volunteer"
expect(fp_tag_rule.preferred_variant_tags).to eq "member,volunteer"
expect(fp_tag_rule.preferred_matched_variants_visibility).to eq "hidden"
# FilterPaymentMethods rule
expect(fpm_tag_rule.preferred_customer_tags).to eq "member,volunteer"
expect(fpm_tag_rule.preferred_payment_method_tags).to eq "member,volunteer"
expect(fpm_tag_rule.preferred_matched_payment_methods_visibility).to eq "visible"
end
end