Ajax in magento (load product view block)

前端 未结 1 1577
青春惊慌失措
青春惊慌失措 2021-01-01 06:46

What I want to achieve: Clicking on a product link/image (at least in certain areas) to open a pop-up with the full product information (basically all the contents of the pr

相关标签:
1条回答
  • 2021-01-01 07:41

    The Product controller uses a helper to set the active product. You should be able to do the same in your controller!

    Try this before you do your layouting:

    $productId  = (int) $this->getRequest()->getParam('id');
    Mage::helper('catalog/product')->initProduct($productId, $this);
    

    Another thing to be aware of: If you add a block like the product.info block. It needs additional child blocks if it calls them in its template file.

    It would be easiest to use a custom layout xml file. You can then add a specific layout for your action handle (your action handle consists of your routers node in your module's etc/config.xml file under <frontend><routers>, e.g. <Yourmodule> node, make sure to lowercase it! And then with underscores add the controller name and action name, in your case index_index) like this:

    <yourmodule_index_index>
        <remove name="right"/>
        <remove name="left"/>
        <block type="catalog/product_view" name="root" output="toHtml" template="catalog/product/view.phtml">
        <!-- Add all the child blocks you need -->
        </block>
    </yourmodule_index_index>
    

    This makes the view.phtml the root block which renders itself using its toHtml method. Therefore, in your controller action, all you need is my two lines above and then:

    $this->loadLayout();
    $this->renderLayout();
    
    0 讨论(0)
提交回复
热议问题