Printing a new field on the packing slip

Ask the community for help and support.
Post Reply
IainMHamilton
Posts: 4
Joined: Mon Nov 09, 2020 5:05 pm

Printing a new field on the packing slip

Post by IainMHamilton »

Hi,

I wonder if someone could give me a few pointers to help me on my way.

I wanted to add a new field to each product to specify the physical location of the product and to have it print out on the packing slip.

This is what I thought I needed to do :-

1. Add a new field product_location to the products table in the database.
2. Add an extra tab on the admin side to allow the display and edit of the field when the product is displayed/edited using a hook in hooks\admin\categories.
3. Add a hook in hooks\admin\siteWide - listen_databaseOrderProductColumns() - which adds the field into the orders class so that it can be printed out. I can see that $parameters gets passed here << $GLOBALS['OSCOM_Hooks']->call('siteWide', 'databaseOrderProductColumns', $parameters); >> in database_order_builder.php but how do I access it in my hook ?
4. Add code to packingslip.php to print the product location next to the product model.

I have done 1 and 2, but I'm unsure how to access the $parameters array of the orders class to add the key and value to the array.

For step 4 I can see that I can change the core code, but could I use the << echo $OSCOM_Hooks->call('packingslip', 'extraComments') >> call to add it to each product line ? If so, would I do it via the DOM ?

I come from the world of C++/Java/Delphi programming so some of the coding, etc in PHP is unfamiliar to me.

Any help would be appreciated.

Thanks
ecartz
Lead Developer
Lead Developer
Posts: 2637
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 181 times

Re: Printing a new field on the packing slip

Post by ecartz »

Code: Select all

public function listen_databaseOrderProductColumns($parameters) {
  $parameters['column_keys']['order_column_name'] = 'db_column_name';
}
Note that order_column_name and db_column_name are just placeholders. Replace with the actual names, which can be the same.

Also, you seem to be missing

5. Add the column to the cart.
6. Add the column to cartOrderProductColumns.
7. Insert the column in the database at checkout.

I think that there is a way to do #4 with Javascript. We may add a PHP way in the future.
burt
Lead Developer
Lead Developer
Posts: 2423
Joined: Tue Oct 29, 2019 9:37 am
Has thanked: 49 times
Been thanked: 137 times

Re: Printing a new field on the packing slip

Post by burt »

You could also output an extra table just for your use using the extraComments listener. This is how I did something similar for a client, and set it to non-print (so that when printed it does not show but on screen it does) - he wanders around the warehouse picking anf packing with a tablet.
Gamechanger Addon: Queued Emails, try before you buy.
IainMHamilton
Posts: 4
Joined: Mon Nov 09, 2020 5:05 pm

Re: Printing a new field on the packing slip

Post by IainMHamilton »

Thanks for the response.

I made the assumption that the product fields on the packing slip came from the products table and that adding the field in would automatically populate it.
But on closer inspection I can see that they come from the orders_products table. So I can see the need to add it to the cart, etc.

In the end I decided that, as I had to change packingslip.php to add the column into the print-out, I would just get the location field from the database as the products were iterated.

Thanks for the help though, I will try and do the full implementation on my test system so that I get a better understanding of how I can extend without changing core code.

Burt,
I will also try your method - sounds interesting.
Post Reply