Пример #1
0
}
// Create a hash containing the header information for authentication.
$header_info = array("UserName" => API_USERNAME, "Password" => API_PASSWORD, "SecurityToken" => SECURITY_TOKEN);
try {
    // Create a new instance of the client pointing to the wsdl endpoint.
    $client = new ACSoapClient("https://" . STORE_DOMAIN . "/store/ws/AmeriCommerceDb.asmx?wsdl");
    // Create a new header object specifying the namespace, header object type, and hash containing the header details.
    $header = new SoapHeader(AC_NAMESPACE, "AmeriCommerceHeaderInfo", $header_info);
    // Set the header on the client so we can authenticate the request.
    $client->__setSoapHeaders($header);
    // Fetch a product by its ID from the API. Set this ID to something relevant for your store.
    $response = $client->Product_GetByKey(array("piitemID" => 1670));
    // The response is an object that has our result.
    $product = $response->Product_GetByKeyResult;
    // Fill a collection on the product, notice that the product itself is passed in here.
    $response = $client->Product_FillProductVariantCollection(array("poProductTrans" => $product));
    // We get back the same product with the collection filled.
    $product = $response->Product_FillProductVariantCollectionResult;
} catch (Exception $e) {
    print_r($e);
}
?>
<html>
<head>
  <title>AmeriCommerce API Connection Demo</title>
</head>
<body>
  <h3>Item ID</h3>
  <p><?php 
echo $product->itemID->Value;
?>