Generate and send printable order copy

We'd like to sell a magazine - and subscriptions for it, too.

As there is no subscription module yet, I have the following idea:

  1. Customers order a 1-year-subscription (2 issues)
  2. When the 3rd issue comes out, we don't want them to reorder manually (as we do in our current shop, which is quite a headache)
  3. I'd like to have a cronjob which copies orders from #1 when #3 comes out, from #2 when #4 comes out, ... and so on.

How to realize?

  1. a cronjob copies the orders and writes new (updated) orders to the database
  2. the customer gets the new Order Copy via mail.

Part 1 (cronjob) should be possible. How can we realize Part 2? As I understand, 

http://[shop_url]/printable_order_copy?order_id=2&checksum=b2a59bbbd3b49f5d13864f73df8e0300&media=print

runs the creation of the order copy. How is the checksum generated (can be discussed via mail, of course g)? And how/where is the Order Copy delivered to the customer? (didn't get it, yet)

tim

I'm a bit confused in what is a question and what is not. Perhaps you want to provide some clear questions?

To email an order copy:

$order = new ctrl_order('load', $order_id);
$order->email_order_copy('recipient@email.com');

To duplicate an order:

$order = new ctrl_order('load', $order_id);
$order->data['id'] = null;
$order->save();

Sorry, my fault.

The core question was: How to send out a printable order copy?

What you provided (for both tasks) looks very, very, very easier than what I would have created. Thank you very much!

tim

Welcome to LiteCart, where simplicity is key ;)

Hi,
Which file do I make these changes in please:

$order = new ctrl_order('load', $order_id);
$order->email_order_copy('recipient@email.com');

Thanks

tim

Anyone. Depending on when you want to send the email.

$order = new ent_order('load', $order_id);
$order->email_order_copy('recipient@email.com');

I see, Well i'd like to send it to the customer and admin Immediately the checkout process. I'm using litecart 2.5.

I cant get this to work. I thought putting it in ent_order.inc.php in the  public function send_email_notification would work but that does not work.

$order = new ent_order('load', $order_id);
$order->email_order_copy('recipient@email.com');

My Apologies. I got my wires crossed. What I am looking for is a way to send the printable order copy to the customers and admins mailbox

tim

Like I said we are already doing that. The email copy to admins can be set under Admin -> Settings -> Checkout.

Yes I understand you can send the email that contains the order details and the link back to the printable order copy. But I am trying to find a way to send the actual html printable order copy.

tim

Ooh.. to send HTML emails you must change the add_body($message) to add_body($message, [b]true[/b]). This second parameter indicates if the message content is HTML or not. When omitted it defaults to false.

https://github.com/litecart/litecart/blob/2.5.4/public_html/includes/entities/ent_order.inc.php#L779

Here is one example.


$printable_order_copy->snippets['order'] = $this->data;
$printable_order_copy->snippets['text_direction'] = !empty(language::$languages[$this->data['language_code']]['direction']) ? language::$languages[$this->data['language_code']]['direction'] : 'ltr';
$message = $printable_order_copy->stitch('pages/printable_order_copy');

$email = new ent_email();
$email->add_recipient(...)
      ->set_subject(...)
      ->add_body($message, true)
      ->send();```

But it's not that easy in practical life. E-mail clients have several limitations. See https://caniuse.email/

I recommend something like this instead.
https://www.litecart.net/en/addons/317/order-copy-pdf-attachment

Thanks Tim. I tried your solution and it works but the printable order copy looses most it's original html formatting. I understand the reasons for that and See what you mean when you say E-mail clients have several limitations. 

I also tried the PDF vmod, but https://www.prerender.cloud/ is not working.

tim

I see Prerender moved the site to prerender.io but I think the API remains on .cloud. I have future plans of making an official PDF API by LiteCart.

Thanks Tim. PDF API is definitely a mod i'd purchase.

Ce fil de discussion a été fermé en raison d'une longue inactivité. Il n'est pas possible de publier dessus.