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\Invoices to new layout xml config format
  • Loading branch information
Zyava committed Feb 1, 2014
1 parent 185611d commit 4e7c1f7
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@
class Orders extends \Magento\View\Element\Text\ListText
implements \Magento\Backend\Block\Widget\Tab\TabInterface
{

/**
* Initialize grid params
*
*/
protected function _construct()
{
Expand Down
155 changes: 17 additions & 138 deletions app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,12 @@
*/
namespace Magento\Sales\Block\Adminhtml\Order\View\Tab;

class Invoices
extends \Magento\Backend\Block\Widget\Grid\Extended
class Invoices 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\Invoice
*/
protected $_orderInvoice;

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

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

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

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

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

$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' => __('Invoice Date'),
'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->_orderInvoice->getStates(),
'header_css_class' => 'col-status',
'column_css_class' => 'col-status'
));

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

return parent::_prepareColumns();
return __('Invoices');
}

/**
* 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('sales/order_invoice/view',
array(
'invoice_id'=> $row->getId(),
'order_id' => $row->getOrderId()
)
);
}

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


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

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

/**
* 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 @@ -359,9 +359,8 @@ public function addCommentAction()
public function invoicesAction()
{
$this->_initOrder();
$this->getResponse()->setBody(
$this->_view->getLayout()->createBlock('Magento\Sales\Block\Adminhtml\Order\View\Tab\Invoices')->toHtml()
);
$this->_view->loadLayout(false);
$this->_view->renderLayout();
}

/**
Expand Down
17 changes: 10 additions & 7 deletions app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

/**
* Adminhtml sales order edit controller
* Adminhtml sales order invoice edit controller
*
* @category Magento
* @package Magento_Sales
Expand Down Expand Up @@ -78,10 +78,10 @@ protected function _getItemQtys()
/**
* Initialize invoice model instance
*
* @param bool $update
* @return \Magento\Sales\Model\Order\Invoice
* @throws \Magento\Core\Exception
*/
protected function _initInvoice($update = false)
protected function _initInvoice()
{
$this->_title->add(__('Invoices'));

Expand Down Expand Up @@ -411,6 +411,9 @@ public function voidAction()
}
}

/**
* Add comment to invoice action
*/
public function addCommentAction()
{
try {
Expand All @@ -432,14 +435,14 @@ public function addCommentAction()
$response = $this->_view->getLayout()->getBlock('invoice_comments')->toHtml();
} catch (\Magento\Core\Exception $e) {
$response = array(
'error' => true,
'message' => $e->getMessage()
'error' => true,
'message' => $e->getMessage()
);
$response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response);
} catch (\Exception $e) {
$response = array(
'error' => true,
'message' => __('Cannot add new comment.')
'error' => true,
'message' => __('Cannot add new comment.')
);
$response = $this->_objectManager->get('Magento\Core\Helper\Data')->jsonEncode($response);
}
Expand Down
21 changes: 7 additions & 14 deletions app/code/Magento/Sales/Model/Billing/Agreement/OrdersUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Sales orders grid massaction items updater
*/
namespace Magento\Sales\Model\Billing\Agreement;

/**
* Order collection updater on orders tab of view billing agreement page
*/
class OrdersUpdater implements \Magento\Core\Model\Layout\Argument\UpdaterInterface
{
/**
Expand All @@ -37,24 +37,17 @@ class OrdersUpdater implements \Magento\Core\Model\Layout\Argument\UpdaterInterf
protected $_registryManager;

/**
* @param \Magento\Core\Model\Registry $coreRegistry
* @param array $data
* @throws \InvalidArgumentException
* @param \Magento\Core\Model\Registry $registryManager
*/
public function __construct(\Magento\Core\Model\Registry $coreRegistry, array $data = array())
public function __construct(\Magento\Core\Model\Registry $registryManager)
{
$this->_registryManager = isset($data['registry']) ? $data['registry'] : $coreRegistry;

if (false === ($this->_registryManager instanceof \Magento\Core\Model\Registry)) {
throw new \InvalidArgumentException('registry object has to be an instance of \Magento\Core\Model\Registry');
}
$this->_registryManager = $registryManager;
}

/**
* Add billing agreement filter
*
* @param mixed $argument
* @throws \DomainException
* @param \Magento\Sales\Model\Resource\Order\Collection $argument
* @return mixed
* @throws \DomainException
*/
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Magento\Sales\Model;

/**
* Order model
*
Expand Down Expand Up @@ -303,11 +305,10 @@
* @method float getBaseShippingInclTax()
* @method \Magento\Sales\Model\Order setBaseShippingInclTax(float $value)
*/
namespace Magento\Sales\Model;

class Order extends \Magento\Sales\Model\AbstractModel
{
const ENTITY = 'order';

/**
* XML configuration paths
*/
Expand Down Expand Up @@ -360,6 +361,7 @@ class Order extends \Magento\Sales\Model\AbstractModel
*/
const REPORT_DATE_TYPE_CREATED = 'created';
const REPORT_DATE_TYPE_UPDATED = 'updated';

/*
* Identifier for history item
*/
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Sales/Model/Order/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Magento\Sales\Model\Order;

/**
* @method \Magento\Sales\Model\Resource\Order\Invoice _getResource()
* @method \Magento\Sales\Model\Resource\Order\Invoice getResource()
Expand Down Expand Up @@ -110,8 +112,6 @@
* @method float getBaseShippingInclTax()
* @method \Magento\Sales\Model\Order\Invoice setBaseShippingInclTax(float $value)
*/
namespace Magento\Sales\Model\Order;

class Invoice extends \Magento\Sales\Model\AbstractModel
{
/**
Expand Down
Loading

0 comments on commit 4e7c1f7

Please sign in to comment.