Jump to content

Warehouse Location into Delivery Slip


Recommended Posts

I'm looking to understand IN GENERAL how to put various database variables into PDFs like Delivery Slips or Invoices.

 

**OR**

 

How do I replace the REFERENCE variable in the delivery slip with the WAREHOUSE LOCATION variable ?

 

 

 

I guess what I'm looking for is the *name* of the class / object / variable / whatever that contains a product's WAREHOUSE LOCATION

 

thanks

Link to comment
Share on other sites

I guess what I'm looking for is the *name* of the class / object / variable / whatever that contains a product's WAREHOUSE LOCATION

 

OK - I'm getting closer. I've found the DATABASE TABLE "ps_warehouse_product_location" and

 

the FIELDS

id_warehouse_product_location

id_product

id_product_attribute

id_warehouse

location

 

So my question is ... how do I get the "location" field into the Delivery Slip PDF ... thanks in advance

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
  • 2 months later...
  • 3 months later...
  • 1 month later...
  • 2 months later...

Using 1.5.5.0 as test, I got it working.

 

Edit classes/pdf/HTMLTemplateDeliverySlip.php

 

On line 70: 'order_details' => $this->order_invoice->getProducts(), change to 'order_details' => $order_details,

 

Around line 65 (above this line $carrier = new Carrier($this->order->id_carrier);)

Add this code:

		$order_details = $this->order_invoice->getProducts();
		foreach ($order_details as $key => $order_detail)
		{
			$order_details[$key]['warehouse_name'] = "--";
			$order_details[$key]['warehouse_location'] = "--";
			if ($order_detail['id_warehouse'] != 0)
			{
				$warehouse = new Warehouse((int)$order_detail['id_warehouse']);
				$warehouse_location = $warehouse->getProductLocation($order_detail["product_id"],$order_detail["product_attribute_id"],$warehouse->id);
				$order_details[$key]['warehouse_name'] = $warehouse->name;
				$order_details[$key]['warehouse_location'] = $warehouse_location;
			}
		}

Then you can use $product.warehouse_name and $product.warehouse_location in the pdf/delivery-slip.tpl

 

 

  • Like 3
Link to comment
Share on other sites

  • 2 months later...

Using 1.5.5.0 as test, I got it working.

 

Edit classes/pdf/HTMLTemplateDeliverySlip.php

 

On line 70: 'order_details' => $this->order_invoice->getProducts(), change to 'order_details' => $order_details,

 

Around line 65 (above this line $carrier = new Carrier($this->order->id_carrier);)

Add this code:

		$order_details = $this->order_invoice->getProducts();
		foreach ($order_details as $key => $order_detail)
		{
			$order_details[$key]['warehouse_name'] = "--";
			$order_details[$key]['warehouse_location'] = "--";
			if ($order_detail['id_warehouse'] != 0)
			{
				$warehouse = new Warehouse((int)$order_detail['id_warehouse']);
				$warehouse_location = $warehouse->getProductLocation($order_detail["product_id"],$order_detail["product_attribute_id"],$warehouse->id);
				$order_details[$key]['warehouse_name'] = $warehouse->name;
				$order_details[$key]['warehouse_location'] = $warehouse_location;
			}
		}

Then you can use $product.warehouse_name and $product.warehouse_location in the pdf/delivery-slip.tpl

How do I get the location to display?

Link to comment
Share on other sites

  • 3 months later...

Using 1.5.5.0 as test, I got it working.

 

Edit classes/pdf/HTMLTemplateDeliverySlip.php

 

On line 70: 'order_details' => $this->order_invoice->getProducts(), change to 'order_details' => $order_details,

 

Around line 65 (above this line $carrier = new Carrier($this->order->id_carrier);)

Add this code:

		$order_details = $this->order_invoice->getProducts();
		foreach ($order_details as $key => $order_detail)
		{
			$order_details[$key]['warehouse_name'] = "--";
			$order_details[$key]['warehouse_location'] = "--";
			if ($order_detail['id_warehouse'] != 0)
			{
				$warehouse = new Warehouse((int)$order_detail['id_warehouse']);
				$warehouse_location = $warehouse->getProductLocation($order_detail["product_id"],$order_detail["product_attribute_id"],$warehouse->id);
				$order_details[$key]['warehouse_name'] = $warehouse->name;
				$order_details[$key]['warehouse_location'] = $warehouse_location;
			}
		}

Then you can use $product.warehouse_name and $product.warehouse_location in the pdf/delivery-slip.tpl

 

Thanks! Perfect :) :)

Link to comment
Share on other sites

  • 2 months later...

Hi,

 

In fact I want it in the product table of the order detail view...not sure for the english terms ;)

 

So a pictures is better than words  I would like to see warehouse.location where I have highlighted in yellow

 

 

post-624746-0-09009100-1401543945_thumb.png

 

 

Thank you :)

Link to comment
Share on other sites

Okey, so in the product line, on admin order view.
 

Linenumbers are from 1.5.6.2

Step 1
/controllers/admin/AdminOrdersController.php

			if ($product['id_warehouse'] != 0)
			{
				$warehouse = new Warehouse((int)$product['id_warehouse']);
				$product['warehouse_name'] = $warehouse->name;
				/* Delivery location patch*/
				$warehouse_location = $warehouse->getProductLocation($product["product_id"],$product["product_attribute_id"],$warehouse->id);
				$product['warehouse_location'] = $warehouse_location;
				/* Delivery location patch*/
			}
			else
				$product['warehouse_name'] = '--';

Step 2
/admin/themes/default/template/controllers/orders/_product_line.tpl
We must replace this line

{if $display_warehouse}<td align="center">{$product.warehouse_name|escape:'htmlall':'UTF-8'}</td>{/if}

With this slightly modified code

	{if $display_warehouse}<td align="center">{$product.warehouse_name|escape:'htmlall':'UTF-8'}
	<br>{$product.warehouse_location|escape:'htmlall':'UTF-8'}
	</td>{/if}

 
 
This will place warehouse location bellow the warehouse name, in the warehouse column.

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

Hi PhpMadman,

 

 

Very nice of you !! It works like a charm :)

 

I want to thank you for that because I never found the solution on the french prestashop Forum and you give me two in just a minute or so :)

 

Your help is much appreciated :)

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

PhpMadman.

 

I also need to see the location in "order detail" but in version 1.6

 

I tried it your solution but does not work for me.

 

 

 

EDIT: It only works with orders created after putting the location.

 

Is it possible to read the value of table [prefix] _warehouse_product_location the product and not the order?

 

 

Can you help me?

 

Thanks!

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

  • 7 months later...

Hi, i m following this post cause I m trying to add the warehouse location in the invoice pdf. (Prestahsop 1.6.0.14)

 

I made the following override : /override/classes/pdf/HTMLTemplateInvoice.php containing (following @PhpMadman's post)

<?php

class HTMLTemplateInvoice extends HTMLTemplateInvoiceCore
{
	public function getContent()
	{
		$invoice_address = new Address((int)$this->order->id_address_invoice);
		$country = new Country((int)$invoice_address->id_country);

		$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
		$formatted_delivery_address = '';

		if ($this->order->id_address_delivery != $this->order->id_address_invoice)
		{
			$delivery_address = new Address((int)$this->order->id_address_delivery);
			$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
		}

		$customer = new Customer((int)$this->order->id_customer);
		
		$order_details = $this->order_invoice->getProducts();
		foreach ($order_details as $key => $order_detail)
		{
			$order_details[$key]['warehouse_name'] = "--";
			$order_details[$key]['warehouse_location'] = "--";
			if ($order_detail['id_warehouse'] != 0)
			{
				$warehouse = new Warehouse((int)$order_detail['id_warehouse']);
				$warehouse_location = $warehouse->getProductLocation($order_detail["product_id"],$order_detail["product_attribute_id"],$warehouse->id);
				$order_details[$key]['warehouse_name'] = $warehouse->name;
				$order_details[$key]['warehouse_location'] = $warehouse_location;
			}
		}

		'order_details' => $order_details,
		if (Configuration::get('PS_PDF_IMG_INVOICE'))
			foreach ($order_details as &$order_detail)
			{
				if ($order_detail['image'] != null)
				{
					$name = 'product_mini_'.(int)$order_detail['product_id'].(isset($order_detail['product_attribute_id']) ? '_'.(int)$order_detail['product_attribute_id'] : '').'.jpg';
					$order_detail['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_.'p/'.$order_detail['image']->getExistingImgPath().'.jpg', $name, 45, 'jpg', false);
					if (file_exists(_PS_TMP_IMG_DIR_.$name))
						$order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
					else
						$order_detail['image_size'] = false;
				}
			}

		$data = array(
			'order' => $this->order,
			'order_details' => $order_details,
			'cart_rules' => $this->order->getCartRules($this->order_invoice->id),
			'delivery_address' => $formatted_delivery_address,
			'invoice_address' => $formatted_invoice_address,
			'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
			'tax_tab' => $this->getTaxTabContent(),
			'customer' => $customer
		);

		if (Tools::getValue('debug'))
			die(json_encode($data));

		$this->smarty->assign($data);

		return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code));
	}

}

I added the code from line 21 to 33.

and changed the line 35.

 

But it doesn't work.

 

Someone would have an idea about what I made wrong ? 

 

Thanks per advance to anyone who can help.

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

Slightly different solution could be

{$order[orders].order_detail[detail].warehouse_product_location.location|escape:'htmlall':'UTF-8'}

Used in m4_deliveryslip_image.tpl and m4_invoice_label2.tpl templates (M4 PDF Extensions), out of the box.

Link to comment
Share on other sites

Slightly different solution could be

{$order[orders].order_detail[detail].warehouse_product_location.location|escape:'htmlall':'UTF-8'}

Used in m4_deliveryslip_image.tpl and m4_invoice_label2.tpl templates (M4 PDF Extensions), out of the box.

Thanks for the answer.

But something is missing.

When I add this code in the invoice.tpl, it breaks the generation (no more pdf to download, just few html information displayed in the browser)

Link to comment
Share on other sites

Hi to all,

 

I just find this deliveryslip tweak for the warehouse location echo in it, it's really useful !

 

Thanks to Madman for his code.

 

I try to do the same with the invoice because we work mainly without delivery slip and i m on the same situation as mattheoh..

 

I have checked the code for invoice implant and i can't find a clean solution but i m sure there is small modification to do only but where ?

 

If someone or Madman can helps us about this it should be really useful for the community !

 

So, please oh great php master help us to display the {$product.warehouse_location} variable content correcly in the invoice :-)

 

Wish you an Happy coding and Debugging :-)

Best regards,

Sam

 

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

Hi.
 
I haven't been following this thread, but, I do now.
Anyway, there are several people asking for adding in to invoice as well.
 
Using this code from my post
 
Same code goes in both classes/pdf/HTMLTemplateDeliverySlip.php and classes/pdf/HTMLTemplateInvoice.php
 
In delivery-slip.tpl, you should use $product.warehouse_name and $product.warehouse_location
In invoice.tpl, ps changed the syntax, and there it is $order_detail instead. $order_detail.warehouse_name and $order_detail.warehouse_location
 
I havent tested any of this. But it should work.

 
Adding it to orderSlip is a bit more complex. You can just use $order_details, instead, there already is a foreach $this->products, there you have to add the warehouse_*, and it's also another syntax within the php file, and you also have to change the syntax of the foreach.
the tpl file use $order_detail.
 
If anyone does want it on orderSlip, i'll help if needed.

Link to comment
Share on other sites

Hi.

 

Same code goes in both classes/pdf/HTMLTemplateDeliverySlip.php and classes/pdf/HTMLTemplateInvoice.php

 

In delivery-slip.tpl, you should use $product.warehouse_name and $product.warehouse_location

In invoice.tpl, ps changed the syntax, and there it is $order_detail instead. $order_detail.warehouse_name and $order_detail.warehouse_location

 

I havent tested any of this. But it should work.

 

 

Hi, and thanks for your feedback.

I tried to override HTMLTemplateInvoice.php to add the location in the PDF invoices.

I m on Prestashop 1.6.0.14

 

I added the override, of the function getContent(), but the code is a little bit different from TemplateDeliverySlip.php

 

Here 's my override code : 

<?php

class HTMLTemplateInvoice extends HTMLTemplateInvoiceCore
{
	public function getContent()
	{
		$invoice_address = new Address((int)$this->order->id_address_invoice);
		$country = new Country((int)$invoice_address->id_country);

		$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
		$formatted_delivery_address = '';

		if ($this->order->id_address_delivery != $this->order->id_address_invoice)
		{
			$delivery_address = new Address((int)$this->order->id_address_delivery);
			$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
		}

		$customer = new Customer((int)$this->order->id_customer);
		
		$order_details = $this->order_invoice->getProducts();
		foreach ($order_details as $key => $order_detail)
		{
			$order_details[$key]['warehouse_name'] = "--";
			$order_details[$key]['warehouse_location'] = "--";
			if ($order_detail['id_warehouse'] != 0)
			{
				$warehouse = new Warehouse((int)$order_detail['id_warehouse']);
				$warehouse_location = $warehouse->getProductLocation($order_detail["product_id"],$order_detail["product_attribute_id"],$warehouse->id);
				$order_details[$key]['warehouse_name'] = $warehouse->name;
				$order_details[$key]['warehouse_location'] = $warehouse_location;
			}
		}

		'order_details' => $order_details,
		if (Configuration::get('PS_PDF_IMG_INVOICE'))
			foreach ($order_details as &$order_detail)
			{
				if ($order_detail['image'] != null)
				{
					$name = 'product_mini_'.(int)$order_detail['product_id'].(isset($order_detail['product_attribute_id']) ? '_'.(int)$order_detail['product_attribute_id'] : '').'.jpg';
					$order_detail['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_.'p/'.$order_detail['image']->getExistingImgPath().'.jpg', $name, 45, 'jpg', false);
					if (file_exists(_PS_TMP_IMG_DIR_.$name))
						$order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_.$name);
					else
						$order_detail['image_size'] = false;
				}
			}

		$data = array(
			'order' => $this->order,
			'order_details' => $order_details,
			'cart_rules' => $this->order->getCartRules($this->order_invoice->id),
			'delivery_address' => $formatted_delivery_address,
			'invoice_address' => $formatted_invoice_address,
			'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
			'tax_tab' => $this->getTaxTabContent(),
			'customer' => $customer
		);

		if (Tools::getValue('debug'))
			die(json_encode($data));

		$this->smarty->assign($data);

		return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code));
	}

}

as I said in a previous post, 

I added your code from line 21 to 33.
and changed the line 35.
 
Then as you said, I add $order_detail.warehouse_name in invoice.tpl, but doesn't seem to work.
I think I don't modify correctly the function getContent() and specially the part concerning 'order_details' => $order_details (line 35). You can see this code also appears line 52 (don't know if it's important)
 
Do you have an idea of my mistake ?
 
Thanks a lot !
Edited by mattheoh (see edit history)
Link to comment
Share on other sites

Hi.

 

If that simply does not show up in pdf, then the override is not working. And you need to delete the cache/class_index.php file.

Beacuse, that code should crash the pdf.

 

Line 35, should be removed, it's wrong and useless.

Line 52, is the line that send's data to the tpl, so that's the most important one of all ; )

Other than that, it seems fine to me.

Link to comment
Share on other sites

Hi and thanks for your answer !

 

If that simply does not show up in pdf, then the override is not working. And you need to delete the cache/class_index.php file.

 

I m an idiot ! I forgot... Indeed now it's crashing ;-)

 

 

Line 35, should be removed, it's wrong and useless.

Line 52, is the line that send's data to the tpl, so that's the most important one of all ; )

Other than that, it seems fine to me.

 

I deleted the line, but unfortunately, it doesn't seem to work.

I checked an invoice, containing a product which has information in field "location" in ps_product table, but nothing shows up with $order_detail.warehouse_name or $order_detail.warehouse_location added in invoice.tpl.

 

Thanks again for your help !

Link to comment
Share on other sites

That's strange, at very least, it should show -- on all products.

If you don't get that, then warehouse_* don't get added correctly.

If you turn on Debug mode, the pdf should show either -- or undefinded index warehouse_* on each line.

Link to comment
Share on other sites

That's strange, at very least, it should show -- on all products.

If you don't get that, then warehouse_* don't get added correctly.

If you turn on Debug mode, the pdf should show either -- or undefinded index warehouse_* on each line.

It does ! (sorry didn't indicate that)

without turning debug mode , indeed, it shows " -- " on all products lines.

But no location name, on a product line whom has one in the database. (see screens attached)

no more indication if I turn debug mode on

 

l4ncxV2.png.

 

Gz5Pwa4.png

 

Thanks again for your help !

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

For Matt,

 

 

The location field in product_table is present but not used anymore by ps >1.5.6

 

For warehouse_location you have to use advanced stock management, define a warehouse,

and in the product tab go to warehouse, put product in warehouse, define a rack/shelve location

in the field location of the product warehouse tab.

The warehouse_location values are read from ps_warehouse_product_location table

not from the ps_product table.

 

Hope this help,

Regards,

Sam

 

PS: Madman, thanks a lot for your help about this tweak.

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

You're both perfectly right !

My customer was adding the location with store commander, and indeed it was still inserted in the old field in ps_product table.

 

So, I activated the advanced stock management, and fullfilled the informations.

I updated one product to test :

 

RQNYB1Z.png

 

deleted cache/class_index.php , cache...

and can't still see the location in the invoice !

 

XdJIh89.png

 

the code in my invoice.tpl is the following one : <td  style="text-align: left; width: 5%;">{$order_detail.warehouse_location}</td>

 
I m sorry, just feel like a noob ! :-(
Link to comment
Share on other sites

That's very strange. I don't see anything wrong with your code.

And if you updated a product and then places an order on that product, the warehouse should show up.

I don't remember how PS collects the products for order_invoice, but it uses info from the order_details table, it might not show on old orders.

I'll look in to that after work.

  • Like 1
Link to comment
Share on other sites

That's very strange. I don't see anything wrong with your code.

And if you updated a product and then places an order on that product, the warehouse should show up.

I don't remember how PS collects the products for order_invoice, but it uses info from the order_details table, it might not show on old orders.

I'll look in to that after work.

That's what I did ... I updated the product #3260.

And cause it wasn't working on an old invoice containing it, I tried to place a new order (was also thinking that the invoice could extract informations from ps_order_details table)

but same result (it's the screenshot I did).

Maybe it s my override which is not correct.

 

Does it work on your installation, if you place it override/classes/pdf ?

HTMLTemplateInvoice.php

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

Hi to all,

 

I just implant the invoice warehouse product tweak in my ps 1.5.6.1 shop and everything is ok.

Now the delivery slip and invoice contains the famous warehouse product location values :-)

 

For mat, check your ps cache, your template compilation switch too, may be your trouble

come from that because there is no trouble with this code on ps 1.5.

 

Ca marche, yes !!!  :-)

 

Regards,

Sam

  • Like 1
Link to comment
Share on other sites

Yes. It's worked directly and on old orders.

I'm running 1.6.0.9 on my dev site. Havent upgraded yet.

 

post-465501-0-24438300-1428562960_thumb.png

 

 

So, since you do get the --, but not the location, there must be something missing on the product.

Is it checked as stored?

Can you clear all cache?

Do you cache pdf to the harddrive?  I never used it, but I assume you need to delete the pdf file then, to get an real update.

Also do Sam's suggestions.

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

I m becoming crazy...

I clean all the caches, delete class_index.php, checked that the product was stored, tried to edit directly the files without overriding...

 

Can I ask you a last favor PhpMadman ?

on your 1.6.0.9, can you add the two files attached in your folders :

themes/yourtheme/pdf/invoice.tpl (delete the .txt extensions)

override/classes/pdf/HTMLInvoice.php (don't forget to use the original prestashop file in classes/pdf/ and not a modified one)

 

and tell me if it's working.

I just tried on a 1.6.0.11, and it's not working.

If it's working for you, that means, it's not a problem from the code / files, but from my configuration.

 

Thanks a lot to you both !

HTMLTemplateInvoice.php

invoice.tpl.txt

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

thanks a lot for the test and the confirmation.

I found the reason reading the override code.

 

In my ps_order_detail table, I have systematically id_warehouse = 0 , even on new orders. That's why have always in invoices : "--"

 

Now, I have to understand why ! ^^

 

Thanks again for your big help PhpMadman and losdelsolo

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

Yes 0 ! ;-)

 

ps_order_detail :

 

OFgkcRF.png

 

but the id_warehouse is at 1 in ps_warehouse :

 

WRVi1C8.png

 

Now I have to find the guilty !

 

Maybe it could be store commander which wasn t set with advanced stock management...

Do you confirm that it's not necessary to set advanced stock management for each product ? (it's sufficient to store a product in a warehouse and add the location)

let's wait and see the next orders.

 

Thanks again for your help !

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

Finally I got it !

 

yg1J8R1.png

 

 

 

It wasn't an incompatibilty with a module.

I just had to check the advanced stock management in the product concerned

 

7cky1zo.png

 

I have to do a SQL query to do that on all my products.

 

Merci , Merci beaucoup messieurs ;-)

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

Nice. Glad it finally solved.

I'm so used to Advanced stock, that I forget that you need to switch it on in each product when activating it for the first time.

And due to the switches I added in an earlier version of PS (1.6.0.11 i think or as early as 1.6.0.4 and 1.6.0.6), I don't have bother to do that on new products.

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

  • 1 month later...
  • 2 weeks later...

Do you want to show me how:
 

My htmlsupplyordertemplate is like this:

 

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
 
/**
 * @since 1.5
 */
class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
{
public $supply_order;
public $warehouse;
public $address_warehouse;
public $address_supplier;
public $context;
 
public function __construct(SupplyOrder $supply_order, $smarty)
{
$this->supply_order = $supply_order;
$this->smarty = $smarty;
$this->context = Context::getContext();
$this->warehouse = new Warehouse((int)$supply_order->id_warehouse);
$this->address_warehouse = new Address((int)$this->warehouse->id_address);
$this->address_supplier = new Address(Address::getAddressIdBySupplierId((int)$supply_order->id_supplier));
 
// header informations
$this->date = Tools::displayDate($supply_order->date_add);
$this->title = HTMLTemplateSupplyOrderForm::l('Supply order form');
}
 
/**
* @see HTMLTemplate::getContent()
*/
public function getContent()
{
$supply_order_details = $this->supply_order->getEntriesCollection((int)$this->supply_order->id_lang);
$this->roundSupplyOrderDetails($supply_order_details);
 
$this->roundSupplyOrder($this->supply_order);
 
$tax_order_summary = $this->getTaxOrderSummary();
$currency = new Currency((int)$this->supply_order->id_currency);
 
$this->smarty->assign(array(
'warehouse' => $this->warehouse,
'address_warehouse' => $this->address_warehouse,
'address_supplier' => $this->address_supplier,
'supply_order' => $this->supply_order,
'supply_order_details' => $supply_order_details,
'tax_order_summary' => $tax_order_summary,
'currency' => $currency,
));
 
return $this->smarty->fetch($this->getTemplate('supply-order'));
}
 
/**
* @see HTMLTemplate::getBulkFilename()
*/
public function getBulkFilename()
{
return 'supply_order.pdf';
}
 
/**
* @see HTMLTemplate::getFileName()
*/
public function getFilename()
{
return self::l('SupplyOrderForm').sprintf('_%s', $this->supply_order->reference).'.pdf';
}
 
protected function getTaxOrderSummary()
{
$query = new DbQuery();
$query->select('
SUM(price_with_order_discount_te) as base_te,
tax_rate,
SUM(tax_value_with_order_discount) as total_tax_value
');
$query->from('supply_order_detail');
$query->where('id_supply_order = '.(int)$this->supply_order->id);
$query->groupBy('tax_rate');
 
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
 
foreach ($results as &$result)
{
$result['base_te'] = Tools::ps_round($result['base_te'], 2);
$result['tax_rate'] = Tools::ps_round($result['tax_rate'], 2);
$result['total_tax_value'] = Tools::ps_round($result['total_tax_value'], 2);
}
unset($result); // remove reference
 
return $results;
}
 
/**
* @see HTMLTemplate::getHeader()
*/
public function getHeader()
{
$shop_name = Configuration::get('PS_SHOP_NAME');
$path_logo = $this->getLogo();
$width = $height = 0;
 
if (!empty($path_logo))
list($width, $height) = getimagesize($path_logo);
 
$this->smarty->assign(array(
'logo_path' => $path_logo,
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
'title' => $this->title,
'reference' => $this->supply_order->reference,
'date' => $this->date,
'shop_name' => $shop_name,
'width_logo' => $width,
'height_logo' => $height
));
 
return $this->smarty->fetch($this->getTemplate('supply-order-header'));
}
 
/**
* @see HTMLTemplate::getFooter()
*/
public function getFooter()
{
$this->address = $this->address_warehouse;
$free_text = array();
$free_text[] = HTMLTemplateSupplyOrderForm::l('DE: Discount excluded ');
$free_text[] = HTMLTemplateSupplyOrderForm::l(' DI: Discount included');
 
$this->smarty->assign(array(
'shop_address' => $this->getShopAddress(),
'shop_fax' => Configuration::get('PS_SHOP_FAX'),
'shop_phone' => Configuration::get('PS_SHOP_PHONE'),
'shop_details' => Configuration::get('PS_SHOP_DETAILS'),
'free_text' => $free_text,
));
return $this->smarty->fetch($this->getTemplate('supply-order-footer'));
}
 
/**
* Rounds values of a SupplyOrderDetail object
* @param array $collection
*/
protected function roundSupplyOrderDetails(&$collection)
{
foreach ($collection as $supply_order_detail)
{
$supply_order_detail->unit_price_te = Tools::ps_round($supply_order_detail->unit_price_te, 2);
$supply_order_detail->price_te = Tools::ps_round($supply_order_detail->price_te, 2);
$supply_order_detail->discount_rate = Tools::ps_round($supply_order_detail->discount_rate, 2);
$supply_order_detail->price_with_discount_te = Tools::ps_round($supply_order_detail->price_with_discount_te, 2);
$supply_order_detail->tax_rate = Tools::ps_round($supply_order_detail->tax_rate, 2);
$supply_order_detail->price_ti = Tools::ps_round($supply_order_detail->price_ti, 2);
}
}
 
/**
* Rounds values of a SupplyOrder object
* @param SupplyOrder $supply_order
*/
protected function roundSupplyOrder(SupplyOrder &$supply_order)
{
$supply_order->total_te = Tools::ps_round($supply_order->total_te, 2);
$supply_order->discount_value_te = Tools::ps_round($supply_order->discount_value_te, 2);
$supply_order->total_with_discount_te = Tools::ps_round($supply_order->total_with_discount_te, 2);
$supply_order->total_tax = Tools::ps_round($supply_order->total_tax, 2);
$supply_order->total_ti = Tools::ps_round($supply_order->total_ti, 2);
}
}
 
 
Best regards
Link to comment
Share on other sites

Create /override/classes/HTMLTemplateSupplyOrderForm.php

 

And paste the following code.

<?php
class HTMLTemplateSupplyOrderForm extends HTMLTemplateSupplyOrderFormCore
{

	public function getContent()
	{
		$supply_order_details = $this->supply_order->getEntriesCollection((int)$this->supply_order->id_lang);
		
		// Start location patch
		foreach ($supply_order_details as &$order_detail)
		{
			
			$order_detail['warehouse_name'] = "--";
			$order_detail['warehouse_location'] = "--";
			if ($order_detail['id_warehouse'] != 0)
			{
				$warehouse = new Warehouse((int)$order_detail['id_warehouse']);
				$warehouse_location = $warehouse->getProductLocation($order_detail["product_id"],$order_detail["product_attribute_id"],$warehouse->id);
				$order_detail['warehouse_name'] = $warehouse->name;
				$order_detail['warehouse_location'] = $warehouse_location;
			}
		}
		// End location patch
		
		$this->roundSupplyOrderDetails($supply_order_details);
		$this->roundSupplyOrder($this->supply_order);
		$tax_order_summary = $this->getTaxOrderSummary();
		$currency = new Currency((int)$this->supply_order->id_currency);
		$this->smarty->assign(array(
			'warehouse' => $this->warehouse,
			'address_warehouse' => $this->address_warehouse,
			'address_supplier' => $this->address_supplier,
			'supply_order' => $this->supply_order,
			'supply_order_details' => $supply_order_details,
			'tax_order_summary' => $tax_order_summary,
			'currency' => $currency,
		));
		return $this->smarty->fetch($this->getTemplate('supply-order'));
	}
}

It's untestad, but should work. Just edit supply-order.tpl and add $supply_order_detail->warehouse_location

Link to comment
Share on other sites

  • 2 weeks later...

Hi, 

 

I followed PhpMadman solution to implement warehouse location on PS 1.6.0.14 and it works like a charm. Thanks a lot !!

 

I have a question.

 

How can I override pdf/delivery-slip.tpl ? I tried to put this file in override/pdf/delivery-slip.tpl but it doesn't work.

 

Do you have an idea ?

Link to comment
Share on other sites

On Prestashop 1.6 $product.warehouse_name and $product.warehouse_location did not work for me.

I have to use $order_detail.warehouse_location and $order_detail.warehouse_name instead in pdf\delivery-slip.tpl

 

Anyway, :thumbsup: and thank you!

  • Like 1
Link to comment
Share on other sites

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

Finally I got it !

 

yg1J8R1.png

 

 

 

It wasn't an incompatibilty with a module.

I just had to check the advanced stock management in the product concerned

 

7cky1zo.png

 

I have to do a SQL query to do that on all my products.

 

Merci , Merci beaucoup messieurs ;-)

 

Nice!

 

Can anyone advise; how can I make an SQL query to activate Advanced Stock Management for all products at once?

 

We are manually assigning warehouse location for each product now (and clicking this checkbox for each product) and when we currently get orders, the orders get split up in Prestashop (customer makes 1 order, we get 2 invoices: one for the ones with advanced stock management and one for those without it). So we just quickly want to activate it for everything on the fly.

 

Thanks in advance.

Link to comment
Share on other sites

Hi.

 

Export all products, with name, and id, Wholesale price and qty.

Then fix a csv and import them again. In the csv you can add the following

Advanced Stock Management (1/0)
Depends on stock (1/0)
Warehouse (id_warehouse)
 
Qty will be automaticlly be assigned to the warehouse.
Wholeshale price will be assigned as the product cost in warehouse, if i remember correctlly
 
Just remember to to a test run on one product and also check the Force all ID numbers switch.
 
That will assign warehouse for all your products.
 
As for warehouse_location. It's not supported by import, but i do have a script for it somewhere. I'll look for it.
  • Like 1
Link to comment
Share on other sites

 

 

As for warehouse_location. It's not supported by import, but i do have a script for it somewhere. I'll look for it.

 

 

Cool, thanks PhpMadman!

 

Is there any way we can also export the entire catalog of products with warehouse_location included, so we can easily double check that everything really is assigned a location?

When I do a normal product export there is barely any information but I guess it would be possible with a sql query. I just don't know how.

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

  • 1 month later...

Sorry to bump this thread, but does anyone know how to export a product list with warehouse location included?

We still, months later, receive orders where Prestashop splits our orders into two (creating a customer support mess and confused customers) because some products have a warehouse location, and some don't. And there is no way for us to see out entire catalog with warehouse location info.

 

I tried this SQL query variant:

SELECT * FROM ps_warehouse_product_location WHERE ps_warehouse_product_location.id_warehouse_product_location

But it seems to just show the stuff which already has a location.

 

I'm not experienced with database things, as you see.

Link to comment
Share on other sites

SELECT * FROM ps_product p
LEFT OUTER JOIN ps_product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = 1)
LEFT OUTER JOIN ps_warehouse_product_location wpl ON (p.id_product = wpl.id_product)
LEFT OUTER JOIN ps_warehouse w ON (wpl.id_warehouse = w.id_warehouse)

Change the 1 to another ID for different language.

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...
×
×
  • Create New...