From 405ebb08b763f350f33f0502f0e62d6b568c7d72 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 16 Nov 2024 15:01:03 +0100 Subject: [PATCH] Fix(Promotions): Instantiate single promo code with promotion Because promotion codes have the `-> {with_discarded}` scope on the `promotion` association, a promo code that's instantiated with `promotion.codes.new` will not have the promotion associated at the beginning, leading to errors. This passes in the promotion so that the promo code knows where it belongs. --- .../backend/solidus_promotions/admin/promotions_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/promotions/lib/controllers/backend/solidus_promotions/admin/promotions_controller.rb b/promotions/lib/controllers/backend/solidus_promotions/admin/promotions_controller.rb index 6a1e9a9fb7e..f84386e21af 100644 --- a/promotions/lib/controllers/backend/solidus_promotions/admin/promotions_controller.rb +++ b/promotions/lib/controllers/backend/solidus_promotions/admin/promotions_controller.rb @@ -11,8 +11,7 @@ class PromotionsController < BaseController def create @promotion = model_class.new(permitted_resource_params) - @promotion.codes.new(value: params[:single_code]) if params[:single_code].present? - + @promotion.codes.new(promotion: @promotion, value: params[:single_code]) if params[:single_code].present? if params[:code_batch] @code_batch = @promotion.code_batches.new(code_batch_params) end