Jump to content

PS 1.7 - Call custom action with url from AdminOrdersController


mohozah34

Recommended Posts

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();

				}
				
			}
			
			
		}
	
		
	}

 

Edited by mohozah34 (see edit history)
Link to comment
Share on other sites

Hi,

As you can see in the following code : https://github.com/PrestaShop/PrestaShop/blob/develop/classes/controller/AdminController.php#L931
When you want to call an action the method name should be in this format 'process' . ucfirst(Tools::toCamelCase($this->action))
So in your case the name of your method should be processInitkm()
By the way it's not the recommended way to put your changes in this file, you should use overrides.

Regards,

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...