Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Spree
module Admin
module ShippingMethodsControllerDecorator
def self.prepended(base)
base.before_action :load_stores, only: [:edit, :update]
end

private

def load_stores
@stores = Spree::Store.all
end
end
end
end

::Spree::Admin::ShippingMethodsController.prepend(Spree::Admin::ShippingMethodsControllerDecorator)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Spree
module SpreeMultiDomain
module ProductDecorator
def self.prepended(base)
base.has_many :store_products, class_name: 'Spree::StoreProduct', dependent: :destroy
Expand All @@ -9,4 +9,4 @@ def self.prepended(base)
end
end

::Spree::Product.prepend(Spree::ProductDecorator)
::Spree::Product.prepend(SpreeMultiDomain::ProductDecorator)
16 changes: 16 additions & 0 deletions app/models/spree_multi_domain/shipping_method_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module SpreeMultiDomain
module ShippingMethodDecorator
def self.prepended(base)
base.has_and_belongs_to_many :stores
end

def available_for_store?(store)
return true if self.stores.blank?

store_ids.include?(store.id)
end

end
end

::Spree::ShippingMethod.prepend(SpreeMultiDomain::ShippingMethodDecorator)
23 changes: 23 additions & 0 deletions app/models/spree_multi_domain/stock/estimator_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module SpreeMultiDomain
module Stock
module EstimatorDecorator

def shipping_methods(package, display_filter)
package.shipping_methods.select do |ship_method|
calculator = ship_method.calculator

ship_method.available_to_display?(display_filter) &&
ship_method.available_for_store?(order.store) &&
ship_method.include?(order.ship_address) &&
calculator.available?(package) &&
(calculator.preferences[:currency].blank? ||
calculator.preferences[:currency] == currency)
end
end


end
end
end

::Spree::Stock::Estimator.prepend(SpreeMultiDomain::Stock::EstimatorDecorator)
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module Spree
module SpreeMultiDomain
module StoreDecorator
def self.prepended(base)
base.has_many :store_products, class_name: 'Spree::StoreProduct', dependent: :destroy
base.has_many :products, through: :store_products, class_name: 'Spree::Product'
base.has_many :taxonomies
base.has_and_belongs_to_many :promotion_rules, class_name: 'Spree::Promotion::Rules::Store', join_table: 'spree_promotion_rules_stores', association_foreign_key: 'promotion_rule_id'
base.has_many :shipping_methods, class_name: 'Spree::ShippingMethod'
end
end
end

::Spree::Store.prepend(Spree::StoreDecorator)
::Spree::Store.prepend(SpreeMultiDomain::StoreDecorator)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Spree
module SpreeMultiDomain
module TaxonDecorator
def self.prepended(base)
base.scope :by_store, ->(store_id) { joins(:taxonomy).merge(Spree::Taxonomy.by_store(store_id)) }
Expand All @@ -13,4 +13,4 @@ def find_by_store_id_and_permalink!(store_id, permalink)
end
end

::Spree::Taxon.prepend(Spree::TaxonDecorator)
::Spree::Taxon.prepend(SpreeMultiDomain::TaxonDecorator)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Spree
module SpreeMultiDomain
module TaxonomyDecorator
def self.prepended(base)
base.belongs_to :store
Expand All @@ -8,4 +8,4 @@ def self.prepended(base)
end
end

::Spree::Taxonomy.prepend(Spree::TaxonomyDecorator)
::Spree::Taxonomy.prepend(SpreeMultiDomain::TaxonomyDecorator)
7 changes: 7 additions & 0 deletions app/overrides/decorate_admin_shipping_methods_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Deface::Override.new(
virtual_path: 'spree/admin/shipping_methods/_form',
name: 'multi_domain_admin_shipping_method_stores_form',
insert_after: "[data-hook='admin_shipping_method_form_display_field']",
partial: 'spree/admin/shipping_methods/stores',
disabled: false
)
6 changes: 6 additions & 0 deletions app/views/spree/admin/shipping_methods/_stores.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="col-12 col-lg-6">
<div data-hook="admin_shipping_method_form_store_field" class="form-group">
<%= label_tag :shipping_method_stores, Spree.t(:stores) %>
<%= collection_select(:shipping_method, :store_ids, @stores, :id, :unique_name, {}, { multiple: true, class: 'select2' }) %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddShippingMethodsStoresAssociation < ActiveRecord::Migration[6.0]
def change
create_table :spree_shipping_methods_stores, id: false do |t|
t.belongs_to :shipping_method
t.belongs_to :store
end
end
end
2 changes: 1 addition & 1 deletion lib/spree_multi_domain/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Engine < Rails::Engine
def self.activate
%w[app lib].each do |dir|
Dir.glob(File.join(File.dirname(__FILE__), "../../#{dir}/**/*_decorator*.rb")).sort.each do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
require_dependency(c)
end
end

Expand Down