How to access Magento core inside a custom build

News 16-Sep-2014 1 MINUTE, 12 SECONDS

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


    By contacting us through this web form you agree to our latest GDPR compliant privacy policy, which you can read here.

    Success!
    Data sent. Our manager will contact you shortly
    Benefits

    There is no shortage of web design agencies in London, so why Active Webdezign Ltd? What can we bring to your web design project that we believe our competitors can’t match? The following are our pledges to you, and the reasons we believe that we make the ideal development partner to turn to if you are considering a new website.

    Industries

    In our 20 years of being in business we have been honoured to take on web design projects from a very wide variety of different clients. These include such spheres as in B2B, HealthTech, e-Commerce, retail, education, etc. We could go on.