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.

  • just check data by print_r($model); and check index for name – Piyush Feb 24 '18 at 18:31
  • there have not index for name, i need add his – Petro Chaikivskyi Feb 24 '18 at 18:43
  • you must need name in your collection, check your collection and set index value accordingly for column – Piyush Feb 24 '18 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 – Petro Chaikivskyi Feb 24 '18 at 18:52
0

Try it now :

 'label' => $helper->__($model->getName()),
| improve this answer | |
  • it return null. – Petro Chaikivskyi Feb 24 '18 at 18:24
  • make var_dump ($ collection), look at the index of the category name, and write it 'header' => 'yourNameCategory', – Evgeniy Kapelko Feb 24 '18 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();
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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