ПРОВЕРКА И ДОБАВЛЕНИЕ КЛАССА Кнопкам сравнения и Избранное!
Нормального отвеи, ик и не нашёл им.
Ипотому что если гделать по инструкции, То по истечению времени сайт повалит ошибками.
Вот реализация на 2.3 если не нужно что бы избранные были доступны по регистрации
Берет данные из сессии
Впринципе на 2.1.0.1 всё ик же
js присваивает классы активным товарам и меняет функцию на remove Классы сможете увигдеть в html
После сможете стилизовать как захотите
в могдель wishlista
public function getAllWishlist() {
// by nix
if ($data = $this->getWishlist()) {
$out = array();
foreach ($data as $key => $value) {
$out[] = $value['product_id'];
}
return $out;
} else if (isset($this->session->data['wishlist'])) {
return $this->session->data['wishlist'];
}
}
В контроллёры
$this->load->model('account/wishlist');
$data['AllWishlist'] = $this->model_account_wishlist->getAllWishlist();
if(isset( $this->session->data['compare'])){$data['AllCompare'] = $this->session->data['compare'];}
в common.js
Добавить функции уднония ( Заменить переменные var wishlist и var compare)
var wishlist = {
'add': function(product_id) {
$.ajax({
url: 'index.php?route=account/wishlist/add',
type: 'post',
data: 'product_id=' + product_id,
dataType: 'json',
beforeSend: function() {
$('#'+product_id).attr("class", "wish_active");
$('#'+product_id).attr("onclick","wishlist.remove('" + product_id + "')")
},
success: function(json) {
$('.alert').remove();
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">×</button></div>');
}
$('#wishlist-total').html('<span class="wishlist"></span><span class="hidden-xs hidden-sm hidden-md">' + json['total'] + '</span>');
$('#wishlist-total').attr('title', json['total']);
//$('html, body').animate({ scrollTop: 0 }, 'slow');
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
},
'remove': function(product_id) {
$.ajax({
url: 'wishlist/?remove=' + product_id,
type: 'post',
data: 'product_id',
dataType: 'json',
beforeSend: function() {
$('#'+product_id).removeAttr("class", "wish_active");
function addWish(){
$('#'+product_id).attr("onclick","wishlist.add('" + product_id + "')")}
setTimeout(addWish,500);
},
});
} };
var compare = {
'add': function(product_id) {
$.ajax({
url: 'index.php?route=product/compare/add',
type: 'post',
data: 'product_id=' + product_id,
dataType: 'json',
beforeSend: function() {
$('#'+product_id+'com').attr("class", "com_active");
$('#'+product_id+'com').attr("onclick","compare.remove('" + product_id + "')")
},
success: function(json) {
$('.alert').remove();
if (json['success']) {
$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#compare-total').html('<span class="compare"></span><span class="hidden-xs hidden-sm hidden-md">' + json['total'] + '</span>');
//$('html, body').animate({ scrollTop: 0 }, 'slow');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
},
'remove': function(product_id) {
$.ajax({
url: 'compare-products/?remove=' + product_id,
type: 'post',
data: 'product_id',
dataType: 'json',
beforeSend: function() {
$('#'+product_id+'com').removeAttr("class", "com_active");
function addCom(){
$('#'+product_id+'com').attr("onclick","compare.add('" + product_id + "')")}
setTimeout(addCom,500);
},
});
}
}
В предсивление
<div class="wrapper_sr">
<script type="text/javascript">
function ChangeColor(Element) {
Element.setAttribute('style','background-image:catalog/view/theme/default/image/img/zakl-hover.png');
}
</script>
<button
<?php if(isset($AllWishlist)) { ?>
<?php if(in_array($product['product_id'], $AllWishlist)) { ?>
class="wish_active" id="<?php echo $product['product_id']; ?>" onclick="wishlist.remove('<?php echo $product['product_id']; ?>');"
<?php } ?>
<?php } ?>
type="button" id="<?php echo $product['product_id']; ?>" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>'); ChangeColor(this);"><i class="fa fa-heart"></i></button>
<script type="text/javascript">
function ChangeColor(Element) {
Element.setAttribute('style','background-image:catalog/view/theme/default/image/img/zakl-hover.png');
}
</script>
<button
<?php if(isset($AllCompare)) { ?>
<?php if(in_array($product['product_id'], $AllCompare)) { ?>
class="com_active" id="<?php echo $product['product_id']; ?>com" onclick="compare.remove('<?php echo $product['product_id']; ?>');"
<?php } ?>
<?php } ?>
type="button" id="<?php echo $product['product_id']; ?>com" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>'); ChangeColor(this);"><i class="fa fa-exchange"></i></button>
</div>