Thanks a LOT, awesome! I'm trying to make it work but have a couple of questions.
On the line below where the order status is changed, the code chokes on an exception, although the order's status gets updated(?!), but the execution is terminated to this line.
$history->changeIdOrderState((int)$order_state , $kb_order_obj, $use_existings_payment);
I'm trying to pass 2 as the $order_state which in my installation is the Payment Accepted.
PHP Notice: Trying to get property 'precision' of non-object in /path/public_html/classes/Context.php on line 498 PHP Fatal error: Uncaught TypeError: Argument 1 passed to PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision::getPrecision() must be of the type int, null given, called in /path/public_html/classes/Context.php on line 498 and defined in /path/public_html/src/Core/Localization/CLDR/ComputingPrecision.php:41 Stack trace: #0 /path/public_html/classes/Context.php(498): PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision->getPrecision() #1 /path/public_html/classes/order/Order.php(1465): ContextCore->getComputingPrecision() #2 /path/public_html/classes/order/Order.php(1353): OrderCore->setInvoiceDetails() #3 /path/public_html/classes/order/OrderHistory.php(371): OrderCore->setInvoice() #4 /path/public_html/awtest.php(19): OrderHistoryCore->changeIdOrderState( in /path/public_html/src/Core/Localization/CLDR/ComputingPrecision.php on line 41
I think it has something to do with the first argument. is there something wrong witht he casting? I've tried plain number, variable, casted/uncasted.
I've checked the files in the stacktrace, and parameters and types passed seem to be ok to me.
Not sure if it matters, but I'm currently running this as a "standalone" php script and not as Presta standard file etc.
Here's the whole code:
<?php require(dirname(__FILE__).'/config/config.inc.php'); $order_state = 2; //Payment Accepted $bot_employee_id = 14; $kb_order_obj = new Order(4617); $history = new OrderHistory(); $history->id_order = $kb_order_obj->id; $history->id_employee = (int)$bot_employee_id; // $this->context->employee->id; $use_existings_payment = false; if (!$kb_order_obj->hasInvoice()) { $use_existings_payment = true; } $history->changeIdOrderState((int)$order_state , $kb_order_obj, $use_existings_payment); // $carrier = new Carrier($kb_order_obj->id_carrier, $kb_order_obj->id_lang); // $templateVars = array(); // if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $kb_order_obj->shipping_number) { // $templateVars = array('{followup}' => str_replace('@', $kb_order_obj->shipping_number, $carrier->url)); // } // if ($history->addWithemail(true, $templateVars)) { // // synchronizes quantities if needed.. // if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { // foreach ($kb_order_obj->getProducts() as $product) { // if (StockAvailable::dependsOnStock($product['product_id'])) { // StockAvailable::synchronize($product['product_id'],(int) $product['id_shop']); // } // } // } // } echo "Order ID: ".$kb_order_obj->id."\n"; echo "Order reference: ".$kb_order_obj->reference."\n"; ?>