News:

Looking for documentation? Take a look on our wiki

Main Menu

[SOLVED] Empty cart keeps shipping amount

Started by restodo, April 24, 2014, 01:11:19 AM

Previous topic - Next topic

restodo

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

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;
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

restodo

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

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

restodo

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!

Milbo

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?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

restodo

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.

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

AH

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.10.11
php 8.0

restodo

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.



Milbo

It is already in the svn for both trunks
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

AH

Regards
A

Joomla 3.10.11
php 8.0