function products($category_id){
$json = array('success' => true, 'products' => array());
$category = Mage::getModel ('catalog/category')->load($category_id);
$products = Mage::getResourceModel('catalog/product_collection')
// ->addAttributeToSelect('*')
->AddAttributeToSelect('name')
->addAttributeToSelect('price')
->addFinalPrice()
->addAttributeToSelect('small_image')
->addAttributeToSelect('image')
->addAttributeToSelect('thumbnail')
->addAttributeToSelect('short_description')
->addUrlRewrite()
->AddCategoryFilter($category);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
foreach($products as $product){
$json['products'][] = array(
'id' => $product->getId(),
'name' => $product->getName(),
'description' => $product->getShortDescription(),
'pirce' => Mage::helper('core')->currency($product->getPrice(), true, false), //." ".$currencyCode,
'href' => $product->getProductUrl(),
'thumb' => (string)Mage::helper('catalog/image')->init($product, 'thumbnail')
);
}
return $json;
}
完整的插件 REST API 见https://github.com/app-z/magento-android-web-api/blob/master/web-api.php