[英]Get product id in magento
在magento中,我想添加快速浏览功能,例如http://www.timberlandonline.co.uk/on/demandware.store/Sites-TBLGB-Site/default/Link-Category?cgid=men_footwear_boots 。我添加了一个如果我单击任何产品的div,则javascript返回该类别页面中第一个产品的产品ID。但是它应该返回所选div的产品ID。
You need to look into this page ( <path_to_your_template_folder>/template/catalog/product/list.phtml
) carefully. 您需要仔细查看此页面( <path_to_your_template_folder>/template/catalog/product/list.phtml
)。 You will find the following lines of code in different places of this page only:- 您只会在此页面的不同位置找到以下代码行:-
$_productCollection = $this->getLoadedProductCollection();
foreach ($_productCollection as $_product):
$reqProductId = $_product->getId();
endforeach;
If you carefully match the above code & the code in the above-mentioned page, you will know that you need to use the variable " $reqProductId
" properly in your required " INPUT
" element of type " hidden
". 如果您仔细匹配上述代码和上述页面中的代码,您将知道需要在类型为“ hidden
”的所需“ INPUT
”元素中正确使用变量“ $reqProductId
”。 So you will require it to do your part in the main " foreach
" loop. 因此,您将需要它在“ foreach
”主循环中发挥作用。
Hope it helps. 希望能帮助到你。
Try below code to get currently loaded product id: 尝试下面的代码来获取当前加载的产品ID:
$product_id = $this->getProduct()->getId();
When you don't have access to $this
, you can use Magento registry: 当您无权访问$this
,可以使用Magento注册表:
$product_id = Mage::registry('current_product')->getId();
Also for product type i think 我也认为产品类型
$product = Mage::getModel('catalog/product')->load($product_id);
$productType = $product->getTypeID();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.