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
Migrate logic for Spree::Variant
Matthew Kennedy169ed3c9139d
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex ca20fef52d..2ceb2f6b3c 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -43,6 +43,7 @@ module Spreeinverse_of: :varianthas_many :wished_items, dependent: :destroy+ has_many :digitalsbefore_validation :set_cost_currency@@ -59,6 +60,7 @@ module Spreeafter_create :create_stock_itemsafter_create :set_master_out_of_stock, unless: :is_master?+ after_save :destroy_digital, if: :deleted?after_touch :clear_in_stock_cache@@ -302,8 +304,22 @@ module Spree@backordered ||= !in_stock? && stock_items.exists?(backorderable: true)end+ # Is this variant to be downloaded by the customer?+ def digital?+ digitals.present?+ end+private+ # :dependent => :destroy needs to be handled manually+ # spree does not delete variants, just marks them as deleted?+ # optionally keep digitals around for customers who require continued access to their purchases+ def destroy_digital+ return if Spree::DigitalConfiguration[:keep_digitals]++ digitals.map(&:destroy)+ end+def ensure_no_line_itemsif line_items.any?errors.add(:base, :cannot_destroy_if_attached_to_line_items)