Tuesday 3 May 2011

Simple Example to Run Magento Code Outside of Magento

This post must help every magento developer because this post is realated about to run Magento code outside of Magento. All you need is to have access to Magento’s ‘app/Mage.php‘ file.

This code will help you in several ways

     * Integration with 3rd party items – shared sessions, or just shared themes

     * Ajax calls – although not the preferred solutions for Ajax calls, it is a quick and easy one

This code can help you to get started with

Integration:

         -You might want to integrate Wordpress and steal the navigation from Magento, for instance.

         -You might want to share sessions and users between your CMS and Magento (and share databases).



Ajax:

       -You build your block and template (and any other needed objects) as usual and output them via this code.

Have A look at The Code



This post will inform you on how to run Magento code outside of Magento. All you need is to have access to Magento’s ‘app/Mage.php‘ file.
 

We can see in this block of code that we are grabbing the custom block ‘catalog/product_ajax‘.

This is simply a block that grabs a product collection. In this case, we are able to set the category id to 3.

This block is then setting the .phtml template to ‘ajaxevents.phtml‘ and rendering the view. You hopefully can see how this would be useful for Ajax calls.

Other code that might help you along your way:
From php architect’s book (might be outdated!!! We haven’t tested this particular code):


This code will grab cart information and don't forgive this code does not start session



Code with some interested stuff:


Enjoy Hope it is working

0 comments:

Post a Comment