1, EsiConf::FLD_TAG => 'compare', EsiConf::FLD_PURGE_CONTROLLERS => 'CompareController?id_product', EsiConf::FLD_ASVAR => 1, EsiConf::FLD_TIPURL => 'https://www.litespeedtech.com/support/wiki/doku.php/' . 'litespeed_wiki:cache:lscps:customization_1_6#update_template_for_compare_product_feature', ); $this->esiConf = new EsiConf(self::NAME, EsiConf::TYPE_BUILTIN, $confData); $this->registerEsiModule(); $this->addJsDef('comparedProductsIds', $this); return true; } protected function jsKeyProcess($jskey) { $value = '[]'; if ($jskey != 'comparedProductsIds') { //something wrong, should not happen LSLog::log(__FUNCTION__ . ' unexpected key ' . $jskey, LSLog::LEVEL_EXCEPTION); } elseif (isset(Context::getContext()->cookie->id_compare)) { $compared_products = CompareProduct::getCompareProducts(Context::getContext()->cookie->id_compare); if (is_array($compared_products)) { $value = '[' . implode(',', $compared_products) . ']'; } } return $value; } protected function moduleFieldProcess($params) { $countVal = 0; if ($params['f'] == 'comparedcount' && isset(Context::getContext()->cookie->id_compare)) { $compared_products = CompareProduct::getCompareProducts(Context::getContext()->cookie->id_compare); $countVal = count($compared_products); } return "$countVal"; } public static function isUsed($name) { $res = ($name == self::NAME) && Configuration::get('PS_COMPARATOR_MAX_ITEM') && method_exists('CompareProduct', 'getCompareProducts'); return $res; } } LscCompareProduct::register(); /* * README: If you want to enable comparison, you have to locate the template file and modify it to inject ESI. * For example, the default one is located at * themes/default-bootstrap/product-compare.tpl * You need to identify the actual theme template used. * * Please wrap around * {count($compared_products)} * with {hook h="litespeedEsiBegin" m="lsc_compareproduct" field="comparedcount"} in front * and {hook h="litespeedEsiEnd"} at back * * Please do not add extra space or line break in between. * * Please note, "{count($compared_products)}" appeared twice, both need to be replaced. * Please check the wiki link for more info */