Magento SOAP API v2 を使用して、構成可能な製品に関連するすべての製品を取得しようとしています。catalogProductLink 呼び出しは似ていますが、構成可能な型を処理しません。関連付けられた製品と製品の構成可能なタイプの情報を含む呼び出しが他にありません。他の人はこの問題をどのように解決しましたか?
私は Magento バージョン 1.6 と SOAP API V2 with Java を使用しています。
items() 関数の内容を次のように置き換えます。
if($type == "associated"){
$product = $this->_initProduct($productId);
try
{
$result = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
}
catch (Exception $e)
{
$this->_fault('data_invalid', Mage::helper('catalog')->__('The product is not configurable.'));
}
}
else
{
$typeId = $this->_getTypeId($type);
$product = $this->_initProduct($productId, $identifierType);
$link = $product->getLinkInstance()
->setLinkTypeId($typeId);
$collection = $this->_initCollection($link, $product);
$result = array();
foreach ($collection as $linkedProduct) {
$row = array(
'product_id' => $linkedProduct->getId(),
'type' => $linkedProduct->getTypeId(),
'set' => $linkedProduct->getAttributeSetId(),
'sku' => $linkedProduct->getSku()
);
foreach ($link->getAttributes() as $attribute) {
$row[$attribute['code']] = $linkedProduct->getData($attribute['code']);
}
$result[] = $row;
}
}
return $result;
次に、次のように API を呼び出すことができます。
$client->call($sessionId, 'product_link.list', array('associated', $id_of_your_configurable_product));
基本的に、私のコードは提供されたタイプをチェックしており、「関連付けられている」場合は子製品を返します。もっと良い方法があると確信していますが、Product Link API が最も適切な場所だと思いました。
楽しみ!
(注:このコードは私のものではありません。私はそれを適応させただけで、皆さんを助けるのに良い考えだと思いました)