Hallo,
vielleicht bin ich hier falsch, aber ich habe eine PHP Funktion übernommen, die nun in das Framework Smarty (JTL-Shop) eingebunden werden soll.
Hier mal der Code
Diesen möchte ich über $smarty->assign('textvar', 'ichweißnichtwie'); einbinden. Dafür benötige ich Hilfe.
Würde mich freuen, wenn ich hier Denkanstöße bekommen könnte .. Sag schon mal Danke
Gruß Fredolin
vielleicht bin ich hier falsch, aber ich habe eine PHP Funktion übernommen, die nun in das Framework Smarty (JTL-Shop) eingebunden werden soll.
Hier mal der Code
PHP:
<?php
/**
This is an example of integrating Trusted Shops Customer Reviews
marked with structured data into your website
Make sure you replace value of $tsid with your Trusted Shops ID
Make sure you have a writing permission to the
folder set in $cacheFileName
Requires version PHP 5.+
*/
$tsId = 'PASTE_YOUR_TS-ID_HERE';
$cacheFileName = '/tmp/' . $tsId . '.json';
$cacheTimeOut = 43200; // half a day
$apiUrl = 'http://api.trustedshops.com/rest/public/v2/shops/' . $tsId . '/quality/reviews.json';
$reviewsFound = false;
if (!function_exists('trustedshopscachecheck')) {
function trustedshopscachecheck($filename_cache, $timeout = 10800) {
if (file_exists($filename_cache) && time() - filemtime($filename_cache) < $timeout) {
return true;
}
return false;
}
}
// check if cached version exists
if (!trustedshopscachecheck($cacheFileName, $cacheTimeOut)) {
// load fresh from API
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, $apiUrl);
$output = curl_exec($ch); curl_close($ch);
// Write the contents back to the file
// Make sure you can write to file's destination
file_put_contents($cacheFileName, $output);
}
if ($jsonObject = json_decode(file_get_contents($cacheFileName), true)) {
$result = $jsonObject['response']['data']['shop']['qualityIndicators']['reviewIndicator']['overallMark'];
$count = $jsonObject['response']['data'] ['shop']['qualityIndicators']['reviewIndicator']['activeReviewCount'];
$shopName = $jsonObject['response']['data']['shop']['name'];
$max = "5.00";
if ($count > 0) {
$reviewsFound = true;
}
}
if ($reviewsFound) {
// Output aggregated reviews markup:
$ts_snippet = '<script type="application/ld+json">';
$ts_snippet .= '{';
$ts_snippet .= '"@context": "http://schema.org",';
$ts_snippet .= '"@type": "Organization",';
$ts_snippet .= '"name": "'.$shopName.'",';
$ts_snippet .= '"aggregateRating" : {';
$ts_snippet .= '"@type": "AggregateRating",';
$ts_snippet .= '"ratingValue" : "'.$result.'",';
$ts_snippet .= '"bestRating" : "'.$max.'",';
$ts_snippet .= '"ratingCount" : "'.$count.'"';
$ts_snippet .= '}}';
$ts_snippet .= '</script>';
echo $ts_snippet;
}
Würde mich freuen, wenn ich hier Denkanstöße bekommen könnte .. Sag schon mal Danke
Gruß Fredolin
Zuletzt bearbeitet: