diff --git a/src/BolCom/BasketItemProduct.php b/src/BolCom/BasketItemProduct.php index bf4f4ff..a0a76aa 100644 --- a/src/BolCom/BasketItemProduct.php +++ b/src/BolCom/BasketItemProduct.php @@ -1,87 +1,87 @@ -id = (string)$basketXml->id; - $this->title = (string)$basketXml->title; - $this->type = (string)$basketXml->type; - $this->price = (string)$basketXml->price; - $this->publisher = (string)$basketXml->publisher; - $this->description = (string)$basketXml->shortDescription; - $this->thumbnailurl = (string)$basketXml->images->large; - $this->url = (string)$basketXml->urls->main; - $this->offerid = (string)$basketXml->offers->offer->id; - $this->offerprice = (string)$basketXml->offers->offer->price; - } - } - - public function getBasketItemId() - { - return $this->id; - } - - public function getBasketItemTitle() - { - return $this->title; - } - - public function getBasketItemType() - { - return $this->type; - } - - public function getBasketItemPrice() - { - return $this->price; - } - - public function getBasketItemPublisher() - { - return $this->publisher; - } - - public function getBasketItemDescription() - { - return $this->description; - } - - public function getBasketItemThumbnailurl() - { - if ($this->thumbnailurl == "") { - // Use a default bol.com image - $sThumbnailurl = DEFAULT_PRODUCT_IMAGE; - } else - $sThumbnailurl = $this->thumbnailurl; - return $sThumbnailurl; - } - - public function getBasketItemUrl() - { - return $this->url; - } - - public function getBasketItemOfferId() - { - return $this->offerid; - } - - public function getBasketItemOfferPrice() - { - return $this->offerprice; - } - +id = (string)$basketXml->id; + $this->title = (string)$basketXml->title; + $this->type = (string)$basketXml->type; + $this->price = (string)$basketXml->price; + $this->publisher = (string)$basketXml->publisher; + $this->description = (string)$basketXml->shortDescription; + $this->thumbnailurl = (string)$basketXml->images->large; + $this->url = (string)$basketXml->urls->main; + $this->offerid = (string)$basketXml->offers->offer->id; + $this->offerprice = (string)$basketXml->offers->offer->price; + } + } + + public function getBasketItemId() + { + return $this->id; + } + + public function getBasketItemTitle() + { + return $this->title; + } + + public function getBasketItemType() + { + return $this->type; + } + + public function getBasketItemPrice() + { + return $this->price; + } + + public function getBasketItemPublisher() + { + return $this->publisher; + } + + public function getBasketItemDescription() + { + return $this->description; + } + + public function getBasketItemThumbnailurl() + { + if ($this->thumbnailurl == "") { + // Use a default bol.com image + $sThumbnailurl = "https://s.s-bol.com/nl/static/images/main/noimage_124x100default.gif"; + } else + $sThumbnailurl = $this->thumbnailurl; + return $sThumbnailurl; + } + + public function getBasketItemUrl() + { + return $this->url; + } + + public function getBasketItemOfferId() + { + return $this->offerid; + } + + public function getBasketItemOfferPrice() + { + return $this->offerprice; + } + } \ No newline at end of file diff --git a/src/BolCom/Product.php b/src/BolCom/Product.php index e2c7a93..cc43e07 100644 --- a/src/BolCom/Product.php +++ b/src/BolCom/Product.php @@ -1,69 +1,69 @@ -id = (string)$product->id; - $this->title = (string)$product->title; - $this->price = (string)$product->offerData->offers[0]->price; - $this->description = (string)$product->shortDescription; - $this->thumbnailurl = (string)$product->images[1]->url; - $this->url = (string)$product->urls[0]->value; - $this->offers = (array)$product->offerData->offers; - } - } - - public function getId() - { - return $this->id; - } - - public function getTitle() - { - return $this->title; - } - - public function getFirstAvailablePrice() - { - return $this->price; - } - - public function getDescription() - { - return $this->description; - } - - public function getThumbnailurl() - { - if ($this->thumbnailurl == "") { - // Use a default bol.com image - $sThumbnailurl = DEFAULT_PRODUCT_IMAGE; - } else - $sThumbnailurl = $this->thumbnailurl; - return $sThumbnailurl; - } - - public function getExternalurl() - { - return $this->url; - } - - public function getOffers() - { - return $this->offers; - } - +id = (string)$product->id; + $this->title = (string)$product->title; + $this->price = (string)$product->offerData->offers[0]->price; + $this->description = (string)$product->shortDescription; + $this->thumbnailurl = (string)$product->images[1]->url; + $this->url = (string)$product->urls[0]->value; + $this->offers = (array)$product->offerData->offers; + } + } + + public function getId() + { + return $this->id; + } + + public function getTitle() + { + return $this->title; + } + + public function getFirstAvailablePrice() + { + return $this->price; + } + + public function getDescription() + { + return $this->description; + } + + public function getThumbnailurl() + { + if ($this->thumbnailurl == "") { + // Use a default bol.com image + $sThumbnailurl = "https://s.s-bol.com/nl/static/images/main/noimage_124x100default.gif"; + } else + $sThumbnailurl = $this->thumbnailurl; + return $sThumbnailurl; + } + + public function getExternalurl() + { + return $this->url; + } + + public function getOffers() + { + return $this->offers; + } + } \ No newline at end of file diff --git a/src/BolCom/Request.php b/src/BolCom/Request.php index 4a54767..a5447d2 100644 --- a/src/BolCom/Request.php +++ b/src/BolCom/Request.php @@ -1,126 +1,126 @@ -apiAccessKeyId = $accessKeyId; - $this->apiFormat = $responseFormat; - $this->apiDebugMode = $debugMode; - } catch (Exception $e) { - echo "Exception: " . $e->getMessage() . "\n"; - } - } - - public function fetch($httpMethod, $url, $parameters = '', $content = '') - { - - $parameters .= ($parameters == '' ? '?' : '&'); - $parameters .= 'format=' . $this->apiFormat; - $parameters .= '&apikey=' . $this->apiAccessKeyId; - - $today = gmdate('D, d F Y H:i:s \G\M\T'); - - switch ($httpMethod) { - default: - case 'GET': - $contentType = ($this->apiFormat == 'xml' ? 'application/xml' : 'application/json'); - break; - case 'POST': - case 'PUT': - case 'DELETE': - $contentType = 'application/x-www-form-urlencoded'; - break; - } - - $headers = $httpMethod . " " . $url . $parameters . " HTTP/1.0\r\n"; - $headers .= "Content-type: " . $contentType . "\r\n"; - $headers .= "Host: api.bol.com\r\n"; - $headers .= "Content-length: " . strlen($content) . "\r\n"; - $headers .= "Connection: close\r\n"; - if (!is_null($this->sessionId)) { - $headers .= "X-OpenAPI-Session-ID: " . $this->sessionId . "\r\n"; - } - $headers .= "\r\n"; - - $socket = @fsockopen('ssl://api.bol.com', '443', $errno, $errstr, 30); - if (!$socket) { - throw new \Exception("{$errstr} ({$errno})"); - } - - $opts = array( - 'ssl' => array( - 'verify_peer' => TRUE, // Override default FALSE for PHP < 5.6.0 - 'verify_peer_name' => TRUE, // Override default FALSE for PHP < 5.6.0 - 'allow_self_signed' => FALSE, // Disallow self signed certificates - 'SNI_enabled' => TRUE, // Allow for the API server to use SNI - ), - ); - stream_context_set_option($socket, $opts); - - fputs($socket, $headers); - fputs($socket, $content); - - $result = ''; - - while (!feof($socket)) { - $result .= fgets($socket); - } - fclose($socket); - - $this->httpResponseCode = intval(substr($result, 9, 3)); - - list($header, $body) = explode("\r\n\r\n", $result, 2); - - $this->httpFullHeader = $header; - - $json_request = (json_decode($body) != NULL) ? true : false; - - if (!$json_request) { - if (strpos($body, "apiDebugMode) { - echo '
Debug info

----

http request:
https://api.bol.com' . $url . $parameters . '

'; - echo 'header request:
' . print_r($headers, 1) . '
'; - if ($content) echo 'content:
' . htmlspecialchars($content) . '

'; - echo 'header response:
' . self::getFullHeader(); - echo '----
'; - } - - return $body_return; - } - - public function getHttpResponseCode() - { - return $this->httpResponseCode; - } - - public function getFullHeader() - { - return $this->httpFullHeader; - } - - public function getSessionId() - { - return $this->sessionId; - } - - public function setSessionId($sessionId) - { - $this->sessionId = '' . $sessionId; - } - -} +apiAccessKeyId = $accessKeyId; + $this->apiFormat = $responseFormat; + $this->apiDebugMode = $debugMode; + } catch (Exception $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } + } + + public function fetch($httpMethod, $url, $parameters = '', $content = '') + { + + $parameters .= ($parameters == '' ? '?' : '&'); + $parameters .= 'format=' . $this->apiFormat; + $parameters .= '&apikey=' . $this->apiAccessKeyId; + + $today = gmdate('D, d F Y H:i:s \G\M\T'); + + switch ($httpMethod) { + default: + case 'GET': + $contentType = ($this->apiFormat == 'xml' ? 'application/xml' : 'application/json'); + break; + case 'POST': + case 'PUT': + case 'DELETE': + $contentType = 'application/x-www-form-urlencoded'; + break; + } + + $headers = $httpMethod . " " . $url . $parameters . " HTTP/1.0\r\n"; + $headers .= "Content-type: " . $contentType . "\r\n"; + $headers .= "Host: api.bol.com\r\n"; + $headers .= "Content-length: " . strlen($content) . "\r\n"; + $headers .= "Connection: close\r\n"; + if (!is_null($this->sessionId)) { + $headers .= "X-OpenAPI-Session-ID: " . $this->sessionId . "\r\n"; + } + $headers .= "\r\n"; + + $socket = @fsockopen('ssl://api.bol.com', '443', $errno, $errstr, 30); + if (!$socket) { + throw new \Exception("{$errstr} ({$errno})"); + } + + $opts = array( + 'ssl' => array( + 'verify_peer' => TRUE, // Override default FALSE for PHP < 5.6.0 + 'verify_peer_name' => TRUE, // Override default FALSE for PHP < 5.6.0 + 'allow_self_signed' => FALSE, // Disallow self signed certificates + 'SNI_enabled' => TRUE, // Allow for the API server to use SNI + ), + ); + stream_context_set_option($socket, $opts); + + fputs($socket, $headers); + fputs($socket, $content); + + $result = ''; + + while (!feof($socket)) { + $result .= fgets($socket); + } + fclose($socket); + + $this->httpResponseCode = intval(substr($result, 9, 3)); + + list($header, $body) = explode("\r\n\r\n", $result, 2); + + $this->httpFullHeader = $header; + + $json_request = (json_decode($body) != NULL) ? true : false; + + if (!$json_request) { + if (strpos($body, "apiDebugMode) { + echo '
Debug info

----

http request:
https://api.bol.com' . $url . $parameters . '

'; + echo 'header request:
' . print_r($headers, 1) . '
'; + if ($content) echo 'content:
' . htmlspecialchars($content) . '

'; + echo 'header response:
' . self::getFullHeader(); + echo '----
'; + } + + return $body_return; + } + + public function getHttpResponseCode() + { + return $this->httpResponseCode; + } + + public function getFullHeader() + { + return $this->httpFullHeader; + } + + public function getSessionId() + { + return $this->sessionId; + } + + public function setSessionId($sessionId) + { + $this->sessionId = '' . $sessionId; + } + +}