Jump to content

Help - Display Phone Number in Supplier Page?


Zeke Taylor

Recommended Posts

Hi all,

 

Hoping someone can shed some light on this conundrum for me, in the Back Office, Brands and Suppliers (AdminSuppliersController.php) I'd like to display the address data as well as the existing data.

The existing code looks like this.

class AdminSuppliersControllerCore extends AdminController
{
    public $bootstrap = true;

    public function __construct()
    {
        $this->table = 'supplier';
	        $this->className = 'Supplier';

        parent::__construct();

        $this->addRowAction('view');
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->allow_export = true;

        $this->_defaultOrderBy = 'name';
        $this->_defaultOrderWay = 'ASC';

        $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->trans('Delete selected', array(), 'Admin.Actions'),
                'icon' => 'icon-trash',
                'confirm' => $this->trans('Delete selected items?', array(), 'Admin.Notifications.Warning'),
            ),
        );

        $this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (a.`id_supplier` = ps.`id_supplier`)';
        $this->_group = 'GROUP BY a.`id_supplier`';

        $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su');

        $this->fields_list = array(
            'id_supplier' => array('title' => $this->trans('ID', array(), 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs'),
            'logo' => array('title' => $this->trans('Logo', array(), 'Admin.Global'), 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false),
            'name' => array('title' => $this->trans('Name', array(), 'Admin.Global')),
            'products' => array('title' => $this->trans('Number of products', array(), 'Admin.Catalog.Feature'), 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
            'active' => array('title' => $this->trans('Enabled', array(), 'Admin.Global'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'class' => 'fixed-width-xs'),
        );
    }

 

This data is pulled from the "suppliers" table but the address data is stored in the "address" table, how do I tell it to also load the data from the "address" table and match to the "id_supplier"?

I hope someone can help.

Thanks in advance.

 

 

Edited by Zeke Taylor (see edit history)
Link to comment
Share on other sites

Did you mean in the administration in the list of suppliers?

Code to display both phone and mobile phone:

public function __construct()
    {
        $this->table = 'supplier';
        $this->className = 'Supplier';

        parent::__construct();

        $this->addRowAction('view');
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->allow_export = true;

        $this->_defaultOrderBy = 'name';
        $this->_defaultOrderWay = 'ASC';

        $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->trans('Delete selected', array(), 'Admin.Actions'),
                'icon' => 'icon-trash',
                'confirm' => $this->trans('Delete selected items?', array(), 'Admin.Notifications.Warning'),
            ),
        );

        $this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products';
        $this->_select = 'su.*';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (a.`id_supplier` = ps.`id_supplier`)';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'address` su ON (a.`id_supplier` = su.`id_supplier`)';
        $this->_group = 'GROUP BY a.`id_supplier`';

        $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su');

        $this->fields_list = array(
            'id_supplier' => array('title' => $this->trans('ID', array(), 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs'),
            'logo' => array('title' => $this->trans('Logo', array(), 'Admin.Global'), 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false),
            'name' => array('title' => $this->trans('Name', array(), 'Admin.Global')),
            'phone' => array('title' => $this->trans('Phone', array(), 'Admin.Global')),
            'phone_mobile' => array('title' => $this->trans('Phone mobile', array(), 'Admin.Global')),
            'products' => array('title' => $this->trans('Number of products', array(), 'Admin.Catalog.Feature'), 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
            'active' => array('title' => $this->trans('Enabled', array(), 'Admin.Global'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'class' => 'fixed-width-xs'),
        );
    }

 

Link to comment
Share on other sites

 

1 hour ago, Guest said:

Did you mean in the administration in the list of suppliers?

Code to display both phone and mobile phone:

 

That is awesome, exactly what I need to happen!

 

Once that JOIN statement (the bit I wasn't sure of) was in place I was able to expand on it and add other elements of the address info easy enough, thank you so much for that.


        $this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products';
        $this->_select = 'su.*';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (a.`id_supplier` = ps.`id_supplier`)';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'address` su ON (a.`id_supplier` = su.`id_supplier`)';
        $this->_group = 'GROUP BY a.`id_supplier`';

        $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su');

        $this->fields_list = array(
            'id_supplier' => array('title' => $this->trans('ID', array(), 'Admin.Global'), 'align' => 'center', 'class' => 'fixed-width-xs'),
            'logo' => array('title' => $this->trans('Logo', array(), 'Admin.Global'), 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false),
            'name' => array('title' => $this->trans('Name', array(), 'Admin.Global')),
			'products' => array('title' => $this->trans('No. of products', array(), 'Admin.Catalog.Feature'), 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true),
            'phone' => array('title' => $this->trans('Phone', array(), 'Admin.Global')),
            'address1' => array('title' => $this->trans('Address', array(), 'Admin.Global')),
			'address2' => array('title' => $this->trans('Address', array(), 'Admin.Global')),
            'postcode' => array('title' => $this->trans('Post Code', array(), 'Admin.Global')),
            'active' => array('title' => $this->trans('Enabled', array(), 'Admin.Global'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'class' => 'fixed-width-xs'),
        );
    }

 

There is the small side effect that it no longer counts the products attached to that supplier, if you click into the supplier it does still shows you the products however and hasn't affected the count under brands.

Link to comment
Share on other sites

I gladly helped.
Next time, you better screen what you need.

 

Added:

$this->_select = 'su.*';

$this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'address` su ON (a.`id_supplier` = su.`id_supplier`)';

 

Edited by Guest (see edit history)
Link to comment
Share on other sites

6 minutes ago, Guest said:

I gladly helped.
Next time, you better screen what you need.

 

Added:


$this->_select = 'su.*';

$this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'address` su ON (a.`id_supplier` = su.`id_supplier`)';

 

 

I shall remember for next time 😉👍

Do you know what might be causing it not able to show the count of products any longer?

image.thumb.png.7794eccf0a3bc93a0b7aff0729cd4b82.png

Link to comment
Share on other sites

Sorry, I didn't notice any mistakes.

$this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products, su.*';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (a.`id_supplier` = ps.`id_supplier`)';
        $this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'address` su ON (a.`id_supplier` = su.`id_supplier`)';
        $this->_group = 'GROUP BY a.`id_supplier`';
Edited by Guest (see edit history)
Link to comment
Share on other sites

5 minutes ago, Guest said:

Sorry, I didn't notice any mistakes.


$this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products, su.*';
        $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (a.`id_supplier` = ps.`id_supplier`)';
        $this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'address` su ON (a.`id_supplier` = su.`id_supplier`)';
        $this->_group = 'GROUP BY a.`id_supplier`';

You sir, are a Ledgend! 🤝👏

Yep, that's worked beautifully! 👌 Thank you so much!

Link to comment
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
×
×
  • Create New...