Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Fixed not-found error if using a mount-path for the Spree engine. #180

Open
wants to merge 4 commits into
base: 2-4-stable
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
2 changes: 1 addition & 1 deletion app/controllers/spree/static_content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Spree::StaticContentController < Spree::StoreController
layout :determine_layout

def show
@page = Spree::Page.by_store(current_store).visible.find_by_slug!(request.path)
@page = Spree::Page.by_store(current_store).visible.find_by_slug!(::StaticPage.remove_spree_mount_point_if_exists(request.path))
end

private
Expand Down
11 changes: 10 additions & 1 deletion lib/spree_static_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ def self.remove_spree_mount_point(path)
regex = Regexp.new '\A' + Rails.application.routes.url_helpers.spree_path
path.sub( regex, '').split('?')[0]
end

def self.remove_spree_mount_point_if_exists(path)
spree_path = Rails.application.routes.url_helpers.spree_path
if spree_path == "/"
return path
else
return remove_spree_mount_point(path)
end
end
end

class Spree::StaticPage
def self.matches?(request)
return false if request.path =~ /(^\/+(admin|account|cart|checkout|content|login|pg\/|orders|products|s\/|session|signup|shipments|states|t\/|tax_categories|user)+)/
!Spree::Page.visible.find_by_slug(request.path).nil?
!Spree::Page.visible.find_by_slug(::StaticPage.remove_spree_mount_point_if_exists(request.path)).nil?
end
end