使用自定义集合的 Magento 网格视图
我目前正在为 Magento 编写 EPOS 集成。当下订单时,它的 ID 被放置在队列文件中。每分钟一次,cron 会查看队列,向 EPOS Web api 触发最高订单,然后根据结果将 ID 移动到成功列表文件或失败列表文件。
为了向用户显示这些列表的内容,我创建了一个管理页面,用于读取文件(包含序列化数组),创建一个包含订单 ID、客户名称和每个订单的时间戳的 varien_object,然后存储所有这些位于 Varien_Data_collection 的实例中。然后将该集合传递给 grid.php 中的 _prepareCollection 函数以渲染网格视图。
在 1.4.1.1 中,网格渲染良好,但分页已损坏且过滤不起作用。
在 1.3.2.4 中,网格呈现但显示“未找到记录”。
有谁知道可能导致这些问题的原因,以及是否有更好的方法在 Magento 中显示文件中的信息?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以看到条目(1.4+)但无法过滤的原因是Magento正在使用集合api来修改对象。如果您只是从模型中提取值,这没什么大不了的,但如果您正在搜索和过滤,Magento 需要集合作为数据库的实例。它使用 Varien_Db_Select 对象来进行解析为原始 sql 的查询,因此这不适用于数组。
我建议尝试以不同的方式处理数据。
听起来您正在使用平面文件,因此构建 sql 查询来为您获取所有内容的明显解决方案不会减少它。我会尝试创建一个 Zend_Db_Table 实例,并动态填充值。
像这样的事情:
诚然,我从来没有做过这样的事情,但以前我遇到过自定义网格过滤器问题,并且知道如果你想搜索,你需要将数据放在一些表格中种类。查看Zend 的文档了解此事。我很确定 Magento 内部有办法做到这一点,但我无法开始考虑解决方案。
我的建议是,将您的 cron 作业数据存储在数据库中,这将使提取数据变得更加容易。
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:
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.