<?php

$serviceUrl = "https://mws.amazonservices." . CODICE . "/Products/2011-10-01";

$config = array(
    'ServiceURL' => $serviceUrl,
    'ProxyHost' => null,
    'ProxyPort' => -1,
    'ProxyUsername' => null,
    'ProxyPassword' => null,
    'MaxErrorRetry' => 3,
);

function getMatchingProductForIdASIN($asinLists) {
    global $MERCHANT_ID, $MARKETPLACE_ID, $config;
    $service = new MarketplaceWebServiceProducts_Client(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APPLICATION_NAME, APPLICATION_VERSION, $config);
    $request = new MarketplaceWebServiceProducts_Model_GetMatchingProductForIdRequest();
    $request->setSellerId(MERCHANT_ID);
    $request->setMarketplaceId(MARKETPLACE_ID);
    $idListObj = new MarketplaceWebServiceProducts_Model_IdListType();
    $idListObj->setId($asinLists);
    $request->setIdList($idListObj);
    $request->setIdType('ASIN');
    return array('service' => $service, 'request' => $request);
}

function invokeGetMatchingProductForId(MarketplaceWebServiceProducts_Interface $service, $request) {
    try {
        $response = $service->GetMatchingProductForId($request);
        $dom = new DOMDocument();
        $dom->loadXML($response->toXML());
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->saveXML();
        $xml = str_replace("ns2:", "", $dom->saveXML());
        $res = simplexml_load_string($xml);
        return $res;
    } catch (MarketplaceWebServiceProducts_Exception $ex) {
        return "";
    }
}
