Jump to content

Get Carrier name by ID


fortuner

Recommended Posts

Hello!

I'm stuck with getting Carrier name for order in Backoffice.

I've got order id and carrier id and I need to get carreir name.

I've wrote a query in Order.php as follows:

public static function getCarrierName($id_order)
{
	return Db::getInstance()->executeS('
		SELECT
		
		cl.`name` as `carrier_name`
		FROM `'._DB_PREFIX_.'order_carrier` oc
		LEFT JOIN `'._DB_PREFIX_.'carrier` cl
			ON (oc.`id_carrier` = cl.`id_carrier`)
		WHERE oc.`id_order` = '.(int)$id_order);
	
}

when I use this in module like this:

$orders = Order::getOrdersWithInformations($limit);
$body = array();
foreach ($orders as $order)
{
 $id_order = $order['id_order'];
 $carrier = array();
 $carrier = Order::getCarrierName((int)$id_order);
 $tr = array();
 $tr[] = array(
  'id' => 'status',
  'value' => $carrier,
  'class' => 'text-center',
 );
}

it throws [object Object] error.

And if I use

$carrier['carrier_name']

it throws null

 

I assume my mistake is in calling array value.

Please help somebody, i'm desperate

Link to comment
Share on other sites

  • 4 years later...
On 7/19/2016 at 2:33 AM, fortuner said:

Hello!

I'm stuck with getting Carrier name for order in Backoffice.

I've got order id and carrier id and I need to get carreir name.

I've wrote a query in Order.php as follows:


public static function getCarrierName($id_order)
{
	return Db::getInstance()->executeS('
		SELECT
		
		cl.`name` as `carrier_name`
		FROM `'._DB_PREFIX_.'order_carrier` oc
		LEFT JOIN `'._DB_PREFIX_.'carrier` cl
			ON (oc.`id_carrier` = cl.`id_carrier`)
		WHERE oc.`id_order` = '.(int)$id_order);
	
}

when I use this in module like this:


$orders = Order::getOrdersWithInformations($limit);
$body = array();
foreach ($orders as $order)
{
 $id_order = $order['id_order'];
 $carrier = array();
 $carrier = Order::getCarrierName((int)$id_order);
 $tr = array();
 $tr[] = array(
  'id' => 'status',
  'value' => $carrier,
  'class' => 'text-center',
 );
}

it throws [object Object] error.

And if I use

$carrier['carrier_name']

it throws null

 

I assume my mistake is in calling array value.

Please help somebody, i'm desperate

not oc.`id_carrier`

but a.`id_carrier`

regarding to AdminOrdersConstroller constructor.

Edited by Inter Svetainė (see edit history)
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...