Skip to content

Commit fecc8e0

Browse files
Slabko,Michael(mslabko)Slabko,Michael(mslabko)
Slabko,Michael(mslabko)
authored and
Slabko,Michael(mslabko)
committed
Merge pull request #3 from magento-nord/MAGETWO-44704
MAGETWO-44704: Swatches attributes: empty value is missing, although "Values Required" = No
2 parents 33314bb + d33e67c commit fecc8e0

File tree

5 files changed

+58
-39
lines changed

5 files changed

+58
-39
lines changed

app/code/Magento/Sales/Model/Rss/OrderStatus.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ public function getRssData()
113113
public function getCacheKey()
114114
{
115115
$order = $this->getOrder();
116-
return 'rss_order_status_data_' . md5($order->getId() . $order->getIncrementId() . $order->getCustomerId());
116+
$key = '';
117+
if ($order !== null) {
118+
$key = md5($order->getId() . $order->getIncrementId() . $order->getCustomerId());
119+
}
120+
return 'rss_order_status_data_' . $key;
117121
}
118122

119123
/**
@@ -150,7 +154,7 @@ protected function getOrder()
150154
$order = $this->orderFactory->create();
151155
$order->load($data['order_id']);
152156

153-
if ($order->getIncrementId() != $data['increment_id'] || $order->getCustomerId() != $data['customer_id']) {
157+
if ($order->getIncrementId() !== $data['increment_id'] || $order->getCustomerId() !== $data['customer_id']) {
154158
$order = null;
155159
}
156160
$this->order = $order;

app/code/Magento/Sales/Test/Unit/Model/Rss/OrderStatusTest.php

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ protected function setUp()
132132
]
133133
);
134134
}
135-
public function testGetData()
135+
136+
public function testGetRssData()
136137
{
137-
$this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($this->order));
138-
$this->requestInterface->expects($this->any())->method('getParam')
139-
->with('data')
140-
->will($this->returnValue('eyJvcmRlcl9pZCI6MSwiaW5jcmVtZW50X2lkIjoiMTAwMDAwMDAxIiwiY3VzdG9tZXJfaWQiOjF9'));
138+
$this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);
139+
$requestData = base64_encode('{"order_id":1,"increment_id":"100000001","customer_id":1}');
140+
141+
$this->requestInterface->expects($this->any())->method('getParam')->with('data')->willReturn($requestData);
142+
141143
$resource = $this->getMockBuilder('\Magento\Sales\Model\ResourceModel\Order\Rss\OrderStatus')
142144
->setMethods(['getAllCommentCollection'])
143145
->disableOriginalConstructor()
@@ -148,15 +150,34 @@ public function testGetData()
148150
'created_at' => '2014-10-09 18:25:50',
149151
'comment' => 'Some comment',
150152
];
151-
$resource->expects($this->once())->method('getAllCommentCollection')->will($this->returnValue([$comment]));
152-
$this->orderStatusFactory->expects($this->once())->method('create')->will($this->returnValue($resource));
153+
$resource->expects($this->once())->method('getAllCommentCollection')->willReturn([$comment]);
154+
$this->orderStatusFactory->expects($this->once())->method('create')->willReturn($resource);
153155
$this->urlInterface->expects($this->any())->method('getUrl')
154156
->with('sales/order/view', ['order_id' => 1])
155157
->will($this->returnValue('http://magento.com/sales/order/view/order_id/1'));
156158

157159
$this->assertEquals($this->feedData, $this->model->getRssData());
158160
}
159161

162+
/**
163+
* @expectedException \InvalidArgumentException
164+
* @expectedExceptionMessage Order not found.
165+
*/
166+
public function testGetRssDataWithError()
167+
{
168+
$this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);
169+
170+
$requestData = base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}');
171+
172+
$this->requestInterface->expects($this->any())->method('getParam')->with('data')->willReturn($requestData);
173+
174+
$this->orderStatusFactory->expects($this->never())->method('create');
175+
176+
$this->urlInterface->expects($this->never())->method('getUrl');
177+
178+
$this->assertEquals($this->feedData, $this->model->getRssData());
179+
}
180+
160181
public function testIsAllowed()
161182
{
162183
$this->scopeConfigInterface->expects($this->once())->method('getValue')
@@ -165,13 +186,29 @@ public function testIsAllowed()
165186
$this->assertTrue($this->model->isAllowed());
166187
}
167188

168-
public function testGetCacheKey()
189+
/**
190+
* @param string $requestData
191+
* @param string $result
192+
* @dataProvider getCacheKeyDataProvider
193+
*/
194+
public function testGetCacheKey($requestData, $result)
169195
{
170196
$this->requestInterface->expects($this->any())->method('getParam')
171197
->with('data')
172-
->will($this->returnValue('eyJvcmRlcl9pZCI6MSwiaW5jcmVtZW50X2lkIjoiMTAwMDAwMDAxIiwiY3VzdG9tZXJfaWQiOjF9'));
198+
->will($this->returnValue($requestData));
173199
$this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($this->order));
174-
$this->assertEquals('rss_order_status_data_' . md5('11000000011'), $this->model->getCacheKey());
200+
$this->assertEquals('rss_order_status_data_' . $result, $this->model->getCacheKey());
201+
}
202+
203+
/**
204+
* @return array
205+
*/
206+
public function getCacheKeyDataProvider()
207+
{
208+
return [
209+
[base64_encode('{"order_id":1,"increment_id":"100000001","customer_id":1}'), md5('11000000011')],
210+
[base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}'), '']
211+
];
175212
}
176213

177214
public function testGetCacheLifetime()

app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/js.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ require([
265265
setRowVisibility('is_unique', false);
266266
setRowVisibility('frontend_class', false);
267267
break;
268-
<?php $hiddenFields = $block->helper('Magento\Catalog\Helper\Data')->getAttributeHiddenFields() ?>
268+
<?php $hiddenFields = $this->helper('Magento\Catalog\Helper\Data')->getAttributeHiddenFields() ?>
269269
<?php foreach ($hiddenFields as $type => $fields): ?>
270270
<?php if (in_array($type, array('swatch_visual', 'swatch_text'))) continue ?>
271271
case '<?php echo $block->escapeHtml($type); ?>':

app/code/Magento/Swatches/view/adminhtml/web/js/text.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,8 @@ define([
4444
data: data
4545
});
4646

47-
if (isNewOption) {
48-
visibleRadio = $$('#swatch-text-options-panel [name="defaulttext[]"]').findAll(function (el) {
49-
return el.up().up().visible();
50-
});
51-
52-
if (visibleRadio.length === 1) {
53-
visibleRadio[0].checked = true;
54-
}
55-
56-
if (!this.isReadOnly) {
57-
this.enableNewOptionDeleteButton(data.id);
58-
}
47+
if (isNewOption && !this.isReadOnly) {
48+
this.enableNewOptionDeleteButton(data.id);
5949
}
6050
this.itemCount++;
6151
this.totalItems++;

app/code/Magento/Swatches/view/adminhtml/web/js/visual.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,8 @@ define([
4646
data: data
4747
});
4848

49-
if (isNewOption) {
50-
visibleRadio = $$('#swatch-visual-options-panel [name="defaultvisual[]"]').findAll(
51-
function (el) {
52-
return el.up().up().visible();
53-
}
54-
);
55-
56-
if (visibleRadio.length === 1) {
57-
visibleRadio[0].checked = true;
58-
}
59-
60-
if (!this.isReadOnly) {
61-
this.enableNewOptionDeleteButton(data.id);
62-
}
49+
if (isNewOption && !this.isReadOnly) {
50+
this.enableNewOptionDeleteButton(data.id);
6351
}
6452
this.itemCount++;
6553
this.totalItems++;

0 commit comments

Comments
 (0)