Jump to content

Listing product names in back-office


Recommended Posts

I am trying to make a simple list of all product names in the back-office's product tab I created.

 

Here's what I have written in the module's .tpl:

{if isset($products) && $products}
<ul>
    {foreach from=$products item=product}
    <li>{$product.name}</li>
    {/foreach}
</ul>
{/if}

The output is just:

<ul></ul>

I guess it isn't as simple as that...

 

 

Link to comment
Share on other sites

let's clarify ;) perhaps i missed something

 

 

back-office's product tab I created.

 

what you created? if you created tab in back office it means that this tab must be somewhere defined (like a controller, part of module etc.)

Link to comment
Share on other sites

Sorry I misunderstood something :D

    
    public function hookDisplayAdminProductsExtra($params){
        if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product')))){
            $this->prepareNewTab();
            return $this->display(__FILE__, 'product-tab.tpl');
        }
    }

The function that is called is there:

public function prepareNewTab(){
    
        $this->context->smarty->assign(array(
            'custom_field' => $this->getCustomField((int)Tools::getValue('id_product')),
            'languages' => $this->context->controller->_languages,
            'default_language' => (int)Configuration::get('PS_LANG_DEFAULT')
        ));
Edited by frogtaku (see edit history)
Link to comment
Share on other sites

okay so where you've got $products variable defined? ;)

at the moment there are only:

            'custom_field' => $this->getCustomField((int)Tools::getValue('id_product')),
            'languages' => $this->context->controller->_languages,
            'default_language' => (int)Configuration::get('PS_LANG_DEFAULT')
Link to comment
Share on other sites

So, looking at other threads, I tried this method and commented where it won't work:

public function prepareNewTab(){
    
        $products = Product::getProducts($this->context->language->id, 0, 100);
        $products_all = Product::getProductsProperties($this->context->language->id, $products);
        //=> WILL PRODUCE A FATAL ERROR ON TAB
    
        $this->context->smarty->assign(array(
            'custom_field' => $this->getCustomField((int)Tools::getValue('id_product')),
            'languages' => $this->context->controller->_languages,
            'default_language' => (int)Configuration::get('PS_LANG_DEFAULT'),
            'products' => $products_all; // TAB WON'T LOAD CORRECTLY
        ));
    
    }

Any idea?

 

Edit:

 

Looking at the module page, it tells me I have a syntax error and a missing class. I guess it's refering to the Product class. Should I declare it? How would it affect the existing code? The lack of documentation on its use for a module is a little bothersome.

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

×
×
  • Create New...