Prestashop / CSV Import
Discover how to easily connect Prestashop
Connect API's with PHP
Connect to Stanley/Stella Product API in PHP
The first step of the integration is to call the Stanley/Stella Product REST API from the PHP code.
The standard output of the Stanley/Stella API is a “flat” list of product variants (SKU’s).
In our PHP code, we added the grouping of the variants at style level and the sorting of the variants by colors and sizes.
For simplicity, we only download the product data in 1 language (English).
See the following PHP code as inspiration. Feel free to extend this code with additional data coming from the API.
Sample PHP Code
<?php
function getAllSTSTProducts() {
$url = "https://api.stanleystella.com/webrequest/products/get_json";
$jsonData = array(
'jsonrpc' => '2.0',
'method' => 'call',
'params' => array(
'db_name' => "production_api",
'password' => "Test0220",
'user' => "test@stanleystella.com",
"LanguageCode" => "en_US"
),
'id' => 0
);
$ch = curl_init($url);
$jsonDataEncoded = json_encode($jsonData);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
$jsonDataDecoded = json_decode(json_decode($result)->result, true);
curl_close($ch);
// Sort the data by style, color and size
foreach ($jsonDataDecoded as $key => $row) {
$styleorder[$key] = $row['SequenceStyle'];
$sizeorder[$key] = $row['SizeSequence'];
$colororder[$key] = $row['ColorSequence'];
}
array_multisort($styleorder, SORT_ASC, $colororder, SORT_ASC, $sizeorder, SORT_ASC, $jsonDataDecoded); return $jsonDataDecoded;
}
function getAllSTSTProductsGrouped() {
$stpm = getAllSTSTProducts();
$allstststyles = array();
foreach ($stpm as $key => $variant) {
$stylecode = $variant["StyleCode"];
if (!isset($allstststyles[$stylecode])) {
$allstststyles[$stylecode] = array();
$allstststyles[$stylecode]["StyleCode"] = $variant["StyleCode"];
$allstststyles[$stylecode]["StyleName"] = $variant["StyleName"];
$allstststyles[$stylecode]["Type"] = $variant["Type"];
$allstststyles[$stylecode]["Category"] = $variant["Category"];
$allstststyles[$stylecode]["Gender"] = $variant["Gender"];
$allstststyles[$stylecode]["Fit"] = $variant["Fit"];
$allstststyles[$stylecode]["Neckline"] = $variant["Neckline"];
$allstststyles[$stylecode]["Sleeve"] = $variant["Sleeve"];
$allstststyles[$stylecode]["ShortDescription"] = $variant["ShortDescription"];
$allstststyles[$stylecode]["LongDescription"] = $variant["LongDescription"];
$allstststyles[$stylecode]["SequenceStyle"] = $variant["SequenceStyle"];
}
if (!isset($allstststyles[$stylecode]["variants"])) $allstststyles[$stylecode]["variants"] = array();
$var = array();
$var["B2BSKUREF"] = $variant["B2BSKUREF"];
$var["ColorCode"] = $variant["ColorCode"];
$var["Color"] = $variant["Color"];
$var["ColorSequence"] = $variant["ColorSequence"];
$var["SizeCode"] = $variant["SizeCode"];
$var["SizeCodeNavision"] = $variant["SizeCodeNavision"];
$var["SizeSequence"] = $variant["SizeSequence"];
$var["Stock"] = $variant["Stock"];
$var["Price<10 EUR"] = $variant["Price<10 EUR"];
$var["SKU_Start_Date"] = $variant["SKU_Start_Date"];
$var["Published"] = $variant["Published"];
$allstststyles[$stylecode]["variants"][$variant["B2BSKUREF"]] = $var;
}
return($allstststyles);
}