How to use a external Script to run Magento Code.

Sunday, September 23, 2012
To make any external script to perform any task we need to include ‘app/Mage.php‘ of our Magento installation. Then, we can use the code of magento in that external script.
For example, to fetch Product data from Magento shop in any external script.

/**
* Include Mage.php of your Magento installation
*/
require_once("../magento/app/Mage.php");

Mage::app('default');
/**
* To get Product Data
* For example productId is '11'
*/
$productId = 11;
$product = Mage::getModel('catalog/product')->load($productId);
/**
*To Print name,,sku, price and quantity of the product
*/
echo "Name: ".$product->getName();
echo "Sku: ".$product->geSku();
echo "Price: ".$product->getPrice();
echo "Quantity: ".$product->getStockItem()->getQty();

/**
* To Get all products
*/
$allProducts = Mage::getModel('catalog/product')
->getCollection();

If you have any further queries, please feel free to comment on it.

12 comments:

  1. Anonymous said...:

    Thank you so much, you saved me a lot of work :)

  1. rajthegr8 said...:

    Thanks friend...Keep following...

  1. Anonymous said...:

    ok and how to run magento from remote server?

  1. cannycookie said...:

    Mage 1.7.02 is setting my header as content disposition: attachment. So all echo output not going to screen but download file. Any idea how to override this header or why it's happening?

  1. Unknown said...:

    Hi Raj,

    Nice post,thanks for sharing this information. Looking forward for more posts like this.









    Magento Developers

  1. Varien said...:

    Hi the information on this blog is just amazing it keeps us coming back time and time again ,personally i met my wife using this site so i couldnt love it any more i have done my best to promote this blog as i feel that others need to see this thang ,cheers for all your effort spent in making this fabulous site

  1. Hi the information on this blog is just amazing it keeps us coming back time and time again ,personally i met my wife using this site so i couldnt love it any more i have done my best to promote this blog as i feel that others need to see this thang ,cheers for all your effort spent in making this fabulous site

  1. Magento Experts Developers has become the best source for the developers.

  1. Unknown said...:

    Wow, seriously well formulated and well written, You have the gift Magento Developers

  1. Anonymous said...:

    Nice post,thanks for sharing this information

  1. Anonymous said...:

    how to add shooping cart

  1. Unknown said...:

    The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..
    magento development company in bangalore 

Post a Comment