
Sometimes default PrestaShop back-office configuration is not user-friendly for some store owners. Luckily, there are plenty of ways to customize it. For instance, today I want to share with you some tips on configuring sorting fields in Prestashop back-office.
For example, you don’t need a Base Price filter in your product grid and want to add sorting by Final Price. Simply open file override/controllers/admin/AdminProductsController.php and replace all the code with the following one
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?php class AdminProductsController extends AdminProductsControllerCore { public function __construct() { parent::__construct(); $this->fields_list['price_final'] = array( 'title' => $this->l('Final price'), 'width' => 90, 'type' => 'price', 'align' => 'right', ); } public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = null) { $orderByPriceFinal = (empty($orderBy) ? ($this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : 'id_'.$this->table) : $orderBy); $orderWayPriceFinal = (empty($orderWay) ? ($this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderby') : 'ASC') : $orderWay); AdminController::getList($id_lang, $orderBy, $orderWay, $start, $limit, $this->context->shop->id); $nb = count($this->_list); if ($this->_list) { for ($i = 0; $i < $nb; $i++) { $this->_list[$i]['price'] = Tools::convertPrice($this->_list[$i]['price'], $this->context->currency, true, $this->context); $this->_list[$i]['price_tmp'] = Product::getPriceStatic($this->_list[$i]['id_product'], true, null, 2, null, false, true, 1, true); } } if ($orderByPriceFinal == 'price_final') { if (strtolower($orderWayPriceFinal) == 'desc') uasort($this->_list, 'cmpPriceDesc'); else uasort($this->_list, 'cmpPriceAsc'); } for ($i = 0; $this->_list && $i < $nb; $i++) { $this->_list[$i]['price_final'] = $this->_list[$i]['price_tmp']; unset($this->_list[$i]['price_tmp']); } if ($orderByPriceFinal == 'price_final') { $order = (string)Tools::getValue('productOrderway'); usort($this->_list, create_function('$a, $b','return $a["price_final"] ' . (strtolower($order) == 'desc' ? '<' : '>') . ' $b["price_final"];') ); } } } |

Thanks for tip. Can you tell me how to put add by image ( i want to see all my products without pictures).
Thanks