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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
VEN-278 Add Storefront API Store endpoint (#11597)
Aleksandar Petrushev66486c7803bb
diff --git a/api/app/controllers/spree/api/v2/storefront/stores_controller.rb b/api/app/controllers/spree/api/v2/storefront/stores_controller.rbindex 187e7038ec..6699fee62e 100644--- a/api/app/controllers/spree/api/v2/storefront/stores_controller.rb+++ b/api/app/controllers/spree/api/v2/storefront/stores_controller.rb@@ -3,6 +3,10 @@ module Spreemodule V2module Storefrontclass StoresController < ::Spree::Api::V2::ResourceController+ def current+ render_serialized_payload { serialize_resource(current_store) }+ end+privatedef model_classdiff --git a/api/app/serializers/spree/v2/storefront/store_serializer.rb b/api/app/serializers/spree/v2/storefront/store_serializer.rbindex ece9a71aef..0b9028fb8e 100644--- a/api/app/serializers/spree/v2/storefront/store_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/store_serializer.rb@@ -5,8 +5,8 @@ module Spreeset_type :storeattributes :name, :url, :meta_description, :meta_keywords, :seo_title, :default_currency,- :default, :supported_currencies, :facebook, :twitter, :instagram, :default_locale, :customer_support_email,- :description, :address, :contact_phone, :supported_locales, :settings+ :default, :supported_currencies, :facebook, :twitter, :instagram, :default_locale,+ :customer_support_email, :description, :address, :contact_phone, :supported_localeshas_many :menushas_many :cms_pagesdiff --git a/api/config/routes.rb b/api/config/routes.rbindex d8f03e1bce..e702fb4279 100644--- a/api/config/routes.rb+++ b/api/config/routes.rb@@ -47,6 +47,7 @@ Spree::Core::Engine.add_routes doresources :products, only: %i[index show]resources :taxons, only: %i[index show], id: /.+/get '/stores/:code', to: 'stores#show', as: :store+ get '/store', to: 'stores#current', as: :current_storeresources :menus, only: %i[index show]resources :cms_pages, only: %i[index show]diff --git a/api/docs/v2/storefront/index.yaml b/api/docs/v2/storefront/index.yamlindex 339ad43389..fb8fde4b10 100644--- a/api/docs/v2/storefront/index.yaml+++ b/api/docs/v2/storefront/index.yaml@@ -1249,6 +1249,22 @@ paths:'404':$ref: '#/components/responses/404NotFound'summary: Retrieve a Product+ /api/v2/storefront/store:+ get:+ description: 'Returns the current Store. [Read more about Stores](https://dev-docs.spreecommerce.org/internals/stores)'+ tags:+ - Stores+ operationId: show-store+ parameters:+ - $ref: '#/components/parameters/StoreIncludeParam'+ - $ref: '#/components/parameters/SparseFieldsStore'+ responses:+ '200':+ $ref: '#/components/responses/Store'+ '403':+ $ref: '#/components/responses/403Forbidden'+ security:+ - bearerAuth: []/api/v2/storefront/taxons:get:description: 'Returns a list of Taxons. [Read more about Taxons](https://dev-docs.spreecommerce.org/internals/products#taxons-and-taxonomies)'@@ -3055,6 +3071,13 @@ components:- $ref: '#/components/schemas/Variant'- $ref: '#/components/schemas/Image'- $ref: '#/components/schemas/Taxon'+ StoreIncludes:+ x-internal: true+ title: Store Includes+ anyOf:+ - $ref: '#/components/schemas/Country'+ - $ref: '#/components/schemas/Menu'+ - $ref: '#/components/schemas/CmsPage'ProductProperty:title: Product Propertytype: object@@ -3145,6 +3168,122 @@ components:example: New Yorkdescription: State namex-internal: true+ Store:+ type: object+ description: 'Stores are the center of the Spree ecosystem. Each Spree installation can have multiple Stores. Each Store operates on a different domain or subdomain.'+ title: Store+ x-internal: true+ properties:+ id:+ type: string+ example: '1'+ type:+ type: string+ default: store+ attributes:+ type: object+ properties:+ name:+ type: string+ example: Spree Demo+ description: Name of the Store+ url:+ type: string+ example: spree-demo.com+ description: Store Url+ meta_description:+ type: string+ example: Luxury clothing store for men and women.+ description: Meta description for SEO+ meta_keywords:+ type: string+ example: luxury clothing men women+ description: Meta keywords for SEO+ seo_title:+ type: string+ example: Buy Luxury Clothing With Ease+ description: The title for SEO+ default_currency:+ type: string+ example: EUR+ description: Default currency of the store+ default:+ type: boolean+ example: true+ description: Indicates if the Store is the default one+ supported_currencies:+ type: string+ example: EUR,USD,GBP+ description: All currencies supported by store+ facebook:+ type: string+ example: https://www.facebook.com/mystorename+ description: URL of Facebook page+ twitter:+ type: string+ example: https://twitter.com/mystorename+ description: URL of Twitter page+ instagram:+ type: string+ example: https://instagram.com/mystorename+ description: URL of Instagram page+ default_locale:+ type: string+ example: en+ description: Default locale of the Store+ supported_locales:+ type: string+ example: en,es,de+ description: Supported locales of the Store+ customer_support_email:+ type: string+ example: [email protected]+ description: This email is visible to your Store visitors in the Footer section+ description:+ type: string+ example: Mystore has been selling luxury clothing for more than 20 years and has 15 stores currently.+ description: Description of the Store which is visible in the Footer+ address:+ type: string+ example: 813 Howard Street, Oswego NY 13126, USA+ description: Address of the Store which is visible in the Footer+ contact_phone:+ type: string+ example: '+123456789'+ description: Contact phone number of the Store which is visible in the Footer+ favicon_path:+ type: string+ example: '/assets/favicon.ico'+ relationships:+ type: object+ properties:+ menus:+ type: object+ description: Menus+ properties:+ data:+ type: array+ items:+ $ref: '#/components/schemas/Relation'+ cms_pages:+ type: object+ description: CMS Pages+ properties:+ data:+ type: array+ items:+ $ref: '#/components/schemas/Relation'+ default_country:+ type: object+ description: Default Country of the Store+ properties:+ data:+ $ref: '#/components/schemas/Relation'+ required:+ - id+ - type+ - attributes+ - relationshipsShipment:type: objecttitle: Shipment@@ -3834,6 +3973,20 @@ components:[More information](https://jsonapi.org/format/#fetching-includes)example: 'default_variant,variants,option_types,product_properties,taxons,images,primary_variant'+ StoreIncludeParam:+ name: include+ in: query+ schema:+ type: string+ description: |-+ Specify what related resources (relationships) you would like to receive in the response body. Eg.++ ```+ default_country,menus,cms_pages+ ```++ [More information](https://jsonapi.org/format/#fetching-includes)+ example: 'default_country,menus,cms_pages'ProductImageTransformationSizeParam:in: queryname: 'image_transformation[size]'@@ -3975,6 +4128,13 @@ components:schema:type: stringexample: 'price,description,name'+ SparseFieldsStore:+ name: 'fields[store]'+ in: query+ description: 'Specify the fields you would like returned in the response body. [More information](https://jsonapi.org/format/#fetching-sparse-fieldsets).'+ schema:+ type: string+ example: 'name,url,supported_locales'SparseFieldsShippingRate:in: queryname: 'fields[shipping_rate]'@@ -8362,6 +8522,140 @@ components:prev: 'http://localhost:3000/api/v2/storefront/products?page=1'last: 'http://localhost:3000/api/v2/storefront/products?page=5'first: 'http://localhost:3000/api/v2/storefront/products?page=1'+ Store:+ description: 200 Success - Returns the `store` object.+ content:+ application/vnd.api+json:+ schema:+ type: object+ properties:+ data:+ $ref: '#/components/schemas/Store'+ included:+ type: array+ items:+ $ref: '#/components/schemas/StoreIncludes'+ required:+ - data+ examples:+ Store without includes:+ value:+ data:+ id: '3'+ type: store+ attributes:+ name: Mystore+ url: spree-demo.com+ meta_description: Luxury clothing store for men and women.+ meta_keywords: luxury clothing men women+ seo_title: ''+ default_currency: USD+ default: true+ supported_currencies: EUR,GBP,USD+ facebook: 'https://www.facebook.com/mystorename'+ twitter: 'https://twitter.com/mystorename'+ instagram: 'https://instagram.com/mystorename'+ default_locale: en+ customer_support_email: '[email protected]'+ description: 'Mystore has been selling luxury clothing for more than 20 years and has 15 stores currently.'+ address: '813 Howard Street, Oswego NY 13126, USA'+ contact_phone: '+123456789'+ supported_locales: en+ favicon_path: '/assets/favicon.ico'+ relationships:+ menus:+ data:+ - id: '10'+ type: menu+ - id: '11'+ type: menu+ cms_pages:+ data:+ - id: '5'+ type: cms_page+ default_country:+ data:+ id: '2'+ type: country+ Store with Includes:+ value:+ data:+ id: '3'+ type: store+ attributes:+ name: Mystore+ url: spree-demo.com+ meta_description: Luxury clothing store for men and women.+ meta_keywords: luxury clothing men women+ seo_title: ''+ default_currency: USD+ default: true+ supported_currencies: EUR,GBP,USD+ facebook: 'https://www.facebook.com/mystorename'+ twitter: 'https://twitter.com/mystorename'+ instagram: 'https://instagram.com/mystorename'+ default_locale: en+ customer_support_email: '[email protected]'+ description: 'Mystore has been selling luxury clothing for more than 20 years and has 15 stores currently.'+ address: '813 Howard Street, Oswego NY 13126, USA'+ contact_phone: '+123456789'+ supported_locales: en+ favicon_path: '/assets/favicon.ico'+ relationships:+ menus:+ data:+ - id: '10'+ type: menu+ - id: '11'+ type: menu+ cms_pages:+ data:+ - id: '5'+ type: cms_page+ default_country:+ data:+ id: '2'+ type: country+ included:+ - id: '2'+ type: country+ attributes:+ iso: US+ iso3: USA+ iso_name: UNITED STATES+ name: United States+ states_required: true+ zipcode_required: true+ default: true+ relationships:+ checkout_zone_applicable_states:+ data: []+ - id: '10'+ type: cms_page+ attributes:+ title: Returns Policy+ content:+ locale: en+ meta_description: ''+ meta_title: ''+ slug: returns-policy+ type: Spree::Cms::Pages::StandardPage+ relationships:+ cms_sections:+ data: []+ - id: '12'+ type: menu+ attributes:+ name: Company+ location: header+ locale: en+ relationships:+ menu_items:+ data:+ - id: '1'+ type: menu_item+ - id: '2'+ type: menu_itemTaxon:description: 200 Success - Returns the `taxon` object.content:diff --git a/api/spec/requests/spree/api/v2/storefront/stores_spec.rb b/api/spec/requests/spree/api/v2/storefront/stores_spec.rbindex d84b77f61f..8d6e4ad412 100644--- a/api/spec/requests/spree/api/v2/storefront/stores_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/stores_spec.rb@@ -51,5 +51,34 @@ describe 'Storefront API v2 Stores spec', type: :request doexpect(json_response['error']).to eq('The resource you were looking for could not be found.')endend++ describe 'stores#current_store' do+ before do+ allow_any_instance_of(Spree::Api::V2::Storefront::StoresController).to receive(:current_store).and_return(store)+ get "/api/v2/storefront/store"+ end++ it 'returns store with attributes' do+ expect(json_response['data']).to have_attribute(:name).with_value(store.name)+ expect(json_response['data']).to have_attribute(:url).with_value(store.url)+ expect(json_response['data']).to have_attribute(:meta_description).with_value(store.meta_description)+ expect(json_response['data']).to have_attribute(:meta_keywords).with_value(store.meta_keywords)+ expect(json_response['data']).to have_attribute(:seo_title).with_value(store.seo_title)+ expect(json_response['data']).to have_attribute(:default_currency).with_value(store.default_currency)+ expect(json_response['data']).to have_attribute(:default).with_value(store.default)+ expect(json_response['data']).to have_attribute(:supported_currencies).with_value(store.supported_currencies)+ expect(json_response['data']).to have_attribute(:facebook).with_value(store.facebook)+ expect(json_response['data']).to have_attribute(:twitter).with_value(store.twitter)+ expect(json_response['data']).to have_attribute(:instagram).with_value(store.instagram)+ expect(json_response['data']).to have_attribute(:default_locale).with_value(store.default_locale)+ expect(json_response['data']).to have_attribute(:supported_locales).with_value(store.supported_locales)+ expect(json_response['data']).to have_attribute(:description).with_value(store.description)+ expect(json_response['data']).to have_attribute(:address).with_value(store.address)+ expect(json_response['data']).to have_attribute(:contact_phone).with_value(store.contact_phone)++ expect(json_response['data']).to have_relationship(:default_country)+ expect(json_response['data']).to have_relationship(:default_country).with_data('id' => store.default_country_id.to_s, 'type' => 'country')+ end+ endendend