diff --git a/promotions/app/models/solidus_promotions/promotion.rb b/promotions/app/models/solidus_promotions/promotion.rb index e36015faca..65e0e7e8b7 100644 --- a/promotions/app/models/solidus_promotions/promotion.rb +++ b/promotions/app/models/solidus_promotions/promotion.rb @@ -138,6 +138,18 @@ def eligibility_results @eligibility_results ||= SolidusPromotions::EligibilityResults.new(self) end + def can_change_apply_automatically? + path.blank? && codes.empty? + end + + def can_change_path? + !apply_automatically? && codes.empty? + end + + def can_change_codes? + !apply_automatically? && path.blank? + end + private def normalize_blank_values diff --git a/promotions/config/locales/en.yml b/promotions/config/locales/en.yml index 06d3f48182..3c4ccfbf13 100644 --- a/promotions/config/locales/en.yml +++ b/promotions/config/locales/en.yml @@ -167,6 +167,10 @@ en: general: General starts_at_placeholder: Immediately codes_present: This promotion has promotion codes defined. You cannot select the apply automatically option. + automatic: "Automatic" + path: "Path" + single_code: "Single code" + multiple_codes: "Multiple codes" edit: order_conditions: Order Conditions calculator: 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 6a1e9a9fb7..f84386e21a 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 diff --git a/promotions/lib/views/backend/solidus_promotions/admin/promotion_code_batches/_form_fields.html.erb b/promotions/lib/views/backend/solidus_promotions/admin/promotion_code_batches/_form_fields.html.erb index 7010098e2c..d29a6266e6 100644 --- a/promotions/lib/views/backend/solidus_promotions/admin/promotion_code_batches/_form_fields.html.erb +++ b/promotions/lib/views/backend/solidus_promotions/admin/promotion_code_batches/_form_fields.html.erb @@ -1,22 +1,22 @@