piribipipi Posted October 13, 2014 Share Posted October 13, 2014 Hola, i created a new payment module from authorize.net module. In my module, i have next php code: if (!Validate::isLoadedObject($cart)) { Logger::addLog('Cart loading failed for cart '.(int)$_POST['x_invoice_num2'], 4); die('An unrecoverable error occured with the cart '.(int)$_POST['x_invoice_num2']); } A client had obtained that error message (An unrecoverable error ocurred with the cart....) when he was validating an order, but order was correctly validated. What happens?? I think that could be that the client have clicked sometimes the "Validate Order" button, because he thought that the process was too slow, but the process had finished and when he clicked the button again process was restarted, but the cart were eliminated and that generated the error.... I hope you understand me... someone could help me with this???? :S thanks Link to comment Share on other sites More sharing options...
NemoPS Posted October 13, 2014 Share Posted October 13, 2014 It would be better to see the whole class. Actually that is not the code that creates order, it simply checks that the cart object exists as prestashop object model instance. WHat you shoud look for is $this->validateOrder(..) or $this->module if it's controller Link to comment Share on other sites More sharing options...
bellini13 Posted October 13, 2014 Share Posted October 13, 2014 As Nemo1 stated, this is just checking that the $cart variable is a valid object and that it exists. if (!Validate::isLoadedObject($cart)) It would be good to see how $cart is defined prior to this? Is it pulled from the context? Is the file that this code is in, called from the customers browser, or from the gateways server? Link to comment Share on other sites More sharing options...
piribipipi Posted October 13, 2014 Author Share Posted October 13, 2014 That code is included into a validation php file, that is inmediatly called after click into "Validate Order" button, so that code is called from customer browser.... Here is how my validation.php file starts: include(dirname(__FILE__). '/../../config/config.inc.php'); include(dirname(__FILE__). '/../../init.php'); /* will include backward file */ include(dirname(__FILE__). '/purchaseorder.php'); $authorizeaim = new Purchaseorder(); /* Does the cart exist and is valid? */ $cart = Context::getContext()->cart; if (!isset($_POST['purchaseorder']) || strlen(trim($_POST['purchaseorder']))==0) { Logger::addLog('Missing purchaseorder', 4); die('You need to add Purchase Order'); } if (!Validate::isLoadedObject($cart)) { Logger::addLog('Cart loading failed for cart '.(int)$_POST['x_invoice_num2'], 4); die('An unrecoverable error occured with the cart '.(int)$_POST['x_invoice_num2']); } if ($cart->id != $_POST['x_invoice_num2']) { Logger::addLog('Conflict between cart id order and customer cart id'); die('An unrecoverable conflict error occured with the cart '.(int)$_POST['x_invoice_num2']); } .......... $authorizeaim->validateOrder((int)$cart->id, 14, (float)$orderTotal, $payment_method, $ErrorMessage, NULL, NULL, false, $customer->secure_key); That code it was copied from authorizeaim module included into prestashop... But the problem is that i dont know why the client entered into the "!Validate::isLoadedObject($cart)" .... because the order is validated!!!! it´s the client triggering this script more than 1 time?? Thanks! Link to comment Share on other sites More sharing options...
bellini13 Posted October 13, 2014 Share Posted October 13, 2014 its not a order issue, it is a cart issue. The code is checking to ensure the cart object is valid, and it is taking the cart object from the context. So as Nemo1 stated, perhaps they double clicked the validate order button. The order was created on the first click and the cart was removed from the context. So when the validate.php is called from that second button click, the cart object in the context would not be valid. Therefore you would enter your if statement Link to comment Share on other sites More sharing options...
piribipipi Posted October 13, 2014 Author Share Posted October 13, 2014 $('#asubmit2').click(function() { $('#asubmit2').attr('disabled','disabled'); //ADDED if ($.trim($('#purchaseorder').val()) == '') { alert(mess_error); $('#asubmit2').attr('disabled',false); //ADDED } else { $('#purchaseorder_form').submit(); return false; } }); Here is javascript code launched when user click "Validate Order" button... I added the line $('#asubmit2').attr('disabled','disabled'); If i´m not wrong, this line disabled button, so client cant click it again and code can´t be launched again... But a client obtained the error after y made that modification :S Link to comment Share on other sites More sharing options...
bellini13 Posted October 13, 2014 Share Posted October 13, 2014 in any event, your code is being triggered because the cart object is not a valid object. how that happened is for you to figure out, we are merely giving you ideas based on our experience. Link to comment Share on other sites More sharing options...
piribipipi Posted October 13, 2014 Author Share Posted October 13, 2014 I´m thankful for your help! I knew that the problem is because $cart is not a valid object, but i dont know why that happens... There are serveral options, but it´s very strange that 2 of the last 5 order had that problem :S I assumed that if I disabled the "Validate Order" buttom, code only could be triggered 1 time... but not... Link to comment Share on other sites More sharing options...
Recommended Posts