Skip to content

Commit

Permalink
Implemented MAGETWO-11122: Configurable Grids (magento#471)
Browse files Browse the repository at this point in the history
- converted Magento\Sales\Block\Adminhtml\Shipment\Grid to new layout xml config format
  • Loading branch information
Zyava committed Feb 1, 2014
1 parent 89e6284 commit fa11131
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 205 deletions.
195 changes: 4 additions & 191 deletions app/code/Magento/Sales/Block/Adminhtml/Shipment/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,200 +24,13 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Magento\Sales\Block\Adminhtml\Shipment;

/**
* Adminhtml sales orders grid
* Adminhtml sales shipments grid
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Sales\Block\Adminhtml\Shipment;

class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
class Grid extends \Magento\Backend\Block\Widget\Grid
{
/**
* @var \Magento\Sales\Model\Resource\Order\Collection\Factory
*/
protected $_collectionFactory;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\Sales\Model\Resource\Order\Collection\Factory $collectionFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\Sales\Model\Resource\Order\Collection\Factory $collectionFactory,
array $data = array()
) {
$this->_collectionFactory = $collectionFactory;
parent::__construct($context, $backendHelper, $data);
}


/**
* Initialization
*/
protected function _construct()
{
parent::_construct();
$this->setId('sales_shipment_grid');
$this->setDefaultSort('created_at');
$this->setDefaultDir('DESC');
}

/**
* Retrieve collection class
*
* @return string
*/
protected function _getCollectionClass()
{
return 'Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection';
}

/**
* Prepare and set collection of grid
*
* @return \Magento\Backend\Block\Widget\Grid\Extended
*/
protected function _prepareCollection()
{
$collection = $this->_collectionFactory->create($this->_getCollectionClass());
$this->setCollection($collection);
return parent::_prepareCollection();
}

/**
* Prepare and add columns to grid
*
* @return \Magento\Backend\Block\Widget\Grid\Extended
*/
protected function _prepareColumns()
{
$this->addColumn('increment_id', array(
'header' => __('Shipment'),
'index' => 'increment_id',
'type' => 'text',
'header_css_class' => 'col-shipment-number',
'column_css_class' => 'col-shipment-number'
));

$this->addColumn('created_at', array(
'header' => __('Ship 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('shipping_name', array(
'header' => __('Ship-to Name'),
'index' => 'shipping_name',
'header_css_class' => 'col-memo',
'column_css_class' => 'col-memo'
));

$this->addColumn('total_qty', array(
'header' => __('Total Quantity'),
'index' => 'total_qty',
'type' => 'number',
'header_css_class' => 'col-qty',
'column_css_class' => 'col-qty'
));

$this->addColumn('action',
array(
'header' => __('Action'),
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => __('View'),
'url' => array('base' => 'sales/shipment/view'),
'field' => 'shipment_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();
}

/**
* Get url for row
*
* @param string $row
* @return string
*/
public function getRowUrl($row)
{
if (!$this->_authorization->isAllowed(null)) {
return false;
}

return $this->getUrl('sales/shipment/view',
array(
'shipment_id' => $row->getId(),
)
);
}

/**
* Prepare and set options for massaction
*
* @return \Magento\Sales\Block\Adminhtml\Shipment\Grid
*/
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('shipment_ids');
$this->getMassactionBlock()->setUseSelectAll(false);

$this->getMassactionBlock()->addItem('pdfshipments_order', array(
'label' => __('PDF Packing Slips'),
'url' => $this->getUrl('sales/shipment/massPrintShipments'),
));

$this->getMassactionBlock()->addItem('print_shipping_label', array(
'label' => __('Print Shipping Labels'),
'url' => $this->getUrl('adminhtml/order_shipment/massPrintShippingLabel'),
));

return $this;
}

/**
* Get url of grid
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('sales/*/*', array('_current' => true));
}

}
26 changes: 17 additions & 9 deletions app/code/Magento/Sales/Controller/Adminhtml/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,40 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Magento\Sales\Controller\Adminhtml;

/**
* Adminhtml sales orders controller
* Adminhtml sales shipment controller
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Sales\Controller\Adminhtml;

class Shipment extends \Magento\Sales\Controller\Adminhtml\Shipment\AbstractShipment
{
/**
* Export shipment grid to CSV format
*/
public function exportCsvAction()
{
$fileName = 'shipments.csv';
$grid = $this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Shipment\Grid');
return $this->_fileFactory->create($fileName, $grid->getCsvFile());
$this->_view->loadLayout();
$fileName = 'shipments.csv';
/** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */
$exportBlock = $this->_view->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export');
return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), \Magento\App\Filesystem::VAR_DIR);
}

/**
* Export shipment grid to Excel XML format
*/
public function exportExcelAction()
{
$fileName = 'shipments.xml';
$grid = $this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Shipment\Grid');
return $this->_fileFactory->create($fileName, $grid->getExcelFile($fileName));
$this->_view->loadLayout();
$fileName = 'shipments.xml';
/** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock */
$exportBlock = $this->_view->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export');
return $this->_fileFactory->create(
$fileName,
$exportBlock->getExcelFile($fileName),
\Magento\App\Filesystem::VAR_DIR
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Magento\Sales\Controller\Adminhtml\Shipment;

/**
* Adminhtml sales orders controller
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Sales\Controller\Adminhtml\Shipment;

class AbstractShipment extends \Magento\Backend\App\Action
{
/**
Expand All @@ -49,6 +49,7 @@ public function __construct(
$this->_fileFactory = $fileFactory;
parent::__construct($context);
}

/**
* Init layout, menu and breadcrumb
*
Expand All @@ -63,15 +64,23 @@ protected function _initAction()
return $this;
}

/**
* Shipments grid
*/
public function gridAction()
{
$this->_view->loadLayout(false);
$this->_view->renderLayout();
}

/**
* Shipments grid
*/
public function indexAction()
{
$this->_title->add(__('Shipments'));

$this->_initAction()
->_addContent($this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Shipment'));
$this->_initAction();
$this->_view->renderLayout();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<update handle="sales_shipment_grid_block"/>
<block class="Magento\Backend\Block\Widget\Grid\Container" name="sales_shipment.grid.container" template="Magento_Backend::widget/grid/container/empty.phtml"/>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<update handle="sales_shipment_grid_block"/>
<block class="Magento\Backend\Block\Widget\Grid\Container" name="sales_shipment.grid.container" template="Magento_Backend::widget/grid/container/empty.phtml"/>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<update handle="formkey"/>
<update handle="sales_shipment_grid_block"/>
<block class="Magento\Backend\Block\Widget\Grid\Container" name="sales_shipment.grid.container" template="Magento_Backend::widget/grid/container/empty.phtml" output="1"/>
</layout>
Loading

0 comments on commit fa11131

Please sign in to comment.