Programmatically: How to implement custom Magento SOAP API clients
Step 1: Create a new module
Create a new folder in the app/code/local directory, and inside it, create a new file called Client.php. This file will contain the code for our custom SOAP API client. Client.php
namespace YourCompany\YourModule\Model;
use Magento\Framework\Soap\SoapAdapter;
use Magento\Framework\Soap\SoapClient;
class Client extends SoapAdapter
{
private $client;
public function __construct(SoapClient $client)
{
$this->client = $client;
}
public function getProducts()
{
$params = array(
'store' => 'your_store_id',
'searchCriteria' => array(
'fulltext' => 'your_search_term'
)
);
$result = $this->client->call('catalogProduct.list', $params);
return $result;
}
}
Step 2: Create a di.xml file
Create a new file called di.xml in the app/code/local/YourCompany/YourModule/etc directory. This file will define the dependencies for our module. di.xml
Step 3: Create a SOAP client instance
To create a SOAP client instance, you need to configure the soap adapter. You can do this by creating a new file called soap.xml in the app/etc/modules directory. soap.xml
your_soap_adapter
Magento\Framework\Soap\SoapAdapter
http://your-magento-url.com/soap/?wsdl
http://your-magento-url.com/soap/?wsdl
Step 4: Use the client in your code
You can now use the client in your code by instantiating it and calling its methods. For example:
$client = \Magento\Framework\App\ObjectManager::getInstance()->get('YourCompany\YourModule\Model\Client');
$result = $client->getProducts();