b2c-controllers

Create Salesforce B2C Commerce storefront controllers using SFRA and Classic patterns.

51|16|Updated Oct 31, 2025
One-click install
npx skills add https://github.com/SalesforceCommerceCloud/b2c-developer-tooling --skill b2c-controllers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: b2c-controllers
Source: https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/tree/main/skills/b2c/skills/b2c-controllers
Command: npx skills add https://github.com/SalesforceCommerceCloud/b2c-developer-tooling --skill b2c-controllers

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill enables developers to implement storefront controllers for Salesforce B2C Commerce using SFRA or Classic patterns, enabling proper request routing, rendering, and API handling.

Core Features & Use Cases

  • Supports both SFRA and Classic controller patterns for storefront endpoints (pages, forms, AJAX).
  • Provides guidance on file placement, controller naming, and middleware usage.
  • Includes examples for rendering templates, returning JSON, and URL generation with URLUtils.
  • Describes extension and override patterns for existing controllers.

Quick Start

  • Create a storefront controller file under cartridge/controllers (for example Home.js) using SFRA or Classic pattern.
  • Expose a route (e.g., Show) and wire in middleware when using SFRA; for Classic, export Show.public = true.
  • Access the endpoint at the standard Controller URL, e.g. /on/demandware.store/Sites-YourSite-Site/en_US/Home-Show

Frequently Asked Questions about b2c-controllers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a storefront controller for Salesforce B2C Commerce?

Storefront controllers for Salesforce B2C Commerce are created by placing a file in cartridge/controllers and exposing routes. SFRA uses middleware for routing, while Classic exports public properties.

What is the difference between SFRA and Classic controller patterns in B2C Commerce?

SFRA controllers use middleware for request routing, while Classic controllers use exported functions with public flags. Both handle storefront pages, form submissions, and AJAX endpoints.

How do I generate URLs in a Salesforce Commerce Cloud storefront controller?

URL generation in storefront controllers uses URLUtils to route endpoints to the standard Controller URL format, handling site and locale parameters correctly.

Can I extend or override existing storefront controllers in SFRA?

Yes, existing storefront controllers can be extended and overridden. The skill describes API patterns and extension techniques to customize behavior without modifying the base cartridge.

How do I return JSON from an AJAX endpoint in a B2C Commerce controller?

Returning JSON from an AJAX endpoint involves using the response object to set the content type and render the payload. The skill provides examples for JSON responses and template rendering.

Where should storefront controller files be placed in a Salesforce Commerce Cloud cartridge?

Storefront controller files must be placed in the cartridge/controllers directory. Correct file placement and naming are required for the platform to route requests to your endpoints.