Author Topic: [SOLVED] Empty cart keeps shipping amount  (Read 2177 times)

restodo

  • Jr. Member
  • **
  • Posts: 77
[SOLVED] Empty cart keeps shipping amount
« on: April 24, 2014, 01:11:19 am »
Hi,

I'm on VM 2.6.0 and I'm using Standard Shipping plugin.

For example I have:

Shipment 1 cost  USD 38
Shipment 2 cost  USD 45
Shipment 3 cost  USD 100

If I remove the products from my cart and one of the shipments was selected, when the site say that my cart is empty the amount it isn't.

If I choose for example Shipment 2, USD 45 will be added to my cart.
When I remove the products in cart, the amount in cart stills USD 45.


Could you tell me where can I check to tell the code to clear Shipment Plugin?


Someone in the forum tells me:
"the issue is still that the variable $this->cart->pricesUnformatted['salesPriceShipment'] Is left populated when there are no products in the cart"


Regards.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Empty cart keeps shipping amount
« Reply #1 on: April 24, 2014, 10:40:53 am »
Please replace the emptyCartValues function in the cart helper with

Code: [Select]
static public function emptyCartValues($cart){

//We delete the old stuff
$cart->products = array();
$cart->_inCheckOut = false;
$cart->_dataValidated = false;
$cart->_confirmDone = false;
$cart->customer_comment = '';
$cart->couponCode = '';
$cart->order_language = '';
$cart->tosAccepted = null;
$cart->virtuemart_shipmentmethod_id = 0; //OSP 2012-03-14
$cart->virtuemart_paymentmethod_id = 0;
$cart->order_number=null;
$cart->pricesUnformatted = null;
$cart->cartData = null;
}
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

restodo

  • Jr. Member
  • **
  • Posts: 77
Re: Empty cart keeps shipping amount
« Reply #2 on: April 24, 2014, 20:36:56 pm »
Thanks for your answer Milbo.

I've modified the function in /components/com_virtuemart/helpers/cart.php and the final was:

   static public function emptyCartValues($cartData){

      //We delete the old stuff
      $cartData->products = array();
      $cartData->_inCheckOut = false;
      $cartData->_dataValidated = false;
      $cartData->_confirmDone = false;
      $cartData->customer_comment = '';
      $cartData->couponCode = '';
      $cartData->order_language = '';
      $cartData->tosAccepted = null;
      $cartData->virtuemart_shipmentmethod_id = 0; //OSP 2012-03-14
      $cartData->virtuemart_paymentmethod_id = 0;
      $cartData->order_number=null;
      $cartData->pricesUnformatted = null;
      $cartData->cartData = null;

   }

I've added only last 2 lines:

      $cartData->pricesUnformatted = null;
      $cartData->cartData = null;

Anyway the problems stills.

If I removed last product on cart, standard shipping cost stays on cart.


Did I edit the correct file?


byPV

  • 3rd party VirtueMart Developer
  • Beginner
  • *
  • Posts: 39
    • Software Solutions byPV
Re: Empty cart keeps shipping amount
« Reply #3 on: April 24, 2014, 21:43:07 pm »
Hi,

there a different problem. The problem is not WHAT is cleared. The problem is that data ARE NOT cleared after removing of the last product.

If you want to clear all data in your cart after removing of the last product, so it is necessary in cart helper class modify the method removeProductCart() in the following way:

Code: [Select]
public function removeProductCart($prod_id=0) {
// Check for cart IDs
if (empty($prod_id))
$prod_id = JRequest::getVar('cart_virtuemart_product_id');
unset($this->products[$prod_id]);
if(isset($this->cartProductsData[$prod_id])){
// hook for plugin action "remove from cart"
if(!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS.DS.'vmcustomplugin.php');
JPluginHelper::importPlugin('vmcustom');
$dispatcher = JDispatcher::getInstance();
$addToCartReturnValues = $dispatcher->trigger('plgVmOnRemoveFromCart',array($this,$prod_id));
unset($this->cartProductsData[$prod_id]);
}
$this->setCartIntoSession();

// Add this line
if (empty($this->products)) $this->emptyCart();

return true;
}

Regards,
Pavel

restodo

  • Jr. Member
  • **
  • Posts: 77
Re: Empty cart keeps shipping amount
« Reply #4 on: April 25, 2014, 04:41:51 am »
Hi,

there a different problem. The problem is not WHAT is cleared. The problem is that data ARE NOT cleared after removing of the last product.

If you want to clear all data in your cart after removing of the last product, so it is necessary in cart helper class modify the method removeProductCart() in the following way:

Code: [Select]
public function removeProductCart($prod_id=0) {
// Check for cart IDs
if (empty($prod_id))
$prod_id = JRequest::getVar('cart_virtuemart_product_id');
unset($this->products[$prod_id]);
if(isset($this->cartProductsData[$prod_id])){
// hook for plugin action "remove from cart"
if(!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS.DS.'vmcustomplugin.php');
JPluginHelper::importPlugin('vmcustom');
$dispatcher = JDispatcher::getInstance();
$addToCartReturnValues = $dispatcher->trigger('plgVmOnRemoveFromCart',array($this,$prod_id));
unset($this->cartProductsData[$prod_id]);
}
$this->setCartIntoSession();

// Add this line
if (empty($this->products)) $this->emptyCart();

return true;
}

Regards,
Pavel

Thanks for your answer.

Your solution works good!! now my cart is ok after was emptied.

Please developers, look at this solution because maybe you've to add to next release of VM 2.6.0


Regards!

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED] Empty cart keeps shipping amount
« Reply #5 on: April 25, 2014, 11:28:01 am »
We want to delete different information if you remove all products then if you did a checkout. It is also actually quite academical, if you add a new product you get the new values and who checks the cart if there is no product in it?
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

restodo

  • Jr. Member
  • **
  • Posts: 77
Re: [SOLVED] Empty cart keeps shipping amount
« Reply #6 on: April 25, 2014, 18:47:07 pm »
We want to delete different information if you remove all products then if you did a checkout. It is also actually quite academical, if you add a new product you get the new values and who checks the cart if there is no product in it?

I'm sorry Milbo I don't understand what you're saying.

Today I've made the following steps with cart helpers modified.

1) Add a product into cart

2) Select a standard shipping method with a fixed amount

3) Select cash on delivery payment method

4) Checkout

After that my cart is empty, the amount in cart is zero and I've received a correct mail with order.

Also If I only do steps 1, 2, 3 and then remove product from cart. My cart is empty and the amount in cart is zero.


If you need to make another test please tell me.


Regards.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED] Empty cart keeps shipping amount
« Reply #7 on: April 25, 2014, 22:37:08 pm »
To checkout is not to remove all products. byPV talked about, what happens, when you remove all products.

His hint is valid. But I see it really as minor problem, because it usually does not happen.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2915
  • VirtueMart Version: 3.6.0
Re: [SOLVED] Empty cart keeps shipping amount
« Reply #8 on: April 26, 2014, 14:46:39 pm »
Does sometime happen that person realises that product is incorrect, then goes and deletes it to choose correct one, have the shipping details stored in session when no products does look odd

Would be usefule if session shipping cost and selection was removed when last item in cart is removed
regards
A

Joomla 3.9.8
php 7.1

restodo

  • Jr. Member
  • **
  • Posts: 77
Re: [SOLVED] Empty cart keeps shipping amount
« Reply #9 on: May 01, 2014, 05:04:19 am »
Does sometime happen that person realises that product is incorrect, then goes and deletes it to choose correct one, have the shipping details stored in session when no products does look odd

Would be usefule if session shipping cost and selection was removed when last item in cart is removed

I'm agree with you. Sometimes happens.

I think if sometimes could happens it'll be solved in future releases.



Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9853
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED] Empty cart keeps shipping amount
« Reply #10 on: May 01, 2014, 11:01:50 am »
It is already in the svn for both trunks
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2915
  • VirtueMart Version: 3.6.0
Re: [SOLVED] Empty cart keeps shipping amount
« Reply #11 on: May 01, 2014, 19:06:33 pm »
 :)
regards
A

Joomla 3.9.8
php 7.1