#2901030: Receipt Printing provides a jQuery print library that can be attached but label printing needs it too so let's move that to the base module. The hook_requirements() is an improvement but it feels like an unnecessary requirement.

CommentFileSizeAuthor
#48 commerce_pos_provide_print_library-2924548-48.patch12.65 KBjnrfred
#43 commerce_pos_provide_print_library-2924548-43.patch8.15 KBjnrfred
#40 commerce_pos_provide_print_library-2924548-40.patch7.14 KBjnrfred
#38 commerce_pos_provide_print_library-2924548-38.patch6.6 KBjnrfred
#38 2018-05-18_222311.png37.89 KBjnrfred
#37 commerce_pos_provide_print_library-2924548-37.patch7.42 KBjnrfred
#36 commerce_pos_provide_jquery_print_library-2924548-36.patch10.93 KBjnrfred
#32 commerce_pos-provide_a_jquery_print_library-2924548-32.patch9.64 KBdeepakaryan1988
#32 commerce_pos-provide_a_jquery_print_library-2924548-32.patch9.64 KBdeepakaryan1988
#28 commerce_pos-provide_a_jquery_print_library-2924548-28.patch6.07 KBdeepakaryan1988
#26 interdiff-2924548-24-26.txt905 bytesdeepakaryan1988
#26 commerce_pos-provide_a_jquery_print_library-2924548-26.patch6.04 KBdeepakaryan1988
#24 commerce_pos-provide_a_jquery_print_library-2924548-24.patch5.75 KBdeepakaryan1988
#21 commerce_pos-provide_a_jquery_print_library-2924548-21.patch5.75 KBdeepakaryan1988
#18 commerce_pos-provide_a_jquery_print_library-2924548-18.patch4.29 KBdeepakaryan1988
#15 commerce_pos-provide_a_jquery_print_library-2924548-15.patch4.3 KBdeepakaryan1988
#13 commerce_pos-provide_a_jquery_print_library-2924548-13.patch713 bytesdeepakaryan1988
#9 commerce_pos-provide_a_jquery_print_library-2924548-9.patch3.49 KBdeepakaryan1988
#7 commerce_pos-provide_a_jquery_print_library-2924548-7.patch1.9 KBdeepakaryan1988
#5 2924548-5.patch1.9 KBtravis-bradbury
#2 commerce_pos-provide_a_jquery_print_library-2924548-2.patch1.37 KBshabana.navas

Comments

tbradbury created an issue. See original summary.

shabana.navas’s picture

Assigned: Unassigned » shabana.navas
Status: Active » Needs review
StatusFileSize
new1.37 KB

Added changes to composer.json so the jQuery.print library is automatically downloaded and added to the commerce_pos/web/libraries directory.

Status: Needs review » Needs work
smccabe’s picture

With receipts and labels both getting merged in, this patch will probably need updating.

travis-bradbury’s picture

Title: Provide a jQuery print library » Use commerce_pos jQuery print library in receipt submodule
Assigned: shabana.navas » travis-bradbury
Category: Feature request » Bug report
Status: Needs work » Needs review
StatusFileSize
new1.9 KB

The labels issue actually added the library to commerce_pos so we just need to change the receipt module to use that one instead of its own.

smccabe’s picture

Status: Needs review » Needs work

All the stuff in the README.md in receipts should probably be moved to the commerce_pos README as well and just referenced from the receipt and labels readmes.

deepakaryan1988’s picture

@tbradbury
I've rerolled the existing latest patch.

Please review it.

deepakaryan1988’s picture

Status: Needs work » Needs review
deepakaryan1988’s picture

@smccabe I have moved the README.md stuff to commerce_pos root.
Please review that.

subhojit777’s picture

Assigned: travis-bradbury » Unassigned
Status: Needs review » Needs work
  1. +++ b/README.md
    @@ -14,3 +14,55 @@ variations, just add it as you would any other field.
    +    }   ¶
    

    Remove these whitespaces.

  2. +++ b/modules/receipt/commerce_pos_receipt.libraries.yml
    @@ -10,12 +10,3 @@ receipt:
    -jQuery.print:
    -  remote: https://github.com/DoersGuild/jQuery.print
    -  version: 1.5.1
    -  license:
    -    name: CC BY 3.0
    -    url: https://github.com/DoersGuild/jQuery.print/blob/master/LICENSE
    -    gpl-compatible: no
    -  js:
    -    /libraries/jQuery.print/jQuery.print.js: {}
    

    Then this should be part of the base module's libraries.yml isn't it.

alexpott’s picture

Re #10.2 it is already there.

index affc0ad..00cb2e4 100644
--- a/README.md

--- a/README.md
+++ b/README.md

We should also be removing the same section from modules/contrib/commerce_pos/modules/receipt/README.md - we only need one set of instructions to maintain.

One thing that gives me pause is the the label and receipt sub modules both use the jQuery print library but the main module does not. Is it worth introducing a small bridge module that handles the jQuery print library? In my mind we should also have a hook_requirements implementation that checks to see if the library has been installed and puts an error on the requirements page if it has not been.

alexpott’s picture

Another thought is that it would be great to make the jQuery.receipt dependency optional and a progressive enhancement as this would make automated testing of receipts and labels much simpler and possible on DrupalCI.

deepakaryan1988’s picture

Status: Needs work » Needs review
StatusFileSize
new713 bytes

I have written the hook_requirement to check the jQuery.print is there not.

travis-bradbury’s picture

Status: Needs review » Needs work
+    $path = base_path() . '/libraries/jQuery.print';
+    if (!file_exists($path)) {

The required file is /libraries/jQuery.print/jQuery.print.js (see commerce_pos.libraries.yml) so we could check for that rather that just the jQuery.print directory.

+  if ($phase == 'install') {
+    $path = base_path() . '/libraries/jQuery.print';
+    if (!file_exists($path)) {
+      drupal_set_message(t('jQuery.print library is not installed.'), 'error');

hook_requirements()'s return value is used to indicate what's wrong, whether the requirement is installed, and a severity. That could be better than a message during install and could be used during the runtime phase too. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

I think this should also be added to the changes in the previous patch rather than a new patch that only adds the requirements hook.

deepakaryan1988’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

Hello @tbradbury
I have done as you suggested in your comment.
Please review it now.

smccabe’s picture

travis-bradbury’s picture

Status: Needs review » Needs work

The issues with trailing whitespace mentioned in #10 are still there. Git points them out when applying the patch:

$ git apply commerce_pos-provide_a_jquery_print_library-2924548-15.patch
commerce_pos-provide_a_jquery_print_library-2924548-15.patch:11: trailing whitespace.
This module depends on the `jQuery.print` plugin which should reside in your 
commerce_pos-provide_a_jquery_print_library-2924548-15.patch:26: trailing whitespace.
3. Add `"libraries/{$name}": ["type:drupal-library"]` 
commerce_pos-provide_a_jquery_print_library-2924548-15.patch:52: trailing whitespace.
    }   
commerce_pos-provide_a_jquery_print_library-2924548-15.patch:59: trailing whitespace.
2. `cd` into libraries folder and run 
warning: 4 lines add whitespace errors.

The hook_requirements implementation needs a bit of work.

+function commerce_pos_receipt_requirements($phase) {
+  $requirements = [];
+  if ($phase == 'install') {
+      $path = base_path() . '/libraries/jQuery.print/jQuery.print.js';
+    if (!file_exists($path)) {
+      $requirements['commerce_pos_receipt'] = [
+        'description' => t("jQuery.print library is not installed."),
+        'severity' => REQUIREMENT_ERROR,
+      ];
+    }
+  }
+
+  return $requirements;
+}

From https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension... we know that REQUIREMENT_ERROR prevents intall:

If a requirement has a severity of REQUIREMENT_ERROR, install.php will abort or at least the module will not install.

I don't think we should prevent install. Let's make it a warning so the user knows the next step, but isn't prevented from installing just because they didn't place the js library in its home yet.

There's also no check during the runtime phase yet. Let's add that so the Drupal status page reports whether the dependency is there or not.

The label module also uses this library so the hook_requirements should probably go in the main module, not the receipt one. I suggest looking at whether either submodule is installed and only warning at runtime if either actually exists.

The patch needs to address Alex's feedback about removing the documentation from the receipt module's README so it's not in two places.

deepakaryan1988’s picture

Hello @tbradbury,
I have addressed all your points in this patch.
Please review this and let me know if it needs further enhancements.

deepakaryan1988’s picture

Status: Needs work » Needs review
alexpott’s picture

Issue summary: View changes

Is it worthwhile working out how we can do progressive enhancement here. I.e. have a module that adds the library and enhance the forms that can use it? Because atm we have hard fails that hard to discover why.

deepakaryan1988’s picture

As discussed with @tbradbury, I have written hook_requirements in core module and moved content of README.md from commerce_receipt to commerce_pos.

Please review now.

Status: Needs review » Needs work
smccabe’s picture

@alexpott

I think so, I don't care about it to much for actual users, but it makes the tests either skip or break on a significant part of functionality. I fought a hard to debug issues because of that just last week.

Do you think a fallback to a specific print button for all jquery.print options?

deepakaryan1988’s picture

Status: Needs work » Needs review
StatusFileSize
new5.75 KB

My bad. Previous patch wasn't well created.
Here is the new one.

travis-bradbury’s picture

Status: Needs review » Needs work

Deepak, there's feedback that is still not addressed from #17 - there's no checking of requirements during the runtime phase so the dependency doesn't show on the status report page.

There's also no check during the runtime phase yet. Let's add that so the Drupal status page reports whether the dependency is there or not.

The label module also uses this library so the hook_requirements should probably go in the main module, not the receipt one. I suggest looking at whether either submodule is installed and only warning at runtime if either actually exists.

Here's a hook_requirements implementation from the Drupal 7 version of this module for an example of checking requirements during the runtime phase.

/**
 * Implements hook_requirements().
 */
function commerce_pos_payment_requirements($phase) {
  $requirements = array();
  $payments_available = commerce_pos_get_payment_options();
  if ($phase == 'runtime') {
    if ($payments_available) {
      $requirements['commerce_pos_payment'] = array(
        'title' => t('Commerce Point of Sale Payment'),
        'severity' => REQUIREMENT_OK,
        'value' => t('Payment Methods Configured'),
      );
    }
    else {
      $link = l(t('configure payment methods here.'), '/admin/commerce/config/custom-offline-payments');
      $requirements['commerce_pos_payment'] = array(
        'title' => t('Commerce Point of Sale Payment'),
        'severity' => REQUIREMENT_WARNING,
        'value' => t("No payment methods configured. Enable Commerce POS Payments for default payment methods or !link", array('!link' => $link)),
      );
    }
  }

  return $requirements;
}

That example brings to mind something else that could improve with this patch. As an error it says "jQuery.print library is not installed.". That doesn't tell the user what to do, it just says what is. In the D7 version's commerce_pos_payment_requirements it describes the state when everything is OK "Payment methods configured" but helps the user figure out what to do if something is wrong: "No payment methods configured. Enable Commerce POS Payments for default payment methods or !link".

deepakaryan1988’s picture

Status: Needs work » Needs review
StatusFileSize
new6.04 KB
new905 bytes

Hello Travis,
I have addressed the issue with this patch.

Status: Needs review » Needs work
deepakaryan1988’s picture

Status: Needs work » Needs review
StatusFileSize
new6.07 KB

I am re-rolling the patch again as previous patch was based on earlier version, so that's why it failed to apply.

alexpott’s picture

Status: Needs review » Needs work

There's also the problem that rather than making the jQuery print library a progressive enhancement we making things more dependent on it. I.e. if you install commere_pos but not the label or receipt modules then you're going to get an irrelevant warning.

travis-bradbury’s picture

I had in mind that we'd be checking for the receipt/labels modules in commerce_pos_requirements() rather than make another module but now it doesn't seem like a great idea. There's already a third module that uses the print library and it's probably no good to have to remember to update the requirements hook every time something else finds a use for the library.

I chatted with Deepak and we decided it'd be better to go with another module as a bridge for this as Alex suggested in #11.

  • Make a print submodule (commerce_pos_print?).
  • Put the readme/hook_requirements() in commerce_pos_print.
  • Little update to receipt, label, reports submodules to use the other module.
deepakaryan1988’s picture

Hello Travis,
Shortly, I'll be uploading the submodule which you have mentioned earlier.

deepakaryan1988’s picture

Hello @tbradbury
Please see this patch and let me know if it needs further enhancement.

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

Status: Needs review » Needs work

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

travis-bradbury’s picture

The hook_help() implementation looks like it was taken right from commerce_pos_label; it calls a function from that module.

    // Main module help for the commerce_pos_label module.
    case 'help.page.commerce_pos_print':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Provides the ability to give print functionality for other sub-modules.') . '</p>';

      $label_formats = commerce_pos_label_get_label_formats();

      // Print out our currently defined label formats.

There's still references to commerce_pos/jQuery.print in the report and label module. They would have to use commerce_pos_print/jQuery.print now.

There shouldn't be any space between the two closing parentheses here.

    $path = base_path() . '/libraries/jQuery.print/jQuery.print.js';
    if (!file_exists($path) ) {
      $requirements['commerce_pos_print'] = [

I'm still not a fan of the description here because it doesn't tell the user what to do.

        'description' => t("jQuery.print library is not installed."),

How about something like "To print receipts, labels, and reports you must install the jQuery.print library."? Typically descriptions also link to somewhere but since we don't have documentation to link to and there's no way to install it from the UI we can assume people will look into the README at that point.

The patch makes all the sub-modules depend on the new print one. Do modules like commerce_pos_receipt actually require the print library? If not, they should recommend the print module, not depend on it. At this point I'm not sure if they already require it and making it optional could be a future enhancement or if we need to leave the print module as optional right now.

jnrfred’s picture

This patch addresses suggestions and issues from #35

jnrfred’s picture

Previous patch failed to apply. Here's a new one

jnrfred’s picture

Status: Needs work » Needs review
StatusFileSize
new37.89 KB
new6.6 KB

This patch creates a new module commerce_pos_print and updates the receipt, label, reports submodules to use the print library as required

Test for PosReceiptTest.php passed locally. I was able to print an order as well.

print library

Status: Needs review » Needs work

The last submitted patch, 38: commerce_pos_provide_print_library-2924548-38.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jnrfred’s picture

Removed the added dependency (commerce_pos_print) for the commerce_pos module. I think since we have added dependencies for label and report sub-modules there's no need to add it to the main module.

jnrfred’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 40: commerce_pos_provide_print_library-2924548-40.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jnrfred’s picture

Status: Needs work » Needs review
StatusFileSize
new8.15 KB

I hope this patch fixes the failing test. :)

Status: Needs review » Needs work

The last submitted patch, 43: commerce_pos_provide_print_library-2924548-43.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

smccabe’s picture

smccabe’s picture

Patch is still looking for commerce_pos_print module, causing tests to fail.

smccabe’s picture

Fred, i think there are some files missing from this patch, the changes are there, but the commerce_pos_print module is missing.

jnrfred’s picture

Status: Needs work » Needs review
StatusFileSize
new12.65 KB

Thanks Shawn for pointing out the missing files. This patch includes the missing files (commerce_pos_print module).

  • smccabe committed b7a8675 on 8.x-2.x authored by jnrfred
    Issue #2924548 by deepakaryan1988, jnrfred, tbradbury, shabana.navas,...
smccabe’s picture

Status: Needs review » Fixed

Cleaned up a little naming and some phpcs issues, otherwise good to go!

Status: Fixed » Closed (fixed)

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