Search code examples
phpmagentosoapmagento-soap-api

Magento, SoapClient, and local WSDL


This is probably a newbie face-palm question, but I can't figure this out. I'm working with a web service from a Magento store (i.e. code in the Magento store is accessing a remote web service). It so happens in this case I have a local WSDL file that I need to reference. I've done this before using a remote URL to the WSDL file and that works fine. However, with a local file, I can't figure out how to reference it. I have it working by putting the file in a wsdl subdirectory of the root of the site and then I can reference it using http://mysite/wsdl/thefile.wsdl. However, I'd prefer to use a relative path to reference it (mainly due to the fact that I plan to deploy this same code to different sites and I'd like to use the same code for all).

I guess my question comes down to this: When you instantiate an instance of PHP's SoapClient like this $client = new SoapClient("thefile.wsdl"), where is it looking for thefile.wsdl? I thought it would be local to the PHP file that instantiates the SoapClient, but it didn't work when I put the file in the same folder. I tried the /includes directory as well as app/code/local.

I'm sure this is a no brainer for seasoned programmers, but sometimes the basics allude me...


Solution

  • Mystery Solved! This is probably obvious to most, but I had to learn it, so perhaps someone else will benefit from it too.

    I didn't realize that, due to Magento's design, the "root" of all pages is /index.php. EVERY page is loaded from that, so OF COURSE it's the root. When you try to instantiate a SoapClient, it looks in the directory of the main root script file, not the current module/class file. I could put the WSDL files in the root of the webserver and loaded them successfully (I guess I hadn't tried that before...).

    What I've done now is to move them to the /media directory and I call them up by getting the media directory using getBaseDir('media'), tack on my sub-directory path, and VIOLA!