Jump to content

Adding E-mail Address on Invoice


Recommended Posts

My client wanted the email address of the customer on the invoice in PrestaShop™ 1.4.0.17. It took me a while to figure it out since i'm not really a programmer but I found a solution and I hope it will help others too.

In classes/customer.php add the following function which allows you to get customer data if you've got the ID.

public function getCustomerByID($id)
   {

       $result = Db::getInstance()->getRow('
       SELECT *
       FROM `'._DB_PREFIX_    .'customer`
       WHERE `active` = 1
       AND `id_customer` = '.$id.'
       ');

       if (!$result)
           return false;
       $this->id = $result['id_customer'];
       foreach ($result AS $key => $value)
           if (key_exists($key, $this))
               $this->{$key} = $value;

       return $this;
   }



Then in classes/PDF.php

AFTER:

        if (!empty($delivery_address->phone_mobile))
       {
           $pdf->Ln(5);
           $pdf->Cell($width, 10, $delivery_address->phone_mobile, 0, 'L');
       }



ADD:

       $customerId = $order->id_customer;
       $customerObject = new Customer();
       $customerObject->getCustomerByID($customerId);

       $pdf->Ln(5);
       $pdf->Cell($width, 10, $customerObject->email, 0, 'L');



Hope somebody finds this helpfull, and if anyone has any suggestions or modifications I'll be glad to know.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...

My client wanted the email address of the customer on the invoice in PrestaShop™ 1.4.0.17. It took me a while to figure it out since i'm not really a programmer but I found a solution and I hope it will help others too.

In classes/customer.php add the following function which allows you to get customer data if you've got the ID.

public function getCustomerByID($id)
{
	$result = Db::getInstance()->getRow('
	SELECT *
	FROM `'._DB_PREFIX_	.'customer`
	WHERE `active` = 1
	AND `id_customer` = '.$id.'
	');
	if (!$result)
		return false;
	$this->id = $result['id_customer'];
	foreach ($result AS $key => $value)
		if (key_exists($key, $this))
			$this->{$key} = $value;
	return $this;
}

Then in classes/PDF.php

AFTER:

		if (!empty($delivery_address->phone_mobile))
	{
		$pdf->Ln(5);
		$pdf->Cell($width, 10, $delivery_address->phone_mobile, 0, 'L');
	}

ADD:

	$customerId = $order->id_customer;
	$customerObject = new Customer();
	$customerObject->getCustomerByID($customerId);

	$pdf->Ln(5);
	$pdf->Cell($width, 10, $customerObject->email, 0, 'L');

Hope somebody finds this helpfull, and if anyone has any suggestions or modifications I'll be glad to know.

 

 

Hi, I'm using Prestashop Version: 1.4.4.0 and I'm unable to locate the code you mention in pdf.php. Does anyone know how to add email addresses to invoices in this version of Prestashop?

 

Thanks

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

I took this approach in 1.4.2.5...

1. Add the classes/customer.php code as andrex84 suggested.

2. Modify classes/PDF.php as follows...

 

AFTER

public static function generateHeaderAddresses(&$pdf, $order, $addressType, $patternRules, $width)
{

 

ADD


$customerId = $order->id_customer;
       $customerObject = new Customer();
       $customerObject->getCustomerByID($customerId);

 

FIND

$pdf->MultiCell($width, 6.0, $addressType[$type]['displayed'], 0, 'L', 0);

 

REPLACE WITH


if ($type == 'invoice')  {
$pdf->MultiCell($width, 6.0, $addressType[$type]['displayed'] . $customerObject->email, 0, 'L', 0);
}
else  {
$pdf->MultiCell($width, 6.0, $addressType[$type]['displayed'], 0, 'L', 0);
}

Link to comment
Share on other sites

  • 4 months later...
  • 2 months later...
  • 1 year later...
  • 3 years later...

For PS 1.6

 

To add an email - edit invoice.tpl in /pdf/

 

add this line within the template table where you want the email to appear

 

<tr>
            <td colspan="12"> 
              Email : {$customer_email}
            </td>
        </tr>
 
The $customer_email is first initialised within HTMLTemplateInvoice.php file found in classes/pdf/
 
'customer_email' => $customer->email,
 
Find the function getContent() 
 
and look for this lines
 
$tpls = array(         
            'customer_email' => $customer->email,
            'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('invoice.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('invoice.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('invoice.product-tab')),
            'tax_tab' => $this->getTaxTabContent(),
            'payment_tab' => $this->smarty->fetch($this->getTemplate('invoice.payment-tab')),
'note_tab' => $this->smarty->fetch($this->getTemplate('invoice.note-tab')),
            'total_tab' => $this->smarty->fetch($this->getTemplate('invoice.total-tab')),
            'shipping_tab' => $this->smarty->fetch($this->getTemplate('invoice.shipping-tab')),
        );
        $this->smarty->assign($tpls);
 
 
Notice 'customer_email' => $customer->email is the new addition.
Link to comment
Share on other sites

×
×
  • Create New...