Jump to content

Prestashop - how to clear cart only after successful payment?


Recommended Posts

Hello guys,

 

I am using a custom payment module which can be found here: 

http://addons.prestashop.com/en/payments-gateways-prestashop-modules/17250-custom-payment-method.html

 

The module's basic functionality was tweaked a bit so that once I create an order it redirects me to the payment gateway and after payment (regardless if successful or not) it redirects me to the return page which display the shipment tracking code and other information (or not if payment failed). I don't mind it creating an error before successful payment. My question is: how can I prevent Prestashop from clearing my cart before heading to the gateway? I noticed that if I go to the gateway and the payment fails I am redirected back to the page with the the cart emptied.

 

Basically I want to comment out that part of the code that clears the cart and add it to the bit that handles successful transfers only. I just need someone to pinpoint it for me.

 

Here's the snippet of code from the module that handles this issue:

/**************************************************************************************************************************************/

$this->module->validateOrder((int)$cart->id,
$id_order_state,
$total, (Tools::strlen($custom_payment->name) ? $custom_payment->name : 'custom payment method'),
null,
$mail_vars,
(int)$currency->id,
false,
$customer->secure_key);
$order = new Order($this->module->currentOrder);
CustomPayment::addOrderCommission($this->module->currentOrder, $this->context->currency->id, $commission);
 
$total_paid = $order->total_paid + $commission;
$order->total_paid = ($total_paid < 0 ? 0 : $total_paid);
$total_paid_tax_excl = $order->total_paid_tax_excl + $commission;
$order->total_paid_tax_excl = ($total_paid_tax_excl < 0 ? 0 : $total_paid_tax_excl);
$total_paid_tax_incl = $order->total_paid_tax_incl + $commission;
$order->total_paid_tax_incl = ($total_paid_tax_incl < 0 ? 0 : $total_paid_tax_incl);
$order->save();
/**************************************************************************************************************************************/
 
Thanks in advance for anyone who can help.
Link to comment
Share on other sites

Hello Vekia,

 

Thank you for your quick reply. If that's the case then can you please elaborate on what's happening in this website: http://rouladfouni.com/shop ?? I just created an account and completed the checkout process and in the end I clicked on "pay by paypal". Once I was redirected I entered wrong credentials (therefore no order payment) and went back to the website and my order was still there. Is there something I'm missing here?

 

Much appreciated. 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Hello Vekia,

 

Thank you for your quick reply. If that's the case then can you please elaborate on what's happening in this website: http://rouladfouni.com/shop ?? I just created an account and completed the checkout process and in the end I clicked on "pay by paypal". Once I was redirected I entered wrong credentials (therefore no order payment) and went back to the website and my order was still there. Is there something I'm missing here?

 

Much appreciated. 

Isn't the fundamental difference that on your site, an order is created BEFORE payment.  I didn't visit this other website, but you failed to mention if an order was created BEFORE you went to paypal..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...