1
votes

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

3
collection.php file is default magento file and no changes in this file. - Pankaj Yadav

3 Answers

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

0
votes

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

0
votes

You haven't initialized and load the collection.

I'm missing such a line as:

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