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
Improve handling scheduled Price Lists
Damian Legawiec720081b27cb8
diff --git a/core/app/models/spree/price_list.rb b/core/app/models/spree/price_list.rbindex a338506539..258d4ca0e0 100644--- a/core/app/models/spree/price_list.rb+++ b/core/app/models/spree/price_list.rb@@ -58,10 +58,13 @@ module Spreeendend+ # Returns price lists applicable for a given pricing context+ # - active: always applies (within date range)+ # - scheduled: applies only within starts_at/ends_at date rangedef self.for_context(context)timezone = context.store&.preferred_timezone || 'UTC'for_store(context.store)- .with_status(:active)+ .with_status(:active, :scheduled).current(timezone).by_positionend@@ -94,6 +97,15 @@ module Spreeactive? || scheduled?end+ # Returns true if the price list is currently in effect+ # (active, or scheduled and within date range)+ def currently_active?+ return true if active? && within_date_range?(Time.current)+ return true if scheduled? && within_date_range?(Time.current)++ false+ end+def add_products(product_ids)return if product_ids.blank?@@ -203,8 +215,11 @@ module Spreeenddef within_date_range?(date)- return false if starts_at.present? && date < starts_at- return false if ends_at.present? && date > ends_at+ timezone = store&.preferred_timezone || Rails.application.config.time_zone+ date_in_tz = date.in_time_zone(timezone)++ return false if starts_at.present? && date_in_tz < starts_at+ return false if ends_at.present? && date_in_tz > ends_attrueenddiff --git a/core/lib/spree/testing_support/factories/price_list_factory.rb b/core/lib/spree/testing_support/factories/price_list_factory.rbindex 588a8267f4..ad1c9df719 100644--- a/core/lib/spree/testing_support/factories/price_list_factory.rb+++ b/core/lib/spree/testing_support/factories/price_list_factory.rb@@ -18,6 +18,8 @@ FactoryBot.define dotrait :scheduled dostatus { 'scheduled' }+ starts_at { 1.hour.from_now }+ ends_at { 1.week.from_now }endtrait :with_date_range do