Product list BO with manufacturers and suppliers columns



  • From the PS forum I have extended the product list with the columns for manufacturers and suppliers. Adapted to TB programming.
    Either:
    controllers / admin / AdminProductsController.php
    or via override
    override / controllers / admin / AdminProductsController.php

    As an an example (german text on image):

    0_1513384576213_6f758b72-5da5-4d16-9589-97803f5fec5f-grafik.png

    The customized file
    0_1513384537636_AdminProductsController.php



  • Can you make a gist, it might do better.



  • @lesley
    Sorry, there is someone on the line with me. I don’t understand what you mean by that.



  • Here you can see the changed code. If it is not completely needed, you can eg omit the lines and the array for the manufacturer or the supplier.

    original part 1

            $idShop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? (int) $this->context->shop->id : 'a.id_shop_default';
            $this->_join .= ' JOIN `'._DB_PREFIX_.'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = image_shop.`id_image`)
    				LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product` AND pd.`active` = 1)';
    
    

    new

            $idShop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? (int) $this->context->shop->id : 'a.id_shop_default';
            $this->_join .= ' JOIN `'._DB_PREFIX_.'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ('.$alias.'.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'shop` shop ON (shop.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$idShop.')
    				LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = image_shop.`id_image`)
    				LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = a.`id_manufacturer`)
    				LEFT JOIN `'._DB_PREFIX_.'supplier` supp ON (supp.id_supplier = a.`id_supplier`)
    				LEFT JOIN `'._DB_PREFIX_.'product_download` pd ON (pd.`id_product` = a.`id_product` AND pd.`active` = 1)';
    

    original part 2

            $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, ';
            $this->_select .= $aliasImage.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`';
    

    new

            $this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, ';
            $this->_select .= 'm.`name` AS `manufacturer_namen`, ';
            $this->_select .= 'shop.name as shopname, supp.`name` AS `supp`, ';
            $this->_select .= $aliasImage.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`';
    

    original part 3

            $this->fields_list['active'] = [
                'title'      => $this->l('Status'),
                'active'     => 'status',
                'filter_key' => $alias.'!active',
                'align'      => 'text-center',
                'type'       => 'bool',
                'class'      => 'fixed-width-sm',
                'orderby'    => false,
            ];
    
            if ($joinCategory && (int) $this->id_current_category) {
                $this->fields_list['position'] = [
                    'title'      => $this->l('Position'),
                    'filter_key' => 'cp!position',
                    'align'      => 'center',
                    'position'   => 'position',
                ];
    

    new

            $this->fields_list['active'] = [
                'title'      => $this->l('Status'),
                'active'     => 'status',
                'filter_key' => $alias.'!active',
                'align'      => 'text-center',
                'type'       => 'bool',
                'class'      => 'fixed-width-sm',
                'orderby'    => false,
            ];
    
    		$this->fields_list['manufacturer_namen'] = [
                'title' 	 => $this->l('Manufacturer'),
                'filter_key' => 'm!name',
                'orderby' 	 => true,
            ];
            
            $this->fields_list['supp'] = [
    			'title' => $this->l('Supplier'),
    			'filter_key' => 'supp!name'
            ];
    
            if ($joinCategory && (int) $this->id_current_category) {
                $this->fields_list['position'] = [
                    'title'      => $this->l('Position'),
                    'filter_key' => 'cp!position',
                    'align'      => 'center',
                    'position'   => 'position',
                ];
    


  • this is working but not if I try to override it. 😞

    I would like to override, @zimmer-media is your code working override in 1.0.7?

    p.s. Overrides are not disabled in “performance”



  • Then probably your override is not set up properly.



  • I cloned the original file AdminProductsController.php, modified as instructions and copied in the directory:

    override/controllers/admin/
    

    Permissions are correct.



  • Well what is your classname with extending? Have you deleted class_index.php in cache directory?



  • @wakabayashi worked! (I have no cache active, didn’t think to it)
    thank you



  • I have no cache active

    Why not? PageCache has its flaws, but the other cache systems should work just fine. Even for development I keep Smarty cache turned on, with “recompile if something has changed”.



  • @traumflug said in Product list BO with manufacturers and suppliers columns:

    Why not? PageCache has its flaws, but the other cache systems should work just fine. Even for development I keep Smarty cache turned on, with “recompile if something has changed”.

    It’s a sandbox. I have no TB installation in production right now.
    I’m going to follow your advice for “recompile if something has changed”.


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.