Post by thng » Thu Nov 16, 2017 8:47 pm

Hi,
OC 2.0.1.1

I'm trying to echo shipping_firstname, shipping_lastname, etc. in admin/view/template/sale/order_shipping.tpl in a table, each piece of address in separate column.
However I can't find the working variable, for example <?php echo $data['shipping_firstname']; ?> and <?php echo $order_info['shipping_firstname']; ?> aren't working.
Should I modify the controller file order.php?

Best regards :)

New member

Posts

Joined
Wed Nov 19, 2014 10:40 pm

Post by straightlight » Thu Nov 16, 2017 10:09 pm

The only modifications needed, in this case, since you wish to output results from TPL files would be to replace:

Code: Select all

<?php echo $data['shipping_firstname']; ?> and <?php echo $order_info['shipping_firstname']; ?>
with:

Code: Select all

<?php echo $shipping_firstname; ?>
If $data and $order_info are being used on different conditions in TPL files, then you need to look at the relevant key names from the related controller files from where you'd like to output those keys in the TPL files.

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 thng » Thu Nov 16, 2017 10:32 pm

Thanks for the reply!
That's exactly my problem, I can't figure out which variable to use, because <?php echo $shipping_firstname; ?> also doesn't work - the variable is undefined :/
I'm too ignorant with php to figure this out in the order.php controller file. There are a few places where shipping_firstname is used:
line 734

Code: Select all

$data['shipping_firstname'] = $order_info['shipping_firstname'];
			$data['shipping_lastname'] = $order_info['shipping_lastname'];
			$data['shipping_company'] = $order_info['shipping_company'];
			$data['shipping_address_1'] = $order_info['shipping_address_1'];
			$data['shipping_address_2'] = $order_info['shipping_address_2'];
			$data['shipping_city'] = $order_info['shipping_city'];
			$data['shipping_postcode'] = $order_info['shipping_postcode'];
			$data['shipping_country_id'] = $order_info['shipping_country_id'];
			$data['shipping_zone_id'] = $order_info['shipping_zone_id'];
			$data['shipping_custom_field'] = $order_info['shipping_custom_field'];
			$data['shipping_method'] = $order_info['shipping_method'];
			$data['shipping_code'] = $order_info['shipping_code'];
			
line 830

Code: Select all

$data['shipping_firstname'] = '';
			$data['shipping_lastname'] = '';
			$data['shipping_company'] = '';
			$data['shipping_address_1'] = '';
			$data['shipping_address_2'] = '';
			$data['shipping_city'] = '';
			$data['shipping_postcode'] = '';
			$data['shipping_country_id'] = '';
			$data['shipping_zone_id'] = '';
			$data['shipping_custom_field'] = array();
			$data['shipping_method'] = '';
			$data['shipping_code'] = '';
line 1345

Code: Select all

// Shipping
			$data['shipping_firstname'] = $order_info['shipping_firstname'];
			$data['shipping_lastname'] = $order_info['shipping_lastname'];
			$data['shipping_company'] = $order_info['shipping_company'];
			$data['shipping_address_1'] = $order_info['shipping_address_1'];
			$data['shipping_address_2'] = $order_info['shipping_address_2'];
			$data['shipping_city'] = $order_info['shipping_city'];
			$data['shipping_postcode'] = $order_info['shipping_postcode'];
			$data['shipping_zone'] = $order_info['shipping_zone'];
			$data['shipping_zone_code'] = $order_info['shipping_zone_code'];
			$data['shipping_country'] = $order_info['shipping_country'];
line 2132

Code: Select all

$replace = array(
					'firstname' => $order_info['shipping_firstname'],
					'lastname'  => $order_info['shipping_lastname'],
					'company'   => $order_info['shipping_company'],
					'address_1' => $order_info['shipping_address_1'],
					'address_2' => $order_info['shipping_address_2'],
					'city'      => $order_info['shipping_city'],
					'postcode'  => $order_info['shipping_postcode'],
					'zone'      => $order_info['shipping_zone'],
					'zone_code' => $order_info['shipping_zone_code'],
					'country'   => $order_info['shipping_country']
				);

				$shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
line 2342

Code: Select all

$replace = array(
					'firstname' => $order_info['shipping_firstname'],
					'lastname'  => $order_info['shipping_lastname'],
					'company'   => $order_info['shipping_company'],
					'address_1' => $order_info['shipping_address_1'],
					'address_2' => $order_info['shipping_address_2'],
					'city'      => $order_info['shipping_city'],
					'postcode'  => $order_info['shipping_postcode'],
					'zone'      => $order_info['shipping_zone'],
					'zone_code' => $order_info['shipping_zone_code'],
					'country'   => $order_info['shipping_country']
				);

				$shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
is the $replace causing the problem? Should I write a new variable for this?

Best regards :)

New member

Posts

Joined
Wed Nov 19, 2014 10:40 pm

Post by straightlight » Thu Nov 16, 2017 10:45 pm

With all these posted lines, from which controller file are you referring?

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 thng » Fri Nov 17, 2017 3:10 am

This is admin/controller/sale/order.php :)

New member

Posts

Joined
Wed Nov 19, 2014 10:40 pm

Post by straightlight » Fri Nov 17, 2017 3:12 am

Into which TPL file are you looking to add the shipping firstname?

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 thng » Fri Nov 17, 2017 3:16 am

In admin/view/template/sale/order_shipping.tpl (and there isn't a order_shipping.php controller file)

New member

Posts

Joined
Wed Nov 19, 2014 10:40 pm

Post by straightlight » Fri Nov 17, 2017 3:24 am

If you want to display the shipping first name manually, in catalog/controller/sale/order.php file,

find the 2nd instance of:

Code: Select all

'shipping_address'   => $shipping_address,
add right below:

Code: Select all

'shipping_firstname' => html_entity_decode($order_info['shipping_firstname'], ENT_QUOTES, 'UTF-8'),
'shipping_lastname' => html_entity_decode($order_info['shipping_lastname'], ENT_QUOTES, 'UTF-8'),
Then, within the $order loop of the order_shipping.tpl file, you could use:

Code: Select all

<?php echo $order['shipping_firstname']; ?> <?php echo $order['shipping_lastname']; ?>
the way you want.

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 thng » Fri Nov 17, 2017 3:47 am

Oh my god, it works! Thank you so much, I wouldn't have ever figured this out on my own :)
Best regards!

New member

Posts

Joined
Wed Nov 19, 2014 10:40 pm
Who is online

Users browsing this forum: No registered users and 88 guests