Created
January 7, 2013 23:05
-
-
Save oliver-montes/4479421 to your computer and use it in GitHub Desktop.
Fichero PHP que lista todos los productos de una tienda magento y los muestra serializados en JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Error reporting | |
| */ | |
| error_reporting(E_ALL | E_STRICT); | |
| /** | |
| * Compilation includes configuration file | |
| */ | |
| define('MAGENTO_ROOT', getcwd()); | |
| $compilerConfig = MAGENTO_ROOT . '/includes/config.php'; | |
| if (file_exists($compilerConfig)) { | |
| include $compilerConfig; | |
| } | |
| $mageFilename = MAGENTO_ROOT . '/app/Mage.php'; | |
| require_once $mageFilename; | |
| #Varien_Profiler::enable(); | |
| if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) { | |
| Mage::setIsDeveloperMode(true); | |
| } | |
| ini_set('display_errors', 1); | |
| umask(0); | |
| Mage::app(); | |
| // Load product collection | |
| $collection = Mage::getModel('catalog/product')->getCollection(); | |
| $collection->addAttributeToSelect('name'); | |
| $collection->addAttributeToSelect('price'); | |
| $products = array(); | |
| foreach ($collection as $product){ | |
| $products[] = array("price" => $product->getPrice(), | |
| "name" => $product->getName() ); | |
| } | |
| header('Content-Type: text/json; charset=utf-8'); | |
| echo(json_encode($products)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment