Skip to content

Commit

Permalink
Implemented MAGETWO-11122: Configurable Grids (magento#471)
Browse files Browse the repository at this point in the history
- moved common order grid parts to appropriate classes
- refactored mass actions block, made action names consistent
- added new acl Magento_Sales::print for pdf generation related mass actions
  • Loading branch information
Zyava committed Feb 1, 2014
1 parent 75b80bc commit 6be4f06
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 53 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/Block/Adminhtml/Creditmemo/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function _prepareMassaction()

$this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
'label'=> __('PDF Credit Memos'),
'url' => $this->getUrl('sales/creditmemo/pdfcreditmemos'),
'url' => $this->getUrl('sales/creditmemo/massPrintCreditMemos'),
));

return $this;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/Block/Adminhtml/Shipment/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected function _prepareMassaction()

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

$this->getMassactionBlock()->addItem('print_shipping_label', array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function emailAction()
}
}

public function pdfcreditmemosAction()
public function massPrintCreditMemosAction()
{
$creditmemosIds = $this->getRequest()->getPost('creditmemo_ids');
if (!empty($creditmemosIds)) {
Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/Sales/Controller/Adminhtml/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function gridAction()
}

/**
* View order detale
* View order details
*/
public function viewAction()
{
Expand Down Expand Up @@ -506,7 +506,7 @@ public function massPrintAction()
/**
* Print invoices for selected orders
*/
public function pdfinvoicesAction()
public function massPrintInvoicesAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
Expand Down Expand Up @@ -545,7 +545,7 @@ public function pdfinvoicesAction()
/**
* Print shipments for selected orders
*/
public function pdfshipmentsAction()
public function massPrintShipmentsAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
Expand Down Expand Up @@ -584,7 +584,7 @@ public function pdfshipmentsAction()
/**
* Print credit memos for selected orders
*/
public function pdfcreditmemosAction()
public function massPrintCreditMemosAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
Expand Down Expand Up @@ -623,7 +623,7 @@ public function pdfcreditmemosAction()
/**
* Print all documents for selected orders
*/
public function pdfdocsAction()
public function massPrintAllAction()
{
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function viewAction()
}
}

public function pdfshipmentsAction()
public function massPrintShipmentsAction()
{
$shipmentIds = $this->getRequest()->getPost('shipment_ids');
if (!empty($shipmentIds)) {
Expand Down
80 changes: 80 additions & 0 deletions app/code/Magento/Sales/Model/Grid/Massaction/ItemsUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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)
*/

/**
* Sales orders grid massaction items updater
*
* @category Magento
* @package Magento_Sales
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Sales\Model\Grid\Massaction;

class ItemsUpdater implements \Magento\Core\Model\Layout\Argument\UpdaterInterface
{
/**
* @var \Magento\AuthorizationInterface
*/
protected $_authorization;

/**
* Mass actions list in the form 'mass action name' => 'acl resource name'
*
* @var array
*/
protected $_items = array(
'print_invoices' => 'Magento_Sales::print',
'print_shipments' => 'Magento_Sales::print',
'print_credit_memos' => 'Magento_Sales::print',
'print_shipping_labels' => 'Magento_Sales::print',
'print_all' => 'Magento_Sales::print',
);

/**
* @param \Magento\AuthorizationInterface $authorization
*/
public function __construct(\Magento\AuthorizationInterface $authorization)
{
$this->_authorization = $authorization;
}

/**
* Remove mass action items in case they aren't allowed for current user
*
* @param mixed $argument
* @return mixed
*/
public function update($argument)
{
foreach ($this->_items as $itemName => $aclResourceName) {
if (false === $this->_authorization->isAllowed($aclResourceName)) {
unset($argument[$itemName]);
}
}

return $argument;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/

/**
* Sales orders grid row url generator
* Sales module grids row url generator
*/
namespace Magento\Sales\Model\Order\Grid\Row;
namespace Magento\Sales\Model\Grid\Row;

class UrlGenerator extends \Magento\Backend\Model\Widget\Grid\Row\UrlGenerator
{
Expand All @@ -48,7 +48,6 @@ public function __construct(
) {
$this->_authorization = $authorization;
parent::__construct($backendUrl, $args);

}

/**
Expand Down
36 changes: 11 additions & 25 deletions app/code/Magento/Sales/Model/Order/Grid/Massaction/ItemsUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,26 @@
*/
namespace Magento\Sales\Model\Order\Grid\Massaction;

class ItemsUpdater implements \Magento\Core\Model\Layout\Argument\UpdaterInterface
class ItemsUpdater extends \Magento\Sales\Model\Grid\Massaction\ItemsUpdater
{
/**
* @var \Magento\AuthorizationInterface
* Mass actions list in the form 'mass action name' => 'acl resource name'
*
* @var array
*/
protected $_authorization;
protected $_orderSpecificItems = array(
'cancel_order' => 'Magento_Sales::cancel',
'hold_order' => 'Magento_Sales::hold',
'unhold_order' => 'Magento_Sales::unhold',
);

/**
* @param \Magento\AuthorizationInterface $authorization
*/
public function __construct(\Magento\AuthorizationInterface $authorization)
{
$this->_authorization = $authorization;
}

/**
* Remove massaction items in case they disallowed for user
* @param mixed $argument
* @return mixed
*/
public function update($argument)
{
if (false === $this->_authorization->isAllowed('Magento_Sales::cancel')) {
unset($argument['cancel_order']);
}

if (false === $this->_authorization->isAllowed('Magento_Sales::hold')) {
unset($argument['hold_order']);
}

if (false === $this->_authorization->isAllowed('Magento_Sales::unhold')) {
unset($argument['unhold_order']);
}
parent::__construct($authorization);

return $argument;
$this->_items = array_merge($this->_items, $this->_orderSpecificItems);
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Sales/etc/adminhtml/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<resource id="Magento_Sales::ship" title="Ship" sortOrder="130" />
<resource id="Magento_Sales::comment" title="Comment" sortOrder="140" />
<resource id="Magento_Sales::emails" title="Send Sales Emails" sortOrder="150" />
<resource id="Magento_Sales::print" title="Print Documents" sortOrder="160" />
</resource>
</resource>
<resource id="Magento_Sales::sales_invoice" title="Invoices" sortOrder="20" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,38 @@
<item name="label" xsi:type="string" translate="true">Unhold</item>
<item name="url" xsi:type="string">sales/order/massUnhold</item>
</item>
<item name="pdfinvoices_order" xsi:type="array">
<item name="print_invoices" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Print Invoices</item>
<item name="url" xsi:type="string">sales/order/pdfinvoices</item>
<item name="url" xsi:type="string">sales/order/massPrintInvoices</item>
</item>
<item name="pdfshipments_order" xsi:type="array">
<item name="print_shipments" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Print Packing Slips</item>
<item name="url" xsi:type="string">sales/order/pdfshipments</item>
<item name="url" xsi:type="string">sales/order/massPrintShipments</item>
</item>
<item name="pdfcreditmemos_order" xsi:type="array">
<item name="print_credit_memos" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Print Credit Memos</item>
<item name="url" xsi:type="string">sales/order/pdfcreditmemos</item>
<item name="url" xsi:type="string">sales/order/massPrintCreditMemos</item>
</item>
<item name="pdfdocs_order" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Print All</item>
<item name="url" xsi:type="string">sales/order/pdfdocs</item>
</item>
<item name="print_shipping_label" xsi:type="array">
<item name="print_shipping_labels" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Print Shipping Labels</item>
<item name="url" xsi:type="string">adminhtml/order_shipment/massPrintShippingLabel</item>
</item>
<item name="print_all" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Print All</item>
<item name="url" xsi:type="string">sales/order/massPrintAll</item>
</item>
</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Export" name="sales.order.grid.export" as="grid.export">
<arguments>
<argument name="exportTypes" xsi:type="array">
<item name="csv" xsi:type="array">
<item name="urlPath" xsi:type="string">sales/*/exportCsv</item>
<item name="urlPath" xsi:type="string">*/*/exportCsv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
</item>
<item name="excel" xsi:type="array">
<item name="urlPath" xsi:type="string">sales/*/exportExcel</item>
<item name="urlPath" xsi:type="string">*/*/exportExcel</item>
<item name="label" xsi:type="string" translate="true">Excel XML</item>
</item>
</argument>
Expand All @@ -103,7 +103,7 @@
<arguments>
<argument name="id" xsi:type="string">sales_order_grid</argument>
<argument name="rowUrl" xsi:type="array">
<item name="generatorClass" xsi:type="string">Magento\Sales\Model\Order\Grid\Row\UrlGenerator</item>
<item name="generatorClass" xsi:type="string">Magento\Sales\Model\Grid\Row\UrlGenerator</item>
<item name="path" xsi:type="string">sales/order/view</item>
<item name="extraParamsTemplate" xsi:type="array">
<item name="order_id" xsi:type="string">getId</item>
Expand Down Expand Up @@ -188,7 +188,6 @@
<argument name="id" xsi:type="string">status</argument>
<argument name="header" xsi:type="string" translate="true">Status</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="currency" xsi:type="string">order_currency_code</argument>
<argument name="index" xsi:type="string">status</argument>
<argument name="options" xsi:type="options" model="Magento\Sales\Model\Resource\Order\Grid\StatusesArray"/>
<argument name="header_css_class" xsi:type="string">col-status</argument>
Expand All @@ -203,7 +202,6 @@
<argument name="getter" xsi:type="string">getId</argument>
<argument name="filter" xsi:type="string">0</argument>
<argument name="sortable" xsi:type="string">0</argument>
<argument name="index" xsi:type="string">stores</argument>
<argument name="is_system" xsi:type="string">1</argument>
<argument name="actions" xsi:type="array">
<item name="view_action" xsi:type="array">
Expand Down

0 comments on commit 6be4f06

Please sign in to comment.