在Magento中获取产品ID

8

您的URL指向404页面。 - Black
2个回答

16

你需要仔细查看这个页面 (<path_to_your_template_folder>/template/catalog/product/list.phtml)。你只会在这个页面的不同位置找到以下代码行:

$_productCollection = $this->getLoadedProductCollection();

foreach ($_productCollection as $_product):
    $reqProductId = $_product->getId();
endforeach;
如果你仔细比较上面的代码和上述页面中的代码,你将会知道需要在类型为“hidden”的所需“INPUT”元素中正确地使用变量“$reqProductId”。因此,您需要在主要的“foreach”循环中使用它来完成自己的部分。
希望对你有所帮助。

1
谢谢。我将每个产品ID存储在锚点标记的ID中,并使用jQuery获取该ID。我也会尝试这种方法。 - blakcaps
有没有办法在管理面板/目录/产品管理中获取产品ID?... https://dev59.com/tF7Va4cB1Zd3GeqPIEXP - enloz

4

使用以下代码获取当前加载的产品ID:

$product_id = $this->getProduct()->getId();

当您无法访问$this时,可以使用Magento注册表:

$product_id = Mage::registry('current_product')->getId();

我认为您需要产品类型方面的资料。
$product = Mage::getModel('catalog/product')->load($product_id); 

$productType = $product->getTypeID();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接