I have a third party extension installed on my website. The extension has a powerful search engine. I have created a mobile app which gets data from magento2 REST APi. However the default magento search algorithm is bad. I want to create a new module which does the following:

  • Accepts search keyword sent from mobile app.
  • Sends the search keyword to the third party extension or use its algorithm to search the data.
  • Return a result.

I know how to create a magento module which extends Api. But I can't find a way to use the third party app in my module.

1 Answer 1


You can create custom module and post data to controller action from mobile app.

Controller File Name : SearchListing.php

// you can trigger the controller action from app posting search term to it
// api url will be : http://domain/front_name/controller_name/action_name
// lets consider in our case url will be http://example.com/api/searchlisting
namespace NameSpace\Modulename\Controller;

use Magento\Framework\App\Action\Context;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use NameSpace\Modulename\Helper\Data as CustomerAPIHelper;

class SearchListing extends \NameSpace\Modulename\Controller\Authentication\Magento\Framework\App\Action\Action
   * @var Magento\Store\Model\StoreManagerInterface
  protected $_storeManagerInterface;

   * @var CustomApiHelper
  protected $_customApiHelper;   

  protected $_productCollectionFactory;

   * @param Context     $context
   * @param Category $_category
   * @param PageFactory $resultPageFactory
   * @param StoreManagerInterface $storeManagerInterface
  public function __construct(
      Context $context,
      StoreManagerInterface $storeManagerInterface,
      CollectionFactory $productCollectionFactory,
      CustomerAPIHelper $customapihelper

  ) {
      $this->_productCollectionFactory = $productCollectionFactory;
      $this->_storeManagerInterface = $storeManagerInterface;
      $this->_customApiHelper = $customapihelper;

  public function execute()
        $request = $this->_request->getParams();
          // get the search term submitted from mobile app
          $search_term = $request["search_term"];
          $temp = array();
          $productCollectionData = array();
          $fieldsToSelect = array('name', 'short_description','price','image');
          // Call to ThirdParty Module to which you will pass $search_term

          $response = $this->ThirdPartyFunctionAcceptingSearchTermAsParameter($search_term);

          echo json_encode(array('status' => true,'data' => $response));  
        } else {
          echo json_encode(array('status' => false,'message' => "Search Term missing"));
    } catch(Exception $e) {
      echo json_encode(array('status' => false,'message' => $e->getMessage()));


    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
        <router id="standard">
            <route id="api" frontName="api">
                <module name="NameSpace_ModuleName" />
  • Thanks for above info. My Problem is that I can't find the function which accept the search term in the third party extension. Is it legal to post the extension name here on stackoverflow? Commented Dec 28, 2017 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.