public function changeIdOrderState($new_order_state = NULL, $id_order) { if ($new_order_state != NULL) { Hook::updateOrderStatus(intval($new_order_state), intval($id_order)); /* Best sellers */ $newOS = new OrderState(intval($new_order_state)); $oldOrderStatus = OrderHistory::getLastOrderState(intval($id_order)); $cart = Cart::getCartByOrderId($id_order); $isValidated = $this->isValidated(); if (Validate::isLoadedObject($cart)) { foreach ($cart->getProducts() as $product) { /* If becoming logable => adding sale */ if ($newOS->logable and (!$oldOrderStatus or !$oldOrderStatus->logable)) { ProductSale::addProductSale($product['id_product'], $product['cart_quantity']); } elseif (!$newOS->logable and ($oldOrderStatus and $oldOrderStatus->logable)) { ProductSale::removeProductSale($product['id_product'], $product['cart_quantity']); } if (!$isValidated and $newOS->logable and isset($oldOrderStatus) and $oldOrderStatus and $oldOrderStatus->id == _PS_OS_ERROR_) { Product::updateQuantity($product); Hook::updateQuantity($product, $order); } } } $this->id_order_state = intval($new_order_state); /* Change invoice number of order ? */ $newOS = new OrderState(intval($new_order_state)); $order = new Order(intval($id_order)); if (!Validate::isLoadedObject($newOS) or !Validate::isLoadedObject($order)) { die(Tools::displayError('Invalid new order state')); } /* The order is valid only if the invoice is available and the order is not cancelled */ $order->valid = $newOS->logable; $order->update(); if ($newOS->invoice and !$order->invoice_number) { $order->setInvoice(); } if ($newOS->delivery and !$order->delivery_number) { $order->setDelivery(); } Hook::postUpdateOrderStatus(intval($new_order_state), intval($id_order)); } }