Reputation: 4144
I create a custom feed for OpenCart.
I am trying to get a list of order details from OpenCart 1.54, however, I cannot find any JSON. Is there a way to return an error message, if the query fails?
Here is the URL to access:
/index.php?route=feed/api&func=getOrderProducts&orderid=1&email=xyz
My plugin files are here:
http://support.cloudcartconnector.com/hc/en-us/articles/202592798-OpenCart
On my test site, this works fine:
public function getOrderProducts($orderid) {
$query = $this->db->query("SELECT op.*, pr.sku, pr.quantity as stock FROM `" . DB_PREFIX . "order_product` op INNER JOIN `product` pr on op.product_id = pr.product_id WHERE op.order_id = '" . $this->db->escape($orderid) . "'");
return $query->rows;
}
I have no order prefix in my database. Here is the response:
[{"order_product_id":"1","order_id":"1","product_id":"43","name":"MacBook","model":"Product 16","quantity":"1","price":"500.0000","total":"500.0000","tax":"89.5000","reward":"600","sku":"macproduct1","stock":"927"}]
On several live sites, the code fails and I receive a blank white page. Here is the route itself:
// example function - getOrders from the database
private function getOrderProducts() {
if($this->request->get['email'] != "[email protected]")
{
return "INVALID EMAIL";
}
$this->load->model('feed/api');
return $this->model_feed_api->getOrderProducts($this->request->get['orderid']);
}
My code for getOrders work fine:
public function getOrders($beginDate, $endDate) {
$query = $this->db->query("select o.*, os.* from `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_status os ON (o.order_status_id = os.order_status_id) where o.Date_Added >= $beginDate AND o.Date_Added <= $endDate");
return $query->rows;
}
The route for getOrderProducts actually works. If I put in a bad email, it returns INVALID EMAIL. Is there a way to return an exception message?
Upvotes: 0
Views: 646
Reputation: 393
$this->request->get['orderid']
Maybe it's order_id
(note underscore). It's a common name of the order ID value for OpenCart.
Change that code into
$this->request->get['order_id']
Upvotes: 1