1

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?

4
  • Do you only need the content block or do you need the entire page with doctype and all?
    – philwinkle
    Commented Oct 25, 2013 at 3:14
  • I only need the content block that's in the main wrapper .. I don't need header/footer etc ..
    – Zak
    Commented Oct 25, 2013 at 17:22
  • If you need the entire product block why do you only create the options block? Commented Oct 26, 2013 at 6:55
  • Did you try recreating that call with getlayout createblock? Commented Oct 26, 2013 at 20:28

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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