I am trying to call a 3rd party soap api and when i am creating an object for soapclient in my helper class its showing as class not found.

soapclient class.
class NTLMSoapClient extends SoapClient {
    function __doRequest($request, $location, $action, $version, $one_way = 0) {
        $headers = array(
        'Method: POST',
        'Connection: Keep-Alive',
        'User-Agent: PHP-SOAP-CURL',
        'Content-Type: text/xml; charset=utf-8',
        'SOAPAction: "' . $action . '"',
        $this->__last_request_headers = $headers;
        $ch = curl_init($location);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
        curl_setopt($ch, CURLOPT_USERPWD, USERNAME . ':' . PASSWORD);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLINFO_HEADER_OUT, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        $response = curl_exec($ch);
        if(is_null($response)) {
            $logger->info('ERP class_soap: '.curl_error($ch), null, 'soap.log');
        $response = preg_replace( '/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $response );
        $errors = curl_error($ch);
        $details = curl_getinfo($ch);
        return $response;
    function __getLastRequestHeaders() {
        return implode("\n", $this->__last_request_headers) . "\n";

Am trying to create an object in helper class i.e. connect.php

namespace Curocarte\Erp\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\Module\Dir;

class Connect extends AbstractHelper
    protected $_moduleReader;

    protected $_helper;

    protected $_dir;

    // protected $_NTLMSoapClient;

    public function __construct(
    \Curocarte\Erp\Helper\Data $helper,
    // \Curocarte\Erp\lib\NTLMSoapClient $NTLMSoapClient,
    \Magento\Framework\Module\Dir\Reader $moduleReader,
    \Magento\Framework\Filesystem\DirectoryList $dir,
    \Magento\Framework\Webapi\Soap\ClientFactory $soapClientFactory,
    array $data = []

     ) {
       $this->_moduleReader = $moduleReader;
       $this->_helper = $helper;
       $this->_dir = $dir;
       // $this->_NTLMSoapClient=$NTLMSoapClient;
       $this->soapClientFactory = $soapClientFactory;

    public function getConnection() {
            $path = $this->_moduleReader->getModuleDir('', 'Curocarte_Erp');
            include_once $path . '/lib/class_soap.php';
            // include_once $this->_dir->getRoot().'/library/class_soap.php'
            set_time_limit( 300 );
            $config = json_decode(file_get_contents($this->_dir->getRoot().'/config.json'), true);
            $erpIndex = array_search('erp_'.$config[0]['mode'], $this->_helper->customArrayColumn($config, 'option'));
            define('USERNAME', $config[$erpIndex]["username"]);
            define('PASSWORD', $config[$erpIndex]["password"]);
            stream_wrapper_register('http', 'NTLMStream') or die("Failed to register protocol");
            $faultString = "";
            $url = $config[$erpIndex]["url"];
            $client = new NTLMSoapClient($url, array('trace' => 1, 'soap_version' => SOAP_1_1, 'cache_wsdl' => WSDL_CACHE_NONE));
            // $client = $this->_NTLMSoapClient($url, array('trace' => 1, 'soap_version' => SOAP_1_1, 'cache_wsdl' => WSDL_CACHE_NONE));
            return $client;
        catch (SoapFault $fault) {
            $faultString = str_replace(chr(10), " ", $fault->faultstring);
            $faultString = str_replace(chr(13), " ", $faultString);
            $faultString = html_entity_decode($faultString);

NTLMSoapClient class is in class_soap.php which i have included

when i run am getting the error as

[2019-06-18 05:53:27] main.CRITICAL: Class Curocarte\Erp\lib\NTLMSoapClient does not exist {"exception":"[object] (ReflectionException(code: 0): Class Curocarte\Erp\lib\NTLMSoapClient does not exist at C:\xampp\htdocs\Magento\vendor\magento\framework\Code\Reader\ClassReader.php:37, ReflectionException(code: 0): Class Curocarte\Erp\lib\NTLMSoapClient does not exist at C:\xampp\htdocs\Magento\vendor\magento\framework\Code\Reader\ClassReader.php:29)"} []

Can anyone provide me some solution how am i supposed to overcome this issue. Thanks in advance.


There are some changes need at the code

 new NTLMSoapClient

need to change

 new \NTLMSoapClient

I assume that class_soap.php location is app/code/Curocarte/Erp/Helper then code

include_once $path . '/lib/class_soap.php';

But if you class_soap.php location is magento project Dir lig folder then

include_once $this->_dir->getRoot().'/library/class_soap.php' is right code.

  • class_soap.php is a file in lib folder and am calling this lib file in my connect.php helper class. inside class_soap.php i have two classes i.e. NTLMStream and NTLMSoapClient. Its in app/code/Curocarte/Erp/lib . – Naveesh kumar Jun 18 '19 at 7:45
  • am trying to send request to soap api using the following code $client=$this->_connect->getConnection(); if ($client) { $req->salesOrderDetails->SalesOrder = $SalesOrder; $resultRequest = $client->ImportSalesOrder($req); } i am able print $SalesOrder data but in the above code am getting the error shown below Warning: Creating default object from empty value in C:\xampp\htdocs\Magento\app\Code\Curocarte\Erp\Observer\OrderImport.php – Naveesh kumar Jun 18 '19 at 10:52
  • Am not able to print the $SalesOrder data from the above code – Naveesh kumar Jun 18 '19 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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