docs/block-development/reference/data-store/schema.md
wc/store/schema)The Schema Store manages the routes associated with WooCommerce Blocks, enabling efficient retrieval and updating of route data for a given namespace. This store streamlines the interaction with resource routes, ensuring that modules can easily access endpoint paths as needed.
To utilize this store you will import the SCHEMA_STORE_KEY in any module referencing it. Assuming @woocommerce/block-data is registered as an external pointing to wc.wcBlocksData you can import the key via:
const { SCHEMA_STORE_KEY } = window.wc.wcBlocksData;
⚠️ You should rarely need to use any of these actions directly as they are mostly used internally by the resolvers.
This returns an action object used to update the store with the provided list of resource routes.
array: An array of routes attached for the given namespace, eg. [ '/wc/blocks/products', '/wc/blocks/products/attributes/(?P<id>[\d]+)' ].string: The namespace the routes belong to, eg. /wc/blocks.object: An action object used to update the store with the provided list of resource routes with the following keys:
string: The action type.object: An object of routes keyed by the route name.string: The namespace the routes belong to, eg. /wc/blocks.This is used for retrieving a route for the given namespace, resource name and (if necessary) ids.
object: The original state.string: The namespace for the route, eg. /wc/blocks,string: The resource being requested, eg. products/attributes/terms.array: Only needed if the route has placeholders for ids.string: The route if it is available.If you are looking for a route for a single product on the wc/blocks namespace, then you'd have [ 20 ] as the ids:
// '/wc/blocks/products/20'
wp.data.select( SCHEMA_STORE_KEY ).getRoute( '/wc/blocks', 'products', [ 20 ] );
This will return all the registered routes for the given namespace as a flat array.
object: The current state.string: The namespace to return routes for.array: An array of all routes for the given namespace.This will returns the route from the given slice of the route state.
object: Slice of the route state from a given namespace and resource name.array (default: []): An array of id references that are to be replaced in route placeholders.string: The route for the given resource entries, or an empty string if no route is found.const store = select( SCHEMA_STORE_KEY );
const route = store.getRouteFromResourceEntries( stateSlice, ids );
This will return the assembled route with placeholders.
string: The route to assemble.array: An array of route placeholders.array: An array of id references that are to be replaced in route placeholders.string: The assembled route with placeholders replaced by actual values.const store = select( SCHEMA_STORE_KEY );
const route = store.assembleRouteWithPlaceholders( route, routePlaceholders, ids );