Royal Posted July 16, 2020 Share Posted July 16, 2020 Hello, I would like to add two columns to the products summary in the order page (in backoffice): Supplier Supplier product reference See attached screenshot for reference. PrestaShop version is 1.7.6.5. 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. Link to comment Share on other sites More sharing options...
Guest Posted July 17, 2020 Share Posted July 17, 2020 Insert {$product | @var_dump} into the tpl template and you will see all the variables. Link to comment Share on other sites More sharing options...
Royal Posted July 17, 2020 Author Share Posted July 17, 2020 (edited) 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. What can I do to fix this behavior? I already purged cache from BO and by delete the content of var/cache folders. Edited July 17, 2020 by Royal Typo (see edit history) Link to comment Share on other sites More sharing options...
Royal Posted July 17, 2020 Author Share Posted July 17, 2020 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. 1 Link to comment Share on other sites More sharing options...
EvaF Posted July 17, 2020 Share Posted July 17, 2020 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) 1 Link to comment Share on other sites More sharing options...
Royal Posted July 18, 2020 Author Share Posted July 18, 2020 (edited) 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". Edited July 18, 2020 by Royal Added screenshot (see edit history) Link to comment Share on other sites More sharing options...
EvaF Posted July 18, 2020 Share Posted July 18, 2020 it works for me: 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: 2 Link to comment Share on other sites More sharing options...
Royal Posted July 20, 2020 Author Share Posted July 20, 2020 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! Link to comment Share on other sites More sharing options...
JulioQ Posted September 30, 2021 Share Posted September 30, 2021 Anybody knows how to do the same but in PrestaShop 1.7.7. Because I cannot find the files and folders you mention many thanks in advance Julio Link to comment Share on other sites More sharing options...
b.a.h.m.a.n Posted October 23, 2021 Share Posted October 23, 2021 any solution in PrestaShop 1.7.7 ? 🙏 Link to comment Share on other sites More sharing options...
pl.sabotinov Posted November 17, 2021 Share Posted November 17, 2021 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now