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\Creditmemos to new layout xml config format
  • Loading branch information
Zyava committed Feb 1, 2014
1 parent 509b461 commit 4ccd440
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 140 deletions.
153 changes: 17 additions & 136 deletions app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/Creditmemos.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,12 @@
namespace Magento\Sales\Block\Adminhtml\Order\View\Tab;

class Creditmemos
extends \Magento\Backend\Block\Widget\Grid\Extended
extends \Magento\View\Element\Text\ListText
implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
/**
* Core registry
*
* @var \Magento\Core\Model\Registry
*/
protected $_coreRegistry = null;

/**
* @var \Magento\Sales\Model\Order\Creditmemo
*/
protected $_orderCreditmemo;

/**
* @var \Magento\Sales\Model\Resource\Order\Collection\Factory
* Initialize grid params
*/
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\Sales\Model\Order\Creditmemo $orderCreditmemo
* @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\Sales\Model\Order\Creditmemo $orderCreditmemo,
\Magento\Core\Model\Registry $coreRegistry,
array $data = array()
) {
$this->_coreRegistry = $coreRegistry;
$this->_orderCreditmemo = $orderCreditmemo;
$this->_collectionFactory = $collectionFactory;
parent::__construct($context, $backendHelper, $data);
}

protected function _construct()
{
parent::_construct();
Expand All @@ -84,123 +48,40 @@ protected function _construct()
}

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


protected function _prepareCollection()
{
$collection = $this->_collectionFactory->create($this->_getCollectionClass())
->addFieldToSelect('entity_id')
->addFieldToSelect('created_at')
->addFieldToSelect('increment_id')
->addFieldToSelect('order_currency_code')
->addFieldToSelect('store_currency_code')
->addFieldToSelect('base_currency_code')
->addFieldToSelect('state')
->addFieldToSelect('grand_total')
->addFieldToSelect('base_grand_total')
->addFieldToSelect('billing_name')
->setOrderFilter($this->getOrder())
;
$this->setCollection($collection);
return parent::_prepareCollection();
}

protected function _prepareColumns()
public function getTabLabel()
{
$this->addColumn('increment_id', array(
'header' => __('Credit Memo'),
'index' => 'increment_id',
'header_css_class' => 'col-memo',
'column_css_class' => 'col-memo'
));

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

$this->addColumn('created_at', array(
'header' => __('Created'),
'index' => 'created_at',
'type' => 'datetime',
'header_css_class' => 'col-period',
'column_css_class' => 'col-period'
));

$this->addColumn('state', array(
'header' => __('Status'),
'index' => 'state',
'type' => 'options',
'options' => $this->_orderCreditmemo->getStates(),
'header_css_class' => 'col-status',
'column_css_class' => 'col-status'
));

$this->addColumn('base_grand_total', array(
'header' => __('Refunded'),
'index' => 'base_grand_total',
'type' => 'currency',
'currency' => 'base_currency_code',
'header_css_class' => 'col-refunded',
'column_css_class' => 'col-refunded'
));

return parent::_prepareColumns();
return __('Credit Memos');
}

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

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

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

/**
* ######################## TAB settings #################################
* @return string
*/
public function getTabLabel()
{
return __('Credit Memos');
}

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

/**
* Can show tab in tabs
*
* @return boolean
*/
public function canShowTab()
{
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 @@ -379,9 +379,8 @@ public function shipmentsAction()
public function creditmemosAction()
{
$this->_initOrder();
$this->getResponse()->setBody(
$this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Order\View\Tab\Creditmemos')->toHtml()
);
$this->_view->loadLayout(false);
$this->_view->renderLayout();
}

/**
Expand Down
65 changes: 65 additions & 0 deletions app/code/Magento/Sales/Model/Order/CreditmemosUpdater.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;

/**
* Credit memo collection updater on credit memos tab of view order page
*/
class CreditmemosUpdater 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\Creditmemo\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,109 @@
<?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_creditmemo.grid.container">
<block class="Magento\Sales\Block\Adminhtml\Creditmemo\Grid" name="sales.order_creditmemo.grid" as="grid">
<arguments>
<argument name="id" xsi:type="string">sales_order_creditmemo_grid</argument>
<argument name="dataSource" xsi:type="object">
<value>Magento\Sales\Model\Resource\Order\Creditmemo\Grid\Collection</value>
<updater>Magento\Sales\Model\Order\CreditmemosUpdater</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/creditmemos">
<param name="_current">1</param>
</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\ColumnSet" as="grid.columnSet" name="sales.order_creditmemo.grid.columnSet">
<arguments>
<argument name="id" xsi:type="string">sales_order_creditmemo_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_creditmemo/view</item>
<item name="extraParamsTemplate" xsi:type="array">
<item name="creditmemo_id" xsi:type="string">getId</item>
</item>
</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="real_creditmemo_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">Credit Memo</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_creditmemo_id</argument>
<argument name="header_css_class" xsi:type="string">col-memo-number</argument>
<argument name="column_css_class" xsi:type="string">col-memo-number</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="billing_name">
<arguments>
<argument name="id" xsi:type="string">billing_name</argument>
<argument name="header" xsi:type="string" translate="true">Bill-to Name</argument>
<argument name="index" xsi:type="string">billing_name</argument>
<argument name="header_css_class" xsi:type="string">col-bill-to-name</argument>
<argument name="column_css_class" xsi:type="string">col-bill-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">Created</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="state">
<arguments>
<argument name="id" xsi:type="string">state</argument>
<argument name="header" xsi:type="string" translate="true">Status</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="index" xsi:type="string">state</argument>
<argument name="options" xsi:type="options" model="Magento\Sales\Model\Resource\Order\Creditmemo\Grid\StatusesArray"/>
<argument name="header_css_class" xsi:type="string">col-status</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="base_grand_total">
<arguments>
<argument name="id" xsi:type="string">grand_total</argument>
<argument name="header" xsi:type="string" translate="true">Refunded</argument>
<argument name="type" xsi:type="string">currency</argument>
<argument name="currency" xsi:type="string">order_currency_code</argument>
<argument name="rate" xsi:type="string">1</argument>
<argument name="index" xsi:type="string">grand_total</argument>
<argument name="header_css_class" xsi:type="string">col-refunded</argument>
<argument name="column_css_class" xsi:type="string">col-refunded</argument>
</arguments>
</block>
</block>
</block>
</referenceBlock>
</layout>
Loading

0 comments on commit 4ccd440

Please sign in to comment.