Admin Grid-将CSS类分配给新订单
-
16-10-2019 - |
题
我想简单地添加一个 new-order
如果在最后一天下达订单,则可以将订单行(或字段,似乎更简单)进行。
为了进行测试,我没有将任何东西移到覆盖班上,我只是直接在 app/code/core/Mage/Adminhtml/Widget/Block/Grid/Column/Renderer/Longtext.php
上课只是为了使它起作用。
我基本上设置了它的喜好,但是我的逻辑将课程应用于所有行,而不仅仅是我指定的行。我觉得我缺少一些简单的东西。这是一些代码:
class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Longtext extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
// ...native code
if ($this->getColumn()->getId() == 'real_order_id') {
// realized this is available already with $row->getData()
// $order = Mage::getModel('sales/order')->loadByIncrementId($text);
$yesterday = strtotime("-1 day", Mage::getModel('core/date')->gmtTimestamp());
$yesterday = Mage::getModel('core/date')->date(null, $yesterday);
if ($row->getCreatedAt() > $yesterday) {
$this->getColumn()->setColumnCssClass('new-order');
};
}
return $text;
}
}
当我打电话 setColumnCssClass()
从这里,它在 getData()
对象,但它正在为所有行添加它;但是,实际上并没有将CSS类应用于列。
解决方案
您应该在网格模板中进行操作。您可以在订单的“ TR”行中添加新ID。例如,我们将突出显示过去24小时内下的订单。
转到App/Design/adminhtml/default/default/template/widget/grid.phtml。从第154行开始:
...
<?php foreach ($this->getCollection() as $_index=>$_item):
$orderCreateAt = strtotime($_item->getCreatedAt());
$last24hours = strtotime('24 hours ago'); ?>
<tr id ="
<?php if($orderCreateAt > $last24hours)
{ echo 'new-order'; }
?>"
title="<?php echo $this->getRowUrl($_item) ?>"<?php if ($_class = $this->getRowClass($_item)):?> class="<?php echo $_class; ?>"<?php endif;?> >
...
现在,在CSS中违抗该样式应该很简单。转到skin/adminhtml/default/default/box.css.css,然后添加您想要的样式
.grid table tr#new-order{
background-color: #FF0000;
}
其他提示
我没有编辑模板,而是添加了一个基本模块来重写 /Adminhtml/Widget/Grid/Column/Renderer/Longtext.php
.
public function render(Varien_Object $row)
{
//...native code
// Custom stuff here. Render the order # in red if the order is less than a day old.
if ($this->getColumn()->getId() == 'real_order_id') {
$yesterday = strtotime("-24 hours", Mage::getModel('core/date')->gmtTimestamp());
$yesterday = Mage::getModel('core/date')->date(null, $yesterday);
if ($row->getCreatedAt() > $yesterday) {
$text = '<span style="color: red; font-weight: bold;">' . $text . '</span>';
};
}
return $text;
}
@osondoar让我朝着正确的方向前进。我希望使用内置方法进行此修改,但这暂时就足够了。接受以前的答案,因为它使我朝着正确的方向前进,但是这种方法也有效。