Comments

smccabe created an issue. See original summary.

cornifex’s picture

StatusFileSize
new1.98 KB

This is just a baseline for now. Was working on the access and page callbacks, but was having some issues with my dev site.

cornifex’s picture

StatusFileSize
new2.72 KB

Access callback needs actual permissions to check. The ones added are just ported over from D7

thejacer87’s picture

Assigned: Unassigned » thejacer87
Status: Active » Needs work
StatusFileSize
new12.25 KB

Here's some more work. Just wanted to post the WIP. If you make a payment on an order and you go to `/admin/commerce/pos/{payment_id}/print-receipt` it will load a page with a "print out".

Next steps, as I see it:

  • create settings page to set the header, footer and whatever else is in the D7 module
  • make the output of the url above be output by ajax

PS, I didn't post an interdiff, because I couldn't get @cornifex's patch to apply cleanly for me.

thejacer87’s picture

StatusFileSize
new18.63 KB
new13.04 KB

created the settings menu. saves the header and footer. also start the conversion to ajax. but something is wrong so i could use a hand with that.

smccabe’s picture

StatusFileSize
new18.38 KB
  • Added a very basic reprint-receipt button, mostly for testing this functionality.
  • Simplified the ajax a lot, as I realised we didn't need a custom ajax command, just a replace.
  • cleaned up some code standards

Still TODO:

  • finish cleaning up code standards
  • Updated receipt body to print pricing totals
  • Update receipt button to not just be an inelegant link
  • setup jquery-print library to handle the printing
  • add defaults for header and footer
  • show the type of transaction on the receipt, have we just paid, voided, etc.
  • possibly move some functionality out of preprocess, it is too bulky right now
  • finish writing tests
moshe weitzman’s picture

StatusFileSize
new20.78 KB
new6.6 KB

Working off the last TODO:

  1. finish cleaning up code standards
    MW: I looked through the PHP code and my eyeballs didn't bleed (at all). The compliance is at least "Good.". I can run phpcs against it and remedy any problems if desired.
  2. Updated receipt body to print pricing totals
    MW: I guess you mean item totals. I've added them to the receipt.
  3. Update receipt button to not just be an inelegant link
    MW: I'm not yet clear on the user interaction that's expected. Where is the Reprint receipt button supposed to appear? Right now, its on the main POS form (commerce_pos), and its hard coded to order 1. I would expect a 'Print receipt' Operation to be added to each row in admin/commerce/orders, admin/commerce/orders/payments, and an action link when viewing order details. I might be missing something because I can't get an order to Save when using the main POS form. It just keeps returning me to an order submission.
  4. setup jquery-print library to handle the printing
    MW: I've added instructions to the README for getting jQuery.print plugin. Its slightly painful, because this is an unsolved problem, even in D8. Seehttps://www.drupal.org/node/2605130. One alternative approach is to rely on Aset Packagist per https://dev.acquia.com/blog/round-up-your-frontend-javascript-libraries-.... If we do that, would be ideal if implemented in Drupal Commerce, so the whole ecosystem could benefit.
  5. add defaults for header and footer
    MW: Not seeing any default HTML for the header/footer in D7. Someone needs to compose it?
  6. show the type of transaction on the receipt, have we just paid, voided, etc.
    MW: Where is the transaction type? Is that $payment->getState()?
  7. possibly move some functionality out of preprocess, it is too bulky right now
    MW: I simplified the preprocess function to not do its own rendering - that is done for us by twig. Further, I consolidated to one variable called 'receipt'.
  8. finish writing tests

Also, CommercePOSSettingsForm is in the visible menu but doesn't do anything yet. Should we comment it out or remove it? Its a bit confusing as we have two links both named Point of Sale. Perhaps its too early to discuss details like this.

smccabe’s picture

1. There is a phpcs.xml in the repo, if it passes against that we're good
2. correct
3. this will actually go on the payment page eventually, that patch isn't finished though, although I do like adding it to the additional sections you mentioned, can you spin out a new issue for that plz
4. talked with Bojanz, lets go with the lightning way
5. @fergy will writeup and add to this issue
6. yes, the state of the most recent payment

fergy’s picture

5.

Header:
(logo??)
Company Name/Store#
Address line 1
Address line 2
Phone #

Footer:
Thanks for shopping at CompanyName!
Return Policy --
Exchange Policy --
Company Motto
Website --

(optional)
Visit our website for a chance to --

moshe weitzman’s picture

Assigned: thejacer87 » moshe weitzman
Status: Needs work » Needs review
StatusFileSize
new20.2 KB
new13.43 KB

1. phpcs is now passing
3. New issue created https://www.drupal.org/node/2915872 (Add receipt print functionality in 3 places). Not sure if there is anything left to do before the Payment patch lands.
4. I'll do this in https://www.drupal.org/node/2916058.
5. Default configuration (with schema) now exists for header/footer.

We should consider deferring test writing until this functionality is on the payment page.

smccabe’s picture

Status: Needs review » Needs work

payments page has landed, we should be good to finish off the last of the stuff here.

#2907670: POS Payment Page

moshe weitzman’s picture

StatusFileSize
new10.4 KB
new21.09 KB

This one is pretty close.

  1. The main uresolved issue is around user experience. We still are showing an ajax link on the POS form.
  2. I've added an 'Show receipt' action link (like 'Add content' link on content listings) on an order detail page and an Operation for each row in admin/commerce/orders (like Edit/Delete on content listings). This necessitated changing our receipt printing to taking an Order as input instead of a Payment. I'd like to add a 'Print receipt' button at bottom or and/or top of these pages once #2916058: Declare Asset Packagist composer repo and config lands.
  3. As a result of above, we now have a Show Receipt page that is themed, and an Ajax receipt route that shows same info but returns via Ajax.
smccabe’s picture

StatusFileSize
new28.05 KB
new18.9 KB
  • Updated AJAX link to properly trigger a jquery print job, now has a ajax print command and will trigger a printer print command
  • Updated line-item formatting to correctly format currency amounts
  • Setup receipt printing to have specific receipt printing CSS
  • Copied over old CSS form D7 for receipt printing
  • Receipt print contents are now passed through a twig template for easier receipt styling

Still TODO

  • Receipt printing needs to trigger on "Finish" button instead of with the "reprint receipt" button. The reprint receipt button was only ever a hack for testing and should be removed
  • Update readme with more indepth instructions for installing the required jquery.print library, both via composer assets and manually
  • Receipt CSS needs to be matched up with receipt output so it properly styles a receipt for printing
  • Add print button to any "View receipt" pages, this is optional for this patch and not required

Optional

The #attached stuff could probably be abstracted somewhat so as to be more user friendly, but that might be overkill is it will be used in 2 places at most I think.

sorabh.v6’s picture

@smccabe I tried to apply patch in #13. But patch is not applying and I am getting error -

Checking patch commerce_pos.libraries.yml...
error: while searching for:
    layout:
      css/commerce_pos_style.css: {}
  js:
    js/commerce_pos.js: {}
error: patch failed: commerce_pos.libraries.yml:4
error: commerce_pos.libraries.yml: patch does not apply
Checking patch gulpfile.js...
error: gulpfile.js: No such file or directory
Checking patch modules/keypad/js/commerce_pos_keypad.js...
Checking patch modules/receipt/README.md...
error: modules/receipt/README.md: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.info.yml...
error: modules/receipt/commerce_pos_receipt.info.yml: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.install...
error: modules/receipt/commerce_pos_receipt.install: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.libraries.yml...
error: modules/receipt/commerce_pos_receipt.libraries.yml: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.links.action.yml...
error: modules/receipt/commerce_pos_receipt.links.action.yml: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.links.menu.yml...
error: modules/receipt/commerce_pos_receipt.links.menu.yml: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.module...
error: modules/receipt/commerce_pos_receipt.module: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.permissions.yml...
error: modules/receipt/commerce_pos_receipt.permissions.yml: already exists in working directory
Checking patch modules/receipt/commerce_pos_receipt.routing.yml...
error: modules/receipt/commerce_pos_receipt.routing.yml: already exists in working directory
Checking patch modules/receipt/config/install/commerce_pos_receipt.settings.yml...
error: modules/receipt/config/install/commerce_pos_receipt.settings.yml: already exists in working directory
Checking patch modules/receipt/config/schema/commerce_pos_receipt.schema.yml...
error: modules/receipt/config/schema/commerce_pos_receipt.schema.yml: already exists in working directory
Checking patch modules/receipt/css/commerce_pos_receipt.css...
error: modules/receipt/css/commerce_pos_receipt.css: already exists in working directory
Checking patch modules/receipt/css/commerce_pos_receipt.css.map...
error: modules/receipt/css/commerce_pos_receipt.css.map: already exists in working directory
Checking patch modules/receipt/css/commerce_pos_receipt_print.css...
Checking patch modules/receipt/css/commerce_pos_receipt_print.css.map...
Checking patch modules/receipt/js/commerce_pos_receipt.js...
Checking patch modules/receipt/sass/commerce_pos_receipt.scss...
error: modules/receipt/sass/commerce_pos_receipt.scss: already exists in working directory
Checking patch modules/receipt/sass/commerce_pos_receipt_print.scss...
Checking patch modules/receipt/src/Ajax/PrintReceiptCommand.php...
Checking patch modules/receipt/src/Controller/PrintController.php...
error: modules/receipt/src/Controller/PrintController.php: already exists in working directory
Checking patch modules/receipt/src/Form/ReceiptSettingsForm.php...
error: modules/receipt/src/Form/ReceiptSettingsForm.php: already exists in working directory
Checking patch modules/receipt/templates/commerce-pos-receipt.html.twig...
error: modules/receipt/templates/commerce-pos-receipt.html.twig: already exists in working directory
Checking patch modules/receipt/tests/src/Functional/LoadTest.php...
error: modules/receipt/tests/src/Functional/LoadTest.php: already exists in working directory
Checking patch src/Form/POSForm.php...
error: while searching for:
  protected function buildOrderForm(array $form, FormStateInterface $form_state) {
    /* @var \Drupal\commerce_order\Entity\Order $order */
    $order = $this->entity;

    $form = parent::buildForm($form, $form_state);


error: patch failed: src/Form/POSForm.php:68
error: src/Form/POSForm.php: patch does not apply

But I can apply patch in #12successfully.

sorabh.v6’s picture

Uploading patchfile and interdiff. I tried to apply patch in #13 but it did not applied using git apply so I applied the patch manually. This patch includes work of TODO in #13, i.e. -

  • Receipt printing needs to trigger on "Finish" button instead of with the "reprint receipt" button. The reprint receipt button was only ever a hack for testing and should be removed
  • Update readme with more indepth instructions for installing the required jquery.print library, both via composer assets and manually
  • Add print button to any "View receipt" pages, this is optional for this patch and not required

Please review.

travis-bradbury’s picture

There's some code standards issues.

🐧 phpcs --standard=phpcs.xml src tests modules commerce_pos.module -s

FILE: /home/tbradbury/src/drupal/commerce_pos/src/Form/POSForm.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 483 | ERROR | [x] Missing function doc comment
     |       |     (Drupal.Commenting.FunctionComment.Missing)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...home/tbradbury/src/drupal/commerce_pos/modules/receipt/README.md
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 19 | WARNING | Line exceeds 80 characters; contains 85 characters
    |         | (Drupal.Files.TxtFileLineLength.TooLong)
----------------------------------------------------------------------


FILE: ...l/commerce_pos/modules/receipt/tests/src/Functional/LoadTest.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
 14 | ERROR | [x] Opening brace should be on the same line as the
    |       |     declaration
    |       |     (Drupal.Classes.ClassDeclaration.BraceOnNewLine)
 34 | ERROR | [x] Opening brace should be on the same line as the
    |       |     declaration
    |       |     (Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine)
 44 | ERROR | [x] Opening brace should be on the same line as the
    |       |     declaration
    |       |     (Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: .../drupal/commerce_pos/modules/receipt/commerce_pos_receipt.module
----------------------------------------------------------------------
FOUND 3 ERRORS AND 3 WARNINGS AFFECTING 5 LINES
----------------------------------------------------------------------
 35 | WARNING | [x] A comma should follow the last multiline array item.
    |         |     Found: 'commerce-pos-receipt'
    |         |     (Drupal.Array.Array.CommaLastItem)
 42 | WARNING | [ ] Format should be "* Implements hook_foo().", "*
    |         |     Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "*
    |         |     Implements hook_foo_BAR_ID_bar() for xyz-bar.html.twig.",
    |         |     "* Implements hook_foo_BAR_ID_bar() for
    |         |     xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar()
    |         |     for block templates." (Drupal.Commenting.HookComment)
 44 | ERROR   | [x] Data types in @param tags need to be fully
    |         |     namespaced
    |         |     (Drupal.Commenting.DataTypeNamespace.DataTypeNamespace)
 44 | ERROR   | [x] Parameter comment must be on the next line
    |         |     (Drupal.Commenting.FunctionComment.ParamCommentNewLine)
 46 | ERROR   | [ ] Description for the @return value is missing
    |         |     (Drupal.Commenting.FunctionComment.MissingReturnComment)
 77 | WARNING | [x] A comma should follow the last multiline array item.
    |         |     Found: ) (Drupal.Array.Array.CommaLastItem)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...al/commerce_pos/modules/receipt/src/Ajax/PrintReceiptCommand.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 14 | ERROR | [x] Missing function doc comment
    |       |     (Drupal.Commenting.FunctionComment.Missing)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: .../commerce_pos/modules/receipt/src/Controller/PrintController.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
 36 | WARNING | [x] A comma should follow the last multiline array item.
    |         |     Found: ) (Drupal.Array.Array.CommaLastItem)
 37 | WARNING | [x] A comma should follow the last multiline array item.
    |         |     Found: ] (Drupal.Array.Array.CommaLastItem)
 60 | WARNING | [x] A comma should follow the last multiline array item.
    |         |     Found: ) (Drupal.Array.Array.CommaLastItem)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 668ms; Memory: 12Mb

The difference between items mentioned as TODO in #13 and fixed in #15 leaves

Receipt CSS needs to be matched up with receipt output so it properly styles a receipt for printing

The #attached stuff could probably be abstracted somewhat so as to be more user friendly, but that might be overkill is it will be used in 2 places at most I think.

For receipt CSS, I tested on a 72mm receipt and thought it looked fine.

sorabh.v6’s picture

Okay, I will remove PHPCS errors.

sorabh.v6’s picture

Updated patch with removed code standard errors. Only errors left in the code are some @todo code which exceeds 80 chars. Patch and interdiff uploading, please review.

Thanks

smccabe’s picture

The TODO's in #13 still need to be done i believe to wrap this up

sorabh.v6’s picture

@smccabe as per #16 @tbradbury tested the receipt on 72 mm and he says it looked good. Can you tell me what kind of styling is required for it?

Also,

The #attached stuff could probably be abstracted somewhat so as to be more user friendly, but that might be overkill is it will be used in 2 places at most I think.

By this, you are indicating about -

$form['#attached']['drupalSettings']['commercePosReceipt'] = [
+    'cssUrl' => Url::fromUri('base:' . $module_path . '/css/commerce_pos_receipt_print.css', ['absolute' => TRUE])->toString(),
+  ];

or

$form['#attached']['library'][] = 'commerce_pos_receipt/receipt';
+  $form['#attached']['library'][] = 'commerce_pos_receipt/jQuery.print';

or both.

subhojit777’s picture

subhojit777’s picture

StatusFileSize
new15.41 KB

Patch rerolled. Will check now whether all the TODO items have been covered.

subhojit777’s picture

Patch in #22 not rerolled correctly.

subhojit777’s picture

StatusFileSize
new7.37 KB
subhojit777’s picture

StatusFileSize
new35.6 KB
subhojit777’s picture

StatusFileSize
new36.46 KB
new1.87 KB

Fixing failing tests.

subhojit777’s picture

  1. +++ b/modules/receipt/commerce_pos_receipt.libraries.yml
    @@ -0,0 +1,21 @@
    +jQuery.print:
    

    The test is going to fail in DrupalCI. Because DrupalCI does not downloads any external library (from GitHub). I too had this same problem. But that was months ago, I don't know the state of DrupalCI now. We can try invoking a command that would download this library first. Otherwise we have to rely on TravisCI/CircleCI.

  2. +++ b/tests/src/FunctionalJavascript/PosFormTest.php
    @@ -23,6 +23,7 @@ class PosFormTest extends JavascriptTestBase {
    +    'commerce_pos_receipt',
    

    This is not good at all. POSForm::ajaxReceipt() should be moved to the sub-module, as a form alter or something.

subhojit777’s picture

I am first going to take care of #13. Then we can address the problems as mentioned in #27

subhojit777’s picture

+++ b/tests/src/FunctionalJavascript/PosFormTest.php
@@ -261,4 +263,12 @@ class PosFormTest extends JavascriptTestBase {
+  protected function waitForAjaxToFinish() {

This can be moved to a base test class.

subhojit777’s picture

StatusFileSize
new36.55 KB
new4.45 KB

TODOs mentioned in #13 are covered in the patch. I made some slight improvements/corrections in the README.

subhojit777’s picture

Working on #27.2

subhojit777’s picture

Status: Needs work » Needs review

Shawn confirmed that #27.2 is in his machine. He will upload the patch.

subhojit777’s picture

Assigned: subhojit777 » Unassigned

Status: Needs review » Needs work

The last submitted patch, 30: 2901030-30.patch, failed testing. View results

smccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new41.23 KB

I did some work on friday that I ran out of time to post a patch for, rolled it in with @subhojit777 work. It solves 27.2 and gets receipts printing properly on order completion. It still needs review and testing, but I figured I better get it up before we start duplicating work.

I had relatively few merge conflicts, so I think the patches merged together fine, let me know if you see any issues.

Status: Needs review » Needs work

The last submitted patch, 35: 2901030-32.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

smccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new42.79 KB

Ok, cleaned out a few bits that got left in during the merge, 27.2 is now fixed up properly.

Also got tests running, their were 2 issues.

  • default tests were set to use the receipts module, but they shouldn't use dependencies in them so removed that.
  • The receipt code being in commerce_pos directly caused dependency issues, having it moved to the right spot fixed that.

I don't think there are any direct TODOs left, I am going to create some spin-off issues for some additional work, but I want to get this large patch in since it is working cleanly.

  • smccabe committed 3143125 on 8.x-2.x
    Issue #2901030 by moshe weitzman, subhojit777, smccabe, thejacer87,...
smccabe’s picture

Status: Needs review » Fixed

Committed, Moshe wins the author credit by virtue of having the most patches. Thanks everyone.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.