Skip to content

Commit 392644b

Browse files
author
Onischenko, Yaroslav(yonischenko)
committed
Merge pull request #585 from magento-nord/develop
[NORD] Bug fixes
2 parents 0611634 + a0fc088 commit 392644b

File tree

31 files changed

+773
-214
lines changed

31 files changed

+773
-214
lines changed

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/AddAttribute.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\ConfigurableProduct\Controller\Adminhtml\Product;
88

99
use Magento\Backend\App\Action;
10+
use Magento\Framework\Controller\ResultFactory;
1011

1112
class AddAttribute extends Action
1213
{
@@ -28,18 +29,11 @@ public function __construct(
2829
}
2930

3031
/**
31-
* Add "super" attribute from popup window
32-
*
33-
* @return void
32+
* @inheritdoc
3433
*/
3534
public function execute()
3635
{
37-
$this->_view->loadLayout('popup');
3836
$this->productBuilder->build($this->getRequest());
39-
$attributeBlock = $this->_view->getLayout()->createBlock(
40-
'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created'
41-
);
42-
$this->_addContent($attributeBlock);
43-
$this->_view->renderLayout();
37+
return $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
4438
}
4539
}

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/AddAttributeTest.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
namespace Magento\ConfigurableProduct\Test\Unit\Controller\Adminhtml\Product;
88

9+
use Magento\Framework\Controller\ResultFactory;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1011

1112
class AddAttributeTest extends \PHPUnit_Framework_TestCase
1213
{
14+
/** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
15+
private $resultFactory;
16+
1317
/** @var \Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute */
1418
protected $controller;
1519

@@ -45,35 +49,39 @@ protected function setUp()
4549
{
4650
$this->objectManagerHelper = new ObjectManagerHelper($this);
4751

48-
$this->context = $this->getMockBuilder('\Magento\Backend\App\Action\Context')
52+
$this->context = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class)
4953
->disableOriginalConstructor()
5054
->getMock();
51-
$this->request = $this->getMock('Magento\Framework\App\RequestInterface');
55+
$this->request = $this->getMock(\Magento\Framework\App\RequestInterface::class);
56+
$this->resultFactory = $this->getMock(\Magento\Framework\Controller\ResultFactory::class, [], [], '', false);
5257
$this->response = $this->getMock(
53-
'\Magento\Framework\App\ResponseInterface',
58+
\Magento\Framework\App\ResponseInterface::class,
5459
[
5560
'sendResponse',
5661
'setBody'
5762
]
5863
);
59-
$this->productBuilder = $this->getMockBuilder('\Magento\Catalog\Controller\Adminhtml\Product\Builder')
64+
$this->productBuilder = $this->getMockBuilder(\Magento\Catalog\Controller\Adminhtml\Product\Builder::class)
6065
->disableOriginalConstructor()
6166
->setMethods(['build'])
6267
->getMock();
63-
$this->view = $this->getMock('\Magento\Framework\App\ViewInterface');
68+
$this->view = $this->getMock(\Magento\Framework\App\ViewInterface::class);
6469

6570
$this->context->expects($this->any())
6671
->method('getRequest')
6772
->will($this->returnValue($this->request));
6873
$this->context->expects($this->any())
6974
->method('getResponse')
7075
->will($this->returnValue($this->response));
76+
$this->context->expects($this->any())
77+
->method('getResultFactory')
78+
->will($this->returnValue($this->resultFactory));
7179
$this->context->expects($this->any())
7280
->method('getView')
7381
->will($this->returnValue($this->view));
7482

7583
$this->controller = $this->objectManagerHelper->getObject(
76-
'\Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute',
84+
\Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute::class,
7785
[
7886
'context' => $this->context,
7987
'productBuilder' => $this->productBuilder
@@ -83,25 +91,16 @@ protected function setUp()
8391

8492
public function testExecute()
8593
{
86-
$product = $this->getMockBuilder('\Magento\Catalog\Model\Product')
94+
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
8795
->disableOriginalConstructor()
8896
->setMethods(['_wakeup', 'getId'])
8997
->getMock();
90-
$layout = $this->getMock('\Magento\Framework\View\LayoutInterface');
91-
$block = $this->getMockBuilder(
92-
'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created'
93-
)
94-
->disableOriginalConstructor()
95-
->setMethods(['setIndex', 'toHtml'])
96-
->getMock();
9798

98-
$this->view->expects($this->once())->method('loadLayout')->with('popup')->willReturnSelf();
9999
$this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
100-
$this->view->expects($this->any())->method('getLayout')->willReturn($layout);
101-
$layout->expects($this->once())->method('createBlock')->willReturn($block);
102-
$layout->expects($this->once())->method('setChild')->willReturnSelf();
103-
$this->view->expects($this->any())->method('renderLayout')->willReturnSelf();
100+
$resultLayout = $this->getMock(\Magento\Framework\View\Result\Layout::class, [], [], '', false);
101+
$this->resultFactory->expects($this->once())->method('create')->with(ResultFactory::TYPE_LAYOUT)
102+
->willReturn($resultLayout);
104103

105-
$this->controller->execute();
104+
$this->assertInstanceOf(\Magento\Framework\View\Result\Layout::class, $this->controller->execute());
106105
}
107106
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
9+
<container name="root">
10+
<block class="Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created" template="Magento_ConfigurableProduct::catalog/product/attribute/new/created.phtml" as="product.attribute.created" />
11+
</container>
12+
</layout>

app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/attribute/new/created.phtml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,4 @@
1818
$('#create_new_attribute').modal('closeModal');
1919

2020
})(window.parent.jQuery);
21-
</script>
22-
<div class="a-center">
23-
<?php echo $block->getCloseButtonHtml() ?>
24-
</div>
21+
</script>

app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getAllOptions($withEmpty = true, $defaultValues = false)
6666
}
6767
$options = $defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId];
6868
if ($withEmpty) {
69-
array_unshift($options, ['label' => '', 'value' => '']);
69+
$options = $this->addEmptyOption($options);
7070
}
7171

7272
return $options;
@@ -89,11 +89,21 @@ public function getSpecificOptions($ids, $withEmpty = true)
8989
->load()
9090
->toOptionArray();
9191
if ($withEmpty) {
92-
array_unshift($options, ['label' => '', 'value' => '']);
92+
$options = $this->addEmptyOption($options);
9393
}
9494
return $options;
9595
}
9696

97+
/**
98+
* @param array $options
99+
* @return array
100+
*/
101+
private function addEmptyOption(array $options)
102+
{
103+
array_unshift($options, ['label' => $this->getAttribute()->getIsRequired() ? '' : ' ', 'value' => '']);
104+
return $options;
105+
}
106+
97107
/**
98108
* Get a text for option value
99109
*

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Source/TableTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testGetSpecificOptions($optionIds, $withEmpty)
120120

121121
$attribute = $this->getMock(
122122
'Magento\Eav\Model\Entity\Attribute\AbstractAttribute',
123-
['getId', 'getStoreId', '__wakeup'],
123+
['getId', 'getStoreId', 'getIsRequired', '__wakeup'],
124124
[],
125125
'',
126126
false
@@ -131,6 +131,9 @@ public function testGetSpecificOptions($optionIds, $withEmpty)
131131
$attribute->expects($this->once())
132132
->method('getStoreId')
133133
->willReturn($storeId);
134+
$attribute->expects($this->any())
135+
->method('getIsRequired')
136+
->willReturn(false);
134137

135138
$this->model->setAttribute($attribute);
136139

@@ -160,7 +163,7 @@ public function testGetSpecificOptions($optionIds, $withEmpty)
160163
->willReturn($options);
161164

162165
if ($withEmpty) {
163-
array_unshift($options, ['label' => '', 'value' => '']);
166+
array_unshift($options, ['label' => ' ', 'value' => '']);
164167
}
165168

166169
$this->assertEquals($options, $this->model->getSpecificOptions($optionIds, $withEmpty));

app/code/Magento/ProductVideo/view/adminhtml/web/js/get-video-information.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ define([
446446
$.unique(errorsMessage).join(', ');
447447
};
448448

449-
if (data.error && data.error.code === 400) {
449+
if (data.error && [400, 402, 403].indexOf(data.error.code) !== -1) {
450450
this._onRequestError(createErrorMessage());
451451

452452
return;

app/code/Magento/ProductVideo/view/adminhtml/web/js/new-video-dialog.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ define([
373373
var url = this.options.saveRemoteVideoUrl,
374374
self = this;
375375

376+
this._getPreviewImage().attr('src', sourceUrl).hide();
376377
this._blockActionButtons(true, true);
377378
$.ajax({
378379
url: url,
@@ -628,7 +629,7 @@ define([
628629
* @private
629630
*/
630631
_create: function () {
631-
var imgs = this.element.closest(this.options.videoSelector).data('images') || [],
632+
var imgs = _.values(this.element.closest(this.options.videoSelector).data('images')) || [],
632633
widget,
633634
uploader,
634635
tmp,
@@ -697,7 +698,7 @@ define([
697698
roles.prop('disabled', false);
698699
file = widget.element.find('#file_name').val();
699700
widget._onGetVideoInformationEditClick();
700-
modalTitleElement = widget.element.closest('.mage-new-video-dialog .modal-title');
701+
modalTitleElement = modal.find('.modal-title');
701702

702703
if (!file) {
703704
widget._blockActionButtons(true);

app/code/Magento/Review/Model/ResourceModel/Rating.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ protected function processRatingCodes(\Magento\Framework\Model\AbstractModel $ob
187187
->where('rating_id = :rating_id');
188188
$old = $connection->fetchPairs($select, [':rating_id' => $ratingId]);
189189
$new = array_filter(array_map('trim', $object->getRatingCodes()));
190-
$this->deleteRatingData($ratingId, $table, array_diff_assoc($old, $new));
190+
$this->deleteRatingData($ratingId, $table, array_keys(array_diff_assoc($old, $new)));
191191

192192
$insert = [];
193193
foreach (array_diff_assoc($new, $old) as $storeId => $title) {
@@ -210,10 +210,10 @@ protected function processRatingStores(\Magento\Framework\Model\AbstractModel $o
210210
->where('rating_id = :rating_id');
211211
$old = $connection->fetchCol($select, [':rating_id' => $ratingId]);
212212
$new = $object->getStores();
213-
$this->deleteRatingData($ratingId, $table, array_diff_assoc($old, $new));
213+
$this->deleteRatingData($ratingId, $table, array_diff($old, $new));
214214

215215
$insert = [];
216-
foreach (array_keys(array_diff_assoc($new, $old)) as $storeId) {
216+
foreach (array_diff($new, $old) as $storeId) {
217217
$insert[] = ['rating_id' => $ratingId, 'store_id' => (int)$storeId];
218218
}
219219
$this->insertRatingData($table, $insert);
@@ -223,18 +223,18 @@ protected function processRatingStores(\Magento\Framework\Model\AbstractModel $o
223223
/**
224224
* @param int $ratingId
225225
* @param string $table
226-
* @param array $data
226+
* @param array $storeIds
227227
* @return void
228228
*/
229-
protected function deleteRatingData($ratingId, $table, array $data)
229+
protected function deleteRatingData($ratingId, $table, array $storeIds)
230230
{
231-
if (empty($data)) {
231+
if (empty($storeIds)) {
232232
return;
233233
}
234234
$connection = $this->getConnection();
235235
$connection->beginTransaction();
236236
try {
237-
$where = ['rating_id = ?' => $ratingId, 'store_id IN(?)' => array_keys($data)];
237+
$where = ['rating_id = ?' => $ratingId, 'store_id IN(?)' => $storeIds];
238238
$connection->delete($table, $where);
239239
$connection->commit();
240240
} catch (\Exception $e) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Swatches\Plugin\Catalog;
7+
8+
use \Magento\Framework\App\Cache\Type\Block;
9+
use \Magento\Framework\App\Cache\Type\Collection;
10+
11+
class CacheInvalidate
12+
{
13+
/**
14+
* @var \Magento\Framework\App\Cache\TypeListInterface
15+
*/
16+
private $typeList;
17+
18+
/**
19+
* @var \Magento\Swatches\Helper\Data
20+
*/
21+
private $swatchHelper;
22+
23+
/**
24+
* @param \Magento\Framework\App\Cache\TypeListInterface $typeList
25+
* @param \Magento\Swatches\Helper\Data $swatchHelper
26+
*/
27+
public function __construct(
28+
\Magento\Framework\App\Cache\TypeListInterface $typeList,
29+
\Magento\Swatches\Helper\Data $swatchHelper
30+
) {
31+
$this->typeList = $typeList;
32+
$this->swatchHelper = $swatchHelper;
33+
}
34+
35+
/**
36+
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject
37+
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
38+
* @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
39+
*/
40+
public function afterSave(
41+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject,
42+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
43+
) {
44+
if ($this->swatchHelper->isSwatchAttribute($subject)) {
45+
$this->typeList->invalidate(Block::TYPE_IDENTIFIER);
46+
$this->typeList->invalidate(Collection::TYPE_IDENTIFIER);
47+
}
48+
return $result;
49+
}
50+
}

0 commit comments

Comments
 (0)