【问题标题】:Extend current API's in Magento to get items in JSON format扩展 Magento 中的当前 API 以获取 JSON 格式的项目
【发布时间】:2010-11-30 05:19:13
【问题描述】:

我是 Magento 的初学者。我正在尝试扩展 Magento 中的当前 API 类以满足我的要求并以 JSON 格式检索数据。我需要:

  1. 我需要获取网站中的所有商店
  2. 我需要获取特定商店中的所有类别和子类别
  3. 我需要获取特定类别中的所有产品。
  4. 检索到的所有数据都应为 JSON 格式。

任何博客/论坛主题?有什么帮助吗?

提前致谢。

【问题讨论】:

  • “扩展API”是指要使用Magento提供的网络服务,还是只想使用现有的库类?
  • 我需要使用网络服务。我需要通过扩展 Magento 中的当前类来扩展它们。

标签: json api magento


【解决方案1】:

请参考这个 Magento wiki 页面http://www.magentocommerce.com/wiki/doc/webservices-api/custom-api#creating_custom_adapter_for_api。

步骤:

  1. 您需要创建一个新的 API 服务器适配器来实现 Mage_Api_Model_Server_Adapter_Interface。

  2. 创建一个控制器来运行您的 api 服务器适配器

  3. 实现Mage_Api_Model_Server_Adapter_Interface::run()方法处理JSON请求并返回JSON结果。请参阅 Mage_Api_Model_Server_Handler_Abstract 了解 Magento API 工作流程。

【讨论】:

【解决方案2】:

从未有过这种情况,但想到的一个想法是调用 SOAP 服务或 XML-RPC,然后将所需的任何数据转换为 JSON。

Magento 提供 SOAP 或 XML-RPC 网络服务,可以自动为用户生成特定角色,非常有用。

【讨论】:

  • 同意这是最简单的方法。我想知道性能影响,但添加额外层的开销可能会满足您的要求。
【解决方案3】:

那将是一种更好的方法,而且一点也不复杂。参考这个看看。 http://www.magentocommerce.com/wiki/5_-_modules_and_development/web_services/additional_information

【讨论】:

    【解决方案4】:

    看这里 https://github.com/app-z/magento-android-web-api
    甚至还有随机产品列表
    是你想要的吗?

    //
    //  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;
    }
    

    【讨论】:

      【解决方案5】:

      Inchoo 为 Magento 编写了一个免费的 REST、JSON 和 AMF 适配器。你可以在这里找到它:http://www.magentocommerce.com/magento-connect/inchoo-api.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-10
        • 2017-07-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多