Last active
December 21, 2015 21:49
-
-
Save AustinMaddox/6371333 to your computer and use it in GitHub Desktop.
Fitment part number request service PHP example.The WPS Fitment Part Number Request web service is meant to find all the parts associated to a single vehicle. Below is a full example of how to do this via PHP using cURL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php error_reporting(E_ALL | E_STRICT); ?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Fitment example</title> | |
</head> | |
<body> | |
<?php | |
// Parameters to send the web service program. | |
// Example: http://www.example.com/fitment_part_number_request_service_example.php?DEALER=###&PASSWORD=###&FITMENT=HONDA HON8300 2012&OUTPUT=json | |
$vars = array( | |
'DEALER' => FILTER_SANITIZE_ENCODED, // Your wpsorders dealer number. | |
'PASSWORD' => FILTER_SANITIZE_ENCODED, // Your wpsorders admin account password. | |
'FITMENT' => FILTER_SANITIZE_STRING, // The three part fitment key obtained from the fitment structure dump. (ie. Make-name Model-number Year) | |
'OUTPUT' => FILTER_SANITIZE_ENCODED // 'json' is used in this example. | |
); | |
// Gets external variables and optionally filters them. | |
$filtered_vars = filter_input_array(INPUT_GET, $vars); | |
// Make the cURL request. | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://www.wpswebservices.com/version2/wsFITS.pgm"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $filtered_vars); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | |
$curl_result = curl_exec($ch); | |
curl_close($ch); | |
// Decode the JSON string into stdObject. | |
$result_json = json_decode($curl_result); | |
// If the result is not valid JSON. | |
if ($result_json === NULL) { | |
echo $curl_result . '<br>' . PHP_EOL; | |
die('The result of the cURL could not decoded with json_decode().'); | |
} | |
// Print the HTML to set up a table. | |
echo '<h2>There are ' . $result_json->response->numFound . ' items that fit a "' . $filtered_vars['FITMENT'] . '" vehicle:</h2>' . PHP_EOL; | |
echo '<table border="1">' . PHP_EOL; | |
echo ' <thead>' . PHP_EOL; | |
echo ' <tr>' . PHP_EOL; | |
echo ' <th>prtnmbr</th><th>name</th><th>listprc</th><th>mainimg</th>' . PHP_EOL; | |
echo ' </tr>' . PHP_EOL; | |
echo ' </thead>' . PHP_EOL; | |
echo ' <tbody>' . PHP_EOL; | |
// For each 'docs' property in the response, do this: | |
foreach ($result_json->response->docs as $a) { | |
$image = (property_exists($a, 'mainimg')) ? $a->mainimg : 'image_coming_soon.jpg'; | |
echo ' <tr>' . PHP_EOL; | |
echo ' <td>' . $a->prtnmbr . '</td>' . PHP_EOL; | |
echo ' <td>' . $a->name . '</td>' . PHP_EOL; | |
echo ' <td>$' . $a->listprc . '</td>' . PHP_EOL; | |
echo ' <td><img src="http://www.wpsstatic.com/WPSIMAGES/thumbs/' . $image . '"></td>' . PHP_EOL; | |
echo ' <tr>' . PHP_EOL; | |
} | |
// Print the closing HTML closing tags. | |
echo ' </tbody>' . PHP_EOL; | |
echo '</table>' . PHP_EOL; | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment