Class: Spree::Stores::ProvisionDefaults

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree/stores/provision_defaults.rb

Overview

Creates the per-store defaults whose shape depends on where the shop is: the default market, the warehouse, the delivery zones and their methods, and pickup. The seeds cannot build these, because when they run nobody has said which country the shop sells from yet — so they are built here, from the merchant's answer, rather than seeded as US and rewritten later.

Two callers only (docs/plans/6.0-store-context-and-first-run-setup.md): the first-run setup endpoint, and the env-credential branch of Spree::Seeds::AdminUser. Never wire this to a settings screen — run against a configured store it reads as a data reset.

Constant Summary collapse

DOMESTIC_AMOUNT =
5
INTERNATIONAL_AMOUNT =
20

Instance Method Summary collapse

Methods included from Spree::ServiceModule::Base

prepended

Instance Method Details

#call(store:, country:, locale: nil, currency: nil) ⇒ Spree::Store

Returns the store, reloaded.

Parameters:

  • store (Spree::Store) —

    the store to provision, already persisted

  • country (Spree::Country) —

    where the shop ships from

  • locale (String, nil) (defaults to: nil) —

    storefront locale, a code from Spree::Locales::ALL (another spelling or region moves to the listed one); defaults to the country's own language, then English

  • currency (String, nil) (defaults to: nil) —

    ISO 4217 code; defaults to the country's own currency. Merchants who ship from one country and price in another currency pass it explicitly.

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/spree/stores/provision_defaults.rb', line 28

def call(store:, country:, locale: nil, currency: nil)
  @store = store
  @country = country
  @currency = resolve_currency(currency, country)
  @locale = resolve_locale(locale, country)

  # Defaults are bookkeeping, not merchant actions — webhooks and
  # subscribers should not hear about each zone and method created here.
  Spree::Events.disable do
    ApplicationRecord.transaction do
      update_default_market
      provision_stock_location
      provision_delivery_zones
      provision_package_type
      provision_pickup
      restate_seeded_calculators
    end
  end

  store.reload
end