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 7209147b66..a5d77cf7ff 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 @@ -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 "FilterProducts" + newRule.peferred_variant_tags = [] + newRule.preferred_matched_variants_visibility = "visible" tagGroup.rules.push(newRule) updateRuleCounts() 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 54e33006e4..c75b50bbf5 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 @@ -7,10 +7,11 @@ angular.module("admin.tagRules").directive 'newTagRuleDialog', ($compile, $templ scope.ruleTypes = [ # { id: "DiscountOrder", name: 'Apply a discount to orders' } - { id: "FilterShippingMethods", name: 'Show/Hide shipping methods' } + { id: "FilterProducts", name: 'Show or Hide variants in my shopfront' } + { id: "FilterShippingMethods", name: 'Show or Hide shipping methods at checkout' } ] - scope.ruleType = "DiscountOrder" + scope.ruleType = scope.ruleTypes[0].id # Set Dialog options template.dialog diff --git a/app/assets/javascripts/admin/tag_rules/directives/tag_rules/filter_products.js.coffee b/app/assets/javascripts/admin/tag_rules/directives/tag_rules/filter_products.js.coffee new file mode 100644 index 0000000000..58e9c47c5b --- /dev/null +++ b/app/assets/javascripts/admin/tag_rules/directives/tag_rules/filter_products.js.coffee @@ -0,0 +1,4 @@ +angular.module("admin.tagRules").directive "filterProducts", -> + restrict: "E" + replace: true + templateUrl: "admin/tag_rules/filter_products.html" diff --git a/app/assets/javascripts/templates/admin/tag_rules/filter_products.html.haml b/app/assets/javascripts/templates/admin/tag_rules/filter_products.html.haml new file mode 100644 index 0000000000..0429dd7cbd --- /dev/null +++ b/app/assets/javascripts/templates/admin/tag_rules/filter_products.html.haml @@ -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::FilterProducts" } + + %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_variant_tags", + name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_variant_tags]", + ng: { value: "rule.preferred_customer_tags" } } + + %span.text-normal {{ $index + 1 }}. Variants with matching tags are + %input.light.ofn-select2{ id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_variants_visibility", + name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_variants_visibility]", + ng: { model: "rule.preferred_matched_variants_visibility"}, + data: 'visibilityOptions', "min-search" => 5 } + -# %tags-with-translation{ object: "rule", "tags-attr" => "shipping_method_tags", "tag-list-attr" => "preferred_shipping_method_tags" } diff --git a/app/serializers/api/admin/tag_rule_serializer.rb b/app/serializers/api/admin/tag_rule_serializer.rb index ac333c23c6..c8fdd58c44 100644 --- a/app/serializers/api/admin/tag_rule_serializer.rb +++ b/app/serializers/api/admin/tag_rule_serializer.rb @@ -24,4 +24,12 @@ module Api::Admin::TagRule object.preferred_shipping_method_tags.split(",") end end + + class FilterProductsSerializer < BaseSerializer + attributes :preferred_matched_variants_visibility, :variant_tags + + def variant_tags + object.preferred_variant_tags.split(",") + end + end end diff --git a/app/views/admin/enterprises/form/_tag_rules.html.haml b/app/views/admin/enterprises/form/_tag_rules.html.haml index 4ed9aeb5c1..37bb699646 100644 --- a/app/views/admin/enterprises/form/_tag_rules.html.haml +++ b/app/views/admin/enterprises/form/_tag_rules.html.haml @@ -25,6 +25,7 @@ %td %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'" } } %td.actions %a{ ng: { click: "deleteTagRule(tagGroup, rule)" }, :class => "delete-tag-rule icon-trash no-text" } .add_rule.text-center diff --git a/spec/features/admin/tag_rules_spec.rb b/spec/features/admin/tag_rules_spec.rb index e91215a21d..af079d3431 100644 --- a/spec/features/admin/tag_rules_spec.rb +++ b/spec/features/admin/tag_rules_spec.rb @@ -22,13 +22,19 @@ feature 'Tag Rules', js: true do find(:css, "tags-input .tags input").set "volunteer\n" # New FilterShippingMethods Rule + expect(page).to have_content 'No rules apply to this tag yet' click_button '+ Add A New Rule' - select2_select 'Show/Hide shipping methods', from: 'rule_type_selector' + select2_select 'Show or Hide shipping methods at checkout', from: 'rule_type_selector' click_button "Add Rule" select2_select "NOT VISIBLE", from: "enterprise_tag_rules_attributes_0_preferred_matched_shipping_methods_visibility" + # New FilterProducts Rule + click_button '+ Add A New Rule' + select2_select 'Show or Hide variants in my shop', from: 'rule_type_selector' + click_button "Add Rule" + select2_select "VISIBLE", from: "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility" + # New DiscountOrder Rule - # expect(page).to have_content 'No rules apply to this tag yet' # click_button '+ Add A New Rule' # select2_select 'Apply a discount to orders', from: 'rule_type_selector' # click_button "Add Rule" @@ -44,12 +50,18 @@ feature 'Tag Rules', js: true do expect(tag_rule.preferred_customer_tags).to eq "volunteer" expect(tag_rule.preferred_shipping_method_tags).to eq "volunteer" expect(tag_rule.preferred_matched_shipping_methods_visibility).to eq "hidden" + + tag_rule = TagRule::FilterProducts.last + 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" end end context "updating" 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" ) } before do login_to_admin_section @@ -72,6 +84,10 @@ feature 'Tag Rules', js: true do expect(page).to have_select2 "enterprise_tag_rules_attributes_1_preferred_matched_shipping_methods_visibility", selected: 'NOT VISIBLE' select2_select 'VISIBLE', from: "enterprise_tag_rules_attributes_1_preferred_matched_shipping_methods_visibility" + # FilterProducts rule + 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" + click_button 'Update' # DiscountOrder rule @@ -82,6 +98,11 @@ feature 'Tag Rules', js: true do expect(fsm_tag_rule.preferred_customer_tags).to eq "member,volunteer" expect(fsm_tag_rule.preferred_shipping_method_tags).to eq "member,volunteer" expect(fsm_tag_rule.preferred_matched_shipping_methods_visibility).to eq "visible" + + # FilterProducts rule + 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" end end