Magento Product api 不提供此类功能
虽然有一些简单的方法可以在自定义模块中扩展特定 API,但如果您不想编写自定义模块,这是最快的方法(因为我认为对于新的 magento 开发人员来说很难)。
在编辑任何内容之前,将原始产品 API 类从 core 复制到 local 文件夹(这样您的 Magento 安装将保持“更新保存”)。
- 从
app/code/core/Mage/Catalog/Model/Product/Api.php复制Api.php
- 至:
app/code/local/Mage/Catalog/Model/Product/Api.php
现在更改复制文件中的info 方法以包含full_url。将以下行添加到$result-array。 (确保在数组行的末尾设置必要的逗号。)
'full_url' => $product->getProductUrl(),
生成的方法代码应如下所示:
public function info($productId, $store = null, $attributes = null, $identifierType = null)
{
$product = $this->_getProduct($productId, $store, $identifierType);
$result = array( // Basic product data
'product_id' => $product->getId(),
'sku' => $product->getSku(),
'set' => $product->getAttributeSetId(),
'type' => $product->getTypeId(),
'categories' => $product->getCategoryIds(),
'websites' => $product->getWebsiteIds(),
'full_url' => $product->getProductUrl(),
);
foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
if ($this->_isAllowedAttribute($attribute, $attributes)) {
$result[$attribute->getAttributeCode()] = $product->getData(
$attribute->getAttributeCode());
}
}
return $result;
}
之后,您可以通过 API 调用 product.info 并使用 full_url 字段。