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
Push For reference of handling store change.
Matthew Kennedy7c823d301ca2
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex 67555dd761..b1afe53f28 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -130,7 +130,8 @@ module Spreebefore_create :link_by_emailbefore_update :homogenize_line_item_currencies, if: :currency_changed?- before_save :reset_order_if_store_association_has_changed+ # TODO: handle_store_change+ # before_save :handle_store_changewith_options presence: true do# we want to have this case_sentive: true as changing it to false causes all SQL to use LOWER(slug)@@ -411,6 +412,24 @@ module Spreeendend+ # TODO: Implement hanedeling of store+ # Removes line items from the order if the line item is not+ # available in the store the order belongs to.+ def sync_line_items_with_order_by_store+ line_items.any? do |line_item|+ line_item_stores = line_item.variant.product.stores++ line_item_available_store_ids = []+ line_item_stores.map do |store|+ line_item_available_store_ids << store.id+ end++ unless line_item_available_store_ids.include?(store.id)+ line_item.destroy+ end+ end+ end+def ensure_line_items_are_in_stockif insufficient_stock_lines.present?restart_checkout_flow@@ -670,11 +689,20 @@ module Spreeprivate- def reset_order_if_store_association_has_changed+ # TODO: Implement hanedeling of store+ # change and store scoped products.+ def handle_store_changereturn if new_record?- if store_id_changed?- empty!+ if store_id_changed? && completed?+ errors.add(:base, Spree.t('errors.messages.once_an_order_is_complete_you_can_not_change_store'))+ throw(:abort)+ elsif store_id_changed? && !completed?+ sync_line_items_with_order_by_store+ update_with_updater!+ self+ else+ trueendenddiff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex c6dca4d2f8..164f3e0ddc 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -894,6 +894,7 @@ en:error: errorerrors:messages:+ once_an_order_is_complete_you_can_not_change_store: Once an order is complete, you can not change the store.blank: can't be blankcould_not_create_taxon: Could not create taxonno_shipping_methods_available: No shipping methods available for selected location, please change your address and try again.