From df9499e92d03c9b0febc40b7d575c264ecb06caf Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Tue, 3 Dec 2024 23:20:04 +0530 Subject: [PATCH] Introducing product brand using taxon_brand_selector --- .../spec/features/adjustment_reasons_spec.rb | 8 ++-- admin/spec/features/orders/show_spec.rb | 10 ++-- admin/spec/features/refund_reasons_spec.rb | 8 ++-- admin/spec/features/return_reasons_spec.rb | 8 ++-- admin/spec/features/roles_spec.rb | 8 ++-- .../spec/features/shipping_categories_spec.rb | 8 ++-- .../features/store_credit_reasons_spec.rb | 8 ++-- admin/spec/features/tax_categories_spec.rb | 4 +- core/app/models/spree/product.rb | 4 ++ core/app/models/spree/taxon_brand_selector.rb | 22 +++++++++ core/config/locales/en.yml | 3 ++ core/lib/spree/app_configuration.rb | 7 +++ .../models/spree/taxon_brand_selector_spec.rb | 46 +++++++++++++++++++ ..._admin_adjustments_controller_decorator.rb | 0 .../spree_order_state_machine_decorator.rb | 0 .../spree_adjustment_decorator.rb | 0 ...returns_default_refund_amount_decorator.rb | 0 .../spree_line_item_decorator.rb | 0 .../spree_order_decorator.rb | 0 .../spree_order_updater_decorator.rb | 0 .../spree_product_decorator.rb | 0 .../spree_shipment_decorator.rb | 0 .../features/solidus_admin/promotions_spec.rb | 8 ++-- .../models/solidus_promotions/promotion.rb | 2 +- .../admin/benefits_controller.rb | 8 ++-- .../admin/promotion_codes_controller.rb | 4 ++ .../admin/promotions_spec.rb | 8 ++-- sample/db/samples/taxonomies.rb | 6 ++- sample/db/samples/taxons.rb | 24 ++++++++++ 29 files changed, 158 insertions(+), 46 deletions(-) create mode 100644 core/app/models/spree/taxon_brand_selector.rb create mode 100644 core/spec/models/spree/taxon_brand_selector_spec.rb rename legacy_promotions/app/decorators/{solidus_legacy_promotions/controllers/solidus_admin => controllers/solidus_legacy_promotions}/solidus_admin_adjustments_controller_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/lib => lib/solidus_legacy_promotions}/spree_order_state_machine_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/models => models/solidus_legacy_promotions}/spree_adjustment_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/models => models/solidus_legacy_promotions}/spree_calculator_returns_default_refund_amount_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/models => models/solidus_legacy_promotions}/spree_line_item_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/models => models/solidus_legacy_promotions}/spree_order_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/models => models/solidus_legacy_promotions}/spree_order_updater_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/models => models/solidus_legacy_promotions}/spree_product_decorator.rb (100%) rename legacy_promotions/app/decorators/{solidus_legacy_promotions/models => models/solidus_legacy_promotions}/spree_shipment_decorator.rb (100%) diff --git a/admin/spec/features/adjustment_reasons_spec.rb b/admin/spec/features/adjustment_reasons_spec.rb index 8af9a711ea0..14499858cfd 100644 --- a/admin/spec/features/adjustment_reasons_spec.rb +++ b/admin/spec/features/adjustment_reasons_spec.rb @@ -26,12 +26,12 @@ before do visit "/admin/adjustment_reasons#{query}" click_on "Add new" + expect(page).to have_selector("dialog") expect(page).to have_content("New Adjustment Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) @@ -69,12 +69,12 @@ Spree::AdjustmentReason.create(name: "Good Reason", code: 5999) visit "/admin/adjustment_reasons#{query}" find_row("Good Reason").click + expect(page).to have_selector("dialog") expect(page).to have_content("Edit Adjustment Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) diff --git a/admin/spec/features/orders/show_spec.rb b/admin/spec/features/orders/show_spec.rb index 7b8aebd5479..986acbac250 100644 --- a/admin/spec/features/orders/show_spec.rb +++ b/admin/spec/features/orders/show_spec.rb @@ -48,7 +48,7 @@ expect(page).to have_content("Order R123456789") open_customer_menu click_on "Edit billing address" - expect(page).to have_css("dialog", wait: 30) + expect(page).to have_css("dialog", wait: 5) within("dialog") do fill_in "Name", with: "John Doe" @@ -74,7 +74,7 @@ open_customer_menu click_on "Edit shipping address" - expect(page).to have_css("dialog", wait: 30) + expect(page).to have_css("dialog", wait: 5) within("dialog") do fill_in "Name", with: "Jane Doe" @@ -119,18 +119,18 @@ expect(Spree::Order.last.line_items.count).to eq(0) find("[aria-selected]", text: "Just another product").click - expect(page).to have_content("Variant added to cart successfully", wait: 30) + expect(page).to have_content("Variant added to cart successfully", wait: 5) expect(Spree::Order.last.line_items.count).to eq(1) expect(Spree::Order.last.line_items.last.quantity).to eq(1) fill_in "line_item[quantity]", with: 4 - expect(page).to have_content("Quantity updated successfully", wait: 30) + expect(page).to have_content("Quantity updated successfully", wait: 5) expect(Spree::Order.last.line_items.last.quantity).to eq(4) accept_confirm("Are you sure?") { click_on "Delete" } - expect(page).to have_content("Line item removed successfully", wait: 30) + expect(page).to have_content("Line item removed successfully", wait: 5) expect(Spree::Order.last.line_items.count).to eq(0) expect(page).to be_axe_clean diff --git a/admin/spec/features/refund_reasons_spec.rb b/admin/spec/features/refund_reasons_spec.rb index ae5a52663eb..cb153264174 100644 --- a/admin/spec/features/refund_reasons_spec.rb +++ b/admin/spec/features/refund_reasons_spec.rb @@ -26,12 +26,12 @@ before do visit "/admin/refund_reasons/#{query}" click_on "Add new" + expect(page).to have_selector("dialog") expect(page).to have_content("New Refund Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) @@ -66,12 +66,12 @@ Spree::RefundReason.create(name: "Return process") visit "/admin/refund_reasons#{query}" find_row("Return process").click + expect(page).to have_selector("dialog") expect(page).to have_content("Edit Refund Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) diff --git a/admin/spec/features/return_reasons_spec.rb b/admin/spec/features/return_reasons_spec.rb index 5932101bf41..706d9166749 100644 --- a/admin/spec/features/return_reasons_spec.rb +++ b/admin/spec/features/return_reasons_spec.rb @@ -26,12 +26,12 @@ before do visit "/admin/return_reasons#{query}" click_on "Add new" + expect(page).to have_selector("dialog") expect(page).to have_content("New Return Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) @@ -68,12 +68,12 @@ Spree::ReturnReason.create(name: "Good Reason") visit "/admin/return_reasons#{query}" find_row("Good Reason").click + expect(page).to have_selector("dialog") expect(page).to have_content("Edit Return Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) diff --git a/admin/spec/features/roles_spec.rb b/admin/spec/features/roles_spec.rb index 0132e2ed205..fb09c9894e0 100644 --- a/admin/spec/features/roles_spec.rb +++ b/admin/spec/features/roles_spec.rb @@ -54,12 +54,12 @@ before do visit "/admin/roles#{query}" click_on "Add new" + expect(page).to have_selector("dialog") expect(page).to have_content("New Role") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) @@ -121,14 +121,14 @@ Spree::Role.create(name: "Reviewer", permission_sets: [settings_edit_permission]) visit "/admin/roles#{query}" find_row("Reviewer").click + expect(page).to have_selector("dialog") expect(page).to have_content("Edit Role") expect(page).to be_axe_clean expect(Spree::Role.find_by(name: "Reviewer").permission_set_ids) .to contain_exactly(settings_edit_permission.id) end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) diff --git a/admin/spec/features/shipping_categories_spec.rb b/admin/spec/features/shipping_categories_spec.rb index 674ce76a00d..703de26bd66 100644 --- a/admin/spec/features/shipping_categories_spec.rb +++ b/admin/spec/features/shipping_categories_spec.rb @@ -26,12 +26,12 @@ before do visit "/admin/shipping_categories#{query}" click_on "Add new" + expect(page).to have_selector("dialog") expect(page).to have_content("New Shipping Category") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) @@ -66,12 +66,12 @@ Spree::ShippingCategory.create(name: "Letter Mail") visit "/admin/shipping_categories#{query}" find_row("Letter Mail").click + expect(page).to have_selector("dialog") expect(page).to have_content("Edit Shipping Category") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) diff --git a/admin/spec/features/store_credit_reasons_spec.rb b/admin/spec/features/store_credit_reasons_spec.rb index b4b2c46aff4..50b2c11d023 100644 --- a/admin/spec/features/store_credit_reasons_spec.rb +++ b/admin/spec/features/store_credit_reasons_spec.rb @@ -26,12 +26,12 @@ before do visit "/admin/store_credit_reasons#{query}" click_on "Add new" + expect(page).to have_selector("dialog") expect(page).to have_content("New Store Credit Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) @@ -66,12 +66,12 @@ Spree::StoreCreditReason.create(name: "New Customer Reward") visit "/admin/store_credit_reasons#{query}" find_row("New Customer Reward").click + expect(page).to have_selector("dialog") expect(page).to have_content("Edit Store Credit Reason") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) diff --git a/admin/spec/features/tax_categories_spec.rb b/admin/spec/features/tax_categories_spec.rb index b91a24256dc..417ee5e1262 100644 --- a/admin/spec/features/tax_categories_spec.rb +++ b/admin/spec/features/tax_categories_spec.rb @@ -28,12 +28,12 @@ before do visit "/admin/tax_categories#{query}" click_on "Add new" + expect(page).to have_selector("dialog") expect(page).to have_content("New Tax Category") expect(page).to be_axe_clean end - it "opens a modal" do - expect(page).to have_selector("dialog") + it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 1754e939497..03193148ec0 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -291,6 +291,10 @@ def gallery @gallery ||= Spree::Config.product_gallery_class.new(self) end + def brand + Spree::Config.brand_selector_class.new(self).call + end + private def any_variants_not_track_inventory? diff --git a/core/app/models/spree/taxon_brand_selector.rb b/core/app/models/spree/taxon_brand_selector.rb new file mode 100644 index 00000000000..4a0a0dce0bd --- /dev/null +++ b/core/app/models/spree/taxon_brand_selector.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Spree + class TaxonBrandSelector + BRANDS_TAXONOMY_NAME = "Brands" + + def initialize(product) + @product = product + end + + def call + product.taxons + .joins(:taxonomy) + .where(spree_taxonomies: { name: BRANDS_TAXONOMY_NAME }) + .first + end + + private + + attr_reader :product + end +end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 6363feef47a..e7e1d1910a5 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -1075,6 +1075,8 @@ en: billing: Billing billing_address: Billing Address both: Both + brand: Brand + brands: Brands calculated_reimbursements: Calculated Reimbursements calculator: Calculator calculator_settings_warning: If you are changing the calculator type or preference source, you must save first before you can edit the calculator settings @@ -2097,6 +2099,7 @@ en: scope: Scope search: Search search_results: Search results for '%{keywords}' + search_results_all: Show all results for '%{keywords}' searching: Searching secure_connection_type: Secure Connection Type security_settings: Security Settings diff --git a/core/lib/spree/app_configuration.rb b/core/lib/spree/app_configuration.rb index 8b0223eeb59..631a609d18d 100644 --- a/core/lib/spree/app_configuration.rb +++ b/core/lib/spree/app_configuration.rb @@ -522,6 +522,13 @@ def payment_canceller # Spree::StoreCreditPrioritizer. class_name_attribute :store_credit_prioritizer_class, default: 'Spree::StoreCreditPrioritizer' + # Allows finding brand for product. + # + # @!attribute [rw] brand_selector_class + # @return [Class] a class with the same public interfaces as + # Spree::TaxonBrandSelector. + class_name_attribute :brand_selector_class, default: 'Spree::TaxonBrandSelector' + # @!attribute [rw] taxon_image_style_default # # Defines which style to default to when style is not provided diff --git a/core/spec/models/spree/taxon_brand_selector_spec.rb b/core/spec/models/spree/taxon_brand_selector_spec.rb new file mode 100644 index 00000000000..7d2d4721e60 --- /dev/null +++ b/core/spec/models/spree/taxon_brand_selector_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Spree::TaxonBrandSelector, type: :model do + let(:taxonomy) { create(:taxonomy, name: "Brands") } + let(:taxon) { create(:taxon, taxonomy: taxonomy, name: "Brand A") } + let(:product) { create(:product, taxons: [taxon]) } + + subject { described_class.new(product) } + + describe "#call" do + context "when the product has a taxon under the 'Brands' taxonomy" do + it "returns the first taxon under 'Brands'" do + expect(subject.call).to eq(taxon) + end + end + + context "when the product has multiple taxons under the 'Brands' taxonomy" do + let(:taxon_b) { create(:taxon, taxonomy: taxonomy, name: "Brand B") } + before { product.taxons << taxon_b } + + it "returns the first taxon under 'Brands'" do + expect(subject.call).to eq(taxon) + end + end + + context "when the product does not have a taxon under the 'Brands' taxonomy" do + let(:other_taxonomy) { create(:taxonomy, name: "Categories") } + let(:other_taxon) { create(:taxon, taxonomy: other_taxonomy, name: "Category A") } + let(:product) { create(:product, taxons: [other_taxon]) } + + it "returns nil" do + expect(subject.call).to be_nil + end + end + + context "when the product has no taxons" do + let(:product) { create(:product) } + + it "returns nil" do + expect(subject.call).to be_nil + end + end + end +end diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/controllers/solidus_admin/solidus_admin_adjustments_controller_decorator.rb b/legacy_promotions/app/decorators/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/controllers/solidus_admin/solidus_admin_adjustments_controller_decorator.rb rename to legacy_promotions/app/decorators/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/lib/spree_order_state_machine_decorator.rb b/legacy_promotions/app/decorators/lib/solidus_legacy_promotions/spree_order_state_machine_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/lib/spree_order_state_machine_decorator.rb rename to legacy_promotions/app/decorators/lib/solidus_legacy_promotions/spree_order_state_machine_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_adjustment_decorator.rb b/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_adjustment_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_adjustment_decorator.rb rename to legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_adjustment_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_calculator_returns_default_refund_amount_decorator.rb b/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_calculator_returns_default_refund_amount_decorator.rb rename to legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_line_item_decorator.rb b/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_line_item_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_line_item_decorator.rb rename to legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_line_item_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_order_decorator.rb b/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_order_decorator.rb rename to legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_order_updater_decorator.rb b/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_updater_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_order_updater_decorator.rb rename to legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_updater_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_product_decorator.rb b/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_product_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_product_decorator.rb rename to legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_product_decorator.rb diff --git a/legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_shipment_decorator.rb b/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_shipment_decorator.rb similarity index 100% rename from legacy_promotions/app/decorators/solidus_legacy_promotions/models/spree_shipment_decorator.rb rename to legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_shipment_decorator.rb diff --git a/legacy_promotions/spec/features/solidus_admin/promotions_spec.rb b/legacy_promotions/spec/features/solidus_admin/promotions_spec.rb index 16f1439ace7..922846e2a51 100644 --- a/legacy_promotions/spec/features/solidus_admin/promotions_spec.rb +++ b/legacy_promotions/spec/features/solidus_admin/promotions_spec.rb @@ -14,13 +14,13 @@ visit "/admin/promotions" expect(page).to have_content("My active Promotion") click_on "Draft" - expect(page).to have_content("My draft Promotion", wait: 30) + expect(page).to have_content("My draft Promotion", wait: 5) click_on "Future" - expect(page).to have_content("My future Promotion", wait: 30) + expect(page).to have_content("My future Promotion", wait: 5) click_on "Expired" - expect(page).to have_content("My expired Promotion", wait: 30) + expect(page).to have_content("My expired Promotion", wait: 5) click_on "All" - expect(page).to have_content("My active Promotion", wait: 30) + expect(page).to have_content("My active Promotion", wait: 5) expect(page).to have_content("My draft Promotion") expect(page).to have_content("My future Promotion") expect(page).to have_content("My expired Promotion") diff --git a/promotions/app/models/solidus_promotions/promotion.rb b/promotions/app/models/solidus_promotions/promotion.rb index e36015facac..7eacbbf61af 100644 --- a/promotions/app/models/solidus_promotions/promotion.rb +++ b/promotions/app/models/solidus_promotions/promotion.rb @@ -9,7 +9,7 @@ class Promotion < Spree::Base belongs_to :original_promotion, class_name: "Spree::Promotion", optional: true has_many :benefits, class_name: "SolidusPromotions::Benefit", dependent: :destroy has_many :conditions, through: :benefits - has_many :codes, class_name: "SolidusPromotions::PromotionCode", dependent: :destroy + has_many :codes, class_name: "SolidusPromotions::PromotionCode", dependent: :destroy, inverse_of: :promotion has_many :code_batches, class_name: "SolidusPromotions::PromotionCodeBatch", dependent: :destroy has_many :order_promotions, class_name: "SolidusPromotions::OrderPromotion", dependent: :destroy diff --git a/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb b/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb index cd0f40da056..354a37ac8ba 100644 --- a/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb +++ b/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb @@ -14,12 +14,12 @@ def new def create @benefit = @benefit_type.new(benefit_params) @benefit.promotion = @promotion - if @benefit.save(validate: false) + if @benefit.save flash[:success] = t("spree.successfully_created", resource: SolidusPromotions::Benefit.model_name.human) redirect_to location_after_save, format: :html else - render :new, layout: false + render :new, layout: false, status: :unprocessable_entity end end @@ -28,7 +28,7 @@ def edit if params.dig(:benefit, :calculator_type) @benefit.calculator_type = params[:benefit][:calculator_type] end - render layout: false + render layout: false, status: :unprocessable_entity end def update @@ -39,7 +39,7 @@ def update t("spree.successfully_updated", resource: SolidusPromotions::Benefit.model_name.human) redirect_to location_after_save, format: :html else - render :edit + render :edit, status: :unprocessable_entity end end diff --git a/promotions/lib/controllers/backend/solidus_promotions/admin/promotion_codes_controller.rb b/promotions/lib/controllers/backend/solidus_promotions/admin/promotion_codes_controller.rb index ee23a457469..0310fc54ceb 100644 --- a/promotions/lib/controllers/backend/solidus_promotions/admin/promotion_codes_controller.rb +++ b/promotions/lib/controllers/backend/solidus_promotions/admin/promotion_codes_controller.rb @@ -48,6 +48,10 @@ def create private + def model_class + SolidusPromotions::PromotionCode + end + def load_promotion @promotion = SolidusPromotions::Promotion .accessible_by(current_ability, :show) diff --git a/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb b/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb index ddc65c9b46f..c02a8066084 100644 --- a/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb +++ b/promotions/spec/system/solidus_promotions/admin/promotions_spec.rb @@ -14,13 +14,13 @@ visit "/admin/solidus/promotions" expect(page).to have_content("My active Promotion") click_on "Draft" - expect(page).to have_content("My draft Promotion", wait: 30) + expect(page).to have_content("My draft Promotion", wait: 5) click_on "Future" - expect(page).to have_content("My future Promotion", wait: 30) + expect(page).to have_content("My future Promotion", wait: 5) click_on "Expired" - expect(page).to have_content("My expired Promotion", wait: 30) + expect(page).to have_content("My expired Promotion", wait: 5) click_on "All" - expect(page).to have_content("My active Promotion", wait: 30) + expect(page).to have_content("My active Promotion", wait: 5) expect(page).to have_content("My draft Promotion") expect(page).to have_content("My future Promotion") expect(page).to have_content("My expired Promotion") diff --git a/sample/db/samples/taxonomies.rb b/sample/db/samples/taxonomies.rb index c3a30e0b79a..aab0f84369c 100644 --- a/sample/db/samples/taxonomies.rb +++ b/sample/db/samples/taxonomies.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true +store = Spree::Store.where(code: 'sample-store').first + taxonomies = [ - { name: "Categories" }, - { name: "Brand" } + { name: "Categories", store: }, + { name: "Brands", store: } ] taxonomies.each do |taxonomy_attrs| diff --git a/sample/db/samples/taxons.rb b/sample/db/samples/taxons.rb index 8d96e53e3a8..f882792a61e 100644 --- a/sample/db/samples/taxons.rb +++ b/sample/db/samples/taxons.rb @@ -4,6 +4,7 @@ Spree::Sample.load_sample("products") categories = Spree::Taxonomy.find_by!(name: "Categories") +brands = Spree::Taxonomy.find_by!(name: "Brands") products = { solidus_bottles: "Solidus Water Bottle", @@ -29,6 +30,29 @@ name: "Categories", taxonomy: categories, }, + { + name: "Brands", + taxonomy: brands + }, + { + name: "Solidus", + taxonomy: brands, + parent: "Brands", + products: [ + products[:solidus_tote], + products[:solidus_hoodie], + products[:solidus_mug_set], + products[:solidus_hat], + products[:solidus_sticker], + products[:solidus_notebook], + products[:solidus_tshirt], + products[:solidus_long_sleeve_tee], + products[:solidus_dark_tee], + products[:solidus_bottles], + products[:solidus_canvas_tote], + products[:solidus_cap] + ] + }, { name: "Clothing", taxonomy: categories,