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?

  • Do you only need the content block or do you need the entire page with doctype and all? – philwinkle Oct 25 '13 at 3:14
  • I only need the content block that's in the main wrapper .. I don't need header/footer etc .. – Zak Oct 25 '13 at 17:22
  • If you need the entire product block why do you only create the options block? – Matthias Zeis Oct 26 '13 at 6:55
  • Did you try recreating that call with getlayout createblock? – Toon Van Dooren Oct 26 '13 at 20:28
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, privacy policy and cookie policy

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