私は Magento を初めて使用し、その API を使用しています。API 呼び出しから製品の URL を取得できる必要があります。url_key と url_path にアクセスできることがわかりましたが、残念ながら、それは製品の URL であるとは限りません (つまり、category/my-product-url.html である可能性があります)。url_key には my-product-url が含まれ、url_path にはmy-product-url.html のみが含まれます。さらに複雑なことに、/category/sub-category/my-product-url.html の場合もあります。では、URL 書き換え情報で設定されているように、カテゴリとすべてを含む完全な URL を取得するにはどうすればよいでしょうか。これには、product.info API 呼び出しからの製品情報が付属しているように見えますが、そうではありません。
13353 次
2 に答える
3
Magento 製品 API はそのような機能を提供しません
カスタム モジュールで特定の API を拡張する簡単な方法がありますが、カスタム モジュールを作成したくない場合は、ここが最も簡単な方法です (新しい magento 開発者にとっては難しいと思います)。
何かを編集する前に、元の製品 API クラスを からフォルダーにコピーしcore
ますlocal
(そうすれば、Magento のインストールは「更新保存」のままになります)。
- 以下から Api.php をコピーします。
app/code/core/Mage/Catalog/Model/Product/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
于 2009-11-20T00:32:00.373 に答える
-1
実際、あなたのパスでさえ間違っています。彼が言及しているのは app\code\core\Mage\Catalog\Model\Product\Product.php です
于 2010-12-22T11:41:19.233 に答える