Magento Themes and Magento Extensions

RUN MAGENTO CODE EXTERNALLY

Share

If you’re working with Magento often you’ll find sometimes you need to use Magento functions and classes outside of the Magento platform. This can be easily achieved with the following lines of code.

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
// Now you can run ANY Magento code you want
// Change 12 to the ID of the product you want to load
$_product = Mage::getModel('catalog/product')->load(12);
echo $_product->getName();

This was only a quick post but hopefully it will be useful to someone.

Here’s an example how to get the site navigation.

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
$_layout = Mage::getSingleton('core/layout');
$_block = $_layout->createBlock('catalog/navigation')->setTemplate('catalog/navigation/left.phtml');
echo $_block->toHtml();

Comments are closed.