star-micronics / star-cloudprnt-for-woocommerce

Print to Star CloudPRNT compatible printers from WooCommerce
MIT License
10 stars 8 forks source link

Isolate print job generator in separate package to allow easy re-use? #10

Closed holtkamp closed 3 years ago

holtkamp commented 3 years ago

We are currently investigating the use of the Star CloudPRNT Protocol to have remote Star printers print orders that are placed using our in-house developed e-commerce platform.

Installing a tool like cputil can be a challenge on Cloud Application Platforms like Heroku. In search of a way to circumvent the use of cputil I encountered this plugin for WooCommerce which seems to be able to generate print jobs directly / without using cputil, right?

Would it be an idea to isolate the functionality that generates print jobs in a separate package and publish it on Packagist.org to allow users to use Composer to include it in their projects?

Would this be something that can be considered? Or does it already exist?

I also noticed this thread which also covers this subject a bit: https://wordpress.org/support/topic/add-custom-images-2/

Lozrus commented 3 years ago

Hi @holtkamp Yes, hosting cputil is easy on your own servers, but not always ideal in other cases, which is one reason that it's not used by the WooCommerce plugin. A pure PHP option would be useful for many and is definitely something that I've considered ((but doesn't exist currently, sorry).

I think some extra work is needed to package it up well, but I'm tidying up the print job generator/document builder APi code a lot in the 2.1 branch of this plugin. It is also being documented as an API that can be used by WordPress/WooCommerce plugin developers to extend the print job. So at least we are making a start.

In the mean-time, I suggest that you pull the cloudprnt/cloudprnt_builde* and cloudprnt/printer_star* files from the 2.1 branch of this project and use the builder class directly. I think it should be reasonable self contained, other than a few constant values defined elsewhere in the code.

Alternatively, for a super easy (but paid) option, Star also have a live cloudPRNT hosting service, which you can use. You just need to connect your printers to this service, instead of to your own, and then use our REST API to send print jobs. Printing in this case just requires an HTTP POST, with the correckt API key and the print job as HTML, Star Markup, PNG, Jpeg etc. So it is very easy, and requires no special dependencies or services to be hosted by you. This is currently only available in Europe, Middle East and African sales regions though.

holtkamp commented 3 years ago

Hi @Lozrus, first of al: thanks for taking the time to write such a detailed response! Great to see 😉

A pure PHP option would be useful for many and is definitely something that I've considered ((but doesn't exist currently, sorry)

No need to be sorry at all, it seems you are already doing a great job on this subject.

I think some extra work is needed to package it up well, but I'm tidying up the print job generator/document builder APi code a lot in the 2.1 branch of this plugin. It is also being documented as an API that can be used by WordPress/WooCommerce plugin developers to extend the print job. So at least we are making a start.

Nice, I am willing to help on getting this "native" approach in the air by providing feedback, testing, etc. I know broad support for PHP versions is probably required, but from my experience being "strict" (such as using typed properties, available from PHP 7.4 eases development and prevents bugs, also by using tools like https://phpstan.org

What PHP version are you thinking of as minimum requirement?

In the mean-time, I suggest that you pull the cloudprnt/cloudprnt_builde and cloudprnt/printer_star files from the 2.1 branch of this project and use the builder class directly. I think it should be reasonable self contained, other than a few constant values defined elsewhere in the code.

Good suggestion, will dive into this and use these files to give it a try.

Alternatively, for a super easy (but paid) option, Star also have a live cloudPRNT hosting service, which you can use. You just need to connect your printers to this service, instead of to your own, and then use our REST API to send print jobs. Printing in this case just requires an HTTP POST, with the correckt API key and the print job as HTML, Star Markup, PNG, Jpeg etc. So it is very easy, and requires no special dependencies or services to be hosted by you. This is currently only available in Europe, Middle East and African sales regions though.

Ah, good idea, I was not aware of this service yet. Maybe it is good to have https://docs.starprinter.online mentioned on a page like https://www.star-m.jp/products/s_print/CloudPRNTSDK/Documentation/en/index.html as well? Or is it still "under the radar" because of the beta status?

To create an account, I read: "Please contact your regional Star Micronics office to request an account.", I will contact the EMEA office and try to see how smooth the onboarding process goes 😉

Looking forward working on this!