Amazon's MWS PHP client library is just a zip file without any namespace, Is there a way to use this library with Laravel application or with any application which uses composer for its dependency management.
1 Answers
Sure, just create your own library directory in your Laravel app. I usually keep mine just inside app
directory and call it Libraries
. Dump the source files inside a folder such as AmazonMWS
.
.config.inc.php
comes with an autoloader but it won't be used. Instead you could probably just open your composer.json
in your Laravel project and tell it to autoload your new Library directory targeting the config. Ex:
"autoload-dev": {
"classmap": [
"app/Libraries/AmazonMWS/Client.php"
]
}
Make sure config.inc.php
is accessible at the AmazonMWS
root.
Then run composer dump-autoload
to regenerate the autoloaders. If done properly then you should be able to instantiate any of the MWS classes without a namespace.
In your Controller, include the following use
:
use \MarketplaceWebServiceProducts_Client;
Now you can call your service as expected:
$config = [...];
$service = new MarketplaceWebServiceProducts_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
APPLICATION_NAME,
APPLICATION_VERSION,
$config);
Or just omit use \MarketplaceWebServiceProducts_Client;
and instantiate directly with namespace prefix, your choice.

- 7,012
- 12
- 68
- 123
-
I put Amazon Classes inside `app\Libraries\AmazonMWS` And updated composer.json with following: `"autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "app/" }, "files": [ "app/Libraries/AmazonMWS" ] }` And i also run `composer dump-autoload` but when i started the server its giving error _Failed opening require 'app/libraries/amazonmws' in c:\...\autoload_real.php_ Why do we add this line? `"classmap: [ "database" ]` – Shreyansh Panchal Aug 04 '16 at 16:04
-
It was just a sample from one of my `composer.json` files. Check my updated answer and try that once. – Jared Eitnier Aug 04 '16 at 16:09
-
I did exactly that and Laravel is producing this error **Class 'MarketplaceWebServiceOrders_Client' not found** – Shreyansh Panchal Aug 04 '16 at 17:27
-
Try to prefix the class with \, so `new \MarketplaceWebServiceOrders_Client`. – Jared Eitnier Aug 04 '16 at 17:55
-
I don't do this sort of thing often so I'm not 100% sure...you may have to potentially add each Class file path into the autoload files array. Try to add that class to the array and give it a shot. – Jared Eitnier Aug 04 '16 at 17:58
-
Think I got this working on my end. See updated answer. – Jared Eitnier Aug 04 '16 at 18:18
-
@ShreyanshPanchal did you figure this out? – Jared Eitnier Aug 10 '16 at 20:03