在管理仪表板magento 1.7.0.2中添加选项卡 [英] add tab in admin dashboard magento 1.7.0.2

查看:88
本文介绍了在管理仪表板magento 1.7.0.2中添加选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

复制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有什么问题.我单击新产品标签,该标签不起作用.如何解决?

I want to add a new product tab in admin dashboard,beside customers.I don't know what wrong with the New.php.I click the new product tab,it's not working.How to fix it?

推荐答案

我设法仅需几行更改就可以完成此工作.

I have managed to get this working with only a few more lines to change.

更新仪表板控制器Mage_Adminhtml_DashboardController以添加新操作

Update the Dashboard controller Mage_Adminhtml_DashboardController to add the new action

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

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

Update the admin layout.xml design\adminhtml\default\default\layout\main.xml to add the new section

<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中的代码更新为以下代码即可.

The you would just need to update your code in the Grids.php to the following.

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

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

This should then work using a call to the url rather than the block content.

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

You then need to select the attributes you want to show. You can do this by selecting all or by attribute code.

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

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

Important is the column index defined in _prepareColumns match these attribute codes Otherwise you will just get an empty row.

我建议将这些更改打包到带有控制器,layout.xml和块文件的新模块中.有关如何执行此操作的很多很棒的教程,但是显然您不必:)

I would suggest packaging these changes into a new module with a controller, layout.xml and block files. There are lots of great tutorials around on how to do this, but obviously you don't have to :)

这篇关于在管理仪表板magento 1.7.0.2中添加选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆