Skip to content

Commit c98e421

Browse files
authored
Merge pull request #4001 from magento-borg/borg-qwerty-2.1
[borg] Bug fixes
2 parents fe1ffdf + aa03171 commit c98e421

File tree

10 files changed

+268
-54
lines changed

10 files changed

+268
-54
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/attribute.phtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<?php
1616
$_helper = $this->helper('Magento\Catalog\Helper\Output');
1717
$_product = $block->getProduct();
18+
19+
if (!$_product instanceof \Magento\Catalog\Model\Product) {
20+
return;
21+
}
22+
1823
$_call = $block->getAtCall();
1924
$_code = $block->getAtCode();
2025
$_className = $block->getCssClass();

app/code/Magento/Checkout/Model/Session.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ public function getQuote()
218218
$quote = $this->quoteRepository->getActive($this->getQuoteId());
219219
}
220220

221+
$customerId = $this->_customer
222+
? $this->_customer->getId()
223+
: $this->_customerSession->getCustomerId();
224+
if ($quote->getData('customer_id') && (int)$quote->getData('customer_id') !== (int)$customerId) {
225+
$quote = $this->quoteFactory->create();
226+
throw new \Magento\Framework\Exception\NoSuchEntityException();
227+
}
228+
221229
/**
222230
* If current currency code of quote is not equal current currency code of store,
223231
* need recalculate totals of quote. It is possible if customer use currency switcher or

app/code/Magento/CurrencySymbol/view/adminhtml/templates/grid.phtml

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,64 @@
55
*/
66

77
// @codingStandardsIgnoreFile
8-
98
?>
109
<?php
1110
/**
12-
* @var \Magento\CurrencySymbol\Block\Adminhtml\System\Currencysymbol $block
11+
* @var $block \Magento\CurrencySymbol\Block\Adminhtml\System\Currencysymbol
1312
*/
14-
?>
1513

16-
<form id="currency-symbols-form" action="<?= /* @escapeNotVerified */ $block->getFormActionUrl() ?>" method="post">
17-
<input name="form_key" type="hidden" value="<?= /* @escapeNotVerified */ $block->getFormKey() ?>" />
14+
$escapeHelper = $this->helper(\Magento\Framework\EscapeHelper::class);
15+
?>
16+
<form id="currency-symbols-form" action="<?php echo $escapeHelper->escapeHtmlAttr($block->getFormActionUrl()) ?>" method="post">
17+
<input name="form_key" type="hidden" value="<?php echo $escapeHelper->escapeHtmlAttr($block->getFormKey()) ?>" />
1818
<fieldset class="admin__fieldset">
1919
<?php foreach ($block->getCurrencySymbolsData() as $code => $data): ?>
2020
<div class="admin__field _required">
21-
<label class="admin__field-label" for="custom_currency_symbol<?php /* @escapeNotVerified */ echo $code; ?>">
22-
<span><?php /* @escapeNotVerified */ echo $code; ?> (<?php /* @escapeNotVerified */ echo $data['displayName']; ?>)</span>
21+
<label class="admin__field-label" for="custom_currency_symbol<?php echo $escapeHelper->escapeHtmlAttr($code); ?>">
22+
<span><?php echo $block->escapeHtml($code); ?> (<?php echo $block->escapeHtml($data['displayName']); ?>)</span>
2323
</label>
2424
<div class="admin__field-control">
25-
<input id="custom_currency_symbol<?php /* @escapeNotVerified */ echo $code; ?>"
25+
<input id="custom_currency_symbol<?php echo $escapeHelper->escapeHtmlAttr($code); ?>"
2626
class="required-entry admin__control-text"
2727
type="text"
28-
value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($data['displaySymbol']); ?>"
28+
value="<?php echo $escapeHelper->escapeHtmlAttr($data['displaySymbol']); ?>"
2929
<?php echo $data['inherited'] ? ' disabled="disabled"' : '';?>
30-
name="custom_currency_symbol[<?php /* @escapeNotVerified */ echo $code; ?>]">
30+
name="custom_currency_symbol[<?php echo $escapeHelper->escapeHtmlAttr($code); ?>]">
3131
<div class="admin__field admin__field-option">
32-
<input id="custom_currency_symbol_inherit<?php /* @escapeNotVerified */ echo $code; ?>"
32+
<input id="custom_currency_symbol_inherit<?php echo $escapeHelper->escapeHtmlAttr($code); ?>"
3333
class="admin__control-checkbox" type="checkbox"
34-
onclick="toggleUseDefault(<?php /* @escapeNotVerified */ echo '\'' . $code . '\',\'' . $block->escapeQuote($data['parentSymbol'], true) . '\''; ?>)"
34+
onclick="toggleUseDefault(<?php /* @noEscape */ echo '\'' . $escapeHelper->escapeHtmlAttr($block->escapeQuote($code, true)) . '\',\'' . $block->escapeQuote($data['parentSymbol'], true) . '\''; ?>)"
3535
<?php echo $data['inherited'] ? ' checked="checked"' : ''; ?>
3636
value="1"
37-
name="inherit_custom_currency_symbol[<?php /* @escapeNotVerified */ echo $code; ?>]">
38-
<label class="admin__field-label" for="custom_currency_symbol_inherit<?php /* @escapeNotVerified */ echo $code; ?>"><span><?php /* @escapeNotVerified */ echo $block->getInheritText(); ?></span></label>
37+
name="inherit_custom_currency_symbol[<?php echo $escapeHelper->escapeHtmlAttr($code); ?>]">
38+
<label class="admin__field-label" for="custom_currency_symbol_inherit<?php echo $escapeHelper->escapeHtmlAttr($code); ?>"><span><?php echo $block->escapeHtml($block->getInheritText()); ?></span></label>
3939
</div>
4040
</div>
4141
</div>
4242
<?php endforeach; ?>
4343
</fieldset>
4444
</form>
4545
<script>
46-
require(['jquery', "mage/mage", 'prototype'], function(jQuery){
46+
require(['jquery', 'mage/mage'], function (jQuery){
47+
jQuery('#currency-symbols-form')
48+
.mage('form')
49+
.mage('validation');
4750

48-
jQuery('#currency-symbols-form').mage('form').mage('validation');
51+
/**
52+
* Toggle the field to use the default value
53+
*
54+
* @param {String} code
55+
* @param {String} value
56+
*/
57+
function toggleUseDefault(code, value) {
58+
var checkbox = jQuery('#custom_currency_symbol_inherit' + code),
59+
input = jQuery('#custom_currency_symbol' + code);
4960

50-
function toggleUseDefault(code, value)
51-
{
52-
checkbox = $('custom_currency_symbol_inherit'+code);
53-
input = $('custom_currency_symbol'+code);
54-
if (checkbox.checked) {
55-
input.value = value;
56-
input.disabled = true;
61+
if (checkbox.is(':checked')) {
62+
input.val(value);
63+
input.prop('disabled', true);
5764
} else {
58-
input.disabled = false;
65+
input.prop('disabled', false);
5966
}
6067
}
6168

app/code/Magento/User/Block/Role/Grid/User.php

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ protected function _construct()
8181
}
8282

8383
/**
84+
* Adds column filter to collection
85+
*
8486
* @param Column $column
8587
* @return $this
8688
*/
@@ -105,6 +107,8 @@ protected function _addColumnFilterToCollection($column)
105107
}
106108

107109
/**
110+
* Prepares collection
111+
*
108112
* @return $this
109113
*/
110114
protected function _prepareCollection()
@@ -117,6 +121,8 @@ protected function _prepareCollection()
117121
}
118122

119123
/**
124+
* Prepares columns
125+
*
120126
* @return $this
121127
*/
122128
protected function _prepareColumns()
@@ -173,52 +179,51 @@ protected function _prepareColumns()
173179
}
174180

175181
/**
182+
* Gets grid url
183+
*
176184
* @return string
185+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
177186
*/
178187
public function getGridUrl()
179188
{
180-
$roleId = $this->getRequest()->getParam('rid');
189+
$roleId = $this->escapeHtml($this->getRequest()->getParam('rid'));
181190
return $this->getUrl('*/*/editrolegrid', ['rid' => $roleId]);
182191
}
183192

184193
/**
194+
* Gets users
195+
*
185196
* @param bool $json
186197
* @return string|array
187198
*/
188199
public function getUsers($json = false)
189200
{
190-
if ($this->getRequest()->getParam('in_role_user') != "") {
191-
return $this->getRequest()->getParam('in_role_user');
201+
$inRoleUser = $this->getRequest()->getParam('in_role_user');
202+
if ($inRoleUser) {
203+
if ($json) {
204+
return $this->getJSONString($inRoleUser);
205+
}
206+
return $this->_escaper->escapeJs($this->escapeHtml($inRoleUser));
192207
}
193-
$roleId = $this->getRequest()->getParam(
194-
'rid'
195-
) > 0 ? $this->getRequest()->getParam(
196-
'rid'
197-
) : $this->_coreRegistry->registry(
198-
'RID'
199-
);
200-
208+
$roleId = $this->getRoleId();
201209
$users = $this->getUsersFormData();
202210
if (false === $users) {
203211
$users = $this->_roleFactory->create()->setId($roleId)->getRoleUsers();
204212
}
205-
if (sizeof($users) > 0) {
213+
if (!empty($users)) {
206214
if ($json) {
207215
$jsonUsers = [];
208-
foreach ($users as $usrid) {
209-
$jsonUsers[$usrid] = 0;
216+
foreach ($users as $userid) {
217+
$jsonUsers[$userid] = 0;
210218
}
211219
return $this->_jsonEncoder->encode((object)$jsonUsers);
212-
} else {
213-
return array_values($users);
214-
}
215-
} else {
216-
if ($json) {
217-
return '{}';
218-
} else {
219-
return [];
220220
}
221+
return array_values($users);
222+
}
223+
if ($json) {
224+
return '{}';
221225
}
226+
return [];
222227
}
223228

224229
/**
@@ -239,6 +244,7 @@ protected function getUsersFormData()
239244
* Restore Users Form Data from the registry
240245
*
241246
* @return array|bool
247+
* @SuppressWarnings(PHPMD.DiscouragedFunctionsSniff)
242248
*/
243249
protected function restoreUsersFormData()
244250
{
@@ -252,4 +258,30 @@ protected function restoreUsersFormData()
252258

253259
return false;
254260
}
261+
262+
/**
263+
* Gets role ID
264+
*
265+
* @return string
266+
*/
267+
private function getRoleId()
268+
{
269+
$roleId = $this->getRequest()->getParam('rid');
270+
if ($roleId <= 0) {
271+
$roleId = $this->_coreRegistry->registry('RID');
272+
}
273+
return $roleId;
274+
}
275+
276+
/**
277+
* Gets JSON string
278+
*
279+
* @param string $input
280+
* @return string
281+
*/
282+
private function getJSONString($input)
283+
{
284+
$output = json_decode($input);
285+
return $output ? $this->_jsonEncoder->encode($output) : '{}';
286+
}
255287
}

app/code/Magento/User/Block/User/Edit/Tab/Roles.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Backend\Block\Widget\Grid\Column;
99

10+
/**
11+
* Roles grid
12+
*/
1013
class Roles extends \Magento\Backend\Block\Widget\Grid\Extended
1114
{
1215
/**
@@ -64,6 +67,8 @@ protected function _construct()
6467
}
6568

6669
/**
70+
* Adds column filter to collection
71+
*
6772
* @param Column $column
6873
* @return $this
6974
*/
@@ -88,6 +93,8 @@ protected function _addColumnFilterToCollection($column)
8893
}
8994

9095
/**
96+
* Prepares collection
97+
*
9198
* @return $this
9299
*/
93100
protected function _prepareCollection()
@@ -99,6 +106,8 @@ protected function _prepareCollection()
99106
}
100107

101108
/**
109+
* Prepares columns
110+
*
102111
* @return $this
103112
*/
104113
protected function _prepareColumns()
@@ -122,6 +131,8 @@ protected function _prepareColumns()
122131
}
123132

124133
/**
134+
* Gets grid url
135+
*
125136
* @return string
126137
*/
127138
public function getGridUrl()
@@ -131,13 +142,20 @@ public function getGridUrl()
131142
}
132143

133144
/**
145+
* Get selected roles
146+
*
134147
* @param bool $json
135148
* @return array|string
136149
*/
137150
public function getSelectedRoles($json = false)
138151
{
139-
if ($this->getRequest()->getParam('user_roles') != "") {
140-
return $this->getRequest()->getParam('user_roles');
152+
$userRoles = $this->getRequest()->getParam('user_roles');
153+
if ($userRoles) {
154+
if ($json) {
155+
$result = json_decode($userRoles);
156+
return $result ? $this->_jsonEncoder->encode($result) : '{}';
157+
}
158+
return $this->_escaper->escapeJs($this->escapeHtml($userRoles));
141159
}
142160
/* @var $user \Magento\User\Model\User */
143161
$user = $this->_coreRegistry->registry('permissions_user');

app/code/Magento/User/Test/Unit/Block/Role/Grid/UserTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public function testGetUsersPositiveNumberOfRolesAndJsonFalse()
130130

131131
$this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
132132
$this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
133-
$this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
134133

135134
$this->registryMock->expects($this->once())
136135
->method('registry')
@@ -157,7 +156,6 @@ public function testGetUsersPositiveNumberOfRolesAndJsonTrue()
157156

158157
$this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
159158
$this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
160-
$this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
161159

162160
$this->registryMock->expects($this->once())
163161
->method('registry')
@@ -182,7 +180,6 @@ public function testGetUsersNoRolesAndJsonFalse()
182180

183181
$this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
184182
$this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
185-
$this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
186183

187184
$this->registryMock->expects($this->once())
188185
->method('registry')
@@ -238,4 +235,21 @@ public function testPrepareColumns()
238235

239236
$this->model->toHtml();
240237
}
238+
239+
public function testGetUsersCorrectInRoleUser()
240+
{
241+
$param = 'in_role_user';
242+
$paramValue = '{"a":"role1","1":"role2","2":"role3"}';
243+
$this->requestInterfaceMock->expects($this->once())->method('getParam')->with($param)->willReturn($paramValue);
244+
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($paramValue);
245+
$this->assertEquals($paramValue, $this->model->getUsers(true));
246+
}
247+
248+
public function testGetUsersIncorrectInRoleUser()
249+
{
250+
$param = 'in_role_user';
251+
$paramValue = 'not_JSON';
252+
$this->requestInterfaceMock->expects($this->once())->method('getParam')->with($param)->willReturn($paramValue);
253+
$this->assertEquals('{}', $this->model->getUsers(true));
254+
}
241255
}

0 commit comments

Comments
 (0)