Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow stand-alone Spree Checkout to run with existing Spree Frontend #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions app/helpers/spree/store_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ module Spree
module StoreHelper
include LocaleHelper

def spree_frontend_path_to_checkout
if Spree::Frontend::Engine.checkout_available?
spree.checkout_root_path
else
spree.checkout_path
end
end

def store_country_iso(store = nil)
store ||= current_store if defined?(current_store)

Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/orders/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</div>

<div class="d-flex flex-column text-center shopping-cart-buttons" data-hook="cart_buttons">
<%= link_to Spree.t('cart_page.checkout'), spree.checkout_path, class: 'btn btn-primary text-uppercase font-weight-bold cart-checkout-btn shopping-cart-buttons-checkout', id: 'checkout-link', method: :get %>
<%= link_to Spree.t('cart_page.checkout'), spree_frontend_path_to_checkout, class: 'btn btn-primary text-uppercase font-weight-bold cart-checkout-btn shopping-cart-buttons-checkout', id: 'checkout-link', method: :get %>
<span class="text-uppercase shopping-cart-buttons-or d-lg-none"><%= Spree.t(:or) %></span>
<%= link_to Spree.t(:continue_shopping), spree.products_path, class: 'btn btn-outline-primary text-uppercase font-weight-bold d-lg-none shopping-cart-buttons-continue' %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/shared/_product_added_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div class="container-fluid">
<div class="row pb-4 justify-content-center">
<div class="col-12 col-lg-8">
<%= link_to spree.checkout_path, class: 'btn btn-primary w-100 font-weight-bold text-uppercase product-added-modal-button', method: :get do %>
<%= link_to spree_frontend_path_to_checkout, class: 'btn btn-primary w-100 font-weight-bold text-uppercase product-added-modal-button', method: :get do %>
<%= Spree.t(:checkout) %>
<% end %>
</div>
Expand Down
11 changes: 6 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
get '/t/*id', to: 'taxons#show', as: :nested_taxons
get '/product_carousel/:id', to: 'taxons#product_carousel'

# non-restful checkout stuff
patch '/checkout/update/:state', to: 'checkout#update', as: :update_checkout
get '/checkout/:state', to: 'checkout#edit', as: :checkout_state
get '/checkout', to: 'checkout#edit', as: :checkout

unless Spree::Frontend::Engine.checkout_available?
# non-restful checkout stuff
patch '/checkout/update/:state', to: 'checkout#update', as: :update_checkout
get '/checkout/:state', to: 'checkout#edit', as: :checkout_state
get '/checkout', to: 'checkout#edit', as: :checkout
end
resources :orders, except: [:index, :new, :create, :destroy]

resources :addresses, except: [:index, :show]
Expand Down
4 changes: 4 additions & 0 deletions lib/spree/frontend/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Engine < ::Rails::Engine
initializer 'spree.frontend.environment', before: :load_config_initializers do |_app|
Spree::Frontend::Config = Spree::Frontend::Configuration.new
end

def self.checkout_available?
@@checkout_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Checkout::Engine')
end
end
end
end