Manufacturer Search in Magento

Put following code into controller file.

$prod_name = Mage::app()->getRequest()->getParam(‘schar’);
//  $model_data = Mage::getModel(‘catalog/product’)->getCollection()->addAttributeToSelect(‘name’)->addFieldToFilter(‘name’,array(‘like’=>$prod_name.’%’));
// print_r($model_data->getData());exit;
$store_id=Mage::app()->getStore()->getStoreId();
$product = Mage::getModel(‘catalog/product’);
$attributes = Mage::getResourceModel(‘eav/entity_attribute_collection’)
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter(‘attribute_code’, ‘manufacturer’);

$attributes->getSelect()
->join(
array(‘attlable’=>’eav_attribute_option’),
‘additional_table.attribute_id = attlable.attribute_id’,
array(‘attlable.option_id’)
);
$attributes->getSelect()
->join(
array(‘attlableval’=>’eav_attribute_option_value’),
‘attlable.option_id = attlableval.option_id’,
array(‘*’)
)
->where(‘attlableval.value like (?)’,$prod_name.’%’)
->where(‘attlableval.store_id =’.$store_id);

$data = $attributes->getData();
// echo “<pre>”;print_r($data);exit;
$result=array();
foreach($data as $sdata)
{
$result[]=array(“data” => $sdata[‘value’],”id” => $sdata[‘option_id’]);
}
$this->getResponse()->setBody(Mage::helper(‘core’)->jsonEncode($result));

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: