题
这个问题涉及以下网格:sales-> orders-> [选择订单] - >信息。
在底部,您可以看到带有订单的网格。我想通过SKU对它们进行排序。
在:/app/code/core/mage/sales/model/order.php i找到:
public function getItemsCollection($filterByTypes = array(), $nonChildrenOnly = false)
{
if (is_null($this->_items)) {
$this->_items = Mage::getResourceModel('sales/order_item_collection')
->setOrderFilter($this);
if ($filterByTypes) {
$this->_items->filterByTypes($filterByTypes);
}
if ($nonChildrenOnly) {
$this->_items->filterByParent();
}
if ($this->getId()) {
foreach ($this->_items as $item) {
$item->setOrder($this);
}
}
}
return $this->_items;
}
这会创建订单网格,但是如何按SKU进行排序?
解决方案
实际上,代码不会创建顺序网格。这将检索订单的订购项目。它在前端和后端都使用。
如果将其修改为按SKU进行排序,则这些项目将由SKU在后端和前端订购。
为此,您需要添加此代码:
$this->_items->getSelect()->order('sku');
紧随其后
if ($nonChildrenOnly) {
$this->_items->filterByParent();
}
当然,不要编辑代码。正确覆盖模型。
但是我不建议这种方法。如果您只想在后端中使用SKU的项目顺序,则可以在模板中对它们进行排序。
模板是 app\design\adminhtml\default\default\template\sales\order\view\items.phtml
。您可以替换呈现项目的代码(我的意思是):
<?php $_items = $this->getItemsCollection() ?>
<?php $i=0;foreach ($_items as $_item):?>
<?php if ($_item->getParentItem()) continue; else $i++;?>
<tbody class="<?php echo $i%2?'even':'odd' ?>">
<?php echo $this->getItemHtml($_item) ?>
<?php echo $this->getItemExtraInfoHtml($_item) ?>
</tbody>
<?php endforeach; ?>
有了这个:
<?php $_items = $this->getItemsCollection() ?>
<?php $_sortedItems = array(); ?>
<?php foreach ($_items as $_item) : ?>
<?php $_sortedItems[$_item->getSku()] = $_item;?>
<?php endforeach;?>
<?php ksort($_sortedItems);//sort by sku?>
<?php $i=0;foreach ($_sortedItems as $_item):?>
<?php if ($_item->getParentItem()) continue; else $i++;?>
<tbody class="<?php echo $i%2?'even':'odd' ?>">
<?php echo $this->getItemHtml($_item) ?>
<?php echo $this->getItemExtraInfoHtml($_item) ?>
</tbody>
<?php endforeach; ?>
再次...不要修改模板。将其放在您自己的主题中并在此处修改。
这是您可以更改和管理主题的方式.