Jump to content

Add supplier to PDF delivery slip


Recommended Posts

oops, sorry for the misread.

Unfortunately supplier_name is not assigned by default by PS in delivery-slip.tpl, it only has the default id_supplier variable.

which means you have to go further deep than the tpl file.

 

Another way without touching any code is to use a supplier reference.

Let say you have a supplier name: Acme, INC.

1. You set the supplier to your product, by editing it.

2. Manually add again, "Acme, INC" to the supplier reference field

3. the supplier reference will be displayed in your delivery slip

 

If you think this solution is way too tedious or you have like 1000+ products and supplier, then you need to start thinking about touching the code is AdminPdf / Order / Product

Link to comment
Share on other sites

Shoot.... You're right, you can't have any other information than id_supplier in your delivery.. terribly sorry for misleading.

 

Ok, looks like we have to go deeper into the rabbit hole.. here goes..

 

1. Copy classes/order/OrderInvoice.php to override/classes/order/OrderInvoice.php

2. Edit the copied file (this is a very excellent way of hacking into PS, without breaking it apart)

go to line around 165, after

 

$row['id_address_delivery'] = $order->id_address_delivery;

 

add:

$row['id_address_delivery'] = $order->id_address_delivery;

$row['supplier_name'] = Supplier::getNameById($row['id_supplier']);

this will get supplier name for your product

 

3. Open pdf/delivery-slip.tpl

look for the product foreach loop, and add the supplier name -> {$product.supplier_name}

{foreach $order_details as $product}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<td style="text-align: left; width: 60%">{$product.product_name} supplier: {$product.supplier_name}
</td>

 

IMPORTANT: DELETE cache/class_index.php otherwise you'll be pulling your hair off.

also.. don't forget to set the supplier reference for your product :)

 

100% tested and worked using PS 1.5.4.1

 

Have fun, tell me if it works on your side and click "like this" :)

Edited by swsindonesia (see edit history)
  • Like 1
Link to comment
Share on other sites

Thanks, it works perfect... but is possible also add supplier address, phone and e-mail?

 

Glad that works well on your side, please take time to edit this topic as [sOLVED]

 

to add more details of your supplier, just query from the Address object, add these code after the modification in OrderInvoice.php

  $row['supplier_name'] = Supplier::getNameById($row['id_supplier']);

  // get more details
  $id_address = Address::getAddressIdBySupplierId($row['id_supplier']);
  $supplier_address_object = Address::initialize($id_address);

$row['supplier_address1'] = $supplier_address_object->address1;
$row['supplier_address2'] = $supplier_address_object->address2;
$row['supplier_postcode'] = $supplier_address_object->postcode;
$row['supplier_city'] = $supplier_address_object->city;
$row['supplier_phone'] = $supplier_address_object->phone;
$row['supplier_phone_mobile'] = $supplier_address_object->phone_mobile;

 

then as you can guess, you can use any variables available there in your tpl such as $product.supplier_address1, $product.supplier_phone, and so on respectively.

You can find more info about this by looking at your database table: ps_address

select * from ps_address where alias='supplier'

 

cheers.

Edited by swsindonesia (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 6 months later...

Shoot.... You're right, you can't have any other information than id_supplier in your delivery.. terribly sorry for misleading.

 

Ok, looks like we have to go deeper into the rabbit hole.. here goes..

 

1. Copy classes/order/OrderInvoice.php to override/classes/order/OrderInvoice.php

2. Edit the copied file (this is a very excellent way of hacking into PS, without breaking it apart)

go to line around 165, after

 

$row['id_address_delivery'] = $order->id_address_delivery;
add:

$row['id_address_delivery'] = $order->id_address_delivery;

$row['supplier_name'] = Supplier::getNameById($row['id_supplier']);
this will get supplier name for your product

 

3. Open pdf/delivery-slip.tpl

look for the product foreach loop, and add the supplier name -> {$product.supplier_name}

{foreach $order_details as $product}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<td style="text-align: left; width: 60%">{$product.product_name} supplier: {$product.supplier_name}
</td>
IMPORTANT: DELETE cache/class_index.php otherwise you'll be pulling your hair off.

also.. don't forget to set the supplier reference for your product :)

 

100% tested and worked using PS 1.5.4.1

 

Have fun, tell me if it works on your side and click "like this" :)

 

How can I add the supplier reference?

Link to comment
Share on other sites

  • 1 month later...

Shoot.... You're right, you can't have any other information than id_supplier in your delivery.. terribly sorry for misleading.

 

Ok, looks like we have to go deeper into the rabbit hole.. here goes..

 

1. Copy classes/order/OrderInvoice.php to override/classes/order/OrderInvoice.php

2. Edit the copied file (this is a very excellent way of hacking into PS, without breaking it apart)

go to line around 165, after

 

$row['id_address_delivery'] = $order->id_address_delivery;
add:

$row['id_address_delivery'] = $order->id_address_delivery;

$row['supplier_name'] = Supplier::getNameById($row['id_supplier']);
this will get supplier name for your product

 

3. Open pdf/delivery-slip.tpl

look for the product foreach loop, and add the supplier name -> {$product.supplier_name}

{foreach $order_details as $product}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<td style="text-align: left; width: 60%">{$product.product_name} supplier: {$product.supplier_name}
</td>
IMPORTANT: DELETE cache/class_index.php otherwise you'll be pulling your hair off.

also.. don't forget to set the supplier reference for your product :)

 

100% tested and worked using PS 1.5.4.1

 

Have fun, tell me if it works on your side and click "like this" :)

 

 

Hi, would this be possible to to with manufacture name ?

Link to comment
Share on other sites

  • 1 year later...

Glad that works well on your side, please take time to edit this topic as [sOLVED]

 

to add more details of your supplier, just query from the Address object, add these code after the modification in OrderInvoice.php

   $row['supplier_name'] = Supplier::getNameById($row['id_supplier']);
  
   // get more details
   $id_address = Address::getAddressIdBySupplierId($row['id_supplier']);
   $supplier_address_object = Address::initialize($id_address);

$row['supplier_address1'] = $supplier_address_object->address1;
$row['supplier_address2'] = $supplier_address_object->address2;
$row['supplier_postcode'] = $supplier_address_object->postcode;
$row['supplier_city'] = $supplier_address_object->city;
$row['supplier_phone'] = $supplier_address_object->phone;
$row['supplier_phone_mobile'] = $supplier_address_object->phone_mobile;

then as you can guess, you can use any variables available there in your tpl such as $product.supplier_address1, $product.supplier_phone, and so on respectively.

You can find more info about this by looking at your database table: ps_address

select * from ps_address where alias='supplier'

 

cheers.

 

 

Great.. This works also on Prestashop 1.6 :)

 

Is it possible to add also supplier description? I have tried add my own custom code in controller, but without luck.

Link to comment
Share on other sites

×
×
  • Create New...