Brand on list of purchased products in PrestaShop 1.7

Several years ago I wrote tutorial about: Product manufacturer on back office order page  that step by step explains how to display manufacturer (brand) near each product on list of purchased products on order details page in shop's back office. Tutorial was dedicated for PrestaShop 1.6 only. Today i want to explain the same thing, but for PrestaShop 1.7. 

 

product list with manufacturer column order detail page

 

How to add brand information to list of purchased products?

Things since 2014 changed a lot. PrestaShop has very flexible core code now it gives much more possibilities than before. But it is also a little more complicated. To apply changes we will have to alter core, not only .tpl file as it was in the past. What is the idea?

  1. We need to build function in Product class that will return product manufacturer (brand) name
  2. We need to add Product class to twig template file that is responsible for list of products on order details page
  3. Then we need to execute a Product class function in twig template file

 

Firstly - let's create a function that will return brand name

in Product object class file file located here: classes/Product.php add a new function that will get product's manufacturer name. The code of function is attached below. It has parameter $id_product - as a result function will return name of manufacturer of product with id equal to $id_product parameter value.

    public static function getProductManufacturerName($id_product) {
      $product = new Product($id_product, false, Context::getContext()->language->id);
      $manufacturer = new Manufacturer($product->id_manufacturer, Context::getContext()->language->id);
      return $manufacturer->name;
    }

 

Secondly - let's add Product Class to twig template file

In PrestaShop 1.7.x branch smarty (.tpl) is continuously changed to twig template engine. Almost each new release of PrestaShop 1.7.x brings new twig files. We need to implement Product class instance into twig template. To achieve this we need to alter file src/prestashopBundle/Controller/Admin/Sell/Order/OrderController.php. At the begining of this file you can find code like:

    namespace PrestaShopBundle\Controller\Admin\Sell\Order

right after it add code:

    use Product;

 

Then, in the same file find code:

return $this->render('@PrestaShop/Admin/Sell/Order/Order/view.html.twig', [
            'showContentHeader' => true,
            'enableSidebar' => true,
            'orderCurrency' => $orderCurrency,
            'meta_title' => $metatitle,
            'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
            'orderForViewing' => $orderForViewing,
            'addOrderCartRuleForm' => $addOrderCartRuleForm->createView(),
            'updateOrderStatusForm' => $updateOrderStatusForm->createView(),
            'updateOrderStatusActionBarForm' => $updateOrderStatusActionBarForm->createView(),
            'addOrderPaymentForm' => $addOrderPaymentForm->createView(),
            'changeOrderCurrencyForm' => $changeOrderCurrencyForm->createView(),
            'privateNoteForm' => $privateNoteForm ? $privateNoteForm->createView() : null,
            'updateOrderShippingForm' => $updateOrderShippingForm->createView(),
            'cancelProductForm' => $cancelProductForm->createView(),
            'invoiceManagementIsEnabled' => $orderForViewing->isInvoiceManagementIsEnabled(),
            'changeOrderAddressForm' => $changeOrderAddressForm ? $changeOrderAddressForm->createView() : null,
            'orderMessageForm' => $orderMessageForm->createView(),
            'addProductRowForm' => $addProductRowForm->createView(),
            'editProductRowForm' => $editProductRowForm->createView(),
            'backOfficeOrderButtons' => $backOfficeOrderButtons,
            'merchandiseReturnEnabled' => $merchandiseReturnEnabled,
            'priceSpecification' => $this->getContextLocale()->getPriceSpecification($orderCurrency->iso_code)->toArray(),
            'previousOrderId' => $orderSiblingProvider->getPreviousOrderId($orderId),
            'nextOrderId' => $orderSiblingProvider->getNextOrderId($orderId),
            'paginationNum' => $paginationNum,
            'paginationNumOptions' => $paginationNumOptions,
            'isAvailableQuantityDisplayed' => $this->configuration->getBoolean('PS_STOCK_MANAGEMENT'),
            'internalNoteForm' => $internalNoteForm->createView(),
        ]);

and at the begining of this array add new variable ProductClass, like i show below:

 $product = new Product();
 return $this->render('@PrestaShop/Admin/Sell/Order/Order/view.html.twig', [
            'ProductClass' => $product,
            'showContentHeader' => true,
            'enableSidebar' => true,
            'orderCurrency' => $orderCurrency,
            'meta_title' => $metatitle,
            'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
            'orderForViewing' => $orderForViewing,
            'addOrderCartRuleForm' => $addOrderCartRuleForm->createView(),
            'updateOrderStatusForm' => $updateOrderStatusForm->createView(),
            'updateOrderStatusActionBarForm' => $updateOrderStatusActionBarForm->createView(),
            'addOrderPaymentForm' => $addOrderPaymentForm->createView(),
            'changeOrderCurrencyForm' => $changeOrderCurrencyForm->createView(),
            'privateNoteForm' => $privateNoteForm ? $privateNoteForm->createView() : null,
            'updateOrderShippingForm' => $updateOrderShippingForm->createView(),
            'cancelProductForm' => $cancelProductForm->createView(),
            'invoiceManagementIsEnabled' => $orderForViewing->isInvoiceManagementIsEnabled(),
            'changeOrderAddressForm' => $changeOrderAddressForm ? $changeOrderAddressForm->createView() : null,
            'orderMessageForm' => $orderMessageForm->createView(),
            'addProductRowForm' => $addProductRowForm->createView(),
            'editProductRowForm' => $editProductRowForm->createView(),
            'backOfficeOrderButtons' => $backOfficeOrderButtons,
            'merchandiseReturnEnabled' => $merchandiseReturnEnabled,
            'priceSpecification' => $this->getContextLocale()->getPriceSpecification($orderCurrency->iso_code)->toArray(),
            'previousOrderId' => $orderSiblingProvider->getPreviousOrderId($orderId),
            'nextOrderId' => $orderSiblingProvider->getNextOrderId($orderId),
            'paginationNum' => $paginationNum,
            'paginationNumOptions' => $paginationNumOptions,
            'isAvailableQuantityDisplayed' => $this->configuration->getBoolean('PS_STOCK_MANAGEMENT'),
            'internalNoteForm' => $internalNoteForm->createView(),
        ]);


And lastly - let's run getProductManufacturerName() function in twig file

Twig template file that is responsible for list of purchased products on order details page is located in this path: /src/PrestaShopBundle/Resources/Views/Admin/Sell/Order/Order/Blocks/View/product.html.twig.

List of purchased products appears as a table with columns and rows. Table has heading,  so we have to add "manufacturer" to table header that will point column with manufacturer (brand) name.

 

Heading

Search for code:

<th>
  <p class="mb-0">{{ 'Total'|trans({}, 'Admin.Global') }}</p>
  <small class="text-muted">{{ orderForViewing.taxMethod }}</small>
</th>

add after:

<th>
  <p class="mb-0">{{ 'Manufacturer'|trans({}, 'Admin.Global') }}</p>
</th>

 

Fill out manufacturer column with manufacturer (brand) name

Search for code: 

<td class="cellProductTotalPrice">{{ product.totalPrice }}</td>

add after:

<td>{{ProductClass.getProductManufacturerName(product.id)}}</td>
author milos myszczuk
Article by Milosz Myszczuk PrestaShop expert, official PrestaShop community moderator. PHP developer, specialist in relative and spatial databases management, GIS Analyst, CEO & founder of VEKIA interactive agency. Read more about VEKIA company
If you like my articles and want much more valuable tips, feel free to send me donation
1.4 version 1.4.11 1.6 404 addon admin advertise ahref ajax alpha animation api app application authentication back office backup badge banner basics block bootstrap button cache carrier cart catalog category certificate changelog chat class clear client clip cms code colors columns comments configuration contact container content controller cookie counter country coupon css csv currency customer dashboard database debug default delete delivery desktop developer device disable discount displayNav displayTop download dynamic editor effect empty encrypt engine error exchange exclude export facebook faceshop fade fancoupon fancybox fanpage fatal feature feed field file fix fixed font footer free friendly url front ftp full gallery generate gift global godaddy google google+ gray grid groupon header help hide highlight homefeatured homepage hook hosting hover howto htaccess html html5 ID image import include input instagram installation integration iPhone issue javascript jquery kgb knowhow languages law left likebox link list livingsocial loading log login logo loyality mail mailing maintenance manufacturer marketing marquee mcrypt menu meta mobile modification module movie moving multilanguage multiupload must have mysql news newsletter notification number open graph order override page password performance PHP phpmyadmin picture pinterest plugin popup post prestashop prestashop 1.0 prestashop 1.1 prestashop 1.2 prestashop 1.3 prestashop 1.4 prestashop 1.5 price rules problem product profile promotion proslider purifier quantity query quick tip random rates register reinsurance release reporting reset responsive restore results ribbon rich text right sales search security seo service shadow share shipping shop shopmania slider smarty social networks SQL SSL statistics stock store style subcategory superuser support switcher tab tablet tag tax template text theme tinyMCE tips and tricks tpl tracking translations tree trends trigger tumblr tutorial twitter update upgrade upload variables video visits voucher vulnerability web2print wide widget width window wishlist wysiwyg youtube zip zopim