1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
<?php
// First we need to feed the techdata SKU, for now we use 1088963 as an example
$td_sku="1088963";
//Following the XML data
$xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r
<OnlineCheck>\r
<Header>\r
<BuyerAccountId>Mon code client</BuyerAccountId>\r
<AuthCode>Mon code d'accés</AuthCode>\r
<Type>Full</Type>\r
</Header>\r
<Item line=\"1\">\r
<ManufacturerItemIdentifier/>\r
<ResellerItemIdentifier/>\r
<DistributorItemIdentifier>$td_sku</DistributorItemIdentifier>\r
<Quantity>1</Quantity>\r
</Item>\r
</OnlineCheck>";
$fp = fsockopen("intcom.xml.techdata-europe.com", 8080, $errno, $errstr, 15);
//Generate the postdata on a valid way, $out4 needs to be calculated, so will be later.
$out1 = "POST /Onlchk HTTP/1.0\r
";
$out2 = "Content-Type: multipart/form-data; boundary=---------------------------2\r
";
$out3 = "Host: intcom.xml.techdata-europe.com:8080\r
";
$out5 = "Connection: close\r
\r
";
$out6 = "-----------------------------2\r
";
$out7 = "Content-Disposition: form-data; name=\"onlinecheck\"\r
\r
";
$out8 = "\r
-----------------------------2--";
//Calculation of the Content-Length:
$tlen=strlen($out6)+strlen($out7)+strlen($xmldata)+strlen($out8);
$out4 = "Content-Length: $tlen\r
";
//Generate full output
$out = $out1.$out2.$out3.$out4.$out5.$out6.$out7.$xmldata.$out8;
fwrite($fp, $out);
$retval = "";
while(!feof($fp)){$retval = "$retval".fgets($fp,128);}
fclose($fp);
list($headers,$body) = explode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>",$retval);
$doc = new DOMDocument();
$doc ->LoadXML($body);
$item_ids = $doc->getElementsByTagname( "OnlineCheck" );
foreach( $item_ids as $item )
{
$error_s = $item->getElementsByTagName( "Errorstatus" ); $tderror = $error_s->item(0)->nodeValue;
$stock_s = $item->getElementsByTagName( "AvailabilityTotal" ); $tdstock = $stock_s->item(0)->nodeValue;
// Reformatting the price to ISO compatible format
$price_s = $item->getElementsByTagName( "UnitPriceAmount" ); $tdprice = str_replace('.','',$price_s->item(0)->nodeValue);
$tdprice=str_replace(',','.',$tdprice);
}
//Rest of handling off the data under here
?> |
Partager