Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix some API code.

Matthew Kennedy528a52f30028
diff --git a/api/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb b/api/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb
index bab403a928..ed5707c484 100644
--- a/api/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb
+++ b/api/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb
@@ -3,6 +3,23 @@ module Spree
module V2
module Storefront
class CmsPagesController < ::Spree::Api::V2::ResourceController
+ private
+
+ def model_class
+ Spree::CmsPage
+ end
+
+ def resource
+ @resource ||= scope.find_by!(title: params[:title])
+ end
+
+ def resource_serializer
+ Spree::Api::Dependencies.storefront_cms_page_serializer.constantize
+ end
+
+ def collection_serializer
+ Spree::Api::Dependencies.storefront_cms_page_serializer.constantize
+ end
end
end
end
diff --git a/api/app/helpers/spree/api/api_helpers.rb b/api/app/helpers/spree/api/api_helpers.rb
index c3d384ca62..a4c36836f4 100644
--- a/api/app/helpers/spree/api/api_helpers.rb
+++ b/api/app/helpers/spree/api/api_helpers.rb
@@ -10,6 +10,7 @@ module Spree
:order_attributes,
:line_item_attributes,
:option_type_attributes,
+ :menu_attributes,
:payment_attributes,
:payment_method_attributes,
:shipment_attributes,
@@ -138,6 +139,10 @@ module Spree
:id, :month, :year, :cc_type, :last_digits, :name
]
+ @@menu_attributes = [
+ :location
+ ]
+
@@user_attributes = [:id, :email, :created_at, :updated_at]
@@property_attributes = [:id, :name, :presentation]
diff --git a/api/app/models/spree/api_dependencies.rb b/api/app/models/spree/api_dependencies.rb
index ad08f3ef53..45d41b4f17 100644
--- a/api/app/models/spree/api_dependencies.rb
+++ b/api/app/models/spree/api_dependencies.rb
@@ -5,6 +5,7 @@ module Spree
INJECTION_POINTS = [
:storefront_cart_create_service, :storefront_cart_add_item_service, :storefront_cart_remove_line_item_service,
:storefront_cart_remove_item_service, :storefront_cart_set_item_quantity_service, :storefront_cart_recalculate_service,
+ :storefront_cms_page_serializer, :storefront_cms_page_finder,
:storefront_cart_update, :storefront_coupon_handler, :storefront_checkout_next_service, :storefront_checkout_advance_service,
:storefront_checkout_update_service, :storefront_checkout_complete_service, :storefront_checkout_add_store_credit_service,
:storefront_checkout_remove_store_credit_service, :storefront_checkout_get_shipping_rates_service,
@@ -61,6 +62,7 @@ module Spree
# serializers
@storefront_address_serializer = 'Spree::V2::Storefront::AddressSerializer'
@storefront_cart_serializer = 'Spree::V2::Storefront::CartSerializer'
+ @storefront_cms_page_serializer = 'Spree::V2::Storefront::CmsPageSerializer'
@storefront_credit_card_serializer = 'Spree::V2::Storefront::CreditCardSerializer'
@storefront_country_serializer = 'Spree::V2::Storefront::CountrySerializer'
@storefront_menu_serializer = 'Spree::V2::Storefront::MenuSerializer'
@@ -84,6 +86,7 @@ module Spree
# finders
@storefront_address_finder = Spree::Dependencies.address_finder
@storefront_country_finder = Spree::Dependencies.country_finder
+ @storefront_cms_page_finder = Spree::Dependencies.cms_page_finder
@storefront_menu_finder = Spree::Dependencies.menu_finder
@storefront_current_order_finder = Spree::Dependencies.current_order_finder
@storefront_completed_order_finder = Spree::Dependencies.completed_order_finder
diff --git a/api/app/serializers/spree/api/v2/platform/cms_page_serializer.rb b/api/app/serializers/spree/api/v2/platform/cms_page_serializer.rb
index a5b0610713..758e69e213 100644
--- a/api/app/serializers/spree/api/v2/platform/cms_page_serializer.rb
+++ b/api/app/serializers/spree/api/v2/platform/cms_page_serializer.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V2
module Platform
- class CountrySerializer < BaseSerializer
+ class CmsPageSerializer < BaseSerializer
include ::Spree::Api::V2::ResourceSerializerConcern
end
end
diff --git a/api/config/routes.rb b/api/config/routes.rb
index a71d4c2588..0c081edbe3 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -165,7 +165,10 @@ Spree::Core::Engine.add_routes do
get '/stores/:code', to: 'stores#show', as: :store
resources :menus, only: %i[index]
- get '/menus/:unique_code', to: 'menus#show', as: :menu
+ get '/menus/:location', to: 'menus#show', as: :menu
+
+ resources :cms_pages, only: %i[index]
+ get '/cms_pages/:title', to: 'cms_page#show', as: :page
end
namespace :platform do
diff --git a/backend/app/views/spree/admin/shared/linkables/_spree_cmspage.html.erb b/backend/app/views/spree/admin/shared/linkables/_spree_cmspage.html.erb
index f00042768d..81cc4c095b 100644
--- a/backend/app/views/spree/admin/shared/linkables/_spree_cmspage.html.erb
+++ b/backend/app/views/spree/admin/shared/linkables/_spree_cmspage.html.erb
@@ -14,7 +14,8 @@
data: { autocomplete_name_value: 'cms_pages',
autocomplete_placeholder_value: Spree.t('admin.navigation.seach_for_a_page'),
autocomplete_clear_value: true,
- autocomplete_url_value: 'pages_api_v2' } %>
+ autocomplete_url_value: 'pages_api_v2',
+ autocomplete_search_query_value: 'title_i_cont' } %>
<%= f.error_message_on :linked_resource_id %>
<small class="form-text text-muted"><%= resource.link %></small>
diff --git a/core/app/finders/spree/cms_pages/find.rb b/core/app/finders/spree/cms_pages/find.rb
new file mode 100644
index 0000000000..f2f0ebd20f
--- /dev/null
+++ b/core/app/finders/spree/cms_pages/find.rb
@@ -0,0 +1,11 @@
+module Spree
+ module CmsPage
+ class Find < ::Spree::BaseFinder
+ def execute
+ return scope.where(title: params[:filter]['title']) if params[:filter].present?
+
+ scope
+ end
+ end
+ end
+end
diff --git a/core/app/finders/spree/menus/find.rb b/core/app/finders/spree/menus/find.rb
index 2090312ea8..d8f6ad61d4 100644
--- a/core/app/finders/spree/menus/find.rb
+++ b/core/app/finders/spree/menus/find.rb
@@ -2,7 +2,7 @@ module Spree
module Menus
class Find < ::Spree::BaseFinder
def execute
- return scope.where(unique_code: params[:filter]['unique_code']) if params[:filter].present?
+ return scope.where(location: params[:filter]['location']) if params[:filter].present?
scope
end
diff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rb
index f2d68da8af..80bd4519db 100644
--- a/core/app/models/spree/ability.rb
+++ b/core/app/models/spree/ability.rb
@@ -62,6 +62,7 @@ module Spree
def apply_user_permissions(user)
can :read, ::Spree::Country
can :read, ::Spree::Menu
+ can :read, ::Spree::CmsPage
can :read, ::Spree::OptionType
can :read, ::Spree::OptionValue
can :create, ::Spree::Order
diff --git a/core/app/models/spree/app_dependencies.rb b/core/app/models/spree/app_dependencies.rb
index 594ffd9165..62a078b0dc 100644
--- a/core/app/models/spree/app_dependencies.rb
+++ b/core/app/models/spree/app_dependencies.rb
@@ -6,7 +6,7 @@ module Spree
:ability_class,
:cart_create_service, :cart_add_item_service, :cart_remove_item_service,
:cart_remove_line_item_service, :cart_set_item_quantity_service, :cart_recalculate_service,
- :cart_update_service, :checkout_next_service, :checkout_advance_service, :checkout_update_service,
+ :cms_page_finder, :cart_update_service, :checkout_next_service, :checkout_advance_service, :checkout_update_service,
:checkout_complete_service, :checkout_add_store_credit_service,
:checkout_remove_store_credit_service, :checkout_get_shipping_rates_service,
:coupon_handler, :menu_finder, :country_finder, :current_order_finder, :credit_card_finder,
@@ -75,6 +75,7 @@ module Spree
def set_default_finders
@address_finder = 'Spree::Addresses::Find'
@country_finder = 'Spree::Countries::Find'
+ @cms_page_finder_finder = 'Spree::CmsPage::Find'
@menu_finder = 'Spree::Menus::Find'
@current_order_finder = 'Spree::Orders::FindCurrent'
@completed_order_finder = 'Spree::Orders::FindComplete'
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 39248e2b4b..a9d8ed0459 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -7,6 +7,7 @@ module Spree
:image_attributes,
:inventory_unit_attributes,
:line_item_attributes,
+ :menu_attributes,
:option_type_attributes,
:option_value_attributes,
:payment_attributes,
@@ -47,6 +48,8 @@ module Spree
@@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]
+ @@menu_attributes = [:location]
+
@@inventory_unit_attributes = [:shipment, :shipment_id, :variant_id]
@@line_item_attributes = [:id, :variant_id, :quantity]