如何在magento中创建搜索web服务


how can we create search webservice in magento?

我正在使用magento制作一个web服务。我已经创建了许多magento项目的web服务,如登录、注册等。我没有使用第三方网络服务(默认的magento网络服务)。

我遵循步骤:只需在magento根目录(webservice)中创建文件夹,然后创建文件serach.php并编写搜索代码:

require("../app/Mage.php");
Mage::app();
if (isset($_REQUEST['search_text']) && ($_REQUEST['search_text'] != "")) {
    $text = $_REQUEST['search_text'];
} else {
    $text = "";
}
$search = "%" . trim($text) . "%";
$collection->addCategoryFilter()->addAttributeToSelect('name')->addAttributeToFilter('name', array(
    'like' => $search
));
echo "";
print_r($collection);
die;

我得到错误:

致命错误:在第700行的/home/demo/public_html/app/code/core/Mage/Coatalog/Model/Resource/Product/Collection.php中对非对象调用成员函数getId()

require("../app/Mage.php"); 
Mage::app(); 
if (isset($_REQUEST['search_text']) && ($_REQUEST['search_text'] != "")) { 
    $text = $_REQUEST['search_text']; 
} 
else{ 
     $text = ""; 
}

$search = "%".trim($text)."%"; 
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku');
$collection->addAttributeToSelect('city');
$collection->joinAttribute('city', 'catalog_product/city', 'entity_id', null, 'inner'); 
$category = Mage::getModel('catalog/category')->load(); 
$productCollection = $collection->addCategoryFilter($category)
                                ->addAttributeToSelect('name')
                                ->addAttributeToFilter('name',array('like'=>$search));

Magento提供内置的易于使用的SOAP和REST API。。两者都易于扩展。。您可以通过会话身份验证参考Vinai Kopps获得的REST API回购

您尚未初始化和加载集合。

我漏掉了这样一行:

  $collection = Mage::getModel('catalog/product')->getCollection()...