How to access Magento core inside a custom build
We have recently been working on a few Magento Ecommerce sites that either incorporate wordpress or a custom build using the Yii framework. If you, like us; have done custom builds like this you find yourself sometimes wanting to access Magento core functionality in your other pages.
Using the below code you can easily access your Magento core
001002003004005006007008 | <?php require_once ( 'app/Mage.php' ); // Path to Magento umask(0); Mage::app(); // Target a specific product by ID (7 in our case) $_product = Mage::getModel()->load(7); echo ->getName(); |
Another quick example would be to access your Magento navigation inside your custom built project:
001002003004005006007008009010 | <?php require_once ( 'app/Mage.php' ); // Path to Magento umask(0); Mage::app(); // Include Magento left navigation $_layout = Mage::getSingleton( 'core/layout' ); $_block = $_layout ->createBlock( 'catalog/navigation' )->setTemplate( 'catalog/navigation/left.phtml' ); echo $_block ->toHtml(); |
Another one we found ourselves using a lot was the inclusion of the basket into our WordPress site:
001002003004005006007008009010011 | <?php require_once ( 'app/Mage.php' ); // Path to Magento umask(0); Mage::app(); // Display shopping cart content $cart = Mage::getModel( 'checkout/cart' )->getQuote(); foreach ( $cart ->getAllItems() as $item ) { $productName = $item ->getProduct()->getName(); $productPrice = $item ->getProduct()->getPrice(); } |
As we said, these are merely a few examples but it should give you an idea of how to access most other core functionality you might be after.
Write to us
or call the number 020 8446 1515