Post by kia » Mon Jun 25, 2018 8:30 pm

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!

kia
New member

Posts

Joined
Fri Feb 17, 2017 7:23 pm

Post by straightlight » Mon Jun 25, 2018 8:32 pm


Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kia » Mon Jun 25, 2018 8:57 pm

Thanks for your reply.

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

kia
New member

Posts

Joined
Fri Feb 17, 2017 7:23 pm

Post by kia » Mon Jun 25, 2018 8:58 pm

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.

kia
New member

Posts

Joined
Fri Feb 17, 2017 7:23 pm

Post by straightlight » Mon Jun 25, 2018 9:05 pm

You could use that extension by also using VQMod by targeting your catalog/controller/mail/order.php file afterwards.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » 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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kia » Mon Jun 25, 2018 9:24 pm

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.

kia
New member

Posts

Joined
Fri Feb 17, 2017 7:23 pm

Post by straightlight » 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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kia » Wed Jun 27, 2018 1:02 am

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.

kia
New member

Posts

Joined
Fri Feb 17, 2017 7:23 pm

Post by straightlight » Wed Jun 27, 2018 1:10 am

Error / Access logs?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kia » Wed Jun 27, 2018 1:36 am

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?

kia
New member

Posts

Joined
Fri Feb 17, 2017 7:23 pm

Post by straightlight » Wed Jun 27, 2018 1:51 am

You checked the error_log file but what about the server's access logs?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kia » Wed Jun 27, 2018 3:14 am

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.

kia
New member

Posts

Joined
Fri Feb 17, 2017 7:23 pm

Post by straightlight » Wed Jun 27, 2018 3:27 am

On your web host's console.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 211 guests