評等擴充功能教學課程

本教學課程會引導您使用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開發評等擴充功能。

  1. 導覽至「Cursor > Settings > Cursor Settings > Tools & MCP」,並驗證「commerce-extensibility」工具集已啟用且沒有錯誤。 如果您看到錯誤,請關閉和開啟工具集。

    Cursor IDE設定顯示已啟用的MCP commerce-extensibility工具集 {width="600" modal="regular"}

    note note
    NOTE
    使用AI輔助開發工具時,代理程式產生的程式碼和回應會有自然變化。
    如果您在程式碼上遇到任何問題,可以隨時要求代理程式協助您進行偵錯。
  2. 如果您有任何檔案新增到Cursor的內容中,請停用它:

    • 瀏覽至​Cursor > 設定 > Cursor設定 > 索引與檔案,並刪除列出的任何檔案。

    檔案清單為空的資料指標索引和檔案設定 {width="600" modal="regular"}

  3. 產生產品評等擴充功能的程式碼:

    • 從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 SKU
    
    note note
    NOTE
    如果代理程式要求搜尋檔案,請允許搜尋。
  4. 請精確回答代理程式的問題,協助其產生最佳程式碼。

    已輸入副檔名提示的代理程式模式中的游標聊天視窗 {width="600" modal="regular"} AI代理程式詢問關於擴充功能需求的問題 {width="600" modal="regular"}

  5. 使用下列範例文字來回答代理程式的問題,以設定隨機分級資料:

    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代理程式建立的 Requirements.md檔案包含實作詳細資料 {width="600" modal="regular"}

  6. 檢閱requirements.md檔案並驗證計畫。

    如果一切看起來正確,請指示代理程式移至​階段2 — 架構規劃

  7. 檢閱架構計畫。

  8. 指示代理程式繼續產生程式碼。

    代理程式會產生必要的程式碼,並提供您後續步驟的詳細摘要。

    評等API的AI代理程式階段2架構計畫 {width="600" modal="regular"} 產生的程式碼檔案和結構的摘要 {width="600" modal="regular"} AI代理程式提供後續步驟以進行測試和部署 {width="600" modal="regular"}

本機測試

  1. 請要求代理程式協助您在本機測試程式碼。

    code language-shell-session
    Test the ratings API locally on a dev server using cURL.
    
  2. 請依照代理程式的指示,並確認API是否在本機運作。

    本機API測試的AI代理程式指示 {width="600" modal="regular"}

    終端機顯示成功的本機API測試結果(含cURL {width="600" modal="regular"})

部署擴充功能

  1. 驗證產生的程式碼後,請使用以下提示來部署擴充功能:

    code language-shell-session
    Deploy the ratings API.
    

    代理程式會在部署前執行部署前準備程度評估。

    AI代理程式部署前準備程度評估檢查清單 {width="600" modal="regular"}

  2. 當您對評估結果有信心時,請指示代理程式繼續進行部署。

    代理程式會使用MCP工具組來自動驗證、建置和部署。

    MCP工具組驗證建置和部署程式 {width="600" modal="regular"}

部署後

您可以先測試API,再將其整合至店面。 代理程式應提供新動作的位置和測試策略。

AI代理程式測試策略,包含已部署的動作URL和測試命令 {width="600" modal="regular"}

您也可以在終端機中使用cURL手動測試API:

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

終端機顯示已部署的評等API的成功cURL測試 {width="600" modal="regular"}

整合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

AI代理程式正在建立店面整合的服務合約檔案 {width="600" modal="regular"}

含端點與回應詳細資訊的評等API合約Markdown檔案 {width="600" modal="regular"}

後續步驟

現在您有了評等API合約,就可以開始建立評等延伸模組的店面(前端)部分了。

recommendation-more-help
2a2029a1-b458-4706-b074-f9c0c06ca6bb