1

I'm currently writing an EPOS integration for Magento. When an order is made, it's ID is placed in a queuefile. Once a minute, a cron looks at the queue, fires the top order to the EPOS web api and then moves the ID to either a successlist file or a faillist file, depending on the outcome.

In order to display the contents of these lists to the user, I created an admin page that reads the file (containing a serialized array), creates a varien_object containing the order ID, customer name and timestamp for each order, and then stores all of these in an instance of a Varien_Data_collection. This collection is then passed to the _prepareCollection function in the grid.php for rendering the grid view.

In 1.4.1.1, the grid renders fine, but the pagination is broken and the filtering doesn't work.

In 1.3.2.4 the grid renders but says there are 'No Records Found'.

Does anybody know what could be causing these issues, and if there is a better way of going about displaying information from a file in Magento?

Geoff
  • 747
  • 3
  • 11
  • 16
  • 1
    synchronisation with a serialised file is difficult, it is not possible to write to the head and tail at the same time. Is there a reason the queue isn't a table in the database? A table can provide row-level locks, allow simultaneous edits and already works with admin grids. Filtering and pagination is done with SQL which is why it cannot work with a file. – clockworkgeek May 04 '11 at 10:31
  • Ideally, it would be in a database, and in the long term I do plan on rewriting this module. However I have inherited this code from the previous developer, and my company are looking for a quick fix to get it working. I agree with you that files are not an ideal situation. Would maybe abandoning the grid view and going with a custom view be a better approach to this problem, if the grid view is implemented with databases in mind? – Geoff May 04 '11 at 11:08
  • 1
    I suppose it is possible to create your own descendent of `Varien_Data_Collection` with `addFieldToFilter()` and `load()` functions to make it compatible with `Varien_Data_Collection_Db`. It would need to respect the current page, page size and order settings too. It sounds less than "quick", maybe someone will answer with a way to fully mimic a DB collection. – clockworkgeek May 04 '11 at 11:45

1 Answers1

0

The reason why you can see the entries (1.4+), but can't filter is that Magento is using the collection api to modify the object. If you are just pulling values out of a model, its no big deal, but if you are searching and filtering, Magento needs the collection to be an instance of a database. It uses Varien_Db_Select objects to make queries which resolve to raw sql, so that's not going to work on an array.

I would recommend trying to deal with the data in a different way.

It sounds like you are working with a flat file, so the obvious solution of constructing a sql query to fetch everything for you won't cut it. I would try creating an instance of Zend_Db_Table, and populating the values on the fly.

Something like this:

class Foo_Bar_Model_Resource_Success_Collection extends Mage_Core_Model_Resource_Db_Abstract
{
    public function _construct()
    {
        //declare write adapter in config
        $table = new Zend_Db_Table('my_db.my_table'); 

        foreach($this->getEposArray() as $entry)  
            $table->insert($entry);

        $this->_init('my_table', 'id');
    }
}

Admittedly, I've never done anything quite like this, but have had the custom grid filter problem crop up on me before, and know that if you want to search, you need to have your data in a table of some sort. Check out Zend's docs on the matter. I'm pretty sure that there's a way to do this inside of Magento, but I couldn't begin to think about a solution.

My advice, store your cron job data in a database, it will make pulling the data back out much easier.

ontek
  • 574
  • 6
  • 12