Skip to content

Commit ab841f5

Browse files
authored
Merge pull request #4635 from magento-tsg-csl3/2.2-develop-pr37
[TSG-CSL3] For 2.2 (pr37)
2 parents b27db9a + 4234647 commit ab841f5

File tree

19 files changed

+529
-118
lines changed

19 files changed

+529
-118
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Massaction/Extended.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
*/
66
namespace Magento\Backend\Block\Widget\Grid\Massaction;
77

8+
use Magento\Framework\Data\Collection\AbstractDb;
9+
use Magento\Framework\DB\Select;
10+
811
/**
912
* Grid widget massaction block
1013
*
1114
* @api
1215
* @deprecated 100.2.0 in favour of UI component implementation
1316
* @method \Magento\Quote\Model\Quote setHideFormElement(boolean $value) Hide Form element to prevent IE errors
1417
* @method boolean getHideFormElement()
15-
* @author Magento Core Team <core@magentocommerce.com>
18+
* @author Magento Core Team <core@magentocommerce.com>
1619
* @TODO MAGETWO-31510: Remove deprecated class
1720
* @since 100.0.2
1821
*/
@@ -155,7 +158,7 @@ public function getItemsJson()
155158
*/
156159
public function getCount()
157160
{
158-
return sizeof($this->_items);
161+
return count($this->_items);
159162
}
160163

161164
/**
@@ -212,6 +215,7 @@ public function getGridJsObjectName()
212215
* Retrieve JSON string of selected checkboxes
213216
*
214217
* @return string
218+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
215219
*/
216220
public function getSelectedJson()
217221
{
@@ -226,6 +230,7 @@ public function getSelectedJson()
226230
* Retrieve array of selected checkboxes
227231
*
228232
* @return string[]
233+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
229234
*/
230235
public function getSelected()
231236
{
@@ -247,6 +252,8 @@ public function getApplyButtonHtml()
247252
}
248253

249254
/**
255+
* Get mass action javascript code
256+
*
250257
* @return string
251258
*/
252259
public function getJavaScript()
@@ -263,6 +270,8 @@ public function getJavaScript()
263270
}
264271

265272
/**
273+
* Get grid ids in JSON format
274+
*
266275
* @return string
267276
*/
268277
public function getGridIdsJson()
@@ -280,15 +289,24 @@ public function getGridIdsJson()
280289
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
281290
}
282291

283-
$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
284-
285-
if (!empty($gridIds)) {
286-
return join(",", $gridIds);
292+
if ($allIdsCollection instanceof AbstractDb) {
293+
$idsSelect = clone $allIdsCollection->getSelect();
294+
$idsSelect->reset(Select::ORDER);
295+
$idsSelect->reset(Select::LIMIT_COUNT);
296+
$idsSelect->reset(Select::LIMIT_OFFSET);
297+
$idsSelect->reset(Select::COLUMNS);
298+
$idsSelect->columns($massActionIdField);
299+
$idList = $allIdsCollection->getConnection()->fetchCol($idsSelect);
300+
} else {
301+
$idList = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
287302
}
288-
return '';
303+
304+
return implode(',', $idList);
289305
}
290306

291307
/**
308+
* Retrieve massaction block js object name
309+
*
292310
* @return string
293311
*/
294312
public function getHtmlId()

app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,12 @@ protected function _getNewOptionsWithTheSameTitlesErrorRows(array $sourceProduct
681681
ksort($outerTitles);
682682
ksort($innerTitles);
683683
if ($outerTitles === $innerTitles) {
684-
$errorRows = array_merge($errorRows, $innerData['rows'], $outerData['rows']);
684+
foreach ($innerData['rows'] as $innerDataRow) {
685+
$errorRows[] = $innerDataRow;
686+
}
687+
foreach ($outerData['rows'] as $outerDataRow) {
688+
$errorRows[] = $outerDataRow;
689+
}
685690
}
686691
}
687692
}
@@ -715,7 +720,9 @@ protected function _findOldOptionsWithTheSameTitles()
715720
}
716721
}
717722
if ($optionsCount > 1) {
718-
$errorRows = array_merge($errorRows, $outerData['rows']);
723+
foreach ($outerData['rows'] as $dataRow) {
724+
$errorRows[] = $dataRow;
725+
}
719726
}
720727
}
721728
}
@@ -742,7 +749,9 @@ protected function _findNewOldOptionsTypeMismatch()
742749
ksort($outerTitles);
743750
ksort($innerTitles);
744751
if ($outerTitles === $innerTitles && $outerData['type'] != $innerData['type']) {
745-
$errorRows = array_merge($errorRows, $outerData['rows']);
752+
foreach ($outerData['rows'] as $dataRow) {
753+
$errorRows[] = $dataRow;
754+
}
746755
}
747756
}
748757
}
@@ -955,8 +964,10 @@ public function validateRow(array $rowData, $rowNumber)
955964

956965
$multiRowData = $this->_getMultiRowFormat($rowData);
957966

958-
foreach ($multiRowData as $optionData) {
959-
$combinedData = array_merge($rowData, $optionData);
967+
foreach ($multiRowData as $combinedData) {
968+
foreach ($rowData as $key => $field) {
969+
$combinedData[$key] = $field;
970+
}
960971

961972
if ($this->_isRowWithCustomOption($combinedData)) {
962973
if ($this->_isMainOptionRow($combinedData)) {
@@ -1106,15 +1117,15 @@ protected function _getMultiRowFormat($rowData)
11061117
foreach ($rowData['custom_options'] as $name => $customOption) {
11071118
$i++;
11081119
foreach ($customOption as $rowOrder => $optionRow) {
1109-
$row = array_merge(
1110-
[
1111-
self::COLUMN_STORE => '',
1112-
self::COLUMN_TITLE => $name,
1113-
self::COLUMN_SORT_ORDER => $i,
1114-
self::COLUMN_ROW_SORT => $rowOrder
1115-
],
1116-
$this->processOptionRow($name, $optionRow)
1117-
);
1120+
$row = [
1121+
self::COLUMN_STORE => '',
1122+
self::COLUMN_TITLE => $name,
1123+
self::COLUMN_SORT_ORDER => $i,
1124+
self::COLUMN_ROW_SORT => $rowOrder
1125+
];
1126+
foreach ($this->processOptionRow($name, $optionRow) as $key => $value) {
1127+
$row[$key] = $value;
1128+
}
11181129
$name = '';
11191130
$multiRow[] = $row;
11201131
}
@@ -1197,6 +1208,8 @@ private function addFileOptions($result, $optionRow)
11971208
*
11981209
* @return boolean
11991210
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
1211+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1212+
* @SuppressWarnings(PHPMD.NPathComplexity)
12001213
*/
12011214
protected function _importData()
12021215
{
@@ -1234,9 +1247,10 @@ protected function _importData()
12341247
$optionsToRemove[] = $this->_rowProductId;
12351248
}
12361249
}
1237-
foreach ($multiRowData as $optionData) {
1238-
$combinedData = array_merge($rowData, $optionData);
1239-
1250+
foreach ($multiRowData as $combinedData) {
1251+
foreach ($rowData as $key => $field) {
1252+
$combinedData[$key] = $field;
1253+
}
12401254
if (!$this->isRowAllowedToImport($combinedData, $rowNumber)) {
12411255
continue;
12421256
}
@@ -1403,7 +1417,9 @@ protected function _collectOptionMainData(
14031417
if (!$this->_isRowHasSpecificType($this->_rowType)
14041418
&& ($priceData = $this->_getPriceData($rowData, $nextOptionId, $this->_rowType))
14051419
) {
1406-
$prices[$nextOptionId] = $priceData;
1420+
if ($this->_isPriceGlobal) {
1421+
$prices[$nextOptionId][Store::DEFAULT_STORE_ID] = $priceData;
1422+
}
14071423
}
14081424

14091425
if (!isset($products[$this->_rowProductId])) {
@@ -1468,6 +1484,9 @@ protected function _collectOptionTypeData(
14681484
$specificTypeData = $this->_getSpecificTypeData($rowData, 0, false);
14691485
//For others stores
14701486
if ($specificTypeData) {
1487+
if (isset($specificTypeData['price'])) {
1488+
$typePrices[$nextValueId][$this->_rowStoreId] = $specificTypeData['price'];
1489+
}
14711490
$typeTitles[$nextValueId++][$this->_rowStoreId] = $specificTypeData['title'];
14721491
}
14731492
}
@@ -1505,6 +1524,7 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
15051524
* @param array &$prices
15061525
* @param array &$typeValues
15071526
* @return $this
1527+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
15081528
*/
15091529
protected function _compareOptionsWithExisting(array &$options, array &$titles, array &$prices, array &$typeValues)
15101530
{
@@ -1515,7 +1535,9 @@ protected function _compareOptionsWithExisting(array &$options, array &$titles,
15151535
$titles[$optionId] = $titles[$newOptionId];
15161536
unset($titles[$newOptionId]);
15171537
if (isset($prices[$newOptionId])) {
1518-
$prices[$newOptionId]['option_id'] = $optionId;
1538+
foreach ($prices[$newOptionId] as $storeId => $priceStoreData) {
1539+
$prices[$newOptionId][$storeId]['option_id'] = $optionId;
1540+
}
15191541
}
15201542
if (isset($typeValues[$newOptionId])) {
15211543
$typeValues[$optionId] = $typeValues[$newOptionId];
@@ -1548,8 +1570,10 @@ private function restoreOriginalOptionTypeIds(array &$typeValues, array &$typePr
15481570
$optionType['option_type_id'] = $existingTypeId;
15491571
$typeTitles[$existingTypeId] = $typeTitles[$optionTypeId];
15501572
unset($typeTitles[$optionTypeId]);
1551-
$typePrices[$existingTypeId] = $typePrices[$optionTypeId];
1552-
unset($typePrices[$optionTypeId]);
1573+
if (isset($typePrices[$optionTypeId])) {
1574+
$typePrices[$existingTypeId] = $typePrices[$optionTypeId];
1575+
unset($typePrices[$optionTypeId]);
1576+
}
15531577
// If option type titles match at least in one store, consider current option type as existing
15541578
break;
15551579
}
@@ -1606,7 +1630,7 @@ protected function _parseRequiredData(array $rowData)
16061630
if (!isset($this->_storeCodeToId[$rowData[self::COLUMN_STORE]])) {
16071631
return false;
16081632
}
1609-
$this->_rowStoreId = $this->_storeCodeToId[$rowData[self::COLUMN_STORE]];
1633+
$this->_rowStoreId = (int)$this->_storeCodeToId[$rowData[self::COLUMN_STORE]];
16101634
} else {
16111635
$this->_rowStoreId = Store::DEFAULT_STORE_ID;
16121636
}
@@ -1722,7 +1746,7 @@ protected function _getPriceData(array $rowData, $optionId, $type)
17221746
) {
17231747
$priceData = [
17241748
'option_id' => $optionId,
1725-
'store_id' => Store::DEFAULT_STORE_ID,
1749+
'store_id' => $this->_rowStoreId,
17261750
'price_type' => 'fixed',
17271751
];
17281752

@@ -1749,28 +1773,30 @@ protected function _getPriceData(array $rowData, $optionId, $type)
17491773
*/
17501774
protected function _getSpecificTypeData(array $rowData, $optionTypeId, $defaultStore = true)
17511775
{
1776+
$data = [];
1777+
$priceData = [];
1778+
$customOptionRowPrice = $rowData[self::COLUMN_ROW_PRICE];
1779+
if (!empty($customOptionRowPrice) || $customOptionRowPrice === '0') {
1780+
$priceData['price'] = (double)rtrim($rowData[self::COLUMN_ROW_PRICE], '%');
1781+
$priceData['price_type'] = ('%' == substr($rowData[self::COLUMN_ROW_PRICE], -1)) ? 'percent' : 'fixed';
1782+
}
17521783
if (!empty($rowData[self::COLUMN_ROW_TITLE]) && $defaultStore && empty($rowData[self::COLUMN_STORE])) {
17531784
$valueData = [
17541785
'option_type_id' => $optionTypeId,
17551786
'sort_order' => empty($rowData[self::COLUMN_ROW_SORT]) ? 0 : abs($rowData[self::COLUMN_ROW_SORT]),
17561787
'sku' => !empty($rowData[self::COLUMN_ROW_SKU]) ? $rowData[self::COLUMN_ROW_SKU] : '',
17571788
];
1758-
1759-
$priceData = false;
1760-
if (!empty($rowData[self::COLUMN_ROW_PRICE])) {
1761-
$priceData = [
1762-
'price' => (double)rtrim($rowData[self::COLUMN_ROW_PRICE], '%'),
1763-
'price_type' => 'fixed',
1764-
];
1765-
if ('%' == substr($rowData[self::COLUMN_ROW_PRICE], -1)) {
1766-
$priceData['price_type'] = 'percent';
1767-
}
1768-
}
1769-
return ['value' => $valueData, 'title' => $rowData[self::COLUMN_ROW_TITLE], 'price' => $priceData];
1789+
$data['value'] = $valueData;
1790+
$data['title'] = $rowData[self::COLUMN_ROW_TITLE];
1791+
$data['price'] = $priceData;
17701792
} elseif (!empty($rowData[self::COLUMN_ROW_TITLE]) && !$defaultStore && !empty($rowData[self::COLUMN_STORE])) {
1771-
return ['title' => $rowData[self::COLUMN_ROW_TITLE]];
1793+
if ($priceData) {
1794+
$data['price'] = $priceData;
1795+
}
1796+
$data['title'] = $rowData[self::COLUMN_ROW_TITLE];
17721797
}
1773-
return false;
1798+
1799+
return $data ?: false;
17741800
}
17751801

17761802
/**
@@ -1828,7 +1854,9 @@ protected function _saveTitles(array $titles)
18281854
{
18291855
$titleRows = [];
18301856
foreach ($titles as $optionId => $storeInfo) {
1831-
foreach ($storeInfo as $storeId => $title) {
1857+
//for use default
1858+
$uniqStoreInfo = array_unique($storeInfo);
1859+
foreach ($uniqStoreInfo as $storeId => $title) {
18321860
$titleRows[] = ['option_id' => $optionId, 'store_id' => $storeId, 'title' => $title];
18331861
}
18341862
}
@@ -1852,11 +1880,19 @@ protected function _saveTitles(array $titles)
18521880
protected function _savePrices(array $prices)
18531881
{
18541882
if ($prices) {
1855-
$this->_connection->insertOnDuplicate(
1856-
$this->_tables['catalog_product_option_price'],
1857-
$prices,
1858-
['price', 'price_type']
1859-
);
1883+
$optionPriceRows = [];
1884+
foreach ($prices as $storesData) {
1885+
foreach ($storesData as $row) {
1886+
$optionPriceRows[] = $row;
1887+
}
1888+
}
1889+
if ($optionPriceRows) {
1890+
$this->_connection->insertOnDuplicate(
1891+
$this->_tables['catalog_product_option_price'],
1892+
$optionPriceRows,
1893+
['price', 'price_type']
1894+
);
1895+
}
18601896
}
18611897

18621898
return $this;
@@ -1923,7 +1959,9 @@ protected function _saveSpecificTypeTitles(array $typeTitles)
19231959
{
19241960
$optionTypeTitleRows = [];
19251961
foreach ($typeTitles as $optionTypeId => $storesData) {
1926-
foreach ($storesData as $storeId => $title) {
1962+
//for use default
1963+
$uniqStoresData = array_unique($storesData);
1964+
foreach ($uniqStoresData as $storeId => $title) {
19271965
$optionTypeTitleRows[] = [
19281966
'option_type_id' => $optionTypeId,
19291967
'store_id' => $storeId,

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/OptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class OptionTest extends \Magento\ImportExport\Test\Unit\Model\Import\AbstractIm
7979
* @var array
8080
*/
8181
protected $_expectedPrices = [
82-
2 => ['option_id' => 2, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 0],
83-
3 => ['option_id' => 3, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 2]
82+
0 => ['option_id' => 2, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 0],
83+
1 => ['option_id' => 3, 'store_id' => 0, 'price_type' => 'fixed', 'price' => 2]
8484
];
8585

8686
/**

0 commit comments

Comments
 (0)