Используйте этот код, чтобы рассчитывать как на кнопку продукта на странице продукта, так и на странице продукта, поместите этот код в view.phtml
<?php
if (!is_dir('clickcounter')) {
@mkdir('clickcounter', 0777,true);
}
$filename=$_product->getSku().'.txt';
$dir='clickcounter' ;
if(!file_exists($dir.'/'.$filename)){
file_put_contents($dir.'/'.$filename, '0');
}
if(isset($_GET['click']) == 'yes'){
file_put_contents($dir.'/'.$filename, ((int) file_get_contents($dir.'/'.$filename)) + 1);
header('Location: ' . $_SERVER['SCRIPT_NAME']);
?>
///// Ajax Update ///
function myAjax() {
jQuery.ajax({
type: "POST",
url: '?click=yes',
data:{action:'call_this'},
cache: false,
success: function (html) {
//location.reload(true);
jQuery(".favourite-img").replaceWith(jQuery('.favourite-img', jQuery(html)));
jQuery('#likeme').addClass('disabled');
}
});
}
</script>
//// HTML Code ///
<a id="likeme" class="disabled" href="javascript:void(0)" >
<div class="favourite-product">
<div class="favourite-img"><?php echo file_get_contents($dir.'/'.$filename); ?></div>
</div>
</a>