【问题标题】:How to add limit option in Magento API call如何在 Magento API 调用中添加限制选项
【发布时间】:2010-04-29 08:22:50
【问题描述】:

我正在为我的商店创建网络服务。我正在使用 magento API 从商店收集产品列表。但它显示所有 500 条记录。我希望它每页有 25 条记录。在 API 调用中添加什么?或者对此应用什么过滤器?

//创建肥皂对象 $proxy = new SoapClient('http://localhsot/magento/api/soap/?wsdl');

// create authorized session id using api user name and api key
// $sessionId = $proxy->login('apiUser', 'apiKey');
$sessionId = $proxy->login('test_admin', '12345678');

    $filters = array(


    );


 // Get list of product
$productlist = $proxy->call($sessionId, 'product.list', array($filters));

print_r($productlist ); 

【问题讨论】:

    标签: magento


    【解决方案1】:

    那没用,你能通过 id 来限制它吗:

    $filters = array('id'=>array("gteq"=>1), 'id'=>array("lteq"=>1000));
    

    这样你可以添加一些分页吗?

    【讨论】:

      【解决方案2】:

      我知道这是一个老问题,但我一直在努力解决这个问题。我创建了自己的 SOAP API 端点,它与默认的 catalogProductList 函数完全相同,但有一个额外的参数。请看下面的代码:

      $collection = Mage::getModel('catalog/product')->getCollection()
          ->addStoreFilter($this->_getStoreId($store))
          ->addAttributeToSelect('name');
      if($limit) {
          $collection->setOrder('updated_at', 'ASC');
          $collection->setPageSize($limit);
      }
      /** @var $apiHelper Mage_Api_Helper_Data */
      $apiHelper = Mage::helper('api');
      $filters = $apiHelper->parseFilters($filters, $this->_filtersMap);
      try {
          foreach ($filters as $field => $value) {
              $collection->addFieldToFilter($field, $value);
          }
      } catch (Mage_Core_Exception $e) {
          $this->_fault('filters_invalid', $e->getMessage());
      }
      $result = array();
      foreach ($collection as $product) {
          $result[] = array(
              'product_id' => $product->getId(),
              'sku'        => $product->getSku(),
              'name'       => $product->getName(),
              'set'        => $product->getAttributeSetId(),
              'type'       => $product->getTypeId(),
              'category_ids' => $product->getCategoryIds(),
              'website_ids'  => $product->getWebsiteIds(),
              'updated_at'  => $product->getUpdatedAt(),
              'created_at'  => $product->getCreatedAt()
          );
      }
      return $result;
      

      从那里我们跟踪最后一个 updated_at 值并将其用作过滤器以获取下一个 [LIMIT] 项。默认情况下,updated_at 和 created_at 不在响应中,并且列表不是由 updated_at 排序的,所以我添加了这个。

      【讨论】:

        【解决方案3】:

        我不确定,但你可以试试这个,因为 API 正在处理集合,这是限制集合大小的方法

        $filters = array(
            'setPageSize' => 10
        );
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-12-30
          • 2018-01-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多