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\Order\View\Tab\Shipments to new layout xml config format
  • Loading branch information
Zyava committed Feb 1, 2014
1 parent fa11131 commit 8815fcb
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 96 deletions.
120 changes: 28 additions & 92 deletions app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/Shipments.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace Magento\Sales\Block\Adminhtml\Order\View\Tab;

class Shipments
extends \Magento\Backend\Block\Widget\Grid\Extended
extends \Magento\View\Element\Text\ListText
implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
/**
Expand All @@ -41,29 +41,22 @@ class Shipments
protected $_coreRegistry = null;

/**
* @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 \Magento\View\Element\Context $context
* @param \Magento\Core\Model\Registry $coreRegistry
* @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,
\Magento\View\Element\Context $context,
\Magento\Core\Model\Registry $coreRegistry,
array $data = array()
) {
$this->_coreRegistry = $coreRegistry;
$this->_collectionFactory = $collectionFactory;
parent::__construct($context, $backendHelper, $data);
$this->_coreRegistry = $coreRegistry;
parent::__construct($context, $data);
}

/**
* Initialize grid params
*/
protected function _construct()
{
parent::_construct();
Expand All @@ -72,110 +65,53 @@ protected function _construct()
}

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

protected function _prepareCollection()
public function getTabLabel()
{
$collection = $this->_collectionFactory->create($this->_getCollectionClass())
->addFieldToSelect('entity_id')
->addFieldToSelect('created_at')
->addFieldToSelect('increment_id')
->addFieldToSelect('total_qty')
->addFieldToSelect('shipping_name')
->setOrderFilter($this->getOrder())
;
$this->setCollection($collection);
return parent::_prepareCollection();
return __('Shipments');
}

protected function _prepareColumns()
/**
* Return Tab title
*
* @return string
*/
public function getTabTitle()
{
$this->addColumn('increment_id', array(
'header' => __('Shipment'),
'index' => 'increment_id',
'header_css_class' => 'col-memo',
'column_css_class' => 'col-memo'
));

$this->addColumn('shipping_name', array(
'header' => __('Ship-to Name'),
'index' => 'shipping_name',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
));

$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('total_qty', array(
'header' => __('Total Quantity'),
'index' => 'total_qty',
'type' => 'number',
'header_css_class' => 'col-qty',
'column_css_class' => 'col-qty'
));

return parent::_prepareColumns();
return __('Order Shipments');
}

/**
* Retrieve order model instance
*
* @return \Magento\Sales\Model\Order
*/
public function getOrder()
protected function _getOrder()
{
return $this->_coreRegistry->registry('current_order');
}

public function getRowUrl($row)
{
return $this->getUrl(
'adminhtml/order_shipment/view',
array(
'shipment_id'=> $row->getId(),
'order_id' => $row->getOrderId()
));
}

public function getGridUrl()
{
return $this->getUrl('sales/*/shipments', array('_current' => true));
}

/**
* ######################## TAB settings #################################
* Can show tab in tabs
*
* @return boolean
*/
public function getTabLabel()
{
return __('Shipments');
}

public function getTabTitle()
{
return __('Order Shipments');
}

public function canShowTab()
{
if ($this->getOrder()->getIsVirtual()) {
if ($this->_getOrder()->getIsVirtual()) {
return false;
}
return true;
}

/**
* Tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
Expand Down
5 changes: 2 additions & 3 deletions app/code/Magento/Sales/Controller/Adminhtml/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,8 @@ public function invoicesAction()
public function shipmentsAction()
{
$this->_initOrder();
$this->getResponse()->setBody(
$this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Order\View\Tab\Shipments')->toHtml()
);
$this->_view->loadLayout(false);
$this->_view->renderLayout();
}

/**
Expand Down
65 changes: 65 additions & 0 deletions app/code/Magento/Sales/Model/Order/ShipmentsUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-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.
*
* @category Magento
* @package Magento_Sales
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Magento\Sales\Model\Order;

/**
* Shipment collection updater on shipments tab of view order page
*/
class ShipmentsUpdater implements \Magento\Core\Model\Layout\Argument\UpdaterInterface
{
/**
* @var \Magento\Core\Model\Registry
*/
protected $_registryManager;

/**
* @param \Magento\Core\Model\Registry $registryManager
*/
public function __construct(\Magento\Core\Model\Registry $registryManager)
{
$this->_registryManager = $registryManager;
}

/**
* Add order filter
*
* @param \Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection $argument
* @return mixed
* @throws \DomainException
*/
public function update($argument)
{
$order = $this->_registryManager->registry('current_order');

if (!$order) {
throw new \DomainException('Undefined order object');
}

$argument->setOrderFilter($order->getId());
return $argument;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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">
<referenceBlock name="sales_order_shipment.grid.container">
<block class="Magento\Sales\Block\Adminhtml\Shipment\Grid" name="sales.order_shipment.grid" as="grid">
<arguments>
<argument name="id" xsi:type="string">sales_order_shipment_grid</argument>
<argument name="dataSource" xsi:type="object">
<value>Magento\Sales\Model\Resource\Order\Shipment\Grid\Collection</value>
<updater>Magento\Sales\Model\Order\ShipmentsUpdater</updater>
</argument>
<argument name="use_ajax" xsi:type="string">true</argument>
<argument name="default_sort" xsi:type="string">created_at</argument>
<argument name="default_dir" xsi:type="string">DESC</argument>
<argument name="save_parameters_in_session" xsi:type="string">1</argument>
<argument name="grid_url" xsi:type="url" path="sales/order/shipments">
<param name="_current">1</param>
</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\ColumnSet" as="grid.columnSet" name="sales.order_shipment.grid.columnSet">
<arguments>
<argument name="id" xsi:type="string">sales_order_shipment_grid</argument>
<argument name="rowUrl" xsi:type="array">
<item name="generatorClass" xsi:type="string">Magento\Sales\Model\Grid\Row\UrlGenerator</item>
<item name="path" xsi:type="string">sales/order_shipment/view</item>
<item name="extraParamsTemplate" xsi:type="array">
<item name="shipment_id" xsi:type="string">getId</item>
</item>
</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="real_shipment_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">Shipment</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="index" xsi:type="string">increment_id</argument>
<argument name="id" xsi:type="string">real_shipment_id</argument>
<argument name="header_css_class" xsi:type="string">col-shipment-number</argument>
<argument name="column_css_class" xsi:type="string">col-shipment-number</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="shipping_name">
<arguments>
<argument name="id" xsi:type="string">shipping_name</argument>
<argument name="header" xsi:type="string" translate="true">Ship-to Name</argument>
<argument name="index" xsi:type="string">shipping_name</argument>
<argument name="header_css_class" xsi:type="string">col-ship-to-name</argument>
<argument name="column_css_class" xsi:type="string">col-ship-to-name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="created_at">
<arguments>
<argument name="header" xsi:type="string" translate="true">Ship Date</argument>
<argument name="type" xsi:type="string">datetime</argument>
<argument name="index" xsi:type="string">created_at</argument>
<argument name="id" xsi:type="string">created_at</argument>
<argument name="header_css_class" xsi:type="string">col-period</argument>
<argument name="column_css_class" xsi:type="string">col-period</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="total_qty">
<arguments>
<argument name="id" xsi:type="string">total_qty</argument>
<argument name="header" xsi:type="string" translate="true">Total Quantity</argument>
<argument name="type" xsi:type="string">number</argument>
<argument name="index" xsi:type="string">total_qty</argument>
<argument name="header_css_class" xsi:type="string">col-qty</argument>
<argument name="column_css_class" xsi:type="string">col-qty</argument>
</arguments>
</block>
</block>
</block>
</referenceBlock>
</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_order_shipment_grid_block"/>
<block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Shipments" name="sales_order_shipment.grid.container" output="1"/>
</layout>
Loading

0 comments on commit 8815fcb

Please sign in to comment.