开发者

Extend current API's in Magento to get items in JSON format

I am a beginner to Magento. I am trying to extend the current API classes in Magento to fulfill my requirements and retrieve data in JSON f开发者_如何转开发ormat. I need:

  1. I need to get all stores in a website
  2. I need to get all Categories and Subcategories in a specific store
  3. I need to get all products in a specific Category.
  4. All data retrieved should be in JSON format.

Any blog/Forum topic? Any kind of help?

Thanks in advance.


Please refer to this Magento wiki page http://www.magentocommerce.com/wiki/doc/webservices-api/custom-api#creating_custom_adapter_for_api.

Steps:

  1. You need to create a new API Server Adapter that should implement Mage_Api_Model_Server_Adapter_Interface.

  2. Create a controller that will run your api server adapter

  3. Implement Mage_Api_Model_Server_Adapter_Interface::run() method for process JSON request and return result in JSON. See Mage_Api_Model_Server_Handler_Abstract for understanding Magento API workflow.


never been is such situation , but an idea came to mind is to invoke a SOAP service or XML-RPC , then convert whatever data needed to JSON.

Magento offers SOAP or XML-RPC web service to be automatically generated with specific roles for users, very useful.


That would be a better approach and it is not at all complicated. Refer to this to see. http://www.magentocommerce.com/wiki/5_-_modules_and_development/web_services/additional_information


See here https://github.com/app-z/magento-android-web-api
There is even Random Products list
Is it what you want?

//
//  Random Products Items
//  
//  http://localhost/magento/web-api.php?route=feed/web_api/random&limit=4&key=key1
//
function random_products($limit){
    $json = array('success' => true);

    $products = Mage::getModel('catalog/product')->getCollection();
    $products->addAttributeToSelect(array('name', 'thumbnail', 'price')); //feel free to add any other attribues you need.

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products); 
    $products->getSelect()->order('RAND()')->limit($limit);

    foreach($products as $product){ 
        $json['products'][] = array(
                'id'        => $product->getId(),
                'name'      => $product->getName(),
                'href'      => $product->getProductUrl(),
                'thumb'     => (string)Mage::helper('catalog/image')->init($product, 'thumbnail'),
                'pirce'     => Mage::helper('core')->currency($product->getPrice(), true, false) //." ".$currencyCode,
            );
    }
    return $json;
}


Inchoo has written a free REST, JSON, and AMF adapter for Magento. You can find it here: http://www.magentocommerce.com/magento-connect/inchoo-api.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜