Jump to content

Add supplier name and supplier reference to order in BO


Royal
 Share

Recommended Posts

Hello,

I would like to add two columns to the products summary in the order page (in backoffice):

  1. Supplier
  2. Supplier product reference

See attached screenshot for reference. PrestaShop version is 1.7.6.5.

Cattura.thumb.PNG.653ff99250e288892b711d5205b23741.PNG

To show  the columns, I added the following code to admin/themes/default/template/controllers/orders/_product_line.php starting at line 75:

<td>
	{if $product.supplier_name}{l s='Reference number:'} {$product.supplier_name}<br />{/if}
</td>
<td>
	{if $product.product_supplier_reference}{l s='Supplier reference:'} {$product.product_supplier_reference}{/if}
</td>

The columns appear in the products summary, but the supplier name and reference code are missing. When I open an order in BO, a notice pops up with error "[8] Undefined index: supplier_name".

I also tried with {Supplier::getnamebyid($id)}, but I don't know how to pass the product's supplier_id.

Any help would be very appreciated! Thank you.

Share this post


Link to post
Share on other sites

Insert {$product | @var_dump} into the tpl template and you will see all the variables.

Share this post


Link to post
Share on other sites

  • ventura pinned and unpinned this topic

Thank you for your reply. I used the var dump, and it turns out all the relevant variables are empty:

["id_supplier"]=> string(1) "0"
["product_supplier_reference"]=> string(0) ""
["supplier_reference"]=> string(0) ""

even though the supplier parameters are set correctly in the product page.

Screenshot of the Suppliers section for the ordered product.

What can I do to fix this behavior? I already purged cache from BO and by delete the content of var/cache folders.

Edited by Royal
Typo (see edit history)

Share this post


Link to post
Share on other sites

I managed to get the supplier name by selecting a supplier as the default supplier (even if there's only one supplier enabled) and using this code:

<td>
	{if $product.id_supplier}{Supplier::getnamebyid($product.id_supplier)}<br />{/if}
</td>

The problem is that, if a product has more suppliers, the code returns only the default one.

Still no clue on how to get the supplier reference.

  • Thanks 1

Share this post


Link to post
Share on other sites

override getProductsDetail function in classes/order/Order.php ( or classes/order/OrderInvoice.php - don't know which order detail you use)

   public function getProductsDetail()
    {
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT od.*, p.*, ps.*, 
         concat(ifnull(spr.name,""),if(s.name is null or spr.name is null,"","<BR>"), ifnull(group_concat(s.name  SEPARATOR "<BR>" ),"")) as suppliers,
         concat(ifnull(supplier_reference,""),if(s.name is null or supplier_reference is null or supplier_reference="","","<BR>"), ifnull(group_concat(psup.product_supplier_reference SEPARATOR "<BR>" ),"")) as supplier_references 
        FROM `' . _DB_PREFIX_ . 'order_detail` od
        LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = od.product_id)
        LEFT JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)

        LEFT JOIN ' . _DB_PREFIX_ . 'product_supplier psup on psup.id_product = p.id_product
        LEFT JOIN ' . _DB_PREFIX_ . 'supplier s on s.id_supplier = psup.id_supplier 
        LEFT JOIN ' . _DB_PREFIX_ . 'supplier spr on  p.id_supplier = spr.id_supplier
        
        WHERE od.`id_order` = ' . (int) $this->id);
    }

 

and use in tpl

<td>
	{if isset($product.suppliers)}{$product.suppliers}{/if}
</td>
<td>
	{if isset($product.supplier_references)}{$product.supplier_references}{/if}
</td>

( I didn't test it - take it with the reserve)

  • Thanks 1

Share this post


Link to post
Share on other sites

Hi EvaF, thank you for your reply.

I overrode the getProductsDetail function with your code, but the "supplier reference code" column is still empty. I think that the root of the problem is here:

On 7/17/2020 at 10:46 AM, Royal said:

I used the var dump, and it turns out all the relevant variables are empty:

["id_supplier"]=> string(1) "0"
["product_supplier_reference"]=> string(0) ""
["supplier_reference"]=> string(0) ""

even though the supplier parameters are set correctly in the product page.

I don't get why product_supplier_reference and supplier_reference are empty. When I open an order, I get the errors "Undefined index" and "Trying to get property 'value' of non-object".

Cattura.thumb.PNG.733702129c04a25016c1b451822175ae.PNG

Edited by Royal
Added screenshot (see edit history)

Share this post


Link to post
Share on other sites

it works for me:
ps15.thumb.png.ac8c47c44505c1b7c40b1f74551367d9.png

 

the _product_line.tpl

	....
	<td>{$product['suppliers']}</td>
	<td>{$product['supplier_references']}</td>

	<td class="productQuantity text-center">
	...


Because default supplier was twice (see picture above), I have changed a little bit query ( and added also product attribute)

    public function getProductsDetail()
    {

        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT od.*, p.*, ps.*, 
         concat( ifnull(group_concat(spr.name  SEPARATOR "<BR>" ),"")) as suppliers,
         concat(ifnull(group_concat(psup.product_supplier_reference SEPARATOR "<BR>" ),"")) as supplier_references 
        FROM `' . _DB_PREFIX_ . 'order_detail` od
        LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = od.product_id)
        LEFT JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)

        LEFT JOIN ' . _DB_PREFIX_ . 'product_supplier psup on psup.id_product = p.id_product and od.product_attribute_id =psup.id_product_attribute         
        LEFT JOIN ' . _DB_PREFIX_ . 'supplier spr on  spr.id_supplier = psup.id_supplier 
        
        WHERE od.`id_order` = ' . (int) $this->id);

    }

the result:

ps16.thumb.png.56ea6667b3639ab7869693d189b2d1f4.png

 

 

  • Thanks 2

Share this post


Link to post
Share on other sites

Hi EvaF.

I was able to get everything to work thanks to your code. I was using a different syntax in my _product_line.tpl (e.g. {$product..supplier_references} instead of {$product['supplier_references']}, which explains the error.

This thread can now be marked as solved.

Thanks again to everyone who participated in the discussion. Cheers!

Share this post


Link to post
Share on other sites

  • 1 year later...
  • 4 weeks later...
  • 4 weeks later...

Hello, for Prestashop 1.7.7 you have to look for the html.twig file in src/PrestashopBundle/Form/Admin - and there are the templates from admin panel - in several different categories/folders. But you have to override them in module - or just replace the code inside, which is not good for updates - will loose it when updated.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More