VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: restodo on April 24, 2014, 01:11:19 AM

Title: [SOLVED] Empty cart keeps shipping amount
Post by: restodo 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.
Title: Re: Empty cart keeps shipping amount
Post by: Milbo on April 24, 2014, 10:40:53 AM
Please replace the emptyCartValues function in the cart helper with


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;
}
Title: Re: Empty cart keeps shipping amount
Post by: restodo 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?

Title: Re: Empty cart keeps shipping amount
Post by: byPV 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:


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
Title: Re: Empty cart keeps shipping amount
Post by: restodo on April 25, 2014, 04:41:51 AM
Quote from: byPV 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:


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!
Title: Re: [SOLVED] Empty cart keeps shipping amount
Post by: Milbo 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?
Title: Re: [SOLVED] Empty cart keeps shipping amount
Post by: restodo on April 25, 2014, 18:47:07 PM
Quote from: Milbo 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'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.
Title: Re: [SOLVED] Empty cart keeps shipping amount
Post by: Milbo 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.
Title: Re: [SOLVED] Empty cart keeps shipping amount
Post by: AH 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
Title: Re: [SOLVED] Empty cart keeps shipping amount
Post by: restodo on May 01, 2014, 05:04:19 AM
Quote from: Hutson 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

I'm agree with you. Sometimes happens.

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


Title: Re: [SOLVED] Empty cart keeps shipping amount
Post by: Milbo on May 01, 2014, 11:01:50 AM
It is already in the svn for both trunks
Title: Re: [SOLVED] Empty cart keeps shipping amount
Post by: AH on May 01, 2014, 19:06:33 PM
 :)