winpeace
04-30-2011, 09:45 AM
Normally,
User press add to cart button, product goes to cart module.Its ok.
But I want when product add to cart with "add to cart "button automaticly button turns "In your cart "button.
How to do this?
http://i1104.hizliresim.com/2011/4/30/4862.jpg
php code;
<?php if ($ajax_add) { ?>
<a class="button_add_small" title="<?php echo $button_add_to_cart; ?>" onclick="add_to_cart_all(<?php echo $products[$j]['product_id']; ?>,'lst')" id="add_to_cart_all"> </a>
<input type="hidden" id="options_<?php echo $products[$j]['product_id']; ?>" value="<?php echo count($products[$j]['options']); ?>"/>
<input type="hidden" id="url_<?php echo $products[$j]['product_id']; ?>" value="<?php echo $products[$j]['add']; ?>"/>
<?php } else { ?>
<a class="button_add_small" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" > </a>
<?php } ?>
ajax code;
$(document).ready(function () {
$('#add_to_cart').removeAttr('onclick');
$('#add_to_cart').click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('#module_cart .middle').html(html);
},
complete: function () {
var image = $('#image').offset();
var cart = $('#module_cart').offset();
$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
height : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
<!-- ust sepete aynı anda ekleme START -->
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/winpeace_cart',
dataType: 'html',
data: $('#product :input'),
success: function (htmltotal) {
$('.div7').html(htmltotal);
}
});
<!-- ust sepete aynı anda ekleme FINISH -->
}
});
});
});
function add_to_cart_all(id,mdl){
var dataString = 'product_id='+id+'&quantity=1';
var url = $('#url_'+id).val()
if($('#options_'+id).val()>0){
$(location).attr('href',url);
return;
}
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
data: dataString ,
beforeSend :function(tp){
var image = $('#'+mdl+'_'+id).offset();
var cart = $('#module_cart').offset();
$('#'+mdl+'_'+id).before('<img src="' + $('#'+mdl+'_'+id).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; right: ' + image.right + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
height : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/winpeace_cart',
dataType: 'html',
data: $('#product :input'),
success: function (htmltotal) {
$('.div7').html(htmltotal);
}
});
});
},
success: function (html) {
// $('#module_cart').css('display','none');
// $('#module_cart .middle').html(html);
},
complete: function () {
}
});
}
User press add to cart button, product goes to cart module.Its ok.
But I want when product add to cart with "add to cart "button automaticly button turns "In your cart "button.
How to do this?
http://i1104.hizliresim.com/2011/4/30/4862.jpg
php code;
<?php if ($ajax_add) { ?>
<a class="button_add_small" title="<?php echo $button_add_to_cart; ?>" onclick="add_to_cart_all(<?php echo $products[$j]['product_id']; ?>,'lst')" id="add_to_cart_all"> </a>
<input type="hidden" id="options_<?php echo $products[$j]['product_id']; ?>" value="<?php echo count($products[$j]['options']); ?>"/>
<input type="hidden" id="url_<?php echo $products[$j]['product_id']; ?>" value="<?php echo $products[$j]['add']; ?>"/>
<?php } else { ?>
<a class="button_add_small" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" > </a>
<?php } ?>
ajax code;
$(document).ready(function () {
$('#add_to_cart').removeAttr('onclick');
$('#add_to_cart').click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('#module_cart .middle').html(html);
},
complete: function () {
var image = $('#image').offset();
var cart = $('#module_cart').offset();
$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
height : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
});
<!-- ust sepete aynı anda ekleme START -->
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/winpeace_cart',
dataType: 'html',
data: $('#product :input'),
success: function (htmltotal) {
$('.div7').html(htmltotal);
}
});
<!-- ust sepete aynı anda ekleme FINISH -->
}
});
});
});
function add_to_cart_all(id,mdl){
var dataString = 'product_id='+id+'&quantity=1';
var url = $('#url_'+id).val()
if($('#options_'+id).val()>0){
$(location).attr('href',url);
return;
}
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/callback',
data: dataString ,
beforeSend :function(tp){
var image = $('#'+mdl+'_'+id).offset();
var cart = $('#module_cart').offset();
$('#'+mdl+'_'+id).before('<img src="' + $('#'+mdl+'_'+id).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; right: ' + image.right + 'px;" />');
params = {
top : cart.top + 'px',
left : cart.left + 'px',
opacity : 0.0,
width : $('#module_cart').width(),
height : $('#module_cart').height()
};
$('#temp').animate(params, 'slow', false, function () {
$('#temp').remove();
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/winpeace_cart',
dataType: 'html',
data: $('#product :input'),
success: function (htmltotal) {
$('.div7').html(htmltotal);
}
});
});
},
success: function (html) {
// $('#module_cart').css('display','none');
// $('#module_cart .middle').html(html);
},
complete: function () {
}
});
}