VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: Kans on June 20, 2013, 12:55:31 PM

Title: Auto close add to cart pop up
Post by: Kans on June 20, 2013, 12:55:31 PM
Is there a way to automatically close the "add to cart" popup after a few seconds?

I tried editing the file facebox.js in /components/com_virtuemart/assets/js/
after the line
   $.facebox.loading()
add:
setTimeout($.facebox.close, 3000);

The problem with this solution is that it also auto closes the "Ask a question about this product" popup and the conditions popup in the check out, which is not good.

If not possible, how can I stay on the product page if I disable the popup?
Title: Re: Auto close add to cart pop up
Post by: jenkinhill on June 20, 2013, 17:00:44 PM
Hide it instead?  http://forum.virtuemart.net/index.php?topic=115975.msg390739#msg390739
Title: Re: Auto close add to cart pop up
Post by: Kans on June 22, 2013, 14:46:39 PM
Hi, thanks for the suggestion but the problem remains.
Hiding it creates the same problem as auto-closing it. By hiding it I also hide the "ask a question about this product" and the "conditions". I only want to do changes to the add to cart popup.

If someone comes up with a solution, please share it! You would make my day:)
Title: Re: Auto close add to cart pop up
Post by: AH on October 25, 2013, 15:59:02 PM
If you are using the new fancybox and want the much loved "auto close"

Edit

components\com_virtuemart\assets\js\vmprices.js

At around line 75

replace

  if(usefancy){
                        $.fancybox({
                                "titlePosition" : "inside",
                                "transitionIn" : "elastic",
                                "transitionOut" : "elastic",
                                "type" : "html",
                                "autoCenter"    :   true,
                                "closeBtn"      :   false,
                                "closeClick"    :   false,
                                "content"       :   txt
                            }
                        );


with this

if(usefancy){
                        $.fancybox({
                                "titlePosition" : "inside",
                                "transitionIn" : "elastic",
                                "transitionOut" : "elastic",
                                "type" : "html",
                                "autoCenter"    :   true,
                                "closeBtn"      :   false,
                                "closeClick"    :   false,
                                "onComplete"    : function(){
                                    setTimeout( function() {$.fancybox.close(); },3500); // 3000 = 3 secs
                                },
                                "content"       :   txt
                            }
                        );


Adjust the timeout as required 3500 = 3.5 secs

This should not affect any other fancybox popups  8)
Title: Re: Auto close add to cart pop up
Post by: beny.rfg on July 26, 2016, 20:13:04 PM
In the versions VM around 3.0.16 is code a little different (using jQuery):


if(usefancy){

  jQuery.fancybox({
"titlePosition" : "inside",
"transitionIn" : "fade",
"transitionOut" : "fade",
"changeFade"    :   "fast",
"type" : "html",
"autoCenter"    :   true,
"closeBtn"      :   false,
"closeClick"    :   false, 
                                        "onComplete"    : function(){
                                    setTimeout( function() {jQuery.fancybox.close(); },800);
                                },
"content"       :   txt

}

);

},
Title: Re: Auto close add to cart pop up
Post by: AH on July 26, 2016, 21:12:14 PM
This is the modified function for VM 3.0.17




Virtuemart.cartEffect = function(form) {

var dat = form.serialize();

if(usefancy){
jQuery.fancybox.showActivity();
}

    jQuery.ajax({
        type: "POST",
        cache: false,
        dataType: "json",
        url: Virtuemart.vmSiteurl + "index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS&format=json"+Virtuemart.vmLang+window.Itemid,
        data: dat
    }).done(

function(datas, textStatus) {

if(datas.stat ==1){
var txt = datas.msg;
} else if(datas.stat ==2){
var txt = datas.msg +"<H4>"+form.find(".pname").val()+"</H4>";
} else {
var txt = "<H4>"+vmCartError+"</H4>"+datas.msg;
}
if(usefancy){
jQuery.fancybox({
                "titlePosition" : "inside",
                "transitionIn" : "fade",
                "transitionOut" : "fade",
                "changeFade"    :   "fast",
                "type"          : "html",
                "autoCenter"    : true,
                "closeBtn"      : false,
                "closeClick"    : false,
                "content"       : txt,
                "autoDimensions": false,
                "width"         : 400,
                "height"        : 'auto',
                "onComplete"    : function () {
                    setTimeout(function () {
                        jQuery.fancybox.close();
                    }, 1500); // 3000 = 3 secs
                }
            });
} else {
jQuery.facebox( txt , 'my-groovy-style');
}


Virtuemart.productUpdate();
});

}

Virtuemart.incrQuantity = (function(event) {
    var rParent = jQuery(this).parent().parent();
    quantity = rParent.find('input[name="quantity[]"]');
    virtuemart_product_id = rParent.find('input[name="virtuemart_product_id[]"]').val();
    Ste = parseInt(quantity.attr("step"));
    if (isNaN(Ste)) Ste = 1;
    Qtt = parseInt(quantity.val());
    if (!isNaN(Qtt)) {
        quantity.val(Qtt + Ste);
        maxQtt = parseInt(quantity.attr("max"));
        if(!isNaN(maxQtt) && quantity.val()>maxQtt){
            quantity.val(maxQtt);
        }
        Virtuemart.setproducttype(event.data.cart,virtuemart_product_id);
    }
});