Printer-friendly invoice on checkout_success

Open to all! Ask other shopowners for help.
User avatar
ReneH4
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 times
Been thanked: 17 times

Re: Printer-friendly invoice on checkout_success

Post by ReneH4 »

You're right, still have to get used to the templating :-)
heatherbell wrote: Fri Jan 21, 2022 8:01 am
ReneH4 wrote: Thu Jan 20, 2022 7:04 pm That would be the best option indeed. But wouldn't that require a core change?
I don't think so - account_history can be copied, edited and placed in /templates/override/includes/pages/

Tags:


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
ReneH4
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 times
Been thanked: 17 times

Re: Printer-friendly invoice on checkout_success

Post by ReneH4 »

If it's Danisch law it explains it all!
Kofod95 wrote: Thu Jan 20, 2022 9:07 pm
ReneH4 wrote: Thu Jan 20, 2022 3:35 pm ["account_history_info.php?order_id=xxxx"] is a page that a customer can return to all the time, but checkout success is just a one-time visit.
Thank you - you are right.
I put it there (checkout success), as it is the norm in Denmark to be offered an option to print an invoice right after purchasing. At the account-menu there is already something that the core order-received mail calls a "detailed invoice", but that is not to printer-friendly. The page in this addon could be linked to from any place, it just makes sure that the customer is logged in, and that it is one of their own orders they are trying to see.
This means I could easily include buttons that links to the invoice other places, and will look into that!
heatherbell wrote: Thu Jan 20, 2022 6:09 pm Probably the customer would expect to find it on account_history - maybe as a button in an additional column after View in the table.
Agreed!
ReneH4 wrote: Thu Jan 20, 2022 7:04 pm But wouldn't that require a core change?
I'm not too far down the rabbit-hole yet, but I don't think it requires a core change - Let's see what I can do next time I have an hour or two ;)

@14Steve14 I'm glad it integrated nicely! Let me know if you need more flexibility from this addon

- One thing I have considered, since this is the PRO-forum, is to include the Supporters Code for Invoice comments and Invoice Numbering on this catalog-invoice. Feel free to ask me to do it!

//Daniel
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Printer-friendly invoice on checkout_success

Post by Kofod95 »

To add a button on the account-history, make a copy of templates/default/includes/pages/account_history.php to the same place in the override-template (or whatever template you use). Open it and find (line 49)

Code: Select all

$order_link = $Linker->build('account_history_info.php')->retain_query_except();
and (line 52)

Code: Select all

$order_link->set_parameter('order_id', (int)$history['orders_id']);
These build the link to the account_history_info, adding the correct order_id, which we want for the invoice.
Copy those two lines (I placed the copies right below the originals) and change the names and parameters as needed. Below is how I did:

Code: Select all

          $order_link = $Linker->build('account_history_info.php')->retain_query_except();
		  //Add invoice link
		  $invoice_link = $Linker->build('invoice.php')->retain_query_except();
		  //End add invoice link
          while ($history = $history_query->fetch_assoc()) {
            $products = $db->query("SELECT SUM(products_quantity) AS count FROM orders_products WHERE orders_id = " . (int)$history['orders_id'])->fetch_assoc();
            $order_link->set_parameter('order_id', (int)$history['orders_id']);
			//Add invoice link parameters
			$invoice_link->set_parameter('oID', (int)$history['orders_id']);
			//End invoice link parameters
Note that the invoice uses 'oID' instead of 'order_id'. If that is not changed the URL linked would be shop/invoice?order_id=X, which the invoice would not recognize and thus not know which invoice to show.

Now all we need is to copy the "view"-button (line 60 - after above change line 66) and make it open in a new window:

Code: Select all

<td class="text-right"><?= new Button(BUTTON_VIEW_ORDER, '', 'btn-primary btn-sm', [], $order_link) ?><?= /*Add Invoice*/ new Button('<i class="fas fa-file-invoice-dollar" title="Invoice"></i>', '', 'btn-primary btn-sm', ['newwindow' => true], $invoice_link) /*End Invoice*/ ?></td>
All lines are from 1.0.8.9

Attached is an update with this included.

//Daniel
You do not have the required permissions to view the files attached to this post.
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
ReneH4
Contributor
Posts: 145
Joined: Mon Oct 26, 2020 12:00 pm
Phoenix Version:
Has thanked: 13 times
Been thanked: 17 times

Re: Printer-friendly invoice on checkout_success

Post by ReneH4 »

Edit..... I must learn to read.... :-)

Edit 2: Differences between 1079 and 1089 are too large to just look at the code and use what's usefull.


Daniel, on which version of Phoenix did you test this?

Just want to be sure befor I install it on my 1079 shop.

Whatever version, this is an excellent add-on, Thank you for that!
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Printer-friendly invoice on checkout_success

Post by Kofod95 »

Untested, but I think you only need this line:
https://github.com/CE-PhoenixCart/Phoen ... ry.php#L58

Let me know if you need more hints; I'm on my phone now, so sorry for the short answer

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Printer-friendly invoice on checkout_success

Post by Kofod95 »

ReneH4 wrote: Fri Jan 28, 2022 11:37 am Differences between 1079 and 1089 are too large to just look at the code and use what's usefull.
Try this as line 58 (obviously, make sure to also define BUTTON_INVOICE in the language-file(s)):

Code: Select all

              <td class="text-right"><?php echo tep_draw_button(BUTTON_VIEW_ORDER, null, tep_href_link('account_history_info.php', tep_get_all_get_params(['order_id']) . 'order_id=' . (int)$history['orders_id'], 'SSL'), 'primary', NULL, 'btn-primary btn-sm') . /*Add invoice*/tep_draw_button(BUTTON_INVOICE, null, tep_href_link('invoice.php', tep_get_all_get_params(['oID']) . 'oID=' . (int)$history['orders_id'], 'SSL'), 'primary', ['newwindow' => true], 'btn-primary btn-sm')/*End Invoice */; ?></td>
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
14Steve14
Senior Contributor
Posts: 922
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Printer-friendly invoice on checkout_success

Post by 14Steve14 »

Kofod95 wrote: Tue Feb 01, 2022 9:39 pm
Try this as line 58 (obviously, make sure to also define BUTTON_INVOICE in the language-file(s)):

Code: Select all

              <td class="text-right"><?php echo tep_draw_button(BUTTON_VIEW_ORDER, null, tep_href_link('account_history_info.php', tep_get_all_get_params(['order_id']) . 'order_id=' . (int)$history['orders_id'], 'SSL'), 'primary', NULL, 'btn-primary btn-sm') . /*Add invoice*/tep_draw_button(BUTTON_INVOICE, null, tep_href_link('invoice.php', tep_get_all_get_params(['oID']) . 'oID=' . (int)$history['orders_id'], 'SSL'), 'primary', ['newwindow' => true], 'btn-primary btn-sm')/*End Invoice */; ?></td>
//Daniel
On my older 1.0.7.9 store I changed the code to look like this and also added in a new <td> for the header. Languages were also created accordingly.

This for the headers

Code: Select all

            <th class="text-right" scope="col"><?php echo TEXT_VIEW_ORDER; ?></th>
            <th class="text-right" scope="col"><?php echo TEXT_PRINT_ORDER; ?></th>
And this for the buttons

Code: Select all

              <td class="text-right"><?php echo tep_draw_button(BUTTON_VIEW_ORDER, null, tep_href_link('account_history_info.php', tep_get_all_get_params(['order_id']) . 'order_id=' . (int)$history['orders_id'], 'SSL'), 'primary', NULL, 'btn-primary btn-sm'); ?></td>
              <td class="text-right"><?php echo tep_draw_button(BUTTON_PRINT_ORDER, null, tep_href_link('invoice.php', tep_get_all_get_params(['oID']) . 'oID=' . (int)$history['orders_id'], 'SSL'), 'primary', ['newwindow' => true], 'btn-primary btn-sm'); ?></td>
Great addition to the code and will be using the newer version in my next store update.
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Printer-friendly invoice on checkout_success

Post by Kofod95 »

Okay, I've thought some more about this for some time and have an idea.
Many shops use pwa or similar, in which case this invoice could only be viewed after ended checkout. So instead of that I want to remove that check and pass a second parameter to the link, meaning that the link could be send by email (fx in n_update_order.php if the order_status allows download to only send after a purchase is final), and the customer can click it with no need to log-in before viewing.

I can think of a few methods for this:
1) pass the customer phone, name or similar as a key (invoice.php?oID=N&key=Bob) (easier links to remember, but who does that anyway?)
2) make a new field in the orders table with a randomly generated code and pass that as the key (probably the most secure)
3) use a md5-hash of any data and pass that as key - the easiest here would be to use the order_id, but that would obviously not be very secure. However, for someone to figure that out, they would need to see a link to an invoice and guess that the key is a md5-hash of oID, which I think is unlikely enough that I consider just doing it like that.
Of course, md5-hashing any other value from the order would be more secure and still not require any new fields to be gathered, but for some reason I somewhat like the simplicity of re-using the order_id.

Anyone got any thoughts or comments to that?
More ideas are also very welcome!

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Omar_one
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: Printer-friendly invoice on checkout_success

Post by Omar_one »

the key system (s06e08 keys) create a randomly generated code and pass that as the key,,
you can check it out


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply