評等擴充功能教學課程
本教學課程會引導您使用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 使用AI輔助開發工具時,代理程式產生的程式碼和回應會有自然變化。
如果您在程式碼上遇到任何問題,可以隨時要求代理程式協助您進行偵錯。 -
如果您有任何檔案新增到Cursor的內容中,請停用它:
- 瀏覽至Cursor > 設定 > Cursor設定 > 索引與檔案,並刪除列出的任何檔案。
{width="600" modal="regular"}
-
產生產品評等擴充功能的程式碼:
- 從Cursor聊天視窗中,選取 代理程式 模式。
- 輸入下列提示:
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是否在本機運作。
{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,再將其整合至店面。 代理程式應提供新動作的位置和測試策略。
您也可以在終端機中使用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合約,就可以開始建立評等延伸模組的店面(前端)部分了。