2014-05-13 19 views
1

我重寫了管理儀表板塊,它是最常見的產品,但它不顯示我的收藏數據。儀表板網格塊重寫不正常

預先感謝您

我的config.xml文件是: -

<blocks> 
    <adminhtml> 
    <rewrite> 
     <dashboard_tab_products_viewed>Companyname_Customdashboard_Block_Adminhtml_Dashboard_Tab_Products_Viewed</dashboard_tab_products_viewed> 
    </rewrite> 
    </adminhtml> 
</blocks> 

我的塊代碼是: -

class Companyname_Customdashboard_Block_Adminhtml_Dashboard_Tab_Products_Viewed extends Mage_Adminhtml_Block_Dashboard_Tab_Products_Viewed 
    { 

public function _prepareCollection() { 

    $categoryIds = array(); 
     $entityIds = array(); 
     $userRoleName = Mage::getSingleton('admin/session')->getUser()->getRole()->getRoleName(); 
     $userRoleId = Mage::getSingleton('admin/session')->getUser()->getId(); 
     if($userRoleName == 'Administrators') { 
      if ($this->getParam('website')) { 
       $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); 
       $storeId = array_pop($storeIds); 
      } else if ($this->getParam('group')) { 
       $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); 
       $storeId = array_pop($storeIds); 
      } else { 
       $storeId = (int)$this->getParam('store'); 
      } 
      $collection = Mage::getResourceModel('reports/product_collection') 
       ->addAttributeToSelect('*') 
       ->addViewsCount() 
       ->setStoreId($storeId) 
       ->addStoreFilter($storeId) 
       ->setPageSize($this->getParam($this->getVarNameLimit(), $this->_defaultLimit)); 
       //var_dump($collection->getSelect()->__toString()); 
      $this->setCollection($collection); 
     } else if($userRoleName == 'salesman') { 
      $collections = Mage::getModel('newgenray_adminenquiry/storeaddress') 
        ->getCollection()->getData(); 
      foreach($collections as $collection) { 
       $userIds = $collection['user_id']; 
       $userId = explode(',', $userIds); 
       if(count($userId)) { 
        if (in_array($userRoleId, $userId)) { 
         $categoryIds[] = $collection['category_id']; 
        } 
       } 
      } 
      $getEntityIds = Mage::getModel('catalog/product') 
        ->getCollection() 
        ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') 
        ->addAttributeToSelect('*') 
        ->addAttributeToFilter('category_id', array('in' => $categoryIds)) 
        ->getData(); 
      foreach($getEntityIds as $getEntityId) { 
       $entityIds[] = $getEntityId['entity_id']; 
      } 
      $collection = Mage::getResourceModel('reports/product_collection') 
       ->addAttributeToSelect('*') 
       ->addViewsCount() 
       ->setStoreId($storeId) 
       ->addStoreFilter($storeId) 
       ->addAttributeToFilter('entity_id', array('in' => $entityIds)) 
       ->setPageSize($this->getParam($this->getVarNameLimit(), $this->_defaultLimit));; 
       //var_dump($collection->getSelect()->__toString()); 
      $this->setCollection($collection); 
     } 
     return parent::_prepareCollection(); 
    } 

    } 

} 

我的問題是核心功能_prepareCollection()是調用在我的block函數_prepareCollection()之後,這就是爲什麼它根據Mage集合獲取數據。

+0

安置自己的_prepareCollection()代碼 –

+0

替換父:: _ prepareCollection();與Mage_Adminhtml_Block_Dashboard_Grid :: _ prepareCollection();並檢查它是否正在工作 –

+0

無法正常工作。給語法錯誤,意外'::' – user3630977

回答

0

用下面的替換函數。

class Companyname_Customdashboard_Block_Adminhtml_Dashboard_Tab_Products_Viewed extends Mage_Adminhtml_Block_Dashboard_Tab_Products_Viewed 
    { 

public function _prepareCollection() { 

    $categoryIds = array(); 
     $entityIds = array(); 
     $userRoleName = Mage::getSingleton('admin/session')->getUser()->getRole()->getRoleName(); 
     $userRoleId = Mage::getSingleton('admin/session')->getUser()->getId(); 
     if($userRoleName == 'Administrators') { 
      if ($this->getParam('website')) { 
       $storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds(); 
       $storeId = array_pop($storeIds); 
      } else if ($this->getParam('group')) { 
       $storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds(); 
       $storeId = array_pop($storeIds); 
      } else { 
       $storeId = (int)$this->getParam('store'); 
      } 
      $collection = Mage::getResourceModel('reports/product_collection') 
       ->addAttributeToSelect('*') 
       ->addViewsCount() 
       ->setStoreId($storeId) 
       ->addStoreFilter($storeId) 
       ->setPageSize($this->getParam($this->getVarNameLimit(), $this->_defaultLimit)); 
       //var_dump($collection->getSelect()->__toString()); 
      $this->setCollection($collection); 
     } else if($userRoleName == 'salesman') { 
      $collections = Mage::getModel('newgenray_adminenquiry/storeaddress') 
        ->getCollection()->getData(); 
      foreach($collections as $collection) { 
       $userIds = $collection['user_id']; 
       $userId = explode(',', $userIds); 
       if(count($userId)) { 
        if (in_array($userRoleId, $userId)) { 
         $categoryIds[] = $collection['category_id']; 
        } 
       } 
      } 
      $getEntityIds = Mage::getModel('catalog/product') 
        ->getCollection() 
        ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') 
        ->addAttributeToSelect('*') 
        ->addAttributeToFilter('category_id', array('in' => $categoryIds)) 
        ->getData(); 
      foreach($getEntityIds as $getEntityId) { 
       $entityIds[] = $getEntityId['entity_id']; 
      } 
      $collection = Mage::getResourceModel('reports/product_collection') 
       ->addAttributeToSelect('*') 
       ->addViewsCount() 
       ->setStoreId($storeId) 
       ->addStoreFilter($storeId) 
       ->addAttributeToFilter('entity_id', array('in' => $entityIds)) 
       ->setPageSize($this->getParam($this->getVarNameLimit(), $this->_defaultLimit));; 
       //var_dump($collection->getSelect()->__toString()); 
      $this->setCollection($collection); 
     } 
     return Mage_Adminhtml_Block_Dashboard_Grid::_prepareCollection();// change here 
    } 

    } 

更多信息Here

+0

對於同樣的問題我應該怎麼做_prepareColumns()函數? – user3630977

+0

是的,如果導致問題。改變它,如果它不讓我們覆蓋我們的c hanges。 –