Post by Tárraga » Tue Sep 21, 2021 8:13 pm

Hi there!

I need to change the order status and add a history with a external php. (something like file.php?order_id=65489&status=sent)

What file should I include so I can access $this->model_checkout_order->addOrderHistory($order_id, $status, $comment, $notify) ?

Newbie

Posts

Joined
Tue Sep 21, 2021 8:10 pm

Post by straightlight » Tue Sep 21, 2021 10:38 pm

Tárraga wrote:
Tue Sep 21, 2021 8:13 pm
Hi there!

I need to change the order status and add a history with a external php. (something like file.php?order_id=65489&status=sent)

What file should I include so I can access $this->model_checkout_order->addOrderHistory($order_id, $status, $comment, $notify) ?
OC version. By following these:

- viewtopic.php?f=202&t=220903#p805005
- https://github.com/opencart/opencart/wiki/Events-System

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by thekrotek » Tue Sep 21, 2021 10:50 pm

Tárraga wrote:
Tue Sep 21, 2021 8:13 pm
What file should I include so I can access $this->model_checkout_order->addOrderHistory($order_id, $status, $comment, $notify) ?
You already have the answer to your question.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by Tárraga » Wed Sep 22, 2021 1:58 pm

I found out how to do this. Here's my code:

Code: Select all

class ControllerCustomStatus extends Controller {
	public function index() {

    $this->load->model('checkout/order');

    $order_id = $this->request->get['id'];
    $status = $this->request->get['status'];

    $this->model_checkout_order->addOrderHistory($order_id, $status, '', '1');
  }
}
Now I'm trying to get the current order status but I can't find the function that returns that. Any ideas?

Newbie

Posts

Joined
Tue Sep 21, 2021 8:10 pm

Post by ADD Creative » Wed Sep 22, 2021 4:24 pm

Be careful with that code, it would allow anyone to change the status of their order. You would need some sort of access control.

To get the status of an order.

Code: Select all

$order_info = $this->model_checkout_order->getOrder($order_id);

$order_info['order_status_id'];

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by straightlight » Wed Sep 22, 2021 6:14 pm

Tárraga wrote:
Wed Sep 22, 2021 1:58 pm
I found out how to do this. Here's my code:

Code: Select all

class ControllerCustomStatus extends Controller {
	public function index() {

    $this->load->model('checkout/order');

    $order_id = $this->request->get['id'];
    $status = $this->request->get['status'];

    $this->model_checkout_order->addOrderHistory($order_id, $status, '', '1');
  }
}
Now I'm trying to get the current order status but I can't find the function that returns that. Any ideas?

Code: Select all

$order_id = $this->request->get['id'];
should be:

Code: Select all

if (isset($this->request->get['order_id'])) {
	$order_id = (int)$this->request->get['order_id'];
} elseif (isset($this->request->post['order_id'])) {
	$order_id = (int)$this->request->post['order_id'];
} else {
	$order_id = 0;
}

$this->load->model('checkout/order');

$order_info = $this->model_checkout_order->getOrder($order_id);

if ($order_info) {
    /* Your code here */
}

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 91 guests