From d111a7c41a52eb7baadc264eb0029750399fb8f6 Mon Sep 17 00:00:00 2001 From: Dmytro Zavalkin Date: Sat, 1 Feb 2014 10:24:12 +0100 Subject: [PATCH] Implemented MAGETWO-11122: Configurable Grids (#471) - converted Magento\Sales\Block\Adminhtml\Invoice\Grid to new layout xml config format --- .../Magento/Sales/Block/Adminhtml/Invoice.php | 1 - .../Sales/Block/Adminhtml/Invoice/Grid.php | 176 +---------------- .../Sales/Controller/Adminhtml/Invoice.php | 22 ++- .../Adminhtml/Invoice/AbstractInvoice.php | 12 +- .../Order/Invoice/Grid/StatusesArray.php | 56 ++++++ .../layout/sales_invoice_exportcsv.xml | 29 +++ .../layout/sales_invoice_exportexcel.xml | 29 +++ .../adminhtml/layout/sales_invoice_grid.xml | 30 +++ .../layout/sales_invoice_grid_block.xml | 177 ++++++++++++++++++ .../adminhtml/layout/sales_invoice_index.xml | 31 +++ 10 files changed, 373 insertions(+), 190 deletions(-) create mode 100644 app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/StatusesArray.php create mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportcsv.xml create mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportexcel.xml create mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid.xml create mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml create mode 100644 app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_index.xml diff --git a/app/code/Magento/Sales/Block/Adminhtml/Invoice.php b/app/code/Magento/Sales/Block/Adminhtml/Invoice.php index 0c8f155569209..db7d2dd492cab 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Invoice.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Invoice.php @@ -36,7 +36,6 @@ class Invoice extends \Magento\Backend\Block\Widget\Grid\Container { - protected function _construct() { $this->_controller = 'adminhtml_invoice'; diff --git a/app/code/Magento/Sales/Block/Adminhtml/Invoice/Grid.php b/app/code/Magento/Sales/Block/Adminhtml/Invoice/Grid.php index 5043c9b50e1fe..a30673f815a42 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Invoice/Grid.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Invoice/Grid.php @@ -31,180 +31,6 @@ */ namespace Magento\Sales\Block\Adminhtml\Invoice; -class Grid extends \Magento\Backend\Block\Widget\Grid\Extended +class Grid extends \Magento\Backend\Block\Widget\Grid { - /** - * @var \Magento\Sales\Model\Resource\Order\Invoice\Grid\CollectionFactory - */ - protected $_collectionFactory; - - /** - * @var \Magento\Sales\Model\Order\InvoiceFactory - */ - protected $_invoiceFactory; - - /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param \Magento\Sales\Model\Order\InvoiceFactory $invoiceFactory - * @param \Magento\Sales\Model\Resource\Order\Invoice\Grid\CollectionFactory $collectionFactory - * @param array $data - */ - public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - \Magento\Sales\Model\Order\InvoiceFactory $invoiceFactory, - \Magento\Sales\Model\Resource\Order\Invoice\Grid\CollectionFactory $collectionFactory, - array $data = array() - ) { - $this->_invoiceFactory = $invoiceFactory; - $this->_collectionFactory = $collectionFactory; - parent::__construct($context, $backendHelper, $data); - } - - protected function _construct() - { - parent::_construct(); - $this->setId('sales_invoice_grid'); - $this->setUseAjax(true); - $this->setDefaultSort('created_at'); - $this->setDefaultDir('DESC'); - $this->setSaveParametersInSession(true); - } - - /** - * Retrieve collection class - * - * @return string - */ - protected function _getCollectionClass() - { - return 'Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection'; - } - - protected function _prepareCollection() - { - $collection = $this->_collectionFactory->create(); - $this->setCollection($collection); - return parent::_prepareCollection(); - } - - protected function _prepareColumns() - { - $this->addColumn('increment_id', array( - 'header' => __('Invoice'), - 'index' => 'increment_id', - 'type' => 'text', - 'header_css_class' => 'col-invoice-number', - 'column_css_class' => 'col-invoice-number' - )); - - $this->addColumn('created_at', array( - 'header' => __('Invoice Date'), - 'index' => 'created_at', - 'type' => 'datetime', - 'header_css_class' => 'col-period', - 'column_css_class' => 'col-period' - )); - - $this->addColumn('order_increment_id', array( - 'header' => __('Order'), - 'index' => 'order_increment_id', - 'type' => 'text', - 'header_css_class' => 'col-order-number', - 'column_css_class' => 'col-order-number' - )); - - $this->addColumn('order_created_at', array( - 'header' => __('Order Date'), - 'index' => 'order_created_at', - 'type' => 'datetime', - 'header_css_class' => 'col-period', - 'column_css_class' => 'col-period' - )); - - $this->addColumn('billing_name', array( - 'header' => __('Bill-to Name'), - 'index' => 'billing_name', - 'header_css_class' => 'col-name', - 'column_css_class' => 'col-name' - )); - - $this->addColumn('state', array( - 'header' => __('Status'), - 'index' => 'state', - 'type' => 'options', - 'options' => $this->_invoiceFactory->create()->getStates(), - 'header_css_class' => 'col-status', - 'column_css_class' => 'col-status' - )); - - $this->addColumn('grand_total', array( - 'header' => __('Amount'), - 'index' => 'grand_total', - 'type' => 'currency', - 'align' => 'right', - 'currency' => 'order_currency_code', - 'header_css_class' => 'col-qty', - 'column_css_class' => 'col-qty' - )); - - $this->addColumn('action', - array( - 'header' => __('Action'), - 'width' => '50px', - 'type' => 'action', - 'getter' => 'getId', - 'actions' => array( - array( - 'caption' => __('View'), - 'url' => array('base'=>'sales/invoice/view'), - 'field' => 'invoice_id' - ) - ), - 'filter' => false, - 'sortable' => false, - 'is_system' => true, - 'header_css_class' => 'col-actions', - 'column_css_class' => 'col-actions' - )); - - $this->addExportType('*/*/exportCsv', __('CSV')); - $this->addExportType('*/*/exportExcel', __('Excel XML')); - - return parent::_prepareColumns(); - } - - protected function _prepareMassaction() - { - $this->setMassactionIdField('entity_id'); - $this->getMassactionBlock()->setFormFieldName('invoice_ids'); - $this->getMassactionBlock()->setUseSelectAll(false); - - $this->getMassactionBlock()->addItem('pdfinvoices_order', array( - 'label'=> __('PDF Invoices'), - 'url' => $this->getUrl('sales/invoice/pdfinvoices'), - )); - - return $this; - } - - public function getRowUrl($row) - { - if (!$this->_authorization->isAllowed(null)) { - return false; - } - - return $this->getUrl('sales/invoice/view', - array( - 'invoice_id'=> $row->getId(), - ) - ); - } - - public function getGridUrl() - { - return $this->getUrl('sales/*/grid', array('_current' => true)); - } - } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice.php index 884d022aabe21..98a43992e4480 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice.php @@ -25,7 +25,7 @@ */ /** - * Adminhtml sales orders controller + * Adminhtml sales invoices controller * * @author Magento Core Team */ @@ -38,9 +38,11 @@ class Invoice extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoic */ public function exportCsvAction() { - $fileName = 'invoices.csv'; - $grid = $this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Invoice\Grid'); - return $this->_fileFactory->create($fileName, $grid->getCsvFile()); + $this->_view->loadLayout(); + $fileName = 'invoices.csv'; + /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */ + $exportBlock = $this->_view->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export'); + return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), \Magento\App\Filesystem::VAR_DIR); } /** @@ -48,8 +50,14 @@ public function exportCsvAction() */ public function exportExcelAction() { - $fileName = 'invoices.xml'; - $grid = $this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Invoice\Grid'); - return $this->_fileFactory->create($fileName, $grid->getExcelFile($fileName)); + $this->_view->loadLayout(); + $fileName = 'invoices.xml'; + /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */ + $exportBlock = $this->_view->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export'); + return $this->_fileFactory->create( + $fileName, + $exportBlock->getExcelFile($fileName), + \Magento\App\Filesystem::VAR_DIR + ); } } diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice.php index 2aa4d18f581a5..569a23a0a4694 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice.php @@ -50,6 +50,7 @@ public function __construct( $this->_fileFactory = $fileFactory; parent::__construct($context); } + /** * Init layout, menu and breadcrumb * @@ -69,10 +70,8 @@ protected function _initAction() */ public function gridAction() { - $this->_view->loadLayout(); - $this->getResponse()->setBody( - $this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Invoice\Grid')->toHtml() - ); + $this->_view->loadLayout(false); + $this->_view->renderLayout(); } /** @@ -82,8 +81,7 @@ public function indexAction() { $this->_title->add(__('Invoices')); - $this->_initAction() - ->_addContent($this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Invoice')); + $this->_initAction(); $this->_view->renderLayout(); } @@ -142,7 +140,7 @@ public function printAction() } } - public function pdfinvoicesAction() + public function massPrintInvoicesAction() { $invoicesIds = $this->getRequest()->getPost('invoice_ids'); if (!empty($invoicesIds)) { diff --git a/app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/StatusesArray.php b/app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/StatusesArray.php new file mode 100644 index 0000000000000..f9362d4599128 --- /dev/null +++ b/app/code/Magento/Sales/Model/Resource/Order/Invoice/Grid/StatusesArray.php @@ -0,0 +1,56 @@ +_invoiceFactory = $invoiceFactory; + } + + /** + * Return option array + * + * @return array + */ + public function toOptionArray() + { + return $this->_invoiceFactory->create()->getStates(); + } +} diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportcsv.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportcsv.xml new file mode 100644 index 0000000000000..925d6e696e1f4 --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportcsv.xml @@ -0,0 +1,29 @@ + + + + + + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportexcel.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportexcel.xml new file mode 100644 index 0000000000000..925d6e696e1f4 --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_exportexcel.xml @@ -0,0 +1,29 @@ + + + + + + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid.xml new file mode 100644 index 0000000000000..cd24f1c4b6529 --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid.xml @@ -0,0 +1,30 @@ + + + + + + + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml new file mode 100644 index 0000000000000..72193b3cb8c42 --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_grid_block.xml @@ -0,0 +1,177 @@ + + + + + + + sales_invoice_grid + Magento\Sales\Model\Resource\Order\Invoice\Grid\Collection + true + created_at + DESC + 1 + + 1 + + + + + entity_id + invoice_ids + 0 + + Magento\Sales\Model\Grid\Massaction\ItemsUpdater + + Print Invoices + sales/invoice/massPrintInvoices + + + + + + + + + */*/exportCsv + CSV + + + */*/exportExcel + Excel XML + + + + + + + sales_invoice_grid + + Magento\Sales\Model\Grid\Row\UrlGenerator + sales/invoice/view + + getId + + + + + + Invoice + text + increment_id + real_invoice_id + col-invoice-number + col-invoice-number + + + + + Invoice Date + datetime + created_at + created_at + col-period + col-period + + + + + Order + text + order_increment_id + order_increment_id + col-order-number + col-order-number + + + + + Order Date + datetime + order_created_at + order_created_at + col-period + col-period + + + + + billing_name + Bill-to Name + billing_name + col-bill-to-name + col-bill-to-name + + + + + state + Status + options + state + + col-status + col-status + + + + + grand_total + Grand Total (Purchased) + currency + invoice_currency_code + 1 + grand_total + col-gtpurchased + col-gtpurchased + + + + + + action + Action + action + getId + 0 + 0 + 1 + + + View + + sales/invoice/view + + invoice_id + + + col-actions + col-actions + + + + + + diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_index.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_index.xml new file mode 100644 index 0000000000000..eaac5d9c06eb5 --- /dev/null +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_invoice_index.xml @@ -0,0 +1,31 @@ + + + + + + + +