In Ihrem Fall müssen Sie einen benutzerdefinierten SOAP-API-Endpunkt implementieren. Glücklicherweise können Sie die Implementierung der herunterladbaren Produkt-API stark wiederverwenden.
Wenn Sie alle unten aufgeführten Dateien erstellen, steht Ihnen die neue SOAP V2-API zur Verfügung: catalogProductAttachLinkList . Um das Hinzufügen / Entfernen von Methoden zu aktivieren, portieren Sie sie einfach von app / code / core / Mage / Downloadable / Model / Link / Api.php nach app / code / community / Intellimage / Attachs / Model / Link / Api.php .
Führen Sie einen der folgenden Schritte aus, um eine neue API zu testen:
<?php
/* SOAP V2 Style */
$client = new SoapClient('http://simple-magento-vagrant.dev/index.php/api/v2_soap/?wsdl');
$sessionId = $client->login('apiUser', 'apiKey');
$productId = 1;
$result = $client->catalogProductAttachLinkList($sessionId, $productId);
print_r($result);
/* SOAP V1 style. If you want to use this style, you may skip creation of custom wsdl.xml and Api/V2.php files proposed below. Adding api.xml and Api.php will be enough */
$client = new SoapClient('http://simple-magento-vagrant.dev/index.php/api/soap/?wsdl');
$sessionId = $client->login('apiUser', 'apiKey');
$productId = 1;
$result = $client->call($sessionId, 'attach_link.list', [$productId]);
print_r($result);
Dateien, die Ihrem Modul hinzugefügt werden sollen:
app / code / community / Intellimage / Attachs / etc / api.xml
<?xml version="1.0"?>
<config>
<api>
<resources>
<catalog_product_attach_link translate="title" module="intellimage_attachs">
<model>attachs/link_api</model>
<title>Category API</title>
<acl>downloadable/link</acl>
<methods>
<list translate="title" module="intellimage_attachs">
<title>Retrieve links and samples list from attach product</title>
<method>items</method>
<acl>downloadable/link/list</acl>
</list>
</methods>
</catalog_product_attach_link>
</resources>
<resources_alias>
<attach_link>catalog_product_attach_link</attach_link>
</resources_alias>
<v2>
<resources_function_prefix>
<attach_link>catalogProductAttachLink</attach_link>
</resources_function_prefix>
</v2>
</api>
</config>
app / code / community / Intellimage / Attachs / etc / wsdl.xml
(Bitte beachten Sie, dass wsi.xml erstellt werden sollte, wenn SOAP V2 WS-I-Kompatibilität erforderlich ist.)
<?xml version="1.0"?>
<config>
<api>
<resources>
<catalog_product_attach_link translate="title" module="intellimage_attachs">
<model>attachs/link_api</model>
<title>Category API</title>
<acl>downloadable/link</acl>
<methods>
<list translate="title" module="intellimage_attachs">
<title>Retrieve links and samples list from attach product</title>
<method>items</method>
<acl>downloadable/link/list</acl>
</list>
</methods>
</catalog_product_attach_link>
</resources>
<resources_alias>
<attach_link>catalog_product_attach_link</attach_link>
</resources_alias>
<v2>
<resources_function_prefix>
<attach_link>catalogProductAttachLink</attach_link>
</resources_function_prefix>
</v2>
</api>
</config>
App / Code / Community / Intellimage / Attachs / Modell / Link / Api / V2.php
<?php
class Intellimage_Attachs_Model_Link_Api_V2 extends Intellimage_Attachs_Model_Link_Api
{
protected function _prepareData(&$var)
{
if (is_object($var)) {
$var = get_object_vars($var);
foreach ($var as $key => &$value) {
$this->_prepareData($value);
}
}
}
public function add($productId, $resource, $resourceType, $store = null, $identifierType = null)
{
$this->_prepareData($resource);
return parent::add($productId, $resource, $resourceType, $store, $identifierType);
}
}
App / Code / Community / Intellimage / Attachs / Model / Link / Api.php
<?php
class Intellimage_Attachs_Model_Link_Api extends Mage_Catalog_Model_Api_Resource
{
public function items($productId, $store = null, $identifierType = null)
{
$product = parent::_getProduct($productId, $store, $identifierType);
$typeInstance = $product->getTypeInstance(true);
$product->setTypeInstance(Mage::getModel('attachs/product_type', $typeInstance), true);
$linkArr = array();
$links = $product->getTypeInstance(true)->getSamples($product);
$downloadHelper = Mage::helper('downloadable');
foreach ($links as $item) {
$tmpLinkItem = array(
'link_id' => $item->getId(),
'title' => $item->getTitle(),
'price' => $item->getPrice(),
'number_of_downloads' => $item->getNumberOfDownloads(),
'is_shareable' => $item->getIsShareable(),
'link_url' => $item->getLinkUrl(),
'link_type' => $item->getLinkType(),
'sample_file' => $item->getSampleFile(),
'sample_url' => $item->getSampleUrl(),
'sample_type' => $item->getSampleType(),
'sort_order' => $item->getSortOrder()
);
$file = Mage::helper('downloadable/file')->getFilePath(
Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile()
);
if ($item->getLinkFile() && !is_file($file)) {
Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
}
if ($item->getLinkFile() && is_file($file)) {
$name = Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile());
$tmpLinkItem['file_save'] = array(
array(
'file' => $item->getLinkFile(),
'name' => $name,
'size' => filesize($file),
'status' => 'old'
));
}
$sampleFile = Mage::helper('downloadable/file')->getFilePath(
Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile()
);
if ($item->getSampleFile() && is_file($sampleFile)) {
$tmpLinkItem['sample_file_save'] = array(
array(
'file' => $item->getSampleFile(),
'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
'size' => filesize($sampleFile),
'status' => 'old'
));
}
if ($item->getNumberOfDownloads() == '0') {
$tmpLinkItem['is_unlimited'] = 1;
}
if ($product->getStoreId() && $item->getStoreTitle()) {
$tmpLinkItem['store_title'] = $item->getStoreTitle();
}
if ($product->getStoreId() && $downloadHelper->getIsPriceWebsiteScope()) {
$tmpLinkItem['website_price'] = $item->getWebsitePrice();
}
$linkArr[] = $tmpLinkItem;
}
unset($item);
unset($tmpLinkItem);
unset($links);
$samples = $product->getTypeInstance(true)->getSamples($product)->getData();
return array('links' => $linkArr, 'samples' => $samples);
}
}