2016-05-13 88 views

回答

0

让我们来看看一步一步:

模板(应用程序/设计/ adminhtml /默认/缺省的/模板/仪表板/ 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()方法。

Block类Mage_Adminhtml_Block_Dashboard(应用程序/代码/核心/法师/ Adminhtml /座/ Dashboard.php)

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

正如你所看到的,它集块 '销售' 与块类Mage_Adminhtml_Block_Dashboard_Sales

Block类Mage_Adminhtml_Block_Dashboard_Sales(应用程序/代码/核心/法师/ Adminhtml /座/仪表板/ 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. 如果你想在重写_prepareLayout用自己的方法
  4. 3.
相关问题