1

复制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。我单击新产品选项卡,它不起作用。如何解决?

4

1 回答 1

2

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

更新仪表板控制器 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 中定义的列索引与这些属性代码匹配,否则您只会得到一个空行。

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

于 2013-05-18T19:45:32.143 回答