Merge branch 'ticket-12804-CacheFooter' into develop

This commit is contained in:
Marion Muszynski 2017-03-21 10:47:13 +01:00
commit b23f1a0fa0
4 changed files with 169 additions and 50 deletions

View File

@ -74,7 +74,8 @@ class Print_Ean extends Module {
}
$label = array(
'ref' => $product->reference,
'name' => $combination['attribute_name'].' - '.$product->name[2],
'name' => $product->name[2],
'attribute' => $combination['attribute_name']
);
$this->printEAN13($ean_generate,$label,1,Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee));
}
@ -88,6 +89,7 @@ class Print_Ean extends Module {
$label = array(
'ref' => $product->reference,
'name' => $product->name[2],
'attribute' => "",
);
$this->printEAN13($ean_generate,$label,1,Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee));
}
@ -108,7 +110,8 @@ class Print_Ean extends Module {
}
$label = array(
'ref' => $product->reference,
'name' => $combination['attribute_name'].' - '.$product->name[2],
'name' => $product->name[2],
'attribute' => $combination['attribute_name'],
);
$this->printEAN13($ean_generate,$label,1,Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee));
}
@ -195,10 +198,13 @@ class Print_Ean extends Module {
public function _getAttributeCombination($id_product, $id_attribute)
{
return Db::getInstance()->getRow('
SELECT pa.*
SELECT pa.*, al.`name` as `attribute_name`
FROM `'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` ac ON (ac.`id_product_attribute` = pa.`id_product_attribute`)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.`id_attribute` = ac.`id_attribute`)
WHERE pa.`id_product` = ' . (int)$id_product .'
AND pa.`id_product_attribute` = ' . (int)$id_attribute.'
AND al.`id_lang` = 2
');
}
@ -283,6 +289,8 @@ class Print_Ean extends Module {
$redis = new Predis\Client();
// .'1'.(strlen($ean13) == 12? 'B': 'F').'0000000150340'.$ean13."\n"
// .'1'.(strlen($ean13) == 12? 'B': (strlen($ean13) == 13? 'F': 'E')).'0000000150340'.$ean13."\n"
// .'1E022000015'.sprintf('%04d', (int) ((1020 - round((5.5 * strlen($ean) + 35) * 0.42 * 10)) / 2)).'B'.$ean13."\n"
$redis->publish(
$queue,
json_encode(array(
@ -293,9 +301,10 @@ class Print_Ean extends Module {
.'C0000'."\n"
.'D11'."\n"
.chr(2).'L'."\n"
.'121100000000100'.substr($label['ref'],0,30)."\n"
.'121100000000100'.substr($label['name'],0,30)."\n"
.'1'.(strlen($ean13) == 12? 'B': (strlen($ean13) == 13? 'F': 'E')).'0000000150340'.$ean13."\n"
.'121100002500'.(strlen($label['ref']) > 20? '330': '380').substr(str_replace(array('é','è','à','ï','ù'),array('e','e','a','i','u'),$label['ref']),0,30)."\n"
.'121100002000300'.substr(str_replace(array('é','è','à','ï','ù'),array('e','e','a','i','u'),$label['name']),0,30)."\n"
.'121100001500340'.substr(str_replace(array('é','è','à','ï','ù'),array('e','e','a','i','u'),$label['attribute']),0,30)."\n"
.'1E0000000150'.(strlen($ean13) == 12? '300': (strlen($ean13) == 13? '300': '340')).$ean13."\n"
.'Q'.sprintf('%04d', $quantity)."\n"
.'E'."\n"
),

View File

@ -157,63 +157,49 @@ class TrustedShopsBbb extends Module
}
global $smarty, $cookie;
if($smarty->tpl_vars['page_name']->value == 'order') {
$filename = _PS_ROOT_DIR_.'/modules/trustedshopsbbb/views/widget'.$cookie->id_lang.'.txt';
$expire = time() -3600;
$cache_id = (int)$cookie->id_lang.'_trustedshopsbbb_leftcolumn';
if (!$this->isTemplateCached($cache_id)) {
$resultArray = array();
if (in_array(strtoupper(Language::getIsoById($cookie->id_lang)), array("FR","ES"), true)) {
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$cookie->id_lang)) . '_ID');
$reviewIndicatorCollector = new ReviewIndicatorCollector((int)($cookie->id_lang));
$resultArray = $reviewIndicatorCollector->getResults();
}
if(count($resultArray)> 0 and (int)$resultArray['count'] > 0){
$smarty->assign(array(
'shopName' => $resultArray['shop_name'],
'result' => $resultArray['result'],
'max' => self::TS_BEST_RATING,
'count' => $resultArray['count'],
'tsId' => $tsId
));
return $this->display(__FILE__, 'views/rich_snippets_2.tpl');
} else {
return false;
}
if(file_exists($filename) && filemtime($filename) > $expire) {
$data = file_get_contents($filename);
$widget = json_decode($data, TRUE);
} else {
$file = fopen($filename, 'w+');
$widget = $this->buildWidget($cookie->id_lang);
fwrite($file, json_encode($widget));
fclose($file);
}
return $this->flushTemplateCache($cache_id);
$smarty->assign(array(
'widget' => $widget,
));
return $this->display(__FILE__, 'views/widget_leftcolumn.tpl');
}
}
public function hookFooter($params){
global $smarty, $cookie;
if($smarty->tpl_vars['page_name']->value == 'order') {
return false;
}
$cache_id = (int)$cookie->id_lang.'_trustedshopsbbb';
$filename = _PS_ROOT_DIR_.'/modules/trustedshopsbbb/views/widget_'.$cookie->id_lang.'.txt';
$expire = time() -3600;
if (!$this->isTemplateCached($cache_id)) {
$resultArray = array();
if (in_array(strtoupper(Language::getIsoById($cookie->id_lang)), array("FR","ES"), true)) {
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$cookie->id_lang)) . '_ID');
$reviewIndicatorCollector = new ReviewIndicatorCollector((int)($cookie->id_lang));
$resultArray = $reviewIndicatorCollector->getResults();
}
if(count($resultArray)> 0 and (int)$resultArray['count'] > 0){
$smarty->assign(array(
'shopName' => $resultArray['shop_name'],
'result' => $resultArray['result'],
'max' => self::TS_BEST_RATING,
'count' => $resultArray['count'],
'resultArray' => $resultArray,
'tsId' => $tsId
));
return $this->display(__FILE__, 'views/rich_snippets.tpl');
} else {
return false;
}
if(file_exists($filename) && filemtime($filename) > $expire) {
$data = file_get_contents($filename);
$widget = json_decode($data, TRUE);
} else {
$file = fopen($filename, 'w+');
$widget = $this->buildWidget($cookie->id_lang);
fwrite($file, json_encode($widget));
fclose($file);
}
return $this->flushTemplateCache($cache_id);
$smarty->assign(array(
'widget' => $widget,
));
return $this->display(__FILE__, 'views/widget.tpl');
}
public function hookOrderConfirmation($params)
{
global $smarty, $cookie;
@ -226,6 +212,26 @@ class TrustedShopsBbb extends Module
}
}
public function buildWidget($id_lang){
$resultArray = array();
if (in_array(strtoupper(Language::getIsoById((int)$id_lang)), array("FR","ES"), true)) {
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$id_lang)) . '_ID');
$reviewIndicatorCollector = new ReviewIndicatorCollector((int)($id_lang));
$resultArray = $reviewIndicatorCollector->getResults();
}
if(count($resultArray)> 0 && (int)$resultArray['count'] > 0){
return array(
'shopName' => $resultArray['shop_name'],
'result' => $resultArray['result'],
'max' => self::TS_BEST_RATING,
'count' => $resultArray['count'],
'resultArray' => $resultArray,
'tsId' => $tsId
);
}
return $resultArray;
}
private function isTemplateCached(&$cache_id)
{
global $smarty;

View File

@ -0,0 +1,39 @@
<script type="text/javascript">
{literal}(function () {
var _tsid = '{/literal}{$widget['tsId']}{literal}';
_tsConfig = {
'yOffset': '0', /* offset from page bottom */
'variant': 'custom_reviews', /* text, default, small, reviews, custom, custom_reviews */
'customElementId': 'customCheckoutDiv', /* required for variants custom and custom_reviews */
'trustcardDirection': '', /* for custom variants: topRight, topLeft, bottomRight, bottomLeft */
'customBadgeWidth': '', /* for custom variants: 40 - 90 (in pixels) */
'customBadgeHeight': '70', /* for custom variants: 40 - 90 (in pixels) */
'disableResponsive': 'false', /* deactivate responsive behaviour */
'disableTrustbadge': 'false', /* deactivate trustbadge */
'customCheckoutElementId': 'customCheckoutDiv'
};
var _ts = document.createElement('script');
_ts.type = 'text/javascript';
_ts.charset = 'utf-8';
_ts.async = true;
_ts.src = 'http://widgets.trustedshops.com/js/' + _tsid + '.js';
var __ts = document.getElementsByTagName('script')[0];
__ts.parentNode.insertBefore(_ts, __ts);
})();
{/literal}
</script>
<script type="application/ld+json">
{literal}
{
"@context": "http://schema.org",
"@type": "LocalBusiness",
"name": "{/literal}{$widget['shopName']}{literal}",
"aggregateRating" : {
"@type": "AggregateRating",
"ratingValue" : "{/literal}{$widget['result']}{literal}",
"bestRating" : "{/literal}{$widget['max']}{literal}",
"ratingCount" : "{/literal}{$widget['count']}{literal}"
}
}
{/literal}
</script>

View File

@ -0,0 +1,65 @@
<div id="customCheckoutDiv2" style="margin-bottom: 15px;"></div>
<script type="text/javascript">
{literal}(function () {
var _tsid = "{/literal}{$widget['tsId']}{literal}";
_tsConfig = {
'yOffset': '0', /* offset from page bottom */
'variant': 'custom_reviews', /* text, default, small, reviews, custom, custom_reviews */
'customElementId': 'customCheckoutDiv2', /* required for variants custom and custom_reviews */
'trustcardDirection': '', /* for custom variants: topRight, topLeft, bottomRight, bottomLeft */
'customBadgeWidth': '', /* for custom variants: 40 - 90 (in pixels) */
'customBadgeHeight': '80', /* for custom variants: 40 - 90 (in pixels) */
'disableResponsive': 'false', /* deactivate responsive behaviour */
'disableTrustbadge': 'false', /* deactivate trustbadge */
'customCheckoutElementId': 'customCheckoutDiv'
};
var _ts = document.createElement('script');
_ts.type = 'text/javascript';
_ts.charset = 'utf-8';
_ts.async = true;
_ts.src = 'http://widgets.trustedshops.com/js/' + _tsid + '.js';
var __ts = document.getElementsByTagName('script')[0];
__ts.parentNode.insertBefore(_ts, __ts);
})();
function onElementInserted(containerSelector, elementSelector, callback) {
var onMutationsObserved = function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length) {
var elements = $(mutation.addedNodes).find(elementSelector);
for (var i = 0, len = elements.length; i < len; i++) {
callback(elements[i]);
}
}
});
};
var target = $(containerSelector)[0];
var config = { childList: true, subtree: true };
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(onMutationsObserved);
observer.observe(target, config);
}
$(document).ready(function(){
onElementInserted('#customCheckoutDiv2', 'div', function(element) {
$('#customCheckoutDiv2 div[id^=\'tsbadge_\']').css('width','200px');
$('#customCheckoutDiv2 div[id^=\'tsCustomBadge\']').css('width','200px');
});
});
{/literal}
</script>
<script type="application/ld+json">
{literal}
{
"@context": "http://schema.org",
"@type": "LocalBusiness",
"name": "{/literal}{$widget['shopName']}{literal}",
"aggregateRating" : {
"@type": "AggregateRating",
"ratingValue" : "{/literal}{$widget['result']}{literal}",
"bestRating" : "{/literal}{$widget['max']}{literal}",
"ratingCount" : "{/literal}{$widget['count']}{literal}"
}
}
{/literal}
</script>