Magento - get current product

前端 未结 4 2003
天涯浪人
天涯浪人 2021-02-05 08:18

I have a sidebar block in my layout that is being displayed on different pages.

In this block I have a list of products, and I want to select the current product when I

4条回答
  •  有刺的猬
    2021-02-05 08:45

    How to get current product id

    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();
    

提交回复
热议问题