Skip to content

Commit 0e29169

Browse files
authored
Merge pull request magento#1561 from magento-honey-badgers/MAGETWO-80201
[Honey Badgers] Bugfixes
2 parents 91765ea + e373d46 commit 0e29169

File tree

25 files changed

+816
-22
lines changed

25 files changed

+816
-22
lines changed

app/code/Magento/Bundle/Model/OptionRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function save(
208208
}
209209
} else {
210210
if (!$existingOption->getOptionId()) {
211-
throw new NoSuchEntityException('Requested option doesn\'t exist');
211+
throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
212212
}
213213

214214
$option->setData(array_merge($existingOption->getData(), $option->getData()));

app/code/Magento/Review/Block/Product/ReviewRenderer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function getReviewsSummaryHtml(
5757
$templateType = self::DEFAULT_VIEW,
5858
$displayIfNoReviews = false
5959
) {
60+
if (!$product->getRatingSummary()) {
61+
$this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
62+
}
63+
6064
if (!$product->getRatingSummary() && !$displayIfNoReviews) {
6165
return '';
6266
}
@@ -68,9 +72,6 @@ public function getReviewsSummaryHtml(
6872

6973
$this->setDisplayIfEmpty($displayIfNoReviews);
7074

71-
if (!$product->getRatingSummary()) {
72-
$this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
73-
}
7475
$this->setProduct($product);
7576

7677
return $this->toHtml();

app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,56 @@
77

88
use Magento\Ui\Controller\Adminhtml\AbstractAction;
99
use Magento\Framework\View\Element\UiComponentInterface;
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\View\Element\UiComponentFactory;
12+
use Psr\Log\LoggerInterface;
13+
use Magento\Framework\Escaper;
14+
use Magento\Framework\Controller\Result\JsonFactory;
1015

1116
class Render extends AbstractAction
1217
{
18+
/**
19+
* @var JsonFactory
20+
*/
21+
private $resultJsonFactory;
22+
23+
/**
24+
* @var Escaper
25+
*/
26+
private $escaper;
27+
28+
/**
29+
* @var LoggerInterface
30+
*/
31+
private $logger;
32+
33+
/**
34+
* @param Context $context
35+
* @param UiComponentFactory $factory
36+
* @param JsonFactory|null $resultJsonFactory
37+
* @param Escaper|null $escaper
38+
* @param LoggerInterface|null $logger
39+
*/
40+
public function __construct(
41+
Context $context,
42+
UiComponentFactory $factory,
43+
JsonFactory $resultJsonFactory = null,
44+
Escaper $escaper = null,
45+
LoggerInterface $logger = null
46+
) {
47+
parent::__construct($context, $factory);
48+
$this->resultJsonFactory = $resultJsonFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
49+
->get(\Magento\Framework\Controller\Result\JsonFactory::class);
50+
$this->escaper = $escaper ?: \Magento\Framework\App\ObjectManager::getInstance()
51+
->get(\Magento\Framework\Escaper::class);
52+
$this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance()
53+
->get(\Psr\Log\LoggerInterface::class);
54+
}
55+
1356
/**
1457
* Action for AJAX request
1558
*
16-
* @return void
59+
* @return void|\Magento\Framework\Controller\ResultInterface
1760
*/
1861
public function execute()
1962
{
@@ -22,10 +65,40 @@ public function execute()
2265
return;
2366
}
2467

25-
$component = $this->factory->create($this->_request->getParam('namespace'));
26-
if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) {
27-
$this->prepareComponent($component);
28-
$this->_response->appendBody((string) $component->render());
68+
try {
69+
$component = $this->factory->create($this->_request->getParam('namespace'));
70+
if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) {
71+
$this->prepareComponent($component);
72+
$this->_response->appendBody((string) $component->render());
73+
}
74+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
75+
$this->logger->critical($e);
76+
$result = [
77+
'error' => $this->escaper->escapeHtml($e->getMessage()),
78+
'errorcode' => $this->escaper->escapeHtml($e->getCode())
79+
];
80+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
81+
$resultJson = $this->resultJsonFactory->create();
82+
$resultJson->setStatusHeader(
83+
\Zend\Http\Response::STATUS_CODE_400,
84+
\Zend\Http\AbstractMessage::VERSION_11,
85+
'Bad Request'
86+
);
87+
return $resultJson->setData($result);
88+
} catch (\Exception $e) {
89+
$this->logger->critical($e);
90+
$result = [
91+
'error' => _('UI component could not be rendered because of system exception'),
92+
'errorcode' => $this->escaper->escapeHtml($e->getCode())
93+
];
94+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
95+
$resultJson = $this->resultJsonFactory->create();
96+
$resultJson->setStatusHeader(
97+
\Zend\Http\Response::STATUS_CODE_400,
98+
\Zend\Http\AbstractMessage::VERSION_11,
99+
'Bad Request'
100+
);
101+
return $resultJson->setData($result);
29102
}
30103
}
31104

app/code/Magento/Ui/Test/Unit/Controller/Adminhtml/Index/RenderTest.php

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\Ui\Test\Unit\Controller\Adminhtml\Index;
77

8-
use \Magento\Ui\Controller\Adminhtml\Index\Render;
8+
use Magento\Ui\Controller\Adminhtml\Index\Render;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
910

1011
/**
1112
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -17,6 +18,11 @@ class RenderTest extends \PHPUnit\Framework\TestCase
1718
*/
1819
private $render;
1920

21+
/**
22+
* @var ObjectManagerHelper
23+
*/
24+
private $objectManagerHelper;
25+
2026
/**
2127
* @var \PHPUnit_Framework_MockObject_MockObject
2228
*/
@@ -73,6 +79,16 @@ class RenderTest extends \PHPUnit\Framework\TestCase
7379
*/
7480
private $uiComponentMock;
7581

82+
/**
83+
* @var \Magento\Framework\Controller\Result\JsonFactory|\PHPUnit_Framework_MockObject_MockObject
84+
*/
85+
private $resultJsonFactoryMock;
86+
87+
/**
88+
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
89+
*/
90+
private $loggerMock;
91+
7692
protected function setUp()
7793
{
7894
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
@@ -114,6 +130,14 @@ protected function setUp()
114130
['render']
115131
);
116132

133+
$this->resultJsonFactoryMock = $this->getMockBuilder(
134+
\Magento\Framework\Controller\Result\JsonFactory::class
135+
)
136+
->disableOriginalConstructor()
137+
->getMock();
138+
139+
$this->loggerMock = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class);
140+
117141
$this->contextMock->expects($this->any())
118142
->method('getRequest')
119143
->willReturn($this->requestMock);
@@ -136,7 +160,70 @@ protected function setUp()
136160
->method('getDataProvider')
137161
->willReturn($this->dataProviderMock);
138162

139-
$this->render = new Render($this->contextMock, $this->uiFactoryMock);
163+
$this->objectManagerHelper = new ObjectManagerHelper($this);
164+
165+
$this->render = $this->objectManagerHelper->getObject(
166+
\Magento\Ui\Controller\Adminhtml\Index\Render::class,
167+
[
168+
'context' => $this->contextMock,
169+
'factory' => $this->uiFactoryMock,
170+
'resultJsonFactory' => $this->resultJsonFactoryMock,
171+
'logger' => $this->loggerMock
172+
]
173+
);
174+
}
175+
176+
public function testExecuteAjaxRequestException()
177+
{
178+
$name = 'test-name';
179+
$renderedData = '<html>data</html>';
180+
181+
$this->requestMock->expects($this->any())
182+
->method('getParam')
183+
->with('namespace')
184+
->willReturn($name);
185+
$this->requestMock->expects($this->any())
186+
->method('getParams')
187+
->willReturn([]);
188+
$this->responseMock->expects($this->once())
189+
->method('appendBody')
190+
->willThrowException(new \Exception('exception'));
191+
192+
$jsonResultMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Json::class)
193+
->disableOriginalConstructor()
194+
->setMethods(['setData'])
195+
->getMock();
196+
197+
$this->resultJsonFactoryMock->expects($this->once())
198+
->method('create')
199+
->willReturn($jsonResultMock);
200+
201+
$jsonResultMock->expects($this->once())
202+
->method('setData')
203+
->willReturnSelf();
204+
205+
$this->loggerMock->expects($this->once())
206+
->method('critical')
207+
->willReturnSelf();
208+
209+
$this->dataProviderMock->expects($this->once())
210+
->method('getConfigData')
211+
->willReturn([]);
212+
213+
$this->uiComponentMock->expects($this->once())
214+
->method('render')
215+
->willReturn($renderedData);
216+
$this->uiComponentMock->expects($this->once())
217+
->method('getChildComponents')
218+
->willReturn([]);
219+
$this->uiComponentMock->expects($this->once())
220+
->method('getContext')
221+
->willReturn($this->uiComponentContextMock);
222+
$this->uiFactoryMock->expects($this->once())
223+
->method('create')
224+
->willReturn($this->uiComponentMock);
225+
226+
$this->render->executeAjaxRequest();
140227
}
141228

142229
public function testExecuteAjaxRequest()

app/code/Magento/Ui/view/base/web/js/grid/filters/filters.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ define([
1010
'underscore',
1111
'mageUtils',
1212
'uiLayout',
13-
'uiCollection'
14-
], function (_, utils, layout, Collection) {
13+
'uiCollection',
14+
'mage/translate',
15+
'jquery'
16+
], function (_, utils, layout, Collection, $t, $) {
1517
'use strict';
1618

1719
/**
@@ -48,6 +50,7 @@ define([
4850
stickyTmpl: 'ui/grid/sticky/filters',
4951
_processed: [],
5052
columnsProvider: 'ns = ${ $.ns }, componentType = columns',
53+
bookmarksProvider: 'ns = ${ $.ns }, componentType = bookmark',
5154
applied: {
5255
placeholder: true
5356
},
@@ -102,7 +105,9 @@ define([
102105
applied: '${ $.provider }:params.filters'
103106
},
104107
imports: {
105-
'onColumnsUpdate': '${ $.columnsProvider }:elems'
108+
onColumnsUpdate: '${ $.columnsProvider }:elems',
109+
onBackendError: '${ $.provider }:lastError',
110+
bookmarksActiveIndex: '${ $.bookmarksProvider }:activeIndex'
106111
},
107112
modules: {
108113
columns: '${ $.columnsProvider }',
@@ -371,6 +376,37 @@ define([
371376
*/
372377
onColumnsUpdate: function (columns) {
373378
columns.forEach(this.addFilter, this);
379+
},
380+
381+
/**
382+
* Provider ajax error listener.
383+
*
384+
* @param {bool} isError - Selected index of the filter.
385+
*/
386+
onBackendError: function (isError) {
387+
var defaultMessage = 'Something went wrong with processing the default view and we have restored the ' +
388+
'filter to its original state.',
389+
customMessage = 'Something went wrong with processing current custom view and filters have been ' +
390+
'reset to its original state. Please edit filters then click apply.';
391+
392+
if (isError) {
393+
this.clear();
394+
395+
$('body').notification('clear')
396+
.notification('add', {
397+
error: true,
398+
message: $.mage.__(this.bookmarksActiveIndex !== 'default' ? customMessage : defaultMessage),
399+
400+
/**
401+
* @param {String} message
402+
*/
403+
insertMethod: function (message) {
404+
var $wrapper = $('<div/>').html(message);
405+
406+
$('.page-main-actions').after($wrapper);
407+
}
408+
});
409+
}
374410
}
375411
});
376412
});

app/code/Magento/Ui/view/base/web/js/grid/provider.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ define([
2121
return Element.extend({
2222
defaults: {
2323
firstLoad: true,
24+
lastError: false,
2425
storageConfig: {
2526
component: 'Magento_Ui/js/grid/data-storage',
2627
provider: '${ $.storageConfig.name }',
@@ -120,7 +121,7 @@ define([
120121

121122
request
122123
.done(this.onReload)
123-
.fail(this.onError);
124+
.fail(this.onError.bind(this));
124125

125126
return request;
126127
},
@@ -144,6 +145,10 @@ define([
144145
return;
145146
}
146147

148+
this.set('lastError', true);
149+
150+
this.firstLoad = false;
151+
147152
alert({
148153
content: $t('Something went wrong.')
149154
});
@@ -157,6 +162,8 @@ define([
157162
onReload: function (data) {
158163
this.firstLoad = false;
159164

165+
this.set('lastError', false);
166+
160167
this.setData(data)
161168
.trigger('reloaded');
162169
},

dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Store/StoreGrid.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ public function searchAndOpenWebsite(Website $website)
9999
$this->_rootElement->find(sprintf($this->storeName, $websiteName), Locator::SELECTOR_XPATH)->click();
100100
}
101101

102+
/**
103+
* Search and open appropriate Website by name.
104+
*
105+
* @param string $websiteName
106+
* @return void
107+
*/
108+
public function searchAndOpenWebsiteByName($websiteName)
109+
{
110+
$this->search(['website_title' => $websiteName]);
111+
$this->_rootElement->find(sprintf($this->storeName, $websiteName), Locator::SELECTOR_XPATH)->click();
112+
}
113+
102114
/**
103115
* Search and open appropriate Store View.
104116
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class Grid extends DataGrid
6060
'selector' => '[name="attribute_set_id"]',
6161
'input' => 'select',
6262
],
63+
'store_id' => [
64+
'selector' => '[name="store_id"]',
65+
'input' => 'select',
66+
],
6367
];
6468

6569
/**

0 commit comments

Comments
 (0)