batZpk Posted December 23, 2016 Share Posted December 23, 2016 Hello, I'm a french developer and i actually work on prestoshop for my boss I have a little problem with my validateOrder function ans i hope find some help on the forum So, I override the valideOrder function because i have some warehouses and won't receive splitted orders. No problems for that ... BUT , when i try to change order state , i have an error on the "front" side : ("We found problems with your order , please contact support") In my backoffice, the order is OK and no problems appears (the pink is the good state) So i don't know why and search in many topics but nothing work :/ I tried to change state whith php code in PayementModule class at the end of file : if($changestate == true){ $mystate = '31'; $new_history = new OrderHistory(); $new_history->id_order = (int)$order->id; $new_history->changeIdOrderState((int)$mystate, $order, true); } But always the error. So for simple, i just want to change the state of my order when appear in the BO , after the confirmation . Can someone help me ? Thanks Link to comment Share on other sites More sharing options...
bellini13 Posted December 23, 2016 Share Posted December 23, 2016 If I had to guess, your payment module is not expecting this order status 31, and thinks it represents a failure state. Maybe you should look at the payment module code (orderConfirmation or paymentReturn hook) Link to comment Share on other sites More sharing options...
batZpk Posted December 23, 2016 Author Share Posted December 23, 2016 (edited) Thanks for you reply You mean i need to check the orderConfirmation or the paymentReturn function present in the Payment Module ? Because i don't know how to use hook in a class PS: This modification is not for a module payment but for all payment Thanks you again Edited December 23, 2016 by batZpk (see edit history) Link to comment Share on other sites More sharing options...
batZpk Posted December 26, 2016 Author Share Posted December 26, 2016 (edited) Hello guys ! Happy christmas !! So , i use this: If I had to guess, your payment module is not expecting this order status 31, and thinks it represents a failure state. Maybe you should look at the payment module code (orderConfirmation or paymentReturn hook) to find a solution for my problem. I learn a lot about hook in prestashop and i try to use many of them to change my order's state but when i try it and obtain a result, my new state is not the last state saved in the order ... someone can help me ? Thanks Edited December 26, 2016 by batZpk (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted December 26, 2016 Share Posted December 26, 2016 well, if i understand you properly, you changed the core PaymentModule class, and hard coded it to use order status 31 when changestate is true. which is fine, i guess... however once the order is created, and the customer is redirected to the order confirmation page, it is the payment module used for payment that is likely have the issue. It either does not know what order status 31 is, or it does not think that order status 31 is 'valid'. Link to comment Share on other sites More sharing options...
batZpk Posted December 27, 2016 Author Share Posted December 27, 2016 (edited) Hello bellini13 i'm glad to see your reply and spend time with me about this subject. So i change anything in the core PaymentModule Class . I prefer to override classes as desired by the Prestashop coding convention. I wanted to be able to work separately on this process in order to make it available later. Following our last message: If I had to guess, your payment module is not expecting this order status 31, and thinks it represents a failure state. Maybe you should look at the payment module code (orderConfirmation or paymentReturn hook) I created a module WHAT I WANT : When an order is update to the "Payment accepted" state, i need to check a param(bool) saved in the DB to know if is a splitted order or not . If yes, i need to check if this state (Payement accepted) is the last state saved and if yes, i need to change to my state (31). The state 31 is for "wait warehouse transfer": I created a module to act on the hooks (also to group other functions to avoid splitted orders with ASM): class splittedorders extends Module { public function __construct() { $this->name = 'splittedorders'; $this->version = '0.1'; $this->displayName = 'Splitted Orders'; $this->author = 'R Baptiste'; parent::__construct(); $this->description = $this->l('Analyse et traite les processus concernant les commandes scindées'); $this->confirmUninstall = $this->l('certain ?'); } public function install() { if ( !parent::install() OR !$this->registerHook('actionOrderStatusPostUpdate') ) return false; return true; } public function uninstall() { if ( !parent::uninstall() ) return false; return true; } //Hook tested separatly public function hookActionPaymentConfirmation($params) { } public function hookDisplayOrderConfirmation($params) { if($params['newStateOrder'] == 2){ $objOrder = $params['objOrder']; $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState((int)31), (int)($objOrder->id)); } } public function hookActionOrderStatusPostUpdate($params) { } } When i try them, i can't update the state of my order for 2 reasons : No update of the state OR the state was saved before the "Payment accepted" state . So i don't know what i need to do Edited December 27, 2016 by batZpk (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted December 27, 2016 Share Posted December 27, 2016 So to confirm, you no longer have a PaymentModule override? you have instead created a module? If so, good choice. If not, and you have both an override and a module, please explain what the override is doing? As for the module, the orderconfirmation hook receives the following parameters $params['total_to_pay'] = $order->getOrdersTotalPaid(); $params['currency'] = $currency->sign; $params['objOrder'] = $order; $params['currencyObj'] = $currency; 'newStateOrder' is not one of them, so your module is coded wrong. If you want to get the current order status, then you should do something like... public function hookDisplayOrderConfirmation($params) { $objOrder = $params['objOrder']; $current_state = $objOrder>getCurrentState(); if($current_state == 2) { $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState((int)31), (int)($objOrder->id)); } } I did not test this, but that should give you an idea of what needs to be done. If this does not work, then you need to figure out what current_state actually is, maybe it is not 2 Link to comment Share on other sites More sharing options...
batZpk Posted December 28, 2016 Author Share Posted December 28, 2016 (edited) Hello Bellini13 , According your older post : So to confirm, you no longer have a PaymentModule override? you have instead created a module? If so, good choice. If not, and you have both an override and a module, please explain what the override is doing? As for the module, the orderconfirmation hook receives the following parameters $params['total_to_pay'] = $order->getOrdersTotalPaid(); $params['currency'] = $currency->sign; $params['objOrder'] = $order; $params['currencyObj'] = $currency; 'newStateOrder' is not one of them, so your module is coded wrong. If you want to get the current order status, then you should do something like... public function hookDisplayOrderConfirmation($params) { $objOrder = $params['objOrder']; $current_state = $objOrder>getCurrentState(); if($current_state == 2) { $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState((int)31), (int)($objOrder->id)); } } I did not test this, but that should give you an idea of what needs to be done. If this does not work, then you need to figure out what current_state actually is, maybe it is not 2 Can you help me with the hookActionPaymentConfirmation ? Because $params no receive $objOrder . Can i try to do that ? $objOrder = new Order($order_id); $current_state = $objOrder>getCurrentState(); $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState((int)31), (int)($objOrder->id)); Thanks Edited December 28, 2016 by batZpk (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted December 28, 2016 Share Posted December 28, 2016 'actionPaymentConfirmation' only receives a single parameter, which is the order ID 'id_order' Hook::exec('actionPaymentConfirmation', array('id_order' => (int)$order->id), null, false, true, false, $order->id_shop); so you can create the Order Object your self if you need, but I don't see any reason you would need the order object $objOrder = new Order($params['id_order']); Link to comment Share on other sites More sharing options...
batZpk Posted December 28, 2016 Author Share Posted December 28, 2016 Thanks for your reply I post my hookActionPaymentConfirmation because when i try to change the state's order, the state still "Payement accepted" and there are no insert in ps_order_history table. public function hookActionPaymentConfirmation($params) { //var_dump($params);die; //récuperer commande $order = new Order($params['id_order']); //recuperer produits $products = OrderDetailCore::getList($order->id); //check entrepots $detailsStocks = array(); foreach ($products as $product){ if($product['split'] == '1'){ $warehouse_list = Warehouse::getWarehousesByProductId($product['product_id'],$product['product_attribute_id']); $warehouseProduct = array(); $warehouseProduct['id_order_detail'] = $product['id_order_detail']; $warehouseProduct['id_order'] = $product['id_order']; $warehouseProduct['id_product'] = $product['product_id']; $warehouseProduct['id_product_attribute'] = $product['product_attribute_id']; $warehouseProduct['quantity'] = $product['product_quantity']; $warehouseProduct['warehouse_final'] = $product['id_warehouse']; $temp = array(); foreach ($warehouse_list as $warehouse){ $warehouseStock = array(); $stock = new StockManager(); $stock = $stock->getProductRealQuantities( $product['product_id'],$product['product_attribute_id'], $warehouse['id_warehouse']); $warehouseStock['id'] = $warehouse['id_warehouse']; $warehouseStock['quantity'] = $stock; array_push($temp, $warehouseStock); } $warehouseProduct['stock']=$temp; array_push($detailsStocks, $warehouseProduct); } } //add transits foreach ($detailsStocks as $product){ $w = 0; $x = 0; foreach ($product['stock'] as $p){ if($p['quantity'] > $x){ $x = $p['quantity']; $w = $p['id']; } } $sql = 'SELECT * FROM '._DB_PREFIX_.'transit WHERE id_product = '.$product['id_product'].' AND id_product_attribute = '.$product['id_product_attribute'].' AND source = '.$product['id_order'].';'; if(!$row = Db::getInstance()->executeS($sql)){ $sql = 'INSERT INTO '._DB_PREFIX_.'transit(id_warehouse_import, id_warehouse_export, id_product, id_product_attribute, quantity, source) VALUES('.$product['warehouse_final'].','.$w.','.$product['id_product'].','.$product['id_product_attribute'].','.$product['quantity'].','.$product['id_order'].');'; if(!$row2 = Db::getInstance()->execute($sql)){ return false; } }; } //changeState $history = new OrderHistory(); $history->id_order = (int)$order->id; $history->changeIdOrderState((int)31, (int)($order->id)); } Why i can't change state's order ? Thanks Link to comment Share on other sites More sharing options...
bellini13 Posted December 28, 2016 Share Posted December 28, 2016 i don't know, you will have to debug the changeIdOrderState function to see what is happening Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now