如何将内容块添加到magento管理仪表板?

时间:2016-05-13 14:34:31

标签: php magento

我想在magento管理信息中心添加新的内容块。我已经在谷歌搜索了一天,但无法找到解决方案。我想把块放在图片的红线上。

Magento admin dashboard

1 个答案:

答案 0 :(得分:0)

让我们一步一步检查:

模板(app / design / adminhtml / default / default / template / dashboard / index.phtml),第98行

<div class="dashboard-container">
<?php echo $this->getChildHtml('store_switcher') ?>
<table cellspacing="25" width="100%">
    <tr>
        <td>
            <!-- Start including the sales blocks -->
            <?php echo $this->getChildHtml('sales') ?>
            <!-- End including -->
            <div class="entry-edit">
                <div class="entry-edit-head"><h4><?php echo $this->__('Last 5 Orders') ?></h4></div>
                <fieldset class="np"><?php echo $this->getChildHtml('lastOrders'); ?></fieldset>
            </div>
            <div class="entry-edit">
                <div class="entry-edit-head"><h4><?php echo $this->__('Last 5 Search Terms') ?></h4></div>
                <fieldset class="np"><?php echo $this->getChildHtml('lastSearches'); ?></fieldset>
            </div>
            <div class="entry-edit">
                <div class="entry-edit-head"><h4><?php echo $this->__('Top 5 Search Terms') ?></h4></div>
                <fieldset class="np"><?php echo $this->getChildHtml('topSearches'); ?></fieldset>
            </div>
        </td>

您可以看到$this->getChildHtml('sales')包含。那是从你的截图中负责这两个块终身销售平均销售

此模板来自阻止Mage_Adminhtml_Block_Dashboard,您可以在其中找到_prepareLayout()方法。

阻止类Mage_Adminhtml_Block_Dashboard (app / code / core / Mage / Adminhtml / Block / Dashboard.php)

protected function _prepareLayout()
{
    ...
        $this->setChild('sales',
            $this->getLayout()->createBlock('adminhtml/dashboard_sales')
        );
    ...
}

如您所见,它使用块类Mage_Adminhtml_Block_Dashboard_Sales设置块'sales'。

阻止类Mage_Adminhtml_Block_Dashboard_Sales (app / code / core / Mage / Adminhtml / Block / Dashboard / Sales.php)

现在它变得有趣了! :)

检查_prepareLayout方法......

protected function _prepareLayout()
{
    if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) {
        return $this;
    }
    $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group');

    $collection = Mage::getResourceModel('reports/order_collection')
        ->calculateSales($isFilter);

    if ($this->getRequest()->getParam('store')) {
        $collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store'));
    } else if ($this->getRequest()->getParam('website')){
        $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds();
        $collection->addFieldToFilter('store_id', array('in' => $storeIds));
    } else if ($this->getRequest()->getParam('group')){
        $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds();
        $collection->addFieldToFilter('store_id', array('in' => $storeIds));
    }

    $collection->load();
    $sales = $collection->getFirstItem();

    // HERE YOU GO!
    $this->addTotal($this->__('Lifetime Sales'), $sales->getLifetime());
    $this->addTotal($this->__('Average Orders'), $sales->getAverage());
}

你(希望)看到了什么:

  1. 仅在Mage_Reports启用
  2. 时才会显示这两个块
  3. 这里的块基本上是硬编码的
  4. 如果您需要介于两者之间的某些内容,请使用您自己的
  5. 重写_prepareLayout方法  3。