问题
There are two API’s for SAP Commerce Store which are present in the Swagger API description but are not currently being used by the store finder page in Spartacus: • “/{baseSiteId}/stores/country/{countryIso}/region/{regionIso}”. • “/{baseSiteId}/stores/country/{countryIso}”
What is the best approach in Spartacus to add a new call for the following API: “/{baseSiteId}/stores/country/{countryIso}/region/{regionIso}”.
回答1:
The OCC API has many endpoints that aren't necessarily used in Spartacus. There are either multiple endpoints to achieve the same thing, or a feature hasn't been build /finalised in Spartacus.
There are various ways to invoke a new API. One approach that is both clean and following the Spartacus architecture, is to customise the StoreFinderService
. The StoreFinderService
is a facade that acts in between the (more complex) state management layer, see diagram below.
If you'd add a method in a custom version of this facade, you could use the httpClient
directly in the service. That is often enough, however if you like/need to store the response in the store, you could introduce custom state, or even extend the connector and adapters. Generally speaking, this complexity is not needed in a project implementation.
来源:https://stackoverflow.com/questions/62319118/existing-but-unused-api-in-sap-commerce-for-store-finder