Extending SFRA models and product decorators from a custom cartridge
Key Takeaway
module.superModule returns the next module with the same name and the same folder location, from a cartridge to the right of the current one on the cartridge path. Use it in your custom cartridge to build on app_storefront_base instead of editing or copying its files.
In Storefront Reference Architecture (SFRA), models turn the objects returned by the B2C Commerce script APIs into pure JSON objects built for the storefront. Models also apply storefront business logic. To change or add to that data, you work in your own custom cartridge instead of editing app_storefront_base, so you can keep taking security updates, bug fixes, and new features. The main tools are the cartridge path, module.superModule, and the viewData object that a controller passes to a template.
Custom cartridges and the cartridge path
Customize SFRA without editing or renaming app_storefront_base or other plug-ins, such as plugin_applepay. Every site needs at least one custom cartridge. Your overrides and extensions live in that custom cartridge.
The cartridge path controls which code runs. B2C Commerce searches the cartridge path from left to right for a controller, script, model, or ISML template. Place your custom cartridge to the left of app_storefront_base so B2C Commerce finds your files first.
Best practices for custom cartridges include writing unit tests for models and checking for naming collisions between cartridges.