Skip to content

Instantly share code, notes, and snippets.

@oliver-montes
Created January 7, 2013 23:05
Show Gist options
  • Select an option

  • Save oliver-montes/4479421 to your computer and use it in GitHub Desktop.

Select an option

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
<?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