これはどこにも文書化されていませんが (他に)、少なくとも Magento 1.6 では、ソース コードで製品オプションの適切な API メソッドを見つけることができます。(その機能が存在するバージョンはわかりません。)
API 自体は、app/code/core/Mage/Catalog/etc/api.xml で定義されています。
<catalog_product_custom_option translate="title" module="catalog">
<title>Catalog product custom options API</title>
<model>catalog/product_option_api</model>
<acl>catalog/product/option</acl>
<methods>
<add translate="title" module="catalog">
<title>Add new custom option into product</title>
<acl>catalog/product/option/add</acl>
</add>
<update translate="title" module="catalog">
<title>Update custom option of product</title>
<acl>catalog/product/option/update</acl>
</update>
<types translate="title" module="catalog">
<title>Get list of available custom option types</title>
<acl>catalog/product/option/types</acl>
</types>
<info translate="title" module="catalog">
<title>Get full information about custom option in product</title>
<acl>catalog/product/option/info</acl>
</info>
<list translate="title" module="catalog">
<title>Retrieve list of product custom options</title>
<acl>catalog/product/option/list</acl>
<method>items</method>
</list>
<remove translate="title" module="catalog">
<title>Remove custom option</title>
<acl>catalog/product/option/remove</acl>
</remove>
</methods>
</catalog_product_custom_option>
呼び出される関数は、app/code/core/Mage/Catalog/Model/Product/Option/Api.php で定義されています。
class Mage_Catalog_Model_Product_Option_Api extends Mage_Catalog_Model_Api_Resource
{
/**
* Add custom option to product
*
* @param string $productId
* @param array $data
* @param int|string|null $store
* @return bool $isAdded
*/
public function add( $productId, $data, $store = null )
/**
* Update product custom option data
*
* @param string $optionId
* @param array $data
* @param int|string|null $store
* @return bool
*/
public function update( $optionId, $data, $store = null )
/**
* Read list of possible custom option types from module config
*
* @return array
*/
public function types()
/**
* Get full information about custom option in product
*
* @param int|string $optionId
* @param int|string|null $store
* @return array
*/
public function info( $optionId, $store = null )
/**
* Retrieve list of product custom options
*
* @param string $productId
* @param int|string|null $store
* @return array
*/
public function items( $productId, $store = null )
/**
* Remove product custom option
*
* @param string $optionId
* @return boolean
*/
public function remove( $optionId )
/**
* Check is type in allowed set
*
* @param string $type
* @return bool
*/
protected function _isTypeAllowed( $type )
}
$data
-array も少しトリッキーです。これは、キーが選択したオプション タイプに部分的に依存するためです。基本的な $data-array は次のようになります。
$data = array (
'is_delete' => 0,
'title' => 'Custom Option Label',
'type' => 'text',
'is_require' => 0,
'sort_order' => 1,
'additional_fields' => array (
0 => array (
'price' => '10.0000',
'price_type' => 'fixed', // 'fixed' or 'percent'
'sku' => '',
),
),
);
はadditional_fields
常に、少なくとも列price
、price_type
およびを含む少なくとも 1 つの行を含んでいますsku
。タイプによっては、さらに追加のフィールド (maf: …) が追加される場合があります。グループ内のタイプには、 でselect
指定された行が複数ある場合がありますadditional_fields
。カスタム オプション タイプ/タイプ グループは次のとおりです。
- テキスト (maf:
'max_characters'
)
- ファイル (maf:
'file_extension', 'image_size_x', 'image_size_y'
)
- 選択 (maf:
'value_id', 'title', 'sort_order'
)
- 日にち
完全なオプション データ配列の例:
// type-group: select, type: checkbox
$data = array (
'is_delete' => 0,
'title' => 'extra Option for that product',
'type' => 'checkbox',
'is_require' => 0,
'sort_order' => 1,
'additional_fields' => array (
0 => array (
'value_id' => '3',
'title' => 'Yes',
'price' => 10.00,
'price_type' => 'fixed',
'sku' => NULL,
'sort_order' => 1,
),
1 => array (
'value_id' => 3,
'title' => 'No',
'price' => 0.00,
'price_type' => 'fixed',
'sku' => NULL,
'sort_order' => 2,
),
),
);
// type-group: text, type: field
$data = array (
'is_delete' => 0,
'title' => 'Custom Option Label',
'type' => 'text',
'is_require' => 0,
'sort_order' => 1,
'additional_fields' => array (
0 => array (
'price' => 10.00,
'price_type' => 'fixed',
'sku' => NULL,
'max_characters' => 150,
),
),
);