Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15
  1. #11
    Join Date
    Jan 2007
    Posts
    1,484
    Plugin Contributions
    10

    Default Re: qz print tray 2.0.7 and printing from admin

    Actually, I got it working with a compiled version and self-signed cert. I followed the instructions you posted a few replies up, https://goo.gl/ts1oGT. My problem was a little mistake of not completely commenting out the password part in sign-message:
    PHP Code:
    $privateKey openssl_get_privatekey(file_get_contents($KEY/*, $PASS */ ); 
    I missed the comma at first in between $KEY, $PASS. Once I fixed it it started to print correctly. Just the little mistakes sometimes.... I just turned 48 and am trying hard to keep from getting reading glasses..... hahaha.

    I did always get that exact "untrusted website" from your screen shot and it wouldn't save the "allow" click on the popup window. Looking at the compiled version of qz-tray.properties, I saw that the path for the override file was C:\\Program Files\\QZ Tray\\auth\\cert.pem instead of just cert.pem. I uninstalled the compiled version and tried the stock version just to check it and once I changed the path it works as expected.

    Thanks again for all of your help, Carl! Hopefully others will see this and it will be easy(er) to get it running in silent mode. Now, on to the USB scale! They do have some info about it:
    https://qz.io/wiki/2.0-usb-communication
    https://qz.io/wiki/2.0-hid-communication

    Zen Cart and it's community are the best!!

  2. #12
    Join Date
    Jan 2007
    Posts
    1,484
    Plugin Contributions
    10

    Default Re: qz print tray 2.0.7 and printing from admin

    In further testing, I couldn't get it to print multiple labels (if the shipment has more than 1 box). Currently, the base shipping code creates as many labels as specified and appends _1, _2, etc to the png file. I had to move the references to the external js files to within the PHP while loop. I also redid the javascript to be a little simpler, here's the complete code in case anyone has a similar need
    PHP Code:
    <?php if ($fedex_labels->RecordCount() > 0) {
      while(!
    $fedex_labels->EOF) {
          
    $label $fedex_labels->fields['labels'];
          
    ?> 
    <script language="javascript" src="includes/javascript/rsvp-3.1.0.min.js"></script>
    <script language="javascript" src="includes/javascript/sha-256.min.js"></script>
    <script language="javascript" src="includes/javascript/qz-tray.js"></script>
    <script language="javascript" src="includes/javascript/trustedCert.js"></script>
    <script language="javascript">
        qz.websocket.connect().then(function() { 
       return qz.printers.find("Zebra ZP 500")               // Pass the printer name into the next Promise
    }).then(function(printer) {
       var options =  {language: "ZPLII" };
       var config = qz.configs.create(printer, options);       // Create a default config for the found printer
       var data = [{ type: 'image', data: 'images/fedex/<?php echo $label?>' }];
       return qz.print(config, data);
    }).catch(function(e) { console.error(e); });
    </script> 
        <?php  $fedex_labels->MoveNext();
      }
     
    ?>

    Zen Cart and it's community are the best!!

  3. #13
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,685
    Plugin Contributions
    9

    Default Re: qz print tray 2.0.7 and printing from admin

    lankee,
    while your code may work, i do not like it. in your OP, you stated you wanted to learn/grow from this experience, so allow me to throw a few things in.

    the inclusion of the 4 javascripts within your while statement is bad. period. and totally unnecessary. you possibly have set cache control on, which means the processing penalty is low, but i would move those out of the while loop. you can certainly put them after the if statement, and it will still work fine.

    the in-line javascript for connect and print needs to be within the while statement, and specifically for the echo of label.

    i like the moving of the setSignaturePromise and setCertificatePromise to another js file; however i have not tested it. and the post link would need to be checked in order to get that properly called. i think the ajax call would be fine.

    and while we are on the topic, i can tell you what i have done; i moved the sign_message.php to MY_ADMIN/sign_message.php (i changed the dash to an underline...be careful... only personal preferences...) i then added to that script:

    require('includes/application_top.php');

    as the first line. in the ADMIN/includes/configure.php i added a new variable called DIR_KEY which made my second line:

    $KEY = DIR_KEY . 'key.pem';

    you can now test your signing w/o actually doing anything. and only when logged into the admin. i suppose you could have done that before as well.... but anyone could have done it, ie without logging into the admin... but i like it MUCH better this way.

    finally i love hard coding stuff as much as the next guy; however it is rarely a good idea. especially when you have test systems set up. i would set up a LABEL_PRINTER_NAME entry into your configuration database, and then use that for your printer name, ie:

    $printer = LABEL_PRINTER_NAME;

    and then later:

    var printer = "<?php echo $printer; ?>";

    doing it this way allows for setting up a test server much easier. especially if you use version control (which i recommend). the configure file is not under version control, and you will need to name the key and certificate the same, but in a small way, your code becomes much more transportable; and if you get a new label printer and need to change the name, you are not modifying code. you can change the printer name via the ADMIN -> CONFIGURATION and then whatever group into which you put the LABEL_PRINTER_NAME.

    just some food for thought....

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  4. #14
    Join Date
    Jan 2007
    Posts
    1,484
    Plugin Contributions
    10

    Default Re: qz print tray 2.0.7 and printing from admin

    All very good ideas! I tried quite a few different ways to get the script to print multiple labels in one go and this was the only way I could get it to print them all. Otherwise it only ever prints the first label. I didn't like doing it this way, either, but that's all I could come up with that works. I suspect to do this properly I would probably need to rewrite the whole block containing the while loop in javascript instead of PHP. If you are able to get it printing multiple files with the current PHP/JS code I would love to see how you did it.

    I will make the changes recommended and add to the admin configuration, that is much better than hard coding. I generally have tried to stay away from it, too. Like I said, I am pretty rusty hahaha.

    Zen Cart and it's community are the best!!

  5. #15
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,685
    Plugin Contributions
    9

    Default Re: qz print tray 2.0.7 and printing from admin

    lankee,
    i have also moved on to printing multiple labels.

    i have found that the best way to handle that is to create your print stream, and when you are done to send that stream to the printer.

    if i tried to send each individual label to the printer, the system would hang during the qz.websocket.connect() part of the function. and despite the code saying it would only try twice, it would get caught into an endless loop. which suggests to me something going on in the timing with javascript and having multiple attempts to connect with multiple print jobs. i may pursue it on the qz-tray forum when i have some time.

    i am reviewing your code and what you stated in #12 above (https://goo.gl/DkNyFD); and i can't seem to make sense of it. you state that you can not get it to print multiple labels, and then your code goes ahead and sends multiple print jobs. if that works for you great.... i moved all of the connect and print calls out of the while loop.

    in any event, i think qz-tray is a great solution for any ZC user who wants/needs the ability to print directly from a browser. thanks again for turning me onto it.

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. v151 How to hide my admin url when printing invoice from back end?
    By gsmsalers in forum General Questions
    Replies: 1
    Last Post: 27 Sep 2013, 09:55 AM
  2. admin URL prints at bottom of page when printing from browser
    By stitchnkitty in forum General Questions
    Replies: 6
    Last Post: 25 May 2010, 11:23 PM
  3. Looking to add print invoice and shipp invoice from admin---> orders
    By r4fdud in forum Upgrading from 1.3.x to 1.3.9
    Replies: 0
    Last Post: 15 Mar 2009, 11:21 PM
  4. Printing customers address's from database
    By cushietushies in forum General Questions
    Replies: 2
    Last Post: 6 Nov 2008, 10:24 AM
  5. Print Syle for invoice and and packaging slip in admin
    By stevefriedman71 in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 25 Aug 2007, 09:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR