Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Automatically set the `starts_at` of Promotion
Damian Legawiecfa1bdf416cd5
diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rbindex f80cc8f24b..4dff892f42 100644--- a/core/app/models/spree/promotion.rb+++ b/core/app/models/spree/promotion.rb@@ -37,7 +37,7 @@ module Spreehas_many :orders, through: :order_promotions, class_name: 'Spree::Order'has_many :store_promotions, class_name: 'Spree::StorePromotion'has_many :stores, class_name: 'Spree::Store', through: :store_promotions- accepts_nested_attributes_for :promotion_actions, :promotion_rules+ accepts_nested_attributes_for :promotion_actions, :promotion_rules, allow_destroy: true## Callbacks@@ -47,6 +47,7 @@ module Spreebefore_validation :set_usage_limit_to_nil, if: -> { multi_codes? }before_validation :set_kindbefore_validation :downcase_code, if: -> { code.present? }+ before_validation :set_starts_at_to_current_time, if: -> { starts_at.blank? }after_commit :generate_coupon_codes, if: -> { multi_codes? }, on: [:create, :update]after_commit :remove_coupons, unless: -> { multi_codes? }, on: :updatebefore_destroy :not_used?@@ -307,6 +308,10 @@ module Spreeself.multi_codes = falseend+ def set_starts_at_to_current_time+ self.starts_at = Time.current+ end+def generate_coupon_codesreturn if number_of_codes.nil?return if number_of_codes <= coupon_codes.count