cancel
Showing results for 
Search instead for 
Did you mean: 

Get Company collection by query string

Get Company collection by query string

Hi @all

I want a to fetch company collection as per full text query. Like if query is "7841 Chicago 74574 test" then it gives me list of companies containing city Chicago and other search terms matching to string.

I've tried to use searchCriteriaBuilder but it doesn't seems to be working fine. 

Thanks!!

3 REPLIES 3

Re: Get Company collection by query string

Hi @rahul691 

To run custom queries with magento 2 , you can refer below example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('employee'); //gives table name with prefix
 
//Select Data from table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql); // gives associated array, table fields as key in array.
 
//Delete Data from table
$sql = "Delete FROM " . $tableName." Where emp_id = 10";
$connection->query($sql);
 
//Insert Data into table
$sql = "Insert Into " . $tableName . " (emp_id, emp_name, emp_code, emp_salary) Values ('','XYZ','ABD20','50000')"; $connection->query($sql); //Update Data into table $sql = "Update " . $tableName . "Set emp_salary = 20000 where emp_id = 12"; $connection->query($sql);

If you want to continue with searchCriteriaBuilder feature, then you need to override function with your plugin or extend with custom model.

Problem Solved? Please click on 'Kudos' & Accept as Solution! 

 

Problem solved? Click Accept as Solution!

Re: Get Company collection by query string

Hi @Bhanu Periwal 

In the searchCriteriaBuilder, can we use a single line string to getList of all companies matching to that single line string?
With Raw query is this standard way as per Magento?

Thanks!!

Re: Get Company collection by query string

Hi @rahul691 

You need to override model below file:

/vendor/magento/module-catalog/Model/ProductRepository.php

then do customisation with function getlist() according to your requirement.

 

It may help you!
Thank you.

Problem solved? Click Accept as Solution!