I have few problems when try make a plugin.

This is my code:


class Uniagro_Tpv_Block_Mibloque extends Mage_Core_Block_Template
    public function methodblock()
        //return "informations about my block !!" ;
        //on initialize la variable
        /* we are doing the query to select all elements of the pfay_test table (thanks to our model test/test and we sort them by id_pfay_test */
     $collection = Mage::getModel('tpv/tpv')->getCollection()->setOrder('id','asc');
         /* then, we check the result of the query and with the function getData() */
        foreach($collection as $data)
             $retour .= $data->getData('banco').' '.$data->getData('codigotienda')
                     .' '.$data->getData('url').'<br />';
         //i return a success message to the user thanks to the Session.
         Mage::getSingleton('adminhtml/session')->addSuccess('Cool Ca marche !!');
         return $retour;      

** config.xml

<?xml version="1.0"?>
                 <frontName>pasarela</frontName> <!-- sirve a modo de ruta del modulo [...]/index y va al modulo -->
            <!-- connection to write -->
            <!-- connection to read -->

** model/Tpv.php

class Uniagro_Tpv_Model_Tpv extends Mage_Core_Model_Abstract
     public function _construct()

** model/Mysql4/Tpv.php

class Uniagro_Tpv_Mysql4_Tpv extends Mage_Core_Model_Mysql4_Abstract
    public function _construct()
        $this->_init('tpv/tpv', 'id');

I'm try some solutions (for example this [fatal error: Call to a member function getCollection() on a non-object in magento

[1]: fatal error: Call to a member function getCollection() on a non-object in magento ) but always send my the same error "Fatal error: Call to a member function setOrder()"

And i review my bd and have the column to order ('id')

2 Answers 2


Add model collection class and try

class Uniagro_Tpv_Mysql4_Tpv_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract{
    public function _construct(){

Edit (As result of the comments):

The Problem was the wrong named/placed class Uniagro_Tpv_Mysql4_Tpv which belongs into the Model area so it has to be Uniagro_Tpv_Model_Mysql4_Tpv

  • Thanks for your answer, but i try to put this code but, have the same error :S
    – Marcos
    Commented Feb 26, 2014 at 12:32
  • have you created the table
    – Helphin
    Commented Feb 26, 2014 at 12:37
  • Yes, I have the table in my bd and exists the column to the order ('id'), if need more code i can write
    – Marcos
    Commented Feb 26, 2014 at 12:42
  • class Uniagro_Tpv_Mysql4_Tpv extends Mage_Core_Model_Mysql4_Abstract missing model class, (ie) Uniagro_Tpv_Mysql4_Tpv to Uniagro_Tpv_Model_Mysql4_Tpv
    – Helphin
    Commented Feb 26, 2014 at 12:44
  • Hey! Thanks for your help! I found it my error....the problem is the PHP for Mysql4/Tpv/Collection.php...i delete this file and I write again and success! Thanks for all!
    – Marcos
    Commented Feb 26, 2014 at 12:53

This should work.

$collection = Mage::getModel('tpv/tpv')->getCollection();
$collection->getSelect()->order('main_table.id ASC');
  • Thanks for response, but don't work...This code give me the error " Fatal error: Call to a member function getSelect() on a non-object"
    – Marcos
    Commented Feb 26, 2014 at 12:34
  • This won't work because in the OP's case getCollection() returns null.
    – Marius
    Commented Feb 26, 2014 at 12:46
  • Hey! Thanks for your help, I found my problem...its for the Collection file, i delete this and make again and it's Ok! Thanks again!
    – Marcos
    Commented Feb 26, 2014 at 12:54

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.