Add a Custom Field To A View

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
4 years 1 month ago #316407

-- HikaShop version -- : 4.2.3
-- Joomla version -- : 3.9.16

Hi

I would like to add a custom field to the view of order / listing.php

The custom field column is named notes and is in the table Order. Would appreciate some guidance please?

Thanks

Dave B)

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
4 years 1 month ago #316415

Hi,

If you edit the custom field via the Display>Custom fields menu, you have the setting "Back-end Listing" that you can activate and the custom field value will appear on the listing without any code modification to order / listing.php
Now this will display the value of the custom field, not the input field. If you want the input field, it will require coding. First in order / listing.php to add the HTML of an input field, and then add a controller via a hikashop plugin to be able to save the data in the custom field column in the database.

Please Log in or Create an account to join the conversation.

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
4 years 1 month ago #316424

Hi Nicolas

thanks for the reply.

It is required in the front end listing under the order number if possible. So I need the value only to be displayed. On this page as well user / cpanel_orders.php again under the order number.

I did find this code in the order / show.php. But on adding it it does not appear

<?php
		foreach($this->fields['order'] as $fieldName => $oneExtraField) {
			if(empty($this->order->$fieldName))
				continue;
?>


<?php
								echo $this->fieldsClass->getFieldName($oneExtraField);
							?>
							
							<?php
								echo $this->fieldsClass->show($oneExtraField,$this->order->$fieldName);
							?>

Thanks

Dave

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
4 years 1 month ago #316426

Hi,

There is no option to display a custom order field on the order listing on the frontend.
The "Frontend order details page" setting of the custom order fields allow you to display them on the order details page, the page you see once you click on the order number of an order.
And you can't just copy paste the code from order / show.php at this code bases itself on data loaded in the view.html.php file which is not loaded on the listing views.
To have it on the listings you'll have to edit the corresponding view file and direct display it.
Supposing that it's a text or text area custom field, you can just use such code:
<?php echo $row->XXX; ?>
where XXX is the column name of the custom field and $row is to be replaced by $order in cpanel_orders.php

Please Log in or Create an account to join the conversation.

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
4 years 1 month ago #316460

Hi Nicolas

thanks for the reply

I would just like to clarify what I should be entering in the code. The field is in the Hikashop field table as per attachment.

Thanks

Dave

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
4 years 1 month ago #316464

Hello Dave,

Sure if you want to display a custom field from the "Order" table, the solution that Nicolas gave you will do the job.

Kind regards,
Mohamed.

Please Log in or Create an account to join the conversation.

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
4 years 1 month ago #316507

Hi

so column name will be field_realname, so it should look like as below?

<?php echo $row->field_realname; ?>

Thanks

Dave

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
4 years 1 month ago #316509

Hi,

No. You should replace field_realname by the column name of your custom field. If you custom field name is "extrapackingrequired", then your code should be:
<?php echo $row->extrapackingrequired; ?>

Please Log in or Create an account to join the conversation.

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
4 years 1 month ago #316522

Hi Nicolas

thanks for this. I have just tried the code and I get an error message

Undefined variable: row in /home/****/public_html/templates/joostrapbase-v3-5/html/com_hikashop/user/cpanel_orders.php on line 15 if I put it at the top

Thanks

Dave

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
4 years 1 month ago #316523

Hi,

As I said in a previous message www.hikashop.com/forum/customers/899314-...o-a-view.html#316426 you need to use $order instead of $row in cpanel_orders.php

Please Log in or Create an account to join the conversation.

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
4 years 1 month ago #316562

Hi Nicolas

sorry I misunderstood the reply. All works as expected, thanks very much for your help

Dave B)

Please Log in or Create an account to join the conversation.

Time to create page: 0.106 seconds
Powered by Kunena Forum