文件Commerce影片和教學課程

建立套件組合產品

最後更新: 2025年5月5日
  • 主題:
  • 目錄管理
  • 管理員工作區
  • 後台開發

建立對象:

  • 初學者
  • 開發人員
  • 使用者

套件產品是一種將數個產品群組在父產品下的方式。 這些子產品可以是已定義的產品集,或提供一些可為客戶提供彈性設定選項的變體。 套裝產品型別的設定時間確實會稍長一些,而且您必須先進行一些規劃,才能進行設定。 不過,提供捆綁式產品可讓客戶更輕鬆地自訂其產品選擇,進而改善購物體驗。

例如,您可以在網站商店中提供名為Learning to surf的產品組合。 套件是父級產品,可作為指定可用選項的已指派子級產品的容器:

  • 標準衝浪板
  • 典型的衝浪板拴扣
  • Red surfboard fins

當需要額外彈性時,建議允許子產品的多個選項。 這需要更複雜地使用選項和子產品。 若要在上一個範例中展開,最後的選項為:

  • 標準衝浪板

  • 典型的衝浪板拴扣

  • 翅膀顏色選擇:

    • 紅色
    • 藍色
    • 黃色

無論套件組合是簡單產品的靜態群組,還是多種不同產品,彈性的設定選項讓套件組合產品型別成為Adobe Commerce商店專屬且功能強大的銷售工具。

在建立套件組合產品之前,請先確認要納入套件組合產品中的所有簡單產品都可在Adobe Commerce中使用。 建立任何不存在的專案。

在本教學課程中,瞭解如何使用REST API和Adobe Commerce管理員建立套件組合產品。

使用REST API來定義套件組合產品:

  1. 建立簡單產品以用於套件組合產品。
  2. 建立套件組合產品並關聯簡單產品。
  3. 取得套件組合產品及所有相關選項。
  4. 從套件產品的一個區段中刪除選項。
  5. 還原套件組合產品的選項。

從Adobe Commerce管理員建立套件組合產品時,您可以先建立簡單產品,或使用自動化工具使用精靈建立簡單產品。

這部影片是給誰看的?

  • 網站管理員
  • 電子商務銷售商
  • 新的Adobe Commerce開發人員,瞭解如何使用REST API在Adobe Commerce中建立套件組合產品

視訊內容

video poster

https://video.tv.adobe.com/v/3454515?learn=on&captions=chi_hant

使用REST建立產品

下列命令會建立定義此範例中的組合產品所需的所有產品:五個簡單產品,以及一個具有三個選項的組合產品。

在提交請求之前,請使用您環境的值更新範例。

  • 變更"attribute-set": 4以使用您環境的屬性集ID取代4。
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3' \
--data '{
  "product": {
    "sku": "10-ft-beginner-surfboard",
    "name": "10 Foot Beginner surfboard",
    "attribute_set_id": 4,
    "price": 100,
    "type_id": "simple",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock":true
      }
    }
  }
}
'
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3' \
--data '{
  "product": {
    "sku": "8-ft-surboard-leash",
    "name": "8 Foot surboard leash",
    "attribute_set_id": 4,
    "price": 50,
    "type_id": "simple",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock":true
      }
    }
  }
}
'
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3' \
--data '{
  "product": {
    "sku": "red-fins-and-fin-plugs",
    "name": "Red fins and fin plugs",
    "attribute_set_id": 4,
    "price": 15,
    "type_id": "simple",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock":true
      }
    }
  }
}
'
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3' \
--data '{
  "product": {
    "sku": "blue-fins-and-fin-plugs",
    "name": "Blue fins and fin plugs",
    "attribute_set_id": 4,
    "price": 15,
    "type_id": "simple",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock":true
      }
    }
  }
}
'
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3' \
--data '{
  "product": {
    "sku": "yellow-fins-and-fin-plugs",
    "name": "Yellow fins and fin plugs",
    "attribute_set_id": 4,
    "price": 15,
    "type_id": "simple",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock":true
      }
    }
  }
}
'

建立套件組合產品並將簡單產品指派為選項

傳送以下POST要求以建立套件組合產品。

在提交請求之前,請使用您環境的值更新範例。

  • 變更"attribute_set_id": 4,並以您環境的屬性集ID取代4。
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3' \
--data '{
  "product": {
    "sku": "beginner-surfboard",
    "name": "Beginner Surfboard",
    "attribute_set_id": 4,
    "status": 1,
    "visibility": 4,
    "type_id": "bundle",
    "extension_attributes": {
      "stock_item": {
        "qty": 100,
        "is_in_stock":true
      },
      "bundle_product_options": [
        {
          "option_id": 0,
          "position": 1,
          "sku": "surfboard-essentials",
          "title": "Beginners 10ft Surfboard",
          "type": "checkbox",
          "required": true,
          "product_links": [
            {
              "sku": "10-ft-beginner-surfboard",
              "option_id": 1,
              "qty": 1,
              "position": 1,
              "is_default": false,
              "price": 100,
              "price_type": 0,
              "can_change_quantity": 0
            }
          ]
        },
        {
          "option_id": 1,
          "position": 2,
          "sku": "surboard-leash",
          "title": "Surfboard leash",
          "type": "checkbox",
          "required": true,
          "product_links": [
            {
              "sku": "8-ft-surboard-leash",
              "option_id": 2,
              "qty": 1,
              "position": 1,
              "is_default": false,
              "price": 50,
              "price_type": 0,
              "can_change_quantity": 0
            }
          ]
        },
        {
          "option_id": 3,
          "position": 2,
          "sku": "surfboard-color",
          "title": "Choose a color for the fins and fin plugs",
          "type": "radio",
          "required": true,
          "product_links": [
            {
              "sku": "red-fins-and-fin-plugs",
              "option_id": 2,
              "qty": 1,
              "position": 1,
              "is_default": false,
              "price": 0,
              "price_type": 0,
              "can_change_quantity": 0
            },
            {
              "sku": "blue-fins-and-fin-plugs",
              "option_id": 2,
              "qty": 1,
              "position": 2,
              "is_default": false,
              "price": 0,
              "price_type": 0,
              "can_change_quantity": 0
            },
            {
              "sku": "yellow-fins-and-fin-plugs",
              "option_id": 3,
              "qty": 1,
              "position": 3,
              "is_default": false,
              "price": 0,
              "price_type": 0,
              "can_change_quantity": 0
            }
          ]
        }
      ]
    },
    "custom_attributes": [
      {
        "attribute_code": "price_view",
        "value": "0"
      }
    ]
  },
  "saveOptions": true
}
'

從套件組合產品刪除選項

使用cURL傳送下列DELETE請求,從套件產品中移除子產品,而不從目錄中刪除產品。

curl --location --request DELETE '{{your.url.here}}/rest/default/V1/bundle-products/beginner-surfboard/options/35/children/blue-fins-and-fin-plugs' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3'

還原產品選項

更新套件產品選項時,請務必加入所有要與此產品相關聯的選項。 如果您的原始選項集包含三個產品且一個已移除,請在POST請求中包含所有三個選項,以確保產品套件指定所有選項。 如果您只包含移除的選項,則更新的產品套件組合只會包含該選項。

檢閱套件產品建立的回應,以找到選項ID。 在該回應中,option_id是35。

...
,
            {
                "option_id": 35,
                "title": "added back color options for fins and fin plugs",
                "required": true,
                "type": "radio",
                "position": 2,
                "sku": "beginner-surfboard",
                "product_links": [
                    {
                        "id": "77",
                        "sku": "red-fins-and-fin-plugs",
                        "option_id": 35,
                        "qty": 1,
                        "position": 1,
                        "is_default": false,
                        "price": 15,
                        "price_type": null,
                        "can_change_quantity": 0
                    },
                    {
                        "id": "78",
                        "sku": "blue-fins-and-fin-plugs",
                        "option_id": 35,
                        "qty": 1,
                        "position": 2,
                        "is_default": false,
                        "price": 15,
                        "price_type": null,
                        "can_change_quantity": 0
                    },
                    {
                        "id": "79",
                        "sku": "yellow-fins-and-fin-plugs",
                        "option_id": 35,
                        "qty": 1,
                        "position": 3,
                        "is_default": false,
                        "price": 15,
                        "price_type": null,
                        "can_change_quantity": 0
                    }
                ]
            }
...

更新產品套件組合以新增您透過提交以下POST請求來移除的選項。

curl --location '{{your.url.here}}/rest/default/V1/bundle-products/options/add' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=41d94540f5bd8b691017a850bc3b82b3' \
--data '{
  "option": {
    "option_id": 35,
    "title": "Choose a color for the fins and fin plugs",
    "required": true,
    "type": "radio",
    "position": 2,
    "sku": "beginner-surfboard",
    "product_links": [
      {
        "sku": "red-fins-and-fin-plugs",
        "option_id": 35,
        "qty": 1,
        "position": 1,
        "is_default": false,
        "price": 0,
        "price_type": null,
        "can_change_quantity": 0,
        "extension_attributes": {}
      },
      {
        "sku": "blue-fins-and-fin-plugs",
        "option_id": 35,
        "qty": 1,
        "position": 2,
        "is_default": false,
        "price": 0,
        "price_type": null,
        "can_change_quantity": 0,
        "extension_attributes": {}
      },
      {
        "sku": "yellow-fins-and-fin-plugs",
        "option_id": 35,
        "qty": 1,
        "position": 3,
        "is_default": false,
        "price": 0,
        "price_type": null,
        "can_change_quantity": 0,
        "extension_attributes": {}
      }
    ],
    "extension_attributes": {}
  }
}'

其他資源

  • 建立套件組合產品教學課程
  • 套件組合產品
  • Adobe Developer REST教學課程
  • Adobe Commerce REST ReDoc
recommendation-more-help
3a5f7e19-f383-4af8-8983-d01154c1402f