在管理仪表板magento 1.7.0.2中添加选项卡

时间:2013-05-18 05:23:00

标签: magento magento-1.7 dashboard

复制Ordered.php

app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products

app/code/local/Mage/Adminhtml/Block/Dashboard/Tab/Products

重命名New.php

我修改了以下代码:

class Mage_Adminhtml_Block_Dashboard_Tab_Products_New extends Mage_Adminhtml_Block_Dashboard_Grid
{

    public function __construct()
    {
        parent::__construct();
        $this->setId('productsNewGrid');
    }

    protected function _prepareCollection()
    {
        if (!Mage::helper('core')->isModuleEnabled('Mage_Sales')) {
            return $this;
        }
        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');
        }

        $todayStartOfDayDate  = Mage::app()->getLocale()->date()
            ->setTime('00:00:00')
            ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

        $todayEndOfDayDate  = Mage::app()->getLocale()->date()
            ->setTime('23:59:59')
            ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

        $collection = Mage::getResourceModel('catalog/product_collection');
        $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());


        $collection
            ->addStoreFilter()
            ->addAttributeToFilter('news_from_date', array('or'=> array(
                0 => array('date' => true, 'to' => $todayEndOfDayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayStartOfDayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToFilter(
                array(
                    array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
                    array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
                    )
              );


        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {

        $this->addColumn('name', array(
            'header'    => $this->__('Product Name'),
            'sortable'  => false,
            'index'     => 'product_name'
        ));

        $this->addColumn('price', array(
            'header'    => $this->__('Price'),
            'width'     => '120px',
            'type'      => 'currency',
            'currency_code' => (string) Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode(),
            'sortable'  => false,
            'index'     => 'product_price'
        ));

        $this->addColumn('ordered_qty', array(
            'header'    => $this->__('Quantity Ordered'),
            'width'     => '120px',
            'align'     => 'right',
            'sortable'  => false,
            'index'     => 'qty_ordered',
            'type'      => 'number'
        ));

        $this->setFilterVisibility(false);
        $this->setPagerVisibility(false);

        return parent::_prepareColumns();
    }

    /*
     * Returns row url to show in admin dashboard
     * $row is bestseller row wrapped in Product model
     *
     * @param Mage_Catalog_Model_Product $row
     *
     * @return string
     */
    public function getRowUrl($row)
    {
        // getId() would return id of bestseller row, and product id we get by getProductId()
        $productId = $row->getProductId();

        // No url is possible for non-existing products
        if (!$productId) {
            return '';
        }

        $params = array('id' => $productId);
        if ($this->getRequest()->getParam('store')) {
            $params['store'] = $this->getRequest()->getParam('store');
        }
        return $this->getUrl('*/catalog_product/edit', $params);
    }
}

然后复制Grids.php

app/code/core/Mage/Adminhtml/Block/Dashboard/

app/code/local/Mage/Adminhtml/Block/Dashboard/

添加了以下代码:

$this->addTab('new_products', array(
        'label'     => $this->__('New Product'),
        'content'   => $this->getLayout()->createBlock('adminhtml/dashboard_tab_products_new')->toHtml(),
        'class'     => 'ajax'
));

我想在管理信息中心中添加一个新的产品标签,除了客户。我不知道New.php有什么问题。我点击新产品标签,它不能正常工作。如何解决?< / p>

1 个答案:

答案 0 :(得分:2)

我已经设法让这个工作只需要更多几行来改变。

更新Dashboard控制器Mage_Adminhtml_DashboardController以添加新操作

public function productsNewAction()
{
    $this->loadLayout();
    $this->renderLayout();
}

更新admin layout.xml design \ adminhtml \ default \ default \ layout \ main.xml以添加新部分

<adminhtml_dashboard_productsnew>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="adminhtml/dashboard_tab_products_new" name="adminhtml.dashboard.tab.products.new"/>
    </block>
</adminhtml_dashboard_productsnew>

您只需要将Grids.php中的代码更新为以下内容。

$this->addTab('new_products', array(
    'label'     => $this->__('New Product'),
    'url'       => $this->getUrl('*/*/productsNew', array('_current'=>true)),
    'class'     => 'ajax'
));

然后,这应该使用对url的调用而不是块内容。

然后,您需要选择要显示的属性。您可以通过选择全部或按属性代码来完成此操作。

$collection->addAttributeToSelect('*')
$collection->addAttributeToSelect('name');

重要的是_prepareColumns中定义的列索引与这些属性代码匹配,否则您将获得一个空行。

我建议将这些更改打包到带有controller,layout.xml和块文件的新模块中。关于如何做到这一点有很多很棒的教程,但显然你不必:)