This is a sample repository to show how to implement a simple form in SFRA. The plugin demonstrates several B2C Commerce concepts in one easy to follow example:
- B2C Commerce form definition: newsletter.xml
- Form ISML using attributes from the form definition
- Controller to show the form and handle submission
- Implementation of CSRF (Cross Site Request Forgery) protection in controller and ISML file
- Custom object (aka CO) creation (requires import of CO metadata, which is included)
- Transaction handling in controller (saves data to persistent CO)
- Use of a middleware event in controller: BeforeComplete
- Use of Logger class to log an error when CO has not been defined
- Sending validation error message back to the client-side
- Clone this repository.
- Install npm dependancies
- Open package.json file and modify
paths.baseproperty to point to your local app_storefront_base cartridge.
npm run compile:jsto create client-side assets. There is no scss to compile.
npm run uploadCartridgeif you have a properly configured dw.json with login credentials to your SB
- In Business Manager, add the plugin_newsletter cartridge to your site's cartridge path. The path must contain the SFRA base cartridge app_storefront_base.
- In Business Manager, under Administration > Site Development > Import & Export, upload and import the newslettersubscription_co_metadata.xml. This custom object definition is required for the demo to work.
- On a browser, invoke the Newsletter-Show route for in your site. For example: https://<your_sandbox>/on/demandware.store/Sites-<your_site>-Site/en_US/Newsletter-Show.
Use the provided NPM scripts to compile and upload changes to your Sandbox.
npm run compile:js- Compiles all js files and aggregates them.
npm run uploadCartridge- Uploads the cartridge to your sandbox. A properly configured dw.json file is required (see initial commit for this repo to find a sample. Modify to point to your sandbox and active version).
Since this is a demonstration plugin, there are no automated tests.
Since this is a demonstration plugin, suggestions for improvement are welcomed. Please contact email@example.com. Only properly commented code will be accepted.