How to get Magento layout outside of Magento

I integreated wordpress in my magento store and I will try to get magento data in wordpress file. I want to same header in my both site magento and wordpress. I tryed to hard and finally got the solution to get any magento layout in wordpress. Below are the script to

get magento layout outside of magento.

<?php
require_once '/home/.../public_html/.../app/Mage.php';
umask(0);
/* not Mage::run(); */
Mage::app('default');
 
// get layout object
$layout = Mage::getSingleton('core/layout');
 
//get block object
$block = $layout->createBlock('page/template_links');
 
/* choose whatever category ID you want */
//$block->setCategoryId(3);
$block->setTemplate('page/template/links.phtml');
 
echo $block->renderView();
?>

Get Magento layout outside of Magento

Below script to get whole magento header section with top links out side of Magento.

<?php
require_once '/home/.../public_html/.../app/Mage.php';
umask(0);
/* not Mage::run(); */
Mage::app('default');
 
$_layout = Mage::getSingleton('core/layout');
 
$block_header = $_layout->createBlock('page/html_header')->setTemplate('page/html/header.phtml');
$block_links = $_layout->createBlock('page/template_links','top.links')->setTemplate('page/template/links.phtml');
 
$block_header->setChild('topLinks',$block_links);
 
$block_topcart = $_layout->createBlock('checkout/cart_sidebar')->setTemplate('checkout/cart/topcart.phtml');
$block_header->setChild('topcart',$block_topcart);
 
$block_links->addLink('My Account | ','/brieven/customer/account/','My Account','','',10);
$block_links->addLink('My Cart | ','/brieven/checkout/cart/','My Cart','','',10);
$block_links->addLink('Checkout | ','/brieven/checkout/','Checkout','','',10);
$block_links->addLink('Site | ','/','Site','','',10);
$block_links->addLink('Log In','/customer/account/login/','Log In','','',10);
 
echo $block_header->toHtml(); 
?>
Where, by calling the static block model, you can then get all fields associated with that block such as the static block title.
<?php
$block = Mage::getModel('cms/block')->load('identifier');
echo $block->getTitle();
echo $block->getContent();
?>
Note: If you get Magento Layout in WordPress Magento core that has the same name as WordPress function for translation “__()”. For this reason it is not possible to include Mage.php inside of WordPress. Copy your functions.php inside of your Magento instalation (../app/code/core/Mage/Core/) to a local folder (../app/code/local/Mage/Core/), and wrap it’s function __() so you get a snippet like this one:
if(! (function_exists('__')) )
{
    function __()
    {
        return Mage::app()->getTranslator()->translate(func_get_args());
    }
}

No comments:

Post a Comment