Class: Spree::Admin::StorefrontController
- Inherits:
-
BaseController
- Object
- BaseController
- BaseController
- Spree::Admin::StorefrontController
- Includes:
- SettingsConcern
- Defined in:
- app/controllers/spree/admin/storefront_controller.rb
Constant Summary
Constants included from LocaleConcern
LocaleConcern::ADMIN_LOCALE_COOKIE
Instance Method Summary collapse
-
#allow_origin ⇒ Object
POST /admin/storefront/allow_origin.
-
#show ⇒ Object
GET /admin/storefront.
-
#update ⇒ Object
PATCH /admin/storefront.
Methods included from SettingsConcern
Methods included from BreadcrumbConcern
#add_breadcrumb_icon_instance_var
Instance Method Details
#allow_origin ⇒ Object
POST /admin/storefront/allow_origin
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/spree/admin/storefront_controller.rb', line 41 def allow_origin origin = normalize_origin(params[:origin]) if origin.nil? flash[:error] = Spree.t('admin.storefront_setup.invalid_origin') else allowed_origin = current_store.allowed_origins.find_or_initialize_by(origin: origin) if allowed_origin.persisted? || allowed_origin.save current_store.update(preferred_storefront_url: origin) if current_store.preferred_storefront_url.blank? flash[:success] = Spree.t('admin.storefront_setup.origin_allowed', origin: origin) else flash[:error] = allowed_origin.errors..to_sentence end end redirect_to spree.admin_storefront_path, status: :see_other end |
#show ⇒ Object
GET /admin/storefront
9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/spree/admin/storefront_controller.rb', line 9 def show @breadcrumb_icon = 'building-store' Spree.t('admin.storefront_setup.title'), spree.admin_storefront_path @publishable_key = find_or_create_publishable_key @deployment_origin = normalize_origin(params[:'deployment-url']) @deployment_origin_allowed = @deployment_origin.present? && current_store.allowed_origin?(@deployment_origin) @vercel_dashboard_url = vercel_dashboard_url @storefront_origins = current_store.allowed_origins.order(:created_at).reject(&:loopback?) end |
#update ⇒ Object
PATCH /admin/storefront
Saves the storefront URL preference (used as the base for links in customer emails and as the setup-task completion signal) and adds it as an allowed origin so browser-based storefronts can call the Store API.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/spree/admin/storefront_controller.rb', line 25 def update origin = normalize_origin(params[:storefront_url]) if origin.nil? flash[:error] = Spree.t('admin.storefront_setup.invalid_origin') elsif current_store.update(preferred_storefront_url: origin) current_store.allowed_origins.find_or_create_by(origin: origin) flash[:success] = Spree.t('admin.storefront_setup.storefront_url_saved', url: origin) else flash[:error] = current_store.errors..to_sentence end redirect_to spree.admin_storefront_path, status: :see_other end |