Page 1 of 1

Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 8:30 pm
by kia
My Opencart needs to send a file as attachment by order confirmation, which is sent to customer's email after successful checkout. I added "$mail->AddAttachment("xyz.pdf");" before "$mail->send();" into catalog/model/checkout/order.php. It works well, but I don't want to send the attachment, if order contains 4 specific products. I know ID's of the products. How can I filter those products? I think some foreach command going through ordered products , and put some if command to check whether order contains one of those products. How can I implent that? How does the commands look like?

Thanks for help!

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 8:32 pm
by straightlight

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 8:57 pm
by kia
Thanks for your reply.

The extension sends email manually, but I want to send attachment automatically by order confirmation email.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 8:58 pm
by kia
straightlight wrote:
Mon Jun 25, 2018 8:32 pm
This extension may be useful: https://www.opencart.com/index.php?rout ... n_id=22210
The extension sends email manually, but I want to send attachment automatically by order confirmation email.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 9:05 pm
by straightlight
You could use that extension by also using VQMod by targeting your catalog/controller/mail/order.php file afterwards.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 9:07 pm
by straightlight
In addition, since you are focusing on specific product IDs, you could also set a condition in that same controller file. Also, your OC version has not been posted.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 9:24 pm
by kia
straightlight wrote:
Mon Jun 25, 2018 9:07 pm
In addition, since you are focusing on specific product IDs, you could also set a condition in that same controller file. Also, your OC version has not been posted.
I have added "$mail->AddAttachment("xyz.pdf");" before "$mail->send();" into catalog/model/checkout/order.php. This sends the attachment by order confirmation by all product ID's, but I want to exclude sending attachment, If order contains one of the specific product ID's. I think it need some few code for "foreach" and "if condition". I know C++ and C#, but I cannot code PHP. I think it is not complicated for someone how know PHP. Can you please advise me how the code look like for this purpose? The Opencart store is 2.3.0.2 version.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Mon Jun 25, 2018 9:33 pm
by straightlight
Since you are still missing posted information in order to provide an accurate solution, I will provide the partial code so for you to tweak it:

Code: Select all

$order_products = $this->model_checkout_order->getOrderProducts($order_info['order_id']);

$order_product_ids = array();

foreach ($order_products as $order_product) {
    $order_product_ids[] = (int)$order_product['product_id'];
}

if (!in_array(array(1, 2, 3, 4), $order_product_ids)) {
    // Add email attachment object here.
}
This should resolved the issue.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Wed Jun 27, 2018 1:02 am
by kia
straightlight wrote:
Mon Jun 25, 2018 9:33 pm
Since you are still missing posted information in order to provide an accurate solution, I will provide the partial code so for you to tweak it:

Code: Select all

$order_products = $this->model_checkout_order->getOrderProducts($order_info['order_id']);

$order_product_ids = array();

foreach ($order_products as $order_product) {
    $order_product_ids[] = (int)$order_product['product_id'];
}

if (!in_array(array(1, 2, 3, 4), $order_product_ids)) {
    // Add email attachment object here.
}
This should resolved the issue.
I have tried this code, but it doesn't work. The whole module has stopped to send email order confirmation both to customer and to store admin. I added this code:

$order_products = $this->model_checkout_order->getOrderProducts($order_info['order_id']);

$order_product_ids = array();

foreach ($order_products as $order_product) {
$order_product_ids[] = (int)$order_product['product_id'];
}

if (!in_array(array(139, 188, 207, 106, 159, 146, 166, 135, 188), $order_product_ids)) {
$mail->AddAttachment("xyz.pdf");
}

$mail->send();

But it seems that it is something wrong.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Wed Jun 27, 2018 1:10 am
by straightlight
Error / Access logs?

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Wed Jun 27, 2018 1:36 am
by kia
straightlight wrote:
Wed Jun 27, 2018 1:10 am
Error / Access logs?
I checked the error_log file on the server. There is no notification error for this. Is there some specific log for email modul? Can you see some log informasion, which shows which emails has been sent after checkout?

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Wed Jun 27, 2018 1:51 am
by straightlight
You checked the error_log file but what about the server's access logs?

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Wed Jun 27, 2018 3:14 am
by kia
straightlight wrote:
Wed Jun 27, 2018 1:51 am
You checked the error_log file but what about the server's access logs?
Where is server access logs located? I cannot find them.

Re: Email attachment by order confirmation sending to cutomer after successful checkout

Posted: Wed Jun 27, 2018 3:27 am
by straightlight
On your web host's console.