Pankaj Yadav
Pankaj Yadav

Reputation: 222

how can we create search webservice in magento?

I am making a web service in magento. I have created many web-service of magento project like login, register, etc in magento project. I am not using third party web-service (default magento webservice).

I am follow the step: just create folder in magento root directory(webservice) then after create file serach.php and write the code for searching:

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;

I am getting the error:

Fatal error: Call to a member function getId() on a non-object in /home/demo/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php on line 700

Upvotes: 1

Views: 246

Answers (3)

S P
S P

Reputation: 4643

You haven't initialized and load the collection.

I'm missing such a line as:

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

Upvotes: 0

huzefam
huzefam

Reputation: 1191

Magento provides inbuilt easy to use SOAP and REST API..both easily extendable ..you can refer to Vinai Kopps got repo for REST API by session authentication

Upvotes: 0

Pankaj Yadav
Pankaj Yadav

Reputation: 222

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));

Upvotes: 0

Related Questions