如何在magento中获取产品名称?

How to get product name in magento?

我正在尝试使用产品 ID 仅获取产品名称

我试过以下方法:

$product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$product->getName();

它加载了整个资源对象,然后我们可以使用 $product->getName() 获取名称,但我只需要一个名称,这样我们就可以减少额外的开销。

$product = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name')->addAttributeToFilter('entity_id', PRODUCT_ID)->load();

它还加载资源对象。

有没有什么最简单的方法可以在不加载资源对象的情况下获取产品名称(例如 'Test product')?

使用getAttributeRawValue() 有了这个你就可以得到你的产品的属性值:

$attribute_value = Mage::getResourceModel('catalog/product')->getAttributeRawValue(PRODUCT_ID, 'attribute_code');

我们还需要传递存储值,以便直接从资源模型中获取产品属性。 您可以使用此代码获取商店 ID:- Mage::app()->getStore().

所以最终查询将是:-

 $attribute_value = Mage::getResourceModel('catalog/product')->getAttributeRawValue(PRODUCT_ID,'attribute_code',Mage::app()->getStore());

试试这个,希望它对你有用。

试试这个:

$product = Mage::registry('current_product'); then
$product->getName();
$product->getId();

您可以尝试此产品:

$id = $this->getRequest()->getParam('id');
$current_product=Mage::getModel('catalog/product')->load($id);