Skip to content

Commit 27e0855

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch '2.1-develop' into MAGETWO-71515
2 parents d10ea87 + 476a1e9 commit 27e0855

File tree

6 files changed

+91
-53
lines changed

6 files changed

+91
-53
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,66 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product\Option;
77

8+
use Magento\Catalog\Model\Product\Option\Value as OptionValue;
9+
use Magento\Directory\Model\Currency;
10+
use Magento\Directory\Model\CurrencyFactory;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\Locale\FormatInterface;
14+
use Magento\Framework\Model\AbstractModel;
15+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
16+
use Magento\Framework\Model\ResourceModel\Db\Context;
17+
use Magento\Store\Model\ScopeInterface;
18+
use Magento\Store\Model\Store;
19+
use Magento\Store\Model\StoreManagerInterface;
20+
821
/**
922
* Catalog product custom option resource model
1023
*
1124
* @author Magento Core Team <core@magentocommerce.com>
1225
*/
13-
class Value extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
26+
class Value extends AbstractDb
1427
{
1528
/**
1629
* Store manager
1730
*
18-
* @var \Magento\Store\Model\StoreManagerInterface
31+
* @var StoreManagerInterface
1932
*/
2033
protected $_storeManager;
2134

2235
/**
2336
* Currency factory
2437
*
25-
* @var \Magento\Directory\Model\CurrencyFactory
38+
* @var CurrencyFactory
2639
*/
2740
protected $_currencyFactory;
2841

2942
/**
3043
* Core config model
3144
*
32-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
45+
* @var ScopeConfigInterface
3346
*/
3447
protected $_config;
3548

3649
/**
37-
* @var \Magento\Framework\Locale\FormatInterface
50+
* @var FormatInterface
3851
*/
3952
private $localeFormat;
4053

4154
/**
4255
* Class constructor
4356
*
44-
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
45-
* @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
46-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
47-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
57+
* @param Context $context
58+
* @param CurrencyFactory $currencyFactory
59+
* @param StoreManagerInterface $storeManager
60+
* @param ScopeConfigInterface $config
4861
* @param string $connectionName
4962
*/
5063
public function __construct(
51-
\Magento\Framework\Model\ResourceModel\Db\Context $context,
52-
\Magento\Directory\Model\CurrencyFactory $currencyFactory,
53-
\Magento\Store\Model\StoreManagerInterface $storeManager,
54-
\Magento\Framework\App\Config\ScopeConfigInterface $config,
64+
Context $context,
65+
CurrencyFactory $currencyFactory,
66+
StoreManagerInterface $storeManager,
67+
ScopeConfigInterface $config,
5568
$connectionName = null
5669
) {
5770
$this->_currencyFactory = $currencyFactory;
@@ -74,10 +87,10 @@ protected function _construct()
7487
* Proceed operations after object is saved
7588
* Save options store data
7689
*
77-
* @param \Magento\Framework\Model\AbstractModel $object
78-
* @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
90+
* @param AbstractModel $object
91+
* @return AbstractDb
7992
*/
80-
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
93+
protected function _afterSave(AbstractModel $object)
8194
{
8295
$this->_saveValuePrices($object);
8396
$this->_saveValueTitles($object);
@@ -88,20 +101,21 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
88101
/**
89102
* Save option value price data.
90103
*
91-
* @param \Magento\Framework\Model\AbstractModel $object
104+
* @param AbstractModel $object
92105
* @return void
93106
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
94107
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
95108
*/
96-
protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $object)
109+
protected function _saveValuePrices(AbstractModel $object)
97110
{
111+
$objectPrice = $object->getPrice();
98112
$priceTable = $this->getTable('catalog_product_option_type_price');
99-
$formattedPrice = $this->getLocaleFormatter()->getNumber($object->getPrice());
113+
$formattedPrice = $this->getLocaleFormatter()->getNumber($objectPrice);
100114

101115
$price = (double)sprintf('%F', $formattedPrice);
102116
$priceType = $object->getPriceType();
103117

104-
if ($object->getPrice() && $priceType) {
118+
if (isset($objectPrice) && $priceType) {
105119
//save for store_id = 0
106120
$select = $this->getConnection()->select()->from(
107121
$priceTable,
@@ -111,7 +125,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
111125
(int)$object->getId()
112126
)->where(
113127
'store_id = ?',
114-
\Magento\Store\Model\Store::DEFAULT_STORE_ID
128+
Store::DEFAULT_STORE_ID
115129
);
116130
$optionTypeId = $this->getConnection()->fetchOne($select);
117131

@@ -120,15 +134,15 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
120134
$bind = ['price' => $price, 'price_type' => $priceType];
121135
$where = [
122136
'option_type_id = ?' => $optionTypeId,
123-
'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
137+
'store_id = ?' => Store::DEFAULT_STORE_ID,
124138
];
125139

126140
$this->getConnection()->update($priceTable, $bind, $where);
127141
}
128142
} else {
129143
$bind = [
130144
'option_type_id' => (int)$object->getId(),
131-
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
145+
'store_id' => Store::DEFAULT_STORE_ID,
132146
'price' => $price,
133147
'price_type' => $priceType,
134148
];
@@ -137,17 +151,17 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
137151
}
138152

139153
$scope = (int)$this->_config->getValue(
140-
\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
141-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
154+
Store::XML_PATH_PRICE_SCOPE,
155+
ScopeInterface::SCOPE_STORE
142156
);
143157

144-
if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE
158+
if ($scope == Store::PRICE_SCOPE_WEBSITE
145159
&& $priceType
146-
&& $object->getPrice()
147-
&& $object->getStoreId() != \Magento\Store\Model\Store::DEFAULT_STORE_ID
160+
&& isset($objectPrice)
161+
&& $object->getStoreId() != Store::DEFAULT_STORE_ID
148162
) {
149163
$baseCurrency = $this->_config->getValue(
150-
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
164+
Currency::XML_PATH_CURRENCY_BASE,
151165
'default'
152166
);
153167

@@ -156,7 +170,7 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
156170
foreach ($storeIds as $storeId) {
157171
if ($priceType == 'fixed') {
158172
$storeCurrency = $this->_storeManager->getStore($storeId)->getBaseCurrencyCode();
159-
/** @var $currencyModel \Magento\Directory\Model\Currency */
173+
/** @var $currencyModel Currency */
160174
$currencyModel = $this->_currencyFactory->create();
161175
$currencyModel->load($baseCurrency);
162176
$rate = $currencyModel->getRate($storeCurrency);
@@ -198,8 +212,8 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
198212
}
199213
}
200214
} else {
201-
if ($scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE
202-
&& !$object->getPrice()
215+
if ($scope == Store::PRICE_SCOPE_WEBSITE
216+
&& !isset($objectPrice)
203217
&& !$priceType
204218
) {
205219
$storeIds = $this->_storeManager->getStore($object->getStoreId())->getWebsite()->getStoreIds();
@@ -217,13 +231,13 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje
217231
/**
218232
* Save option value title data
219233
*
220-
* @param \Magento\Framework\Model\AbstractModel $object
234+
* @param AbstractModel $object
221235
* @return void
222236
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
223237
*/
224-
protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $object)
238+
protected function _saveValueTitles(AbstractModel $object)
225239
{
226-
foreach ([\Magento\Store\Model\Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
240+
foreach ([Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
227241
$titleTable = $this->getTable('catalog_product_option_type_title');
228242
$select = $this->getConnection()->select()->from(
229243
$titleTable,
@@ -238,9 +252,7 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
238252
$optionTypeId = $this->getConnection()->fetchOne($select);
239253
$existInCurrentStore = $this->getOptionIdFromOptionTable($titleTable, (int)$object->getId(), (int)$storeId);
240254

241-
if ($storeId != \Magento\Store\Model\Store::DEFAULT_STORE_ID &&
242-
$object->getData('is_delete_store_title')
243-
) {
255+
if ($storeId != Store::DEFAULT_STORE_ID && $object->getData('is_delete_store_title')) {
244256
$object->unsetData('title');
245257
}
246258

@@ -258,11 +270,11 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
258270
$existInDefaultStore = $this->getOptionIdFromOptionTable(
259271
$titleTable,
260272
(int)$object->getId(),
261-
\Magento\Store\Model\Store::DEFAULT_STORE_ID
273+
Store::DEFAULT_STORE_ID
262274
);
263275
// we should insert record into not default store only of if it does not exist in default store
264-
if (($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInDefaultStore)
265-
|| ($storeId != \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInCurrentStore)
276+
if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore)
277+
|| ($storeId != Store::DEFAULT_STORE_ID && !$existInCurrentStore)
266278
) {
267279
$bind = [
268280
'option_type_id' => (int)$object->getId(),
@@ -275,7 +287,7 @@ protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $obje
275287
} else {
276288
if ($storeId
277289
&& $optionTypeId
278-
&& $object->getStoreId() > \Magento\Store\Model\Store::DEFAULT_STORE_ID
290+
&& $object->getStoreId() > Store::DEFAULT_STORE_ID
279291
) {
280292
$where = [
281293
'option_type_id = ?' => (int)$optionTypeId,
@@ -355,12 +367,12 @@ public function deleteValues($optionTypeId)
355367
/**
356368
* Duplicate product options value
357369
*
358-
* @param \Magento\Catalog\Model\Product\Option\Value $object
370+
* @param OptionValue $object
359371
* @param int $oldOptionId
360372
* @param int $newOptionId
361-
* @return \Magento\Catalog\Model\Product\Option\Value
373+
* @return OptionValue
362374
*/
363-
public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $oldOptionId, $newOptionId)
375+
public function duplicate(OptionValue $object, $oldOptionId, $newOptionId)
364376
{
365377
$connection = $this->getConnection();
366378
$select = $connection->select()->from($this->getMainTable())->where('option_id = ?', $oldOptionId);
@@ -427,16 +439,16 @@ public function duplicate(\Magento\Catalog\Model\Product\Option\Value $object, $
427439
/**
428440
* Get FormatInterface to convert price from string to number format.
429441
*
430-
* @return \Magento\Framework\Locale\FormatInterface
442+
* @return FormatInterface
431443
* @deprecated
432444
*/
433445
private function getLocaleFormatter()
434446
{
435447
if ($this->localeFormat === null) {
436-
$this->localeFormat = \Magento\Framework\App\ObjectManager::getInstance()
437-
->get(\Magento\Framework\Locale\FormatInterface::class);
448+
$this->localeFormat = ObjectManager::getInstance()
449+
->get(FormatInterface::class);
438450
}
439-
451+
440452
return $this->localeFormat;
441453
}
442454
}

app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_grid.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@
166166
<argument name="data" xsi:type="array">
167167
<item name="config" xsi:type="array">
168168
<item name="filter" xsi:type="string">text</item>
169-
<item name="sorting" xsi:type="string">desc</item>
170169
<item name="label" xsi:type="string" translate="true">ID</item>
171170
</item>
172171
</argument>
@@ -187,6 +186,7 @@
187186
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
188187
<item name="dataType" xsi:type="string">date</item>
189188
<item name="label" xsi:type="string" translate="true">Purchase Date</item>
189+
<item name="sorting" xsi:type="string">desc</item>
190190
<item name="dateFormat" xsi:type="string">MMM dd, YYYY, H:mm:ss A</item>
191191
</item>
192192
</argument>

app/code/Magento/Swatches/Model/Plugin/EavAttribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function prepareOptionIds(array $optionsArray)
174174
{
175175
if (isset($optionsArray['value']) && is_array($optionsArray['value'])) {
176176
foreach (array_keys($optionsArray['value']) as $optionId) {
177-
if (isset($optionsArray['delete']) && $optionsArray['delete'][$optionId] == 1) {
177+
if (isset($optionsArray['delete'][$optionId]) && $optionsArray['delete'][$optionId] == 1) {
178178
unset($optionsArray['value'][$optionId]);
179179
}
180180
}

lib/internal/Magento/Framework/Config/Converter/Dom/Flat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public function convert(\DOMNode $source, $basePath = '')
100100
}
101101
} else {
102102
if ($result) {
103-
$result['value'] = $value;
103+
$result['value'] = trim($value);
104104
} else {
105-
$result = $value;
105+
$result = trim($value);
106106
}
107107
}
108108
return $result;

lib/internal/Magento/Framework/Config/Test/Unit/_files/converter/dom/flat/result.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
// @codingStandardsIgnoreFile
67
return [
78
'root' => [
89
'node_one' => [
@@ -11,14 +12,20 @@
1112
'subnode' => [
1213
['attributeThree' => '30'],
1314
['attributeThree' => '40', 'attributeFour' => '40', 'value' => 'Value1'],
15+
['attributeThree' => '50', 'value' => 'value_from_new_line'],
16+
['attributeThree' => '60', 'value' => 'auto_formatted_by_ide_value_due_to_line_size_restriction']
1417
],
1518
'books' => ['attributeFive' => '50'],
1619
],
1720
'multipleNode' => [
1821
'one' => ['id' => 'one', 'name' => 'name1', 'value' => '1'],
1922
'two' => ['id' => 'two', 'name' => 'name2', 'value' => '2'],
23+
'three' => ['id' => 'three', 'name' => 'name3', 'value' => 'value_from_new_line'],
24+
'four' => ['id' => 'four', 'name' => 'name4', 'value' => 'auto_formatted_by_ide_value_due_to_line_size_restriction'],
2025
],
2126
'someOtherVal' => '',
2227
'someDataVal' => '',
28+
'valueFromNewLine' => 'value_from_new_line',
29+
'autoFormattedValue' => 'auto_formatted_by_ide_value_due_to_line_size_restriction'
2330
]
2431
];

lib/internal/Magento/Framework/Config/Test/Unit/_files/converter/dom/flat/source.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<node_one attributeOne = '10' attributeTwo = '20'>
1010
<subnode attributeThree = '30'></subnode>
1111
<subnode attributeThree = '40' attributeFour = '40' >Value1</subnode>
12+
<subnode attributeThree = '50'>
13+
value_from_new_line
14+
</subnode>
15+
<subnode attributeThree = '60'>auto_formatted_by_ide_value_due_to_line_size_restriction
16+
</subnode>
1217
<books attributeFive = '50' />
1318
</node_one>
1419
<multipleNode id="one" name="name1">
@@ -19,4 +24,18 @@
1924
</multipleNode>
2025
<someOtherVal></someOtherVal>
2126
<someDataVal><![CDATA[]]></someDataVal>
27+
<multipleNode id="three" name="name3">
28+
<value>
29+
value_from_new_line
30+
</value>
31+
</multipleNode>
32+
<multipleNode id="four" name="name4">
33+
<value>auto_formatted_by_ide_value_due_to_line_size_restriction
34+
</value>
35+
</multipleNode>
36+
<valueFromNewLine>
37+
value_from_new_line
38+
</valueFromNewLine>
39+
<autoFormattedValue>auto_formatted_by_ide_value_due_to_line_size_restriction
40+
</autoFormattedValue>
2241
</root>

0 commit comments

Comments
 (0)