News:

Looking for documentation? Take a look on our wiki

Main Menu

modification for checkout

Started by guardiano78, May 02, 2018, 19:19:06 PM

Previous topic - Next topic

guardiano78

Hello,
I need to know what is the function that deletes the row in the #__virtuemart_carts table when the order is submitted.

I'll explain with an example:
in my website I have the product "Bottle of milk" with stock 15.

- I put 10 pieces in the cart and go into the cart.
- Someone else is buying 8 pieces of the same product and makes the checkout., Then the stock becomes 7 pieces.
- At this point I decide to finalize the purchase but it happens that I buy the remaining 7 pieces, while the other 3 I had in the cart are lost.

My goal is to recover those 3 pieces by writing a line in another table.

To do this I need to know in which file and which function does the deletion of the row in the table #__virtuemart_carts; so I can do another operation before the row is deleted.

Can anyone help me?
Thanks.

lausianne

Does this happen when doing the shopping on two different browsers? If it is in the same browser, I imagine that there could be a cookie issue.

guardiano78

#2
Hi lausianne,

i use a plugin that save the cart. This is not the problem.
How virtuemart works is fine for me!

I only need to write the remained number of products in another database table before deleting the row in #_virtuemart_carts.
I'm sorry if my explanation is not clear, i try do an example:

How work now:
- I put in the cart 10 pieces of product named AAAA
- the stock for AAAA is 22 pieces
- now another user purchase15 pieces of AAAA
- the new stock for AAAA is 7 pieces
- Now i click on "Complete the Order"
- In the order i bought 7 pieces of AAAA, but the other 3 pieces go losts, infact in #_virtuemart_carts the row is been deleted
- New stock of AAAA is 0

How i would like it work:
- I put in the cart 10 pieces of product named AAAA
- the stock for AAAA is 22 pieces
- now another user purchase15 pieces of AAAA
- the new stock for AAAA is 7 pieces
- Now i click on "Complete the Order"
- In the order i bought 7 pieces of AAAA, the other 3 pieces are written in a specific table in database named for example "product_out_of_stock" (product_id, num_of_products, user_id)and after in #_virtuemart_carts the row is been deleted
- New stock of AAAA is 0


For do this i need to locate the exact file and the exact sourcecode that empty my cart after checkout.
Thank you.

guardiano78

Hello,
is it possible that is in components/com_virtuemart/helpers/cart.php ?

at line 1255 the function


static public function emptyCartValues(&$cart, $session = true){

//We delete the old stuff
$cart->products = array();
$cart->cartProductsData = array();
$cart->cartData = array();
$cart->cartPrices = array();
$cart->cartfields = array();
$cart->_inCheckOut = false;
$cart->_dataValidated = false;
$cart->_confirmDone = false;
$cart->couponCode = '';
$cart->order_language = '';
$cart->virtuemart_shipmentmethod_id = 0; //OSP 2012-03-14
$cart->virtuemart_paymentmethod_id = 0;
$cart->order_number=null;
$cart->_fromCart = false;
$cart->_inConfirm = false;
$cart->totalProduct=false;
$cart->productsQuantity=array();
$cart->virtuemart_order_id = null;

if($session){
$cart->deleteCart();
$cart->setCartIntoSession(false,true);
}
}



????


Thanks.

guardiano78

Hello,

maybe I'm wrong ...
This operation must be done when the comparison between the quantity in the cart and the actual availability is made.

Does anyone know what is the function that deals with the comparison in the cart?
Thanks.

Studio 42

Your explain are very strange, i know VM code but dont understand.
Say for eg. current stock is 5
You do a cart of quantity 10, your stock is -5 after customer's checkout.
If you use stock handle, customer can only buy 5 and stock is 0.
If you use the last case, then you can perhaps suggest user to register as "stay me informed' for the product.
Another solution is to use a simple Joomla system plugin function onAfterRoute checking for stock and save the missing stock in a table, because you dont want prevent the standard add to cart.
Of course you have to get the Joomla user infos(if you get it), if you want send him a mail after or use the session to follow the user actions and collect user informations from order after .

guardiano78

#6
Hello Studio 42,
thank you for response.

In fact I already use a custom plugin that takes care of putting the products out of stock in backorder.
So I just need to insert in the table used by the backorder, the products that could not be sold due to lack of stock.
For the moment I'm proceeding like this:

In cart page:

<?php 
// get Joomla session object
$session JFactory::getSession();

// get current session cart data
$session->set('carrello'$session->get('vmcart',0,'vm')); //i put in session a variable with the cart data before checkout
?>



In cart.php

public function emptyCart(){

// get Joomla session object
$session = JFactory::getSession();

// get current session cart data
$carrello = json_decode($session->get('carrello')); //I get cart data before checkout

self::emptyCartValues($this, $carrello);

}

/**
* emptyCart: Used for payment handling.
*
* @author Valerie Cartan Isaksen
*
*/
static public function emptyCartValues(&$cart, $carrello, $session = true){

JFactory::getApplication()->enqueueMessage('forse ho trovato il punto giusto');
//print_r($cart);
file_put_contents("ciao.txt", print_r($cart->cartProductsData)); //print cart data after checkout -  Array ( [0] => Array ( [virtuemart_product_id] => 73469 [quantity] => 2 [customProductData] => Array ( ) ) )
file_put_contents("ciao.txt", print_r($carrello->cartProductsData)); //print cart data before checkout - Array ( [0] => stdClass Object ( [virtuemart_product_id] => 73469 [quantity] => 4 [customProductData] => Array ( ) ) ) 

                //now i have to compare product_id and quantity between cart data before chechout and cart data after checkout



//We delete the old stuff
$cart->products = array();
$cart->cartProductsData = array();
$cart->cartData = array();
$cart->cartPrices = array();
$cart->cartfields = array();
$cart->_inCheckOut = false;
$cart->_dataValidated = false;
$cart->_confirmDone = false;
$cart->couponCode = '';
$cart->order_language = '';
$cart->virtuemart_shipmentmethod_id = 0; //OSP 2012-03-14
$cart->virtuemart_paymentmethod_id = 0;
$cart->order_number=null;
$cart->_fromCart = false;
$cart->_inConfirm = false;
$cart->totalProduct=false;
$cart->productsQuantity=array();
$cart->virtuemart_order_id = null;

if($session){
$cart->deleteCart();
$cart->setCartIntoSession(false,true);
}
}


This solution may work fine in your opinion?

Thank you.

Studio 42

Hum ,for me your solution is bad because.
- you use a text file
- the file "ciao.txt" have no path
If you want to add trigger, you can create a shipment plugin and function plgVmConfirmedOrder, this should always be called before cart is empty and dont need to modify core file.
for the add to cart the method explained before should work.
If you create a system plugin, you can add the two trigger, you have only to load some Virtuemart class or config perhaps, if it not work
So you need to include
class PlgSystemMYPLUGIN extends JPlugin
{
function onAfterRoute(){
  //Check if option = com_viruemart and task = add or addJS, collect the quantities and set product with lowstock in a table. Do same perhaps on quantity update, product remove ...
}
function plgVmConfirmedOrder(){
  //here you can check the cart content again if needed ?
}
}

guardiano78

Hi Studio 42,
"ciao.txt" only served to display the contents of the arrays.

Unfortunately I do not have the knowledge to create a plugin yet.
But I got the desired result by inserting some code in cart.php as I wrote in the previous post.

Writing the code in the function "emptyCartValues", i verified that it works with all the payment methods i use, including paypal.

Thanks for the help.

Studio 42

I only give you the general concept to do it without hacks