News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Adding a 'delete from cart' button to virtuemart shopping cart module

Started by seriousrakesh, March 06, 2012, 15:01:34 PM

Previous topic - Next topic

seriousrakesh


As mentioned in old version of virtuemart you can see here http://forum.virtuemart.net/index.php?topic=46142.0 but I am not finding solution for new version so give me the solution.

sunrome

It is easy. I get free module mod_vm2_cart, there you can see this button. After install you can look to the code in modules\mod_vm2_cart\tmpl\default.php :

<a class="vmicon vmicon vm2-remove_from_cart" onclick="remove_product_cart(this);">
<span class="product_cart_id" style="display:none;"><?php echo $product["product_cart_id"]; ?></span></a>


This code add button (bin) on module, but it use function remove_product_cart(), this also in this file in tag <Script>

<script type="text/javascript">

function remove_product_cart(elm) {
var cart_id=elm.getChildren('span').get('text');
new Request.HTML({
'url':'index.php?option=com_virtuemart&view=cart&task=delete',
'method':'post',
'data':'cart_virtuemart_product_id='+cart_id,
'onSuccess':function(tree,elms,html,js) {
//jQuery(".vmCartModule").productUpdate();
mod=jQuery(".vmCartModule");
jQuery.getJSON(vmSiteurl+"index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json"+vmLang,
function(datas, textStatus) {
if (datas.totalProduct >0) {
mod.find(".vm_cart_products").html("");
jQuery.each(datas.products, function(key, val) {
jQuery("#hiddencontainer .container").clone().appendTo(".vmCartModule .vm_cart_products");
jQuery.each(val, function(key, val) {
if (jQuery("#hiddencontainer .container ."+key)) mod.find(".vm_cart_products ."+key+":last").html(val) ;
});
});
mod.find(".total").html(datas.billTotal);
mod.find(".show_cart").html(datas.cart_show);
} else {
mod.find(".vm_cart_products").html("");
mod.find(".total").html(datas.billTotal);
}
mod.find(".total_products").html(datas.totalProductTxt);
}
);
}
}).send();
}
</script>


All that's left is to add this code to the appropriate places in the file modules/mod_virtuemart_cart/tmpl/default.php

PS. I don't remember, but if it does not work you need to install plagin _plg_system_vm2_cart. mod_vm2_cart use this plagin for get product's image, perhaps any else.

olejenya


NLD_Kub

Hello Guys,

use this Script, the other have a little Problem with Mootools.

function remove_product_cart(elm) {
var cart_id=elm.getChildren('span').get('text');
jQuery.ajax({
type: 'POST',
url:'index.php?option=com_virtuemart&view=cart&task=delete',
data:'cart_virtuemart_product_id='+cart_id,
success: function(){
mod=jQuery(".vmCartModule");
jQuery.getJSON(window.vmSiteurl+"index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json"+window.vmLang,
function(datas, textStatus) {
if (datas.totalProduct >0) {
mod.find(".vm_cart_products").html("");
jQuery.each(datas.products, function(key, val) {
jQuery("#hiddencontainer .container").clone().appendTo(".vmCartModule .vm_cart_products");
jQuery.each(val, function(key, val) {
if (jQuery("#hiddencontainer .container ."+key)) mod.find(".vm_cart_products ."+key+":last").html(val) ;
});
});
mod.find(".total").html(datas.billTotal);
mod.find(".show_cart").html(datas.cart_show);
} else {
mod.find(".vm_cart_products").html("");
mod.find(".total").html(datas.billTotal);
}
mod.find(".total_products").html(datas.totalProductTxt);
}
);
}
});
}

guimplenchik

Where did you get this free mod_vm2_cart module? Is there anyway to add delete button without installing third party modules?

Kub

Hell,

so its better for IE8
function remove_product_cart(elm) {
jQuery(document).ready(function(){
var cart_id = jQuery(elm).children("span.product_cart_id").text();
jQuery.ajax({
type: "POST",
url:"index.php?option=com_virtuemart&view=cart&task=delete",
data:"cart_virtuemart_product_id="+cart_id,
success: function(){
mod=jQuery(".vmCartModule");
jQuery.getJSON(window.vmSiteurl+"index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json"+window.vmLang,
function(datas, textStatus) {
if (datas.totalProduct >0) {
mod.find(".vm_cart_products").html("");
jQuery.each(datas.products, function(key, val) {
jQuery("#hiddencontainer .container").clone().appendTo(".vmCartModule .vm_cart_products");
jQuery.each(val, function(key, val) {
if (jQuery("#hiddencontainer .container ."+key)) mod.find(".vm_cart_products ."+key+":last").html(val) ;
});
});
mod.find(".total").html(datas.billTotal);
mod.find(".show_cart").html(datas.cart_show);
} else {
mod.find(".vm_cart_products").html("");
mod.find(".total").html(datas.billTotal);
}
mod.find(".total_products").html(datas.totalProductTxt);
}
);
jQuery("#success").fadeIn(500).delay(3000).fadeOut(500);
}
});
});
}


DATURA

Trying to do, as you say, but after activating "plg_system_vm2_cart_j25" stops working "add to cart" button,
and got
"http://xxxxxxxxxx.ru/index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json&_=1356442163804 500 (Internal Server Error)"
in java console.

Module and plug in was downloaded from here:
http://www.linelab.org/download?start=6
http://www.linelab.org/download?download=37:virtuemart-2-slide-cart-module-beta&start=6

Joomla! 2.5.8,
VirtueMart 2.0.16

andrai2

Hello!

Can someone tell me pleae excatly where in modules/mod_virtuemart_cart/tmpl/default.php i have to paste this code (above mentioned) to, to have delete button..?

<script type="text/javascript">

function remove_product_cart(elm) {
   var cart_id=elm.getChildren('span').get('text');
   new Request.HTML({
      'url':'index.php?option=com_virtuemart&view=cart&task=delete',
      'method':'post',
      'data':'cart_virtuemart_product_id='+cart_id,
      'onSuccess':function(tree,elms,html,js) {
         //jQuery(".vmCartModule").productUpdate();
         mod=jQuery(".vmCartModule");
         jQuery.getJSON(vmSiteurl+"index.php?option=com_virtuemart&nosef=1&view=cart&task=viewJS&format=json"+vmLang,
            function(datas, textStatus) {
               if (datas.totalProduct >0) {
                  mod.find(".vm_cart_products").html("");
                  jQuery.each(datas.products, function(key, val) {
                     jQuery("#hiddencontainer .container").clone().appendTo(".vmCartModule .vm_cart_products");
                     jQuery.each(val, function(key, val) {
                        if (jQuery("#hiddencontainer .container ."+key)) mod.find(".vm_cart_products ."+key+":last").html(val) ;
                     });
                  });
                  mod.find(".total").html(datas.billTotal);
                  mod.find(".show_cart").html(datas.cart_show);
               } else {
                  mod.find(".vm_cart_products").html("");
                  mod.find(".total").html(datas.billTotal);
               }
               mod.find(".total_products").html(datas.totalProductTxt);
            }
         );
      }
   }).send();
}
</script>