Hello ,
I have an issue with an custom action i created in Controllers/admin/AdminOrdersController ,
I'm trying to call it with the following url : .../index.php?controller=AdminOrders&action=initkm&token=fe29dbd1ec67b6330319434d7a3cc6dd
I have no errors , the action has to do some stuff in the database and don't render or return anything but nothing happens..
I don't know if i am doing it right , i know i can create a module for this but it's a simple function for cleaning some products from orders.
Thank you for the help !
Controllers/admin/AdminOrdersController ACTION : initKm() :
public function initKm(){ echo "zoulou"; $orders_qy = Db::getInstance()->ExecuteS('SELECT o.id_order as idOrder FROM pskenza_orders o'); echo var_dump($orders_qy); if($orders_qy){ foreach($orders_qy as $o){ $id_order = (int)$o['idOrder']; $order = new Order($id_order); $orders_details_qy = Db::getInstance()->ExecuteS('SELECT * FROM pskenza_order_detail WHERE id_order ='.$id_order.' AND product_reference like "MK%"'); foreach($orders_details_qy as $d){ $order_detail = new OrderDetail((int)$d['id_order_detail']); if ($order_detail->id_order_invoice != 0) { $order_invoice = new OrderInvoice($order_detail->id_order_invoice); $order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl; $order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl; $order_invoice->total_products -= $order_detail->total_price_tax_excl; $order_invoice->total_products_wt -= $order_detail->total_price_tax_incl; $res &= $order_invoice->update(); } $order->total_paid -= $order_detail->total_price_tax_incl; $order->total_paid_tax_incl -= $order_detail->total_price_tax_incl; $order->total_paid_tax_excl -= $order_detail->total_price_tax_excl; $order->total_products -= $order_detail->total_price_tax_excl; $order->total_products_wt -= $order_detail->total_price_tax_incl; $res &= $order->update(); // Reinject quantity in stock $this->reinjectQuantity($order_detail, $order_detail->product_quantity, true); // Update weight SUM $order_carrier = new OrderCarrier((int)$order->getIdOrderCarrier()); if (Validate::isLoadedObject($order_carrier)) { $order_carrier->weight = (float)$order->getTotalWeight(); $res &= $order_carrier->update(); if ($res) { $order->weight = sprintf("%.3f ".Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); } } // Get invoices collection $invoice_collection = $order->getInvoicesCollection(); $invoice_array = array(); foreach ($invoice_collection as $invoice) { /** @var OrderInvoice $invoice */ $invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int)$order->id_shop); $invoice_array[] = $invoice; } $order = $order->refreshShippingCost(); } } } }