2

I'm trying to load a product view into another page, here is how I'm trying to achieve

<?php Mage::register('product',$product);?>
<?php
      $customview = Mage::app()->getLayout()->createBlock('catalog/product_view')->setProductId($id)->setTemplate('templatefolder/customview.phtml');          
      $html = $customview->toHtml();
?>
 <?php Mage::unregister('product');?>
 <?php echo $html; ?>

but in the result none of the childHtml or childchildHtml block is getting load. I need swatches to be displayed.

I think I have to set blocks as a child block of the $customview template object like

<?php
    $container1Block = Mage::getSingleton('core/layout') ->createBlock('core/template_facade', "product.info.container1");
    $container1Block->setDataByKey('alias_in_layout', 'container1');
    $container1Block->setDataByKeyFromRegistry('options_container', 'product');
    $container1Block->append('product.info.options.wrapper');
    $container1Block->append('product.info.options.wrapper.bottom');
 ?>

and then before calling toHtml I should set it as a child $customview->setChild('container1',$container1Block); but the issue remains still, I believe configurable swatches are called because of this code in layout :

 <PRODUCT_TYPE_configurable translate="label" module="catalog">
    <label>Catalog Product View (Configurable)</label>
    <reference name="product.info">
        <block type="catalog/product_view_type_configurable" name="product.info.configurable" as="product_type_data" template="catalog/product/view/type/default.phtml">
            <block type="core/text_list" name="product.info.configurable.extra" as="product_type_data_extra" translate="label">
                <label>Product Extra Info</label>
            </block>
        </block>
        <block type="catalog/product_view_type_configurable" name="product.info.availability" as="product_type_availability" template="catalog/product/view/type/availability/default.phtml" />
    </reference>
    <reference name="product.info.options.wrapper">
        <block type="catalog/product_view_type_configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="catalog/product/view/type/options/configurable.phtml">
            <block type="core/text_list" name="product.info.options.configurable.renderers" as="attr_renderers" />
            <block type="core/text_list" name="product.info.options.configurable.after" as="after" />
        </block>
    </reference>
</PRODUCT_TYPE_configurable>

And the way Im doing this won't be still applied on the block. can anyone please guide me the right way to do it or how to get my code working ?

Thanks

0

Instead of creating the block just in time, I recommend using layout.xml.

In your layout xml you can add the handle for product view to load all needed blocks like this:

<your_handle>
    <update handle="catalog_product_view"/>
</your_handle>

At least I think this is a good starting point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.