$npx -y skills add forcedotcom/sf-skills --skill commerce-b2b-open-code-components-replaceReplace OOTB (out-of-the-box) B2B Commerce components with open source equivalents in site metadata content.json files, or look up the equivalent open code site: component for OOTB definitions. Use when users mention \"replace OOTB components\", \"replace commerce components wi
| 1 | # Replacing OOTB B2B Commerce Components with Open Code |
| 2 | |
| 3 | This skill replaces OOTB (out-of-the-box) B2B Commerce component definitions in site metadata `content.json` files with their open source `site:` equivalents, or looks up the equivalent open code component for given OOTB definitions without making changes. It uses an authoritative mapping loaded from `assets/ootb-to-open-code-mapping.json`. |
| 4 | |
| 5 | ## Scope |
| 6 | |
| 7 | **Modes:** **Full replace** runs the scan (Step 1), user selection if needed, then `content.json` updates (Step 2–3). **Lookup only** (user asks for equivalents but not to change files): apply the mapping-authority rule and report OOTB → `site:` for the named components or for definitions found in the scoped `content.json` — **do not** call Write unless the user confirms replacement. **View-scoped** work: limit file discovery and reads to `sfdc_cms__view/<ViewName>/` (or the path the user gives) instead of all views. |
| 8 | |
| 9 | --- |
| 10 | |
| 11 | ## Prerequisites |
| 12 | |
| 13 | ### Resolve `<package-dir>` |
| 14 | |
| 15 | Read `sfdx-project.json` and pick the active package directory. Extract `packageDirectories[]` and use the entry with `"default": true`; if no entry is flagged default, use the first entry. Use this value as `<package-dir>` everywhere below. If `sfdx-project.json` is missing or has no `packageDirectories`, tell the user and abort. |
| 16 | |
| 17 | ### Delegate setup |
| 18 | |
| 19 | Before replacing components, delegate to the **commerce-b2b-open-code-components-integrate** skill to ensure: |
| 20 | |
| 21 | 1. Open source repository is cloned at `.tmp/b2b-commerce-open-source-components` |
| 22 | 2. Store is selected and site metadata is retrieved locally |
| 23 | 3. Open code components are copied to the store's site metadata |
| 24 | |
| 25 | The integrating skill owns the `.tmp/` clone lifecycle (it prompts the user to reuse or re-clone an existing checkout); this skill assumes the clone is already present. |
| 26 | |
| 27 | Send a plain-text chat reply to the user (per Rule 1): "Before replacing components, I need to verify that the open code components are set up in your store. Let me check..." |
| 28 | |
| 29 | If any prerequisite is not met, the integrating skill will handle it. Once all checks pass, proceed to the replacement workflow. |
| 30 | |
| 31 | **Required state** after prerequisites: |
| 32 | - **Package dir** — the value resolved above (e.g., `force-app`) |
| 33 | - **Store name** — e.g., `My_B2B_Store1` |
| 34 | - **Site metadata path** — `<package-dir>/main/default/digitalExperiences/site/<store-name>/` |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## Replacement Workflow |
| 39 | |
| 40 | ### Step 1: Scan Site and Cross-Reference Mapping |
| 41 | |
| 42 | **This step is MANDATORY.** Always scan the site first before attempting any replacements. |
| 43 | |
| 44 | Send a plain-text chat reply to the user (per Rule 1): "I'm scanning your store's site metadata to find all OOTB commerce components currently in use and checking which have open code equivalents." |
| 45 | |
| 46 | **Step 1a — Find affected files** (one command, simple literal match): |
| 47 | |
| 48 | ```bash |
| 49 | grep -rl '"commerce' \ |
| 50 | <package-dir>/main/default/digitalExperiences/site/<store-name>/sfdc_cms__view/ \ |
| 51 | <package-dir>/main/default/digitalExperiences/site/<store-name>/sfdc_cms__themeLayout/ \ |
| 52 | --include="content.json" |
| 53 | ``` |
| 54 | |
| 55 | **Step 1b — Read the mapping and parse the matched files.** Read `assets/ootb-to-open-code-mapping.json` once into memory. Then, using the **Read** tool, parse each matched file and extract all `"definition"` values that start with `commerce` (e.g., `commerce_builder:cartBadge`). Collect a deduplicated list of OOTB components across all files. |
| 56 | |
| 57 | **Step 1c — List repo components** (one command): |
| 58 | |
| 59 | ```bash |
| 60 | ls .tmp/b2b-commerce-open-source-components/force-app/main/default/sfdc_cms__lwc/ |
| 61 | ``` |
| 62 | |
| 63 | Using the parsed definitions, the `ls` output, and the mapping table, categorize every discovered OOTB component into three groups: |
| 64 | |
| 65 | **Show the user a breakdown and a selectable list:** |
| 66 | |
| 67 | First, inform the user about skipped and unmapped components: |
| 68 | ```text |
| 69 | Found X OOTB components in your site: |
| 70 | |
| 71 | In mapping table but NOT in repo (skipping): |
| 72 | - commerce_builder:quoteSummary → site:quoteSummary (not found in repo) |
| 73 | |
| 74 | No mapping available (not in mapping table): |
| 75 | - commerce_builder:actionButtons |
| 76 | - commerce_builder:layoutHeaderOne |
| 77 | - commerce |