Amazon MWSとは
Amazonマーケットプレイスに出店してるショップ向けに、商品管理や注文管理ができるAPIが提供されている。
Amazon マーケットプレイスWebサービス(MWS)
https://developer.amazonservices.jp/
クライアントライブラリとサンプルコードもある。
PHP クライアントライブラリ
https://developer.amazonservices.jp/doc/bde/feeds/v20090101/php.html
今回はフィードAPIを使用してる。
クラスのオートロードでうまくいかなかった
このライブラリのサンプルコードは__autoload
関数でオートロードしてるため、
composerとかを使ってたらどうもMWSのクラスが見つからない。
PHP Fatal error: Class 'MarketplaceWebService_Client' not found in hoge.php on line 99
そこでspl_autoload_register
を使うように修正した。
元のコードがこれ
function __autoload($className){
$filePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$includePaths = explode(PATH_SEPARATOR, get_include_path());
foreach($includePaths as $includePath){
if(file_exists($includePath . DIRECTORY_SEPARATOR . $filePath)){
require_once $filePath;
return;
}
}
}
修正後はこちら
function MWSAutoLoad($className) {
$filePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$includePaths = explode(PATH_SEPARATOR, get_include_path());
foreach($includePaths as $includePath){
if(file_exists($includePath . DIRECTORY_SEPARATOR . $filePath)){
require_once $filePath;
return;
}
}
}
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
spl_autoload_register('MWSAutoLoad', true, true);
} else {
spl_autoload_register('MWSAutoLoad');
}