Ratings extension tutorial

This tutorial guides you through building a product ratings extension for Adobe Commerce as a Cloud Service using Adobe App Builder and AI-assisted development tools.

Before you begin, complete the prerequisites.

Verify prerequisites

Verify that the following prerequisites are installed:

# Check Node.js version (should be 22.x.x)
node --version

# Check npm version (should be 9.0.0 or higher)
npm --version

# Check Git installation
git --version

# Check Bash shell installation
bash --version

If any of the preceding commands do not return the expected results, refer to the prerequisites for guidance.

Extension development

This section guides you through developing a ratings extension for Adobe Commerce as a Cloud Service using AI-assisted development tools.

  1. Navigate to Cursor > Settings > Cursor Settings > Tools & MCP and verify that the commerce-extensibility toolset is enabled without errors. If you see errors, toggle the toolset off and on.

    Cursor IDE settings showing MCP commerce-extensibility toolset enabled {width="600" modal="regular"}

    note note
    NOTE
    When working with AI-assisted development tools, expect natural variations in the code and responses generated by the agent.
    If you encounter any issues with your code, you can always ask the agent to help you debug it.
  2. Disable any documentation in Cursor’s context:

    • Navigate to Cursor > Settings > Cursor Settings > Indexing & Docs and delete any documentation listed.

    Cursor indexing and docs settings with documentation list empty {width="600" modal="regular"}

  3. Generate code for a product ratings extension:

    • From the Cursor chat window, select Agent mode.
    • Enter the following prompt:
    code language-shell-session
    Implement an Adobe Commerce as a Cloud Service extension to handle Product Ratings.
    
    Implement a REST API to handle GET ratings requests.
    
    GET requests will have to support the following query parameters:
    
    sku -> product SKU
    
    note note
    NOTE
    If the agent requests to search the documentation, allow it.
  4. Answer the agent’s questions precisely to help it generate the best code.

    Cursor chat window in Agent mode with extension prompt entered {width="600" modal="regular"} AI agent asking clarifying questions about extension requirements {width="600" modal="regular"}

  5. Use the following example text to answer the agent’s questions to set up randomized ratings data:

    code language-shell-session
    Yes, this headless extension is for Adobe Commerce as a Cloud Service storefront,
    but we do not need any authentication for the GET API because guest users should be able to use it on the storefront.
    
    This extension is called directly from the storefront, no async invocation, such as events or webhooks, is required.
    
    Start with just the GET API for now, we will implement other CRUD operations at a later time.
    
    We do not need a DB or storage mechanism right now, just return random ratings data between 1 and 5 and a ratings count between 1 and 1000.
    
    The API should only return the average rating for the product and the total number of ratings.
    We do not need to add tests right now.
    

    The agent creates a requirements.md file that serves as the source of truth for the implementation.

    Requirements.md file created by AI agent with implementation details {width="600" modal="regular"}

  6. Review the requirements.md file and verify the plan.

    If everything looks correct, instruct the agent to move to Phase 2 - Architecture Planning.

  7. Review the architecture plan.

  8. Instruct the agent to proceed with code generation.

    The agent generates the necessary code and provides a detailed summary with your next steps.

    AI agent Phase 2 architecture plan for ratings API {width="600" modal="regular"} Summary of generated code files and structure {width="600" modal="regular"} AI agent providing next steps for testing and deployment {width="600" modal="regular"}

Test the extension locally

The following steps cover how to verify the extension works before deploying it.

  1. Ask the agent to help you test the code locally.

    code language-shell-session
    Test the ratings API locally on a dev server using cURL.
    
  2. Follow the agent’s instructions and confirm that the API is working locally.

    AI agent instructions for local API testing {width="600" modal="regular"} Terminal showing successful local API test results with cURL {width="600" modal="regular"}

Deploy the extension

Deploy the extension to Adobe I/O Runtime using the agent.

  1. After verifying the generated code, deploy the extension using the following prompt:

    code language-shell-session
    Deploy the ratings API.
    

    The agent performs a pre-deployment readiness assessment before deploying.

    AI agent pre-deployment readiness assessment checklist {width="600" modal="regular"}

  2. When you are confident with the assessment results, instruct the agent to proceed with deployment.

    The agent uses the MCP toolkit to verify, build, and deploy automatically.

    MCP toolkit verification build and deployment process {width="600" modal="regular"}

Verify the deployment

Test the API before integrating it into the storefront. The agent should provide the location of the new action and a testing strategy.

AI agent testing strategy with deployed action URL and test commands {width="600" modal="regular"}

You can also test the API manually using cURL in a terminal:

curl -s "https://<your-site>.adobeioruntime.net/api/v1/web/ratings/ratings?sku=TEST-SKU-123"

Terminal showing successful cURL test of deployed ratings API {width="600" modal="regular"}

Integrate with Edge Delivery Services

To integrate the ratings API with an Adobe Commerce storefront powered by Edge Delivery Services, ask the agent to create a service contract with requirements for the ratings API:

Create a service contract for the ratings api that I can pass on to the storefront agent. Name it RATINGS_API_CONTRACT.md

AI agent creating service contract file for storefront integration {width="600" modal="regular"}

Ratings API contract markdown file with endpoint and response details {width="600" modal="regular"}

Return to the terminal and run the following command in the extension folder to copy the contract file to the storefront folder:

cp RATINGS_API_CONTRACT.md ../storefront

Connect to the storefront

This section guides you through implementing the storefront portion of the ratings extension using Edge Delivery Services and AI-assisted development tools.

NOTE
The prompts provided are starting points. Although you can use them without modification, consider having a natural conversation with the agent.
When working with AI-assisted development tools, there are always natural variations in the code and responses generated by the agent.
If you encounter any issues with your code, ask the agent to help you debug it.

Storefront prerequisites

Before starting the storefront integration, verify you have the following:

Set up the storefront workspace

Prepare your local storefront environment for development.

  1. Navigate to the storefront folder:

    code language-bash
    cd storefront
    
  2. Open the storefront folder in a new Cursor window.

    Alternatively, if you have the Cursor CLI installed, open the window by using the following command in your terminal:

    code language-bash
    cursor .
    
  3. Start the local development server:

    code language-bash
    npm run start
    
  4. In a browser, navigate to a product page:

    code language-shell-session
    http://localhost:3000/products/llama-plush-shortie/adb336
    
  5. Observe the boilerplate storefront product detail page (PDP) and note the lack of visual product ratings.

Integrate the ratings API

Use the agent to integrate the ratings API into the storefront product detail page.

  1. Use the following prompt with your agent:

    code language-shell-session
    Integrate the ratings API into the PDP to show star ratings and a review count for products. Here's the service contract: @RATINGS_API_CONTRACT.md
    
  2. The agent assesses the task complexity and invokes a phased workflow. During Phase 1 (Requirements Gathering), the agent creates a requirements document and asks clarifying questions such as:

    • Where on the PDP should ratings appear?
    • Should this be a new standalone block, or a slot customization inside the existing PDP drop-in component?
    • What should the fallback be if the API is unavailable or returns no data?
    • Should ratings appear on the PLP (product listing) as well, or PDP only?
    • Are there any design specs or mockups?

    Answer these questions based on your project requirements. The agent updates the requirements document and marks the phase as complete.

  3. During Phase 2 (Architectural Planning), the agent researches documentation and your codebase before proposing an architecture. Expect the agent to:

    • Search Commerce documentation for PDP drop-in containers, slots, and event payloads.
    • Scan your blocks directory and scripts/initializers/ folder for existing PDP-related code.
    • Explore TypeScript definitions for available containers and slot context shapes.

    The agent then presents architecture options such as:

    • Option A: Customize an existing PDP drop-in slot to inject ratings near the product title — a lighter touch that is upgrade-friendly.
    • Option B: Create a new standalone product-ratings block that fetches from the API independently — more flexible and decoupled.
    • Option C: Create a new block that also listens to PDP drop-in events for the product SKU — a hybrid approach.

    The plan also includes details on API integration, performance considerations (lazy loading, caching), security (input sanitization), and a testing approach.

    Review the architecture plan and instruct the agent to proceed.

  4. During Phase 3 (Implementation Approach), the agent asks you to choose between:

    • Option A: Review a detailed implementation plan before code generation (see all files, patterns, and code structure first).
    • Option B: Proceed directly to code generation.

    Select your preferred approach.

  5. During Phase 4 (Implementation), the agent generates code based on the chosen architecture. Depending on the approach, the agent uses several specialized skills:

    • Content modeling: If a new block is needed, the agent designs an author-friendly content structure, such as a configuration table with the API endpoint URL.
    • Block development: The agent creates block files following Edge Delivery Services conventions, including JavaScript decoration functions, scoped CSS styles, ARIA labels for accessibility, and loading and error state handling.
    • Drop-in customization: If the architecture uses slot customization, the agent imports the correct container, uses a verified slot near the product title, and subscribes to product data events for the current SKU.

    Watch the code being generated and ask questions or redirect the agent as needed. The agent produces a production readiness summary when code generation completes.

  6. During Phase 4.5 (Testing), the agent offers to test the implementation. If you accept, the agent:

    • Creates a local test page with the proper scripts and styles.
    • Starts a development server.
    • Runs browser-based verification for visual rendering, interactivity, responsive behavior, accessibility, and performance.
    • Generates a structured test report with the results.

    Follow along in the browser to confirm the behavior and report any issues.

  7. Observe the changes in the codebase, and watch the product page for updates.

    You should see the following changes in your development environment and browser:

    • A product rating component is automatically created.
    • The component is integrated into the PDP using drop-in slots or as a standalone block, depending on the chosen architecture.
    • Stars display with proper fill proportions based on the rating values from your API.

    Product detail page showing star ratings integrated below the product title {width="600" modal="regular"}

Tutorial recap

Here is a summary of the topics covered in this tutorial:

  • Extension development: Learning how to describe new functionality to an AI agent and generate a working REST API using App Builder.
  • Local testing and deployment: Testing the API locally and deploying it using the MCP toolkit.
  • Service contracts: Creating API contracts that bridge backend extensions and storefront implementations.
  • Phased storefront integration: Working through requirements, architecture, and implementation using AI-assisted skills.
  • Drop-in integration: Working with Adobe Commerce drop-in containers and slots.
  • Component reusability: Creating shared components used across multiple blocks.

Next steps

Use the following suggestions to customize your ratings extension or create your own modifications:

Change the star colors

Use the following prompt with your agent:

Change the star fill color to red.

Expected outcome:

The stars change to red.

Product ratings displayed with red star fill color {width="600" modal="regular"}

Add a rating distribution modal

The following steps show how the agent handles complex UI features with visual references.

  1. Before starting: Save the following mock image and paste it into the chat with your storefront agent.

    Mockup showing rating distribution breakdown by star level {width="600" modal="regular"}

  2. Follow these steps to create the ratings distribution modal using the reference image as a guide:

    • Update the API to return additional data representing the ratings distribution.
    • Update the API contract.
    • Update the contract in the storefront codebase.
    • Ask the storefront agent to use the reference image and updated API contract to add the ratings distribution to the PDP page.
  3. Observe the following changes in the codebase, and watch the product page for updates:

    • How the agent interprets the visual mockup
    • Whether it uses appropriate HTML structure for accessibility
    • How it handles the positioning and interaction states

Troubleshoot the distribution modal

If the modal does not behave as expected, try the following:

  • If the modal does not appear, check the browser console for errors.

  • If positioning is off, ask the agent to fix it using the following format:

    code language-shell-session
    adjust the modal position to be...
    

Modal displaying detailed rating distribution with star-level breakdown bars {width="600" modal="regular"}

recommendation-more-help
5ecfe1a6-f74c-4745-a54a-99b24da024bb