Jump to content

Possibility to join tables in construct?


bqzero

Recommended Posts

Hi everybody,

 

I struggle a little creating a new admin tab. so far all is working.

I have a form and a list. however the list is not complete yet. my controller/module comes with its own table containing the id_product and as well field for filepaths. All that is easy listed in the tab. But I figured out that I require not just the id_product, but as well the name of the product. since data for my list is retrieved by the definition in my __construct() I access my module table which of course does not hold the name of the product. It is as well not my desire to extend that table to add the description since it could be changed in the product or the language for other users is different.

 

So my thinking is is it possible to join tables and retrieve the other data as well? I tried the following

    public function __construct()
    {
        $this->table = 'threedviewer';
        $this->className = 'Threedviewer';
        $this->list_id = 'threedviewer';
        $this->identifier = 'id_product';
        $this->lang = false;
	$this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` b ON (b.`id_product` = a.`id_product`) AND b.`id_lang` = "1"';

        $this->fields_list = array(
            'id_product' => array(
                'title' => $this->l('ID'),
                'align' => 'center',
                'class' => 'fixed-width-xs'
            ),
            'name' => array(
                'title' => $this->l('Product'),
                'width' => 'auto',
            ),
            '3dfile' => array(
                'title' => $this->l('3D File'),
                'width' => 'auto',
            )
        );

        $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->l('Delete selected'),
                'icon' => 'icon-trash',
                'confirm' => $this->l('Delete selected items?')
            )
        );
        parent::__construct();
    }

However the join seems to have no effect on retrieving the data outputed from my list

	public function renderList()
	{
		$this->addRowAction('delete');

		$this->bulk_actions = array(
			'delete' => array(
				'text' => $this->l('Delete selected'),
				'confirm' => $this->l('Delete selected items?')
				)
			);
		$this->fields_list = array(
			'id_product' => array(
				'title' => $this->l('Product ID'),
				'align' => 'center',
				'width' => 25
			),
			'name' => array(
				'title' => $this->l('name'),
				'align' => 'center',
				'width' => 25
			),
			'3dfile' => array(
				'title' => $this->l('3D File'),
				'width' => 256,
			),
		);
		print(Product::getProductName($this->l('Product ID'),0,1));
		$lists = parent::renderList();
		parent::initToolbar();
		return $lists;
	}

Has anybody an idea what could be the issue or how to solve it otherwise?

 

 

Best regards,

Christian

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...