Run Magento Code Externally
Posted on April 12, 2010 by BT There have been 4 comment(s)
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();
This post was posted in Magento Tutorials and was tagged with Magento Tips
4 Responses to Run Magento Code Externally
5 Item(s)

hello ? how to execute this script ? i make a php file, load in magento root category, run it and nothing happend...
Posted on July 9, 2010 at 7:53 pm
Create a file in your Magento root and add the following:
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app(); // Change default to whatever store you want to run
echo "it's worked!";
?>
If the string "It's Worked!" is displayed then it has all worked fine
Posted on July 10, 2010 at 12:27 am
Hi,thanks for the tutorials. I got a question beyond this tutorial. I'm trying to create a php file that run automatically when the web was loaded. Do you mind to teach me how to achieve it? Thanks a lot.. :d
Posted on July 16, 2010 at 6:33 pm
hai,, give any idea for create static magento page externally.. i want to display menu bars... please help me...
Posted on January 23, 2012 at 5:05 pm
Thanks a million for your job. But it is echoing the english menu, though the default menu is german. Please what do i change to echo the default menu which is german.
Best Regards
Posted on March 18, 2012 at 12:07 pm