From 2cb9ac17f7ee012b4dd0b195e0367ec83687d8a3 Mon Sep 17 00:00:00 2001 From: Adam Mueller Date: Wed, 27 Nov 2024 15:06:56 -0800 Subject: [PATCH 1/2] Add inverse_of to Promotion#codes association This helps fix an issue when creating a new promotion with a single code. Without the inverse_of parameter, our associated codes won't correctly infer that they're associated to a new promotion and will generate undefined method for nil errors. Co-authored-by: Alistair Norman --- promotions/app/models/solidus_promotions/promotion.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 6ea8b43348e999ca740692c88695536c740aa0c8 Mon Sep 17 00:00:00 2001 From: Adam Mueller Date: Wed, 27 Nov 2024 15:11:58 -0800 Subject: [PATCH 2/2] Fix model class for new PromotionCodesController Unfortunately, our resource controller is hardcoded to look for a `Spree::` object, which obviously doesn't work with the new promotion namespace. Co-authored-by: Alistair Norman --- .../solidus_promotions/admin/promotion_codes_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) 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)