开发者

Get product id in magento

开发者 https://www.devze.com 2023-02-16 11:22 出处:网络
In magento,i want to add quick look feature like this http://www.timberlandonline.co.uk/on/demandware.store/Sites-TBLGB-Site/default/Link-Category?cgid=men_footwear_boots.I have added a hidden input &

In magento,i want to add quick look feature like this http://www.timberlandonline.co.uk/on/demandware.store/Sites-TBLGB-Site/default/Link-Category?cgid=men_footwear_boots.I have added a hidden input & a div in list.phtml.If i click the div of a开发者_StackOverflow社区ny product javascript returns product id of first product in that category page.But it should return product id of the selected div.


You need to look into this page (<path_to_your_template_folder>/template/catalog/product/list.phtml) carefully. 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". So you will require it to do your part in the main "foreach" loop.

Hope it helps.


Try below code to get currently loaded product id:

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

When you don’t have access to $this, you can use Magento registry:

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

Also for product type i think

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

$productType = $product->getTypeID();
0

精彩评论

暂无评论...
验证码 换一张
取 消