评级扩展教程
本教程将指导您使用Adobe Commerce as a Cloud Service和AI辅助开发工具为Adobe App Builder构建产品评级扩展。
在开始之前,请完成先决条件。
验证先决条件
验证是否安装了以下必备组件:
# 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
如果前面的任何命令未返回预期结果,请参阅先决条件获取指导。
扩展开发
此部分将指导您使用AI辅助开发工具为Adobe Commerce as a Cloud Service开发评级扩展。
-
导航到Cursor > Settings > Cursor Settings > Tools & MCP,并验证
commerce-extensibility工具集是否已启用且未出现错误。 如果看到错误,请关闭和打开工具集。 {width="600" modal="regular"}
note note NOTE 使用人工智能辅助开发工具时,预期代码和代理生成的响应会发生自然变化。
如果您遇到任何代码问题,始终可以请求代理帮助您对其进行调试。 -
如果有任何文档添加到光标上下文中,请禁用它:
- 导航到Cursor > 设置 > Cursor设置 > 索引和文档,并删除列出的任何文档。
{width="600" modal="regular"}
-
为产品评级扩展生成代码:
- 在“光标聊天”窗口中,选择 代理 模式。
- 输入以下提示:
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 SKUnote note NOTE 如果代理请求搜索文档,请允许搜索。 -
准确地回答座席的问题以帮助其生成最佳代码。
{width="600" modal="regular"}
{width="600" modal="regular"}
-
使用以下示例文本回答座席的问题,以设置随机评级数据:
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.代理将创建一个
requirements.md文件,用作实现的真实来源。AI代理创建的
{width="600" modal="regular"}
-
查看
requirements.md文件并验证计划。如果一切看起来都正确,请指示代理移至阶段2 — 架构计划。
-
查看体系结构计划。
-
指示代理继续生成代码。
代理程序会生成必要的代码并提供详细的摘要,其中包含后续步骤。
{width="600" modal="regular"}
{width="600" modal="regular"}
{width="600" modal="regular"}
本地测试
-
请求代理帮助您在本地测试代码。
code language-shell-session Test the ratings API locally on a dev server using cURL. -
按照代理的说明操作,并确认API在本地工作。
用于本地API测试的
{width="600" modal="regular"}
{width="600" modal="regular"})
部署扩展
-
验证生成的代码后,使用以下提示部署扩展:
code language-shell-session Deploy the ratings API.代理在部署之前执行部署前就绪性评估。
{width="600" modal="regular"}
-
如果对评估结果有信心,请指示代理继续部署。
代理使用MCP工具包自动验证、构建和部署。
{width="600" modal="regular"}
部署后
您可以在将API集成到店面之前对其进行测试。 代理应提供新操作的位置和测试策略。
具有已部署的操作URL和测试命令的
您还可以在终端中使用cURL手动测试API:
curl -s "https://<your-site>.adobeioruntime.net/api/v1/web/ratings/ratings?sku=TEST-SKU-123"
与Edge Delivery Services集成
要将评级API与由Adobe Commerce提供支持的Edge Delivery Services店面集成,请要求代理创建具有评级API要求的服务合同:
Create a service contract for the ratings api that I can pass on to the storefront agent. Name it RATINGS_API_CONTRACT.md
后续步骤
现在您有了评级API合同,就可以开始构建评级扩展的店面(前端)部分了。