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

Remove a single product from the cart in shopping cart module

Started by DaLi, December 30, 2014, 09:58:48 AM

Previous topic - Next topic

DaLi

Hi,

I am struggling to create the function "remove a product from the cart" in the mod_virtuemart_cart module. With other words, I would like to delete a single product from my shopping cart module which is shown in the sidebar.

This function is already available in virtuemart (via delete product from cart overview) and I aim to reuse this function, however I have some problems with the php includes which will allow me to call the function.

The function is found in "components\com_virtuemart\helpers\cart.php", function:

public function removeProductCart($prod_id=0){
<<Code
}

Question:
Which files / code do I include which will enable me to call the "removeProductCart" function  from  \modules\mod_virtuemart_cart\tmpl\default.php

Specs:
Joomla! 2.5.27
VirtueMart 2.6.12.2

Thanks in advance,



Milbo

use the cart itself


if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DS . 'helpers' . DS . 'cart.php');
$cart = VirtueMartCart::getCart();
$cart->removeProductCart($yourId);

refresh your cart module by ajax or reload and thats it. Btw, it would be nice if you share the code and we can add it to the core

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

fmvm

I try this code and reload page but nothing happens. For example:
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php');
$cart = VirtueMartCart::getCart();
$yourId = 3;
$cart->removeProductCart($yourId);


Joomla 3.3.6, VM 3.0.3

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

fmvm

If I write:
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php');
$cart = VirtueMartCart::getCart();
$yourId[] = 3;
$cart->removeProductCart($yourId);


I get the warning: Illegal offset type in unset in /***/components/com_virtuemart/helpers/cart.php on line 673
unset($this->products[$prod_id]);
and ... on line 674
if(isset($this->cartProductsData[$prod_id])){

Can you write the full code? Thanks

Kuubs

Quote from: fmvm on February 27, 2015, 08:45:45 AM
If I write:
if (!class_exists('VirtueMartCart')) require(VMPATH_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php');
$cart = VirtueMartCart::getCart();
$yourId[] = 3;
$cart->removeProductCart($yourId);


I get the warning: Illegal offset type in unset in /***/components/com_virtuemart/helpers/cart.php on line 673
unset($this->products[$prod_id]);
and ... on line 674
if(isset($this->cartProductsData[$prod_id])){

Can you write the full code? Thanks

Is there any update for this?

roman5527

Hello, How did you finally solve it? Could you share the code? well thank you