在Magento中,我想要添加快速查看功能,类似于这个网站:http://www.timberlandonline.co.uk/on/demandware.store/Sites-TBLGB-Site/default/Link-Category?cgid=men_footwear_boots。我在list.phtml文件中添加了一个隐藏的输入和一个div。如果我点击任何产品的div,javascript会返回该类别页面中第一个产品的产品ID。但它应该返回所选div的产品ID。
你需要仔细查看这个页面 (<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”循环中使用它来完成自己的部分。使用以下代码获取当前加载的产品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();