Jump to content

Attachments on email


jaimeZesis

Recommended Posts

I have a shop with Guest Checkout as the only way to buy the products.

When you have to fill the invoice information I give the customer the option of leave all fields (except name, surname and email) as the default value I set (like for example Direction as direction).

What I'm trying to do, and here is my question, is how I manage to controll if the payment acccepted email should include the invoice pdf or not. I think that the easiest option is to check a value like Direction or Phone (or any other field with a default value set by me), but I don't know how the code should look nor where to place it.

 

EDIT: I know that I can diseable the option of sending the invoice on the backoffice, but then I should create another status and move to it manually when I want to send it.

Edited by jaimeZesis (see edit history)
Link to comment
Share on other sites

In prestashop 1.7 you need to see the order classes in prestashop_files/classes/order

 

In Order.php you have this method addOrderPayment

    /**
     *
     * This method allows to add a payment to the current order
     * @since 1.5.0.1
     * @param float $amount_paid
     * @param string $payment_method
     * @param string $payment_transaction_id
     * @param Currency $currency
     * @param string $date
     * @param OrderInvoice $order_invoice
     * @return bool
     */

see OrderInvoice parameter in this method . You can set it to  null based on the customer address

Link to comment
Share on other sites

I'm working with the version 1.6.1.15

Maybe I should comment in earlier.

I'm placing the code on /classes/order/OrderHistory.php around line 451. The query that I have to take the last value from the ps_address table for the customer I want is:

$direccion = Db::getInstance()->getRow('
                        SELECT address1
                        FROM `'._DB_PREFIX_.'address`
                        WHERE `id_customer` = '.(int)$order->id_customer.
                        ' ORDER BY id_address desc');

After that, I add another condition on the if that looks like

 if ($result['pdf_invoice'] && (int)Configuration::get('PS_INVOICE') && $order->invoice_number

so the result is

if ($result['pdf_invoice'] && (int)Configuration::get('PS_INVOICE') && $order->invoice_number && $direccion['address1'] != 'Direccion') {

I check the value of $direccion['address1'] and it's an empty space, but if I remove the "ORDER BY id_address desc" from the query it contains some value.

PD: The last "Direccion" is just a test value.

 

EDIT: I have realise that if it's a guest checkout nobody is going to change the direction so no order by is needed, and without it, this works perfectly, at least for me.

Edited by jaimeZesis (see edit history)
Link to comment
Share on other sites

 

I check the value of $direccion['address1'] and it's an empty space, but if I remove the "ORDER BY id_address desc" from the query it contains some value.

PD: The last "Direccion" is just a test value.

 

So basically your problem is an SQL one. Have you tried printing the query , then running in pmpmyadmin for example see what returns?

echo('SELECT address1
                        FROM `'._DB_PREFIX_.'address`
                        WHERE `id_customer` = '.(int)$order->id_customer.
                        ' ORDER BY id_address desc');


Link to comment
Share on other sites

The SQL issue is solved, I jsut delete the ORDER BY id_address desc.

The problem now is that the modifications that I did on orderHistory.php only affect when the status is changed from the backoffice, but I want it to do it automatically, when the payment is validated.

Which file has the code that send the payment accepted email?

Link to comment
Share on other sites

Like I said in post #6 from this thread https://www.prestashop.com/forums/topic/629309-attachments-on-email/?p=2615392 you should find all answers in prestashop_files/classes/order

 

In Order.php you have the method setInvoice

            // Update order payment
            if ($use_existing_payment) {
                $id_order_payments = Db::getInstance()->executeS('
					SELECT DISTINCT op.id_order_payment
					FROM `'._DB_PREFIX_.'order_payment` op
					INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.reference = op.order_reference)
					LEFT JOIN `'._DB_PREFIX_.'order_invoice_payment` oip ON (oip.id_order_payment = op.id_order_payment)
					WHERE (oip.id_order != '.(int)$order_invoice->id_order.' OR oip.id_order IS NULL) AND o.id_order = '.(int)$order_invoice->id_order);

                if (count($id_order_payments)) {
                    foreach ($id_order_payments as $order_payment) {
                        Db::getInstance()->execute('
							INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
							SET
								`id_order_invoice` = '.(int)$order_invoice->id.',
								`id_order_payment` = '.(int)$order_payment['id_order_payment'].',
								`id_order` = '.(int)$order_invoice->id_order);
                    }
                    // Clear cache
                    Cache::clean('order_invoice_paid_*');
                }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...