Author Topic: Remove a single product from the cart in shopping cart module  (Read 8782 times)

DaLi

  • Beginner
  • *
  • Posts: 1
Remove a single product from the cart in shopping cart module
« on: December 30, 2014, 09:58:48 am »
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10283
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Remove a single product from the cart in shopping cart module
« Reply #1 on: January 15, 2015, 22:56:42 pm »
use the cart itself

Code: [Select]
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

  • Beginner
  • *
  • Posts: 11
Re: Remove a single product from the cart in shopping cart module
« Reply #2 on: February 23, 2015, 10:54:04 am »
I try this code and reload page but nothing happens. For example:
Code: [Select]
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10283
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Remove a single product from the cart in shopping cart module
« Reply #3 on: February 26, 2015, 14:57:33 pm »
in vm3, I think you need an array
$yourId[] = 3;
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

  • Beginner
  • *
  • Posts: 11
Re: Remove a single product from the cart in shopping cart module
« Reply #4 on: February 27, 2015, 08:45:45 am »
If I write:
Code: [Select]
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
Code: [Select]
unset($this->products[$prod_id]);and ... on line 674
Code: [Select]
if(isset($this->cartProductsData[$prod_id])){
Can you write the full code? Thanks

Kuubs

  • Jr. Member
  • **
  • Posts: 346
Re: Remove a single product from the cart in shopping cart module
« Reply #5 on: November 12, 2020, 12:21:23 pm »
If I write:
Code: [Select]
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
Code: [Select]
unset($this->products[$prod_id]);and ... on line 674
Code: [Select]
if(isset($this->cartProductsData[$prod_id])){
Can you write the full code? Thanks

Is there any update for this?

roman5527

  • Jr. Member
  • **
  • Posts: 236
  • VirtueMart Version: 4.0.6
Re: Remove a single product from the cart in shopping cart module
« Reply #6 on: July 21, 2022, 16:56:15 pm »
Hello, How did you finally solve it? Could you share the code? well thank you