Magento – Get entire product page html block from outside Magento

blocksmagento-1.7product

What I am trying to do is fairly straight forward. I am basically trying to load the product block based on product ID. Imagine an empty CMS page, and just fill it with the product block so it looks identical to the product page. This is what I am trying to accomplish. It needs to be done outside Magento, so calling a block like: {{block type="catalog/product_single" product_id="1" template="catalog/product/singleproduct.phtml"}} is out of the question. This is what I have so far .. but I think I am trying to over-simplify this. I know I am missing something obvious.

require_once '/blah/blah/blah/app/Mage.php';
Mage::app();
$block = new Mage_Catalog_Block_Product_View_Options(); 
$product = Mage::getModel('catalog/product')->load('22335');
$block->setProduct($product);
$block->getBlock('product');
echo $block->toHtml();

Does anyone have anything to add to this to make it work?

Best Answer

Instantiating the Blocks this way might be a bad idea, but I think this should work. Do you have any problems?

require_once '/blah/blah/blah/app/Mage.php';
Mage::app();
$block = Mage::getBlockSingleton('catalog/product_view_options');
$product = Mage::getModel('catalog/product')->load('22335');
$block->setProduct($product);
echo $block->toHtml();
Related Topic