1

I need get the name of category from ('catalog/product') table in Magento 1.9. How can I do it ? Main table is ('productlabels/category')

protected function _prepareCollection()
{
    $collection = Mage::getModel('productlabels/category')->getCollection(); 
    $collection->getSelect()
        ->joinLeft(array('category' => $collection->getTable('catalog/category')), 'main_table.id_category = category.entity_id')
        ->joinLeft(array('labels' => $collection->getTable('productlabels/table_labels')), 'main_table.id_label = labels.id_label');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Also I have an edit form where I need to output my edit data.

protected function _prepareColumns()
{   
    $helper = Mage::helper('productlabels');
    $this->addColumn('name', array(
        'header' => $helper->__('Name'),
        'index'  => 'name',
    ));

    $this->addColumn('category_page_image', array(
        'header' => $helper->__('Label Image'),
        'index'  => 'category_page_image',
        'type' => 'image',
        'renderer' => 'Plumrocket_Productlabels_Block_Adminhtml_Renderer_Image',
        'filter'    => false,
        'sortable'  => false,
        'align' => 'center',
    ));

    return parent::_prepareColumns();
}

Any help would be greatly appreciated.

4
  • just check data by print_r($model); and check index for name
    – Piyush
    Commented Feb 24, 2018 at 18:31
  • there have not index for name, i need add his Commented Feb 24, 2018 at 18:43
  • you must need name in your collection, check your collection and set index value accordingly for column
    – Piyush
    Commented Feb 24, 2018 at 18:46
  • table (productlabels/category) containst column(id_entity - primary key, id_category - index field and id_label - index field) i join magento table (catalog/category) and i dont know how i can add name of category Commented Feb 24, 2018 at 18:52

2 Answers 2

0

Try it now :

 'label' => $helper->__($model->getName()),
2
  • it return null. Commented Feb 24, 2018 at 18:24
  • make var_dump ($ collection), look at the index of the category name, and write it 'header' => 'yourNameCategory', Commented Feb 24, 2018 at 19:00
0

It is right answer. Thank you for those who trying help me.

protected function _prepareCollection()
{
    $collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('name');
    $collection->getSelect()
        ->joinLeft(array('category' => $collection->getTable('productlabels/category_check_list')), 'e.entity_id = category.id_category')
        ->joinLeft(array('labels' => $collection->getTable('productlabels/table_labels')), 'category.id_label = labels.id_label');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

protected function _prepareColumns()
{   
    $helper = Mage::helper('productlabels');
    $this->addColumn('name', array(
        'header' => $helper->__('Name'),
        'index'  => 'name',
    ));

    $this->addColumn('category_page_image', array(
        'header' => $helper->__('Label Image'),
        'index'  => 'category_page_image',
        'type' => 'image',
        'renderer' => 'Plumrocket_Productlabels_Block_Adminhtml_Renderer_Image',
        'filter'    => false,
        'sortable'  => false,
        'align' => 'center',
    ));

    return parent::_prepareColumns();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.