Module: Store::MultiStoreMethods

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/spree/store/multi_store_methods.rb

Constant Summary collapse

RESERVED_CODES =
%w(
  admin default app api www cdn files assets checkout account auth login user
)

Instance Method Summary collapse

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/concerns/spree/store/multi_store_methods.rb', line 49

def can_be_deleted?
  self.class.where.not(id: id).any?
end

#formatted_custom_domainObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/concerns/spree/store/multi_store_methods.rb', line 35

def formatted_custom_domain
  return unless default_custom_domain

  @formatted_custom_domain ||= if Rails.env.development? || Rails.env.test?
    URI::Generic.build(
      scheme: Rails.application.routes.default_url_options[:protocol] || 'http',
      host: default_custom_domain.url,
      port: Rails.application.routes.default_url_options[:port]
    ).to_s
  else
    URI::HTTPS.build(host: default_custom_domain.url).to_s
  end
end

#import_payment_methods_from_storeObject



62
63
64
65
66
67
68
69
# File 'app/models/concerns/spree/store/multi_store_methods.rb', line 62

def import_payment_methods_from_store
  store = Spree::Store.find(import_payment_methods_from_store_id)
  payment_method_ids = store.payment_method_ids

  return if payment_method_ids.empty?

  Spree::StorePaymentMethod.insert_all(payment_method_ids.map { |payment_method_id| { store_id: id, payment_method_id: payment_method_id } })
end

#import_products_from_storeObject



53
54
55
56
57
58
59
60
# File 'app/models/concerns/spree/store/multi_store_methods.rb', line 53

def import_products_from_store
  store = Spree::Store.find(import_products_from_store_id)
  product_ids = store.products.pluck(:id)

  return if product_ids.empty?

  Spree::StoreProduct.insert_all(product_ids.map { |product_id| { store_id: id, product_id: product_id } })
end