Skip to content

Commit 583e376

Browse files
committed
Merge remote-tracking branch 'mainline/2.1-develop' into 2.1.1-PR-DEVELOP
2 parents abd95d0 + e9b4c10 commit 583e376

File tree

12 files changed

+579
-275
lines changed

12 files changed

+579
-275
lines changed

app/code/Magento/Authorizenet/view/frontend/web/js/view/payment/method-renderer/authorizenet-directpost.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
define(
66
[
77
'jquery',
8-
'Magento_Payment/js/view/payment/iframe'
8+
'Magento_Payment/js/view/payment/iframe',
9+
'mage/translate'
910
],
10-
function ($, Component) {
11+
function ($, Component, $t) {
1112
'use strict';
1213

1314
return Component.extend({
1415
defaults: {
1516
template: 'Magento_Authorizenet/payment/authorizenet-directpost',
16-
timeoutMessage: 'Sorry, but something went wrong. Please contact the seller.'
17+
timeoutMessage: $t('Sorry, but something went wrong. Please contact the seller.')
1718
},
1819
placeOrderHandler: null,
1920
validateHandler: null,

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

Lines changed: 155 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use Magento\CatalogImportExport\Model\Import\Product;
1212
use Magento\Framework\App\ResourceConnection;
1313
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
14-
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection as ProductOptionValueCollection;
15+
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory as ProductOptionValueCollectionFactory;
1516

1617
/**
1718
* Entity class which provide possibility to import product custom options
@@ -324,6 +325,16 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
324325
*/
325326
private $productEntityIdentifierField;
326327

328+
/**
329+
* @var ProductOptionValueCollectionFactory
330+
*/
331+
private $productOptionValueCollectionFactory;
332+
333+
/**
334+
* @var array
335+
*/
336+
private $optionTypeTitles;
337+
327338
/**
328339
* @param \Magento\ImportExport\Model\ResourceModel\Import\Data $importData
329340
* @param ResourceConnection $resource
@@ -337,8 +348,7 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
337348
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $dateTime
338349
* @param ProcessingErrorAggregatorInterface $errorAggregator
339350
* @param array $data
340-
* @throws \Magento\Framework\Exception\LocalizedException
341-
*
351+
* @param ProductOptionValueCollectionFactory|null $productOptionValueCollectionFactory
342352
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
343353
*/
344354
public function __construct(
@@ -353,7 +363,8 @@ public function __construct(
353363
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
354364
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $dateTime,
355365
ProcessingErrorAggregatorInterface $errorAggregator,
356-
array $data = []
366+
array $data = [],
367+
ProductOptionValueCollectionFactory $productOptionValueCollectionFactory = null
357368
) {
358369
$this->_resource = $resource;
359370
$this->_catalogData = $catalogData;
@@ -365,6 +376,9 @@ public function __construct(
365376
$this->_scopeConfig = $scopeConfig;
366377
$this->dateTime = $dateTime;
367378

379+
$this->productOptionValueCollectionFactory = $productOptionValueCollectionFactory
380+
?: \Magento\Framework\App\ObjectManager::getInstance()->get(ProductOptionValueCollectionFactory::class);
381+
368382
if (isset($data['connection'])) {
369383
$this->_connection = $data['connection'];
370384
} else {
@@ -781,15 +795,15 @@ protected function _addRowsErrors($errorCode, array $errorNumbers)
781795
protected function _validateMainRow(array $rowData, $rowNumber)
782796
{
783797
if (!empty($rowData[self::COLUMN_STORE]) && !array_key_exists(
784-
$rowData[self::COLUMN_STORE],
785-
$this->_storeCodeToId
786-
)
798+
$rowData[self::COLUMN_STORE],
799+
$this->_storeCodeToId
800+
)
787801
) {
788802
$this->_productEntity->addRowError(self::ERROR_INVALID_STORE, $rowNumber);
789803
} elseif (!empty($rowData[self::COLUMN_TYPE]) && !array_key_exists(
790-
$rowData[self::COLUMN_TYPE],
791-
$this->_specificTypes
792-
)
804+
$rowData[self::COLUMN_TYPE],
805+
$this->_specificTypes
806+
)
793807
) {
794808
// type
795809
$this->_productEntity->addRowError(self::ERROR_INVALID_TYPE, $rowNumber);
@@ -894,9 +908,9 @@ protected function _saveNewOptionData(array $rowData, $rowNumber)
894908
protected function _validateSecondaryRow(array $rowData, $rowNumber)
895909
{
896910
if (!empty($rowData[self::COLUMN_STORE]) && !array_key_exists(
897-
$rowData[self::COLUMN_STORE],
898-
$this->_storeCodeToId
899-
)
911+
$rowData[self::COLUMN_STORE],
912+
$this->_storeCodeToId
913+
)
900914
) {
901915
$this->_productEntity->addRowError(self::ERROR_INVALID_STORE, $rowNumber);
902916
} elseif (!empty($rowData[self::COLUMN_ROW_PRICE]) && !is_numeric(rtrim($rowData[self::COLUMN_ROW_PRICE], '%'))
@@ -1125,7 +1139,7 @@ private function processOptionRow($name, $optionRow)
11251139
if (isset($optionRow['price'])) {
11261140
$percent_suffix = '';
11271141
if (isset($optionRow['price_type']) && $optionRow['price_type'] == 'percent') {
1128-
$percent_suffix = '%';
1142+
$percent_suffix = '%';
11291143
}
11301144
$result[self::COLUMN_ROW_PRICE] = $optionRow['price'] . $percent_suffix;
11311145
}
@@ -1212,6 +1226,12 @@ protected function _importData()
12121226
if ($this->_isReadyForSaving($options, $titles, $typeValues)) {
12131227
if ($this->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) {
12141228
$this->_compareOptionsWithExisting($options, $titles, $prices, $typeValues);
1229+
1230+
$optionsForRestore = $this->getRestoreOriginalOptionTypeIds($typeValues, $typeTitles);
1231+
1232+
$typeValues = $this->restoreTypeValues($typeValues, $optionsForRestore);
1233+
$typePrices = $this->restoreOptionTypesData($typePrices, $optionsForRestore);
1234+
$typeTitles = $this->restoreOptionTypesData($typeTitles, $optionsForRestore);
12151235
}
12161236

12171237
$this->_saveOptions(
@@ -1278,12 +1298,12 @@ protected function _collectOptionMainData(
12781298
$optionData = $this->_getOptionData($rowData, $this->_rowProductId, $nextOptionId, $this->_rowType);
12791299

12801300
if (!$this->_isRowHasSpecificType(
1281-
$this->_rowType
1282-
) && ($priceData = $this->_getPriceData(
1283-
$rowData,
1284-
$nextOptionId,
1285-
$this->_rowType
1286-
))
1301+
$this->_rowType
1302+
) && ($priceData = $this->_getPriceData(
1303+
$rowData,
1304+
$nextOptionId,
1305+
$this->_rowType
1306+
))
12871307
) {
12881308
$prices[$nextOptionId] = $priceData;
12891309
}
@@ -1416,6 +1436,107 @@ protected function _compareOptionsWithExisting(array &$options, array &$titles,
14161436
return $this;
14171437
}
14181438

1439+
/**
1440+
* Returns existing optionsTypes data for restoring original data
1441+
*
1442+
* @param array $typeValues
1443+
* @param array $typeTitles
1444+
* @return array
1445+
*/
1446+
private function getRestoreOriginalOptionTypeIds(array $typeValues, array $typeTitles)
1447+
{
1448+
$optionsForRestore = [];
1449+
foreach ($typeValues as $optionId => $optionTypes) {
1450+
foreach ($optionTypes as $optionTypeKey => $optionType) {
1451+
$optionTypeId = $optionType['option_type_id'];
1452+
if (isset($typeTitles[$optionTypeId]) && is_array($typeTitles[$optionTypeId])) {
1453+
foreach ($typeTitles[$optionTypeId] as $storeId => $optionTypeTitle) {
1454+
$existingTypeId = $this->getExistingOptionTypeId($optionId, $storeId, $optionTypeTitle);
1455+
if ($existingTypeId !== null) {
1456+
$optionsForRestore[] = [
1457+
'searchKey' => $existingTypeId,
1458+
'replaceKey' => $optionTypeId,
1459+
'optionTypeKey' => $optionTypeKey,
1460+
'optionId' => $optionId,
1461+
];
1462+
// If option type titles match at least in one store, consider current option type as existing
1463+
break;
1464+
}
1465+
}
1466+
}
1467+
}
1468+
}
1469+
return $optionsForRestore;
1470+
}
1471+
1472+
/**
1473+
* Returns restored array of typeValues
1474+
*
1475+
* @param array $typeValues
1476+
* @param array $optionsForRestore
1477+
* @return array
1478+
*/
1479+
private function restoreTypeValues(array $typeValues, array $optionsForRestore)
1480+
{
1481+
foreach ($optionsForRestore as $restoreValues) {
1482+
if (isset($typeValues[$restoreValues['optionId']][$restoreValues['optionTypeKey']])) {
1483+
$typeValues[$restoreValues['optionId']][$restoreValues['optionTypeKey']]['option_type_id'] = $restoreValues['searchKey'];
1484+
}
1485+
}
1486+
return $typeValues;
1487+
}
1488+
1489+
/**
1490+
* Restores optionTypes data
1491+
*
1492+
* @param array $optionDataArray
1493+
* @param array $optionsForRestore
1494+
* @return array
1495+
*/
1496+
private function restoreOptionTypesData(array $optionDataArray, array $optionsForRestore)
1497+
{
1498+
foreach ($optionsForRestore as $restoreValues) {
1499+
$replaceKey = $restoreValues['replaceKey'];
1500+
$searchKey = $restoreValues['searchKey'];
1501+
if (isset($optionDataArray[$replaceKey])) {
1502+
$optionDataArray[$searchKey] = $optionDataArray[$replaceKey];
1503+
unset($optionDataArray[$replaceKey]);
1504+
}
1505+
}
1506+
return $optionDataArray;
1507+
}
1508+
1509+
/**
1510+
* Identify ID of the provided option type by its title in the specified store.
1511+
*
1512+
* @param int $optionId
1513+
* @param int $storeId
1514+
* @param string $optionTypeTitle
1515+
* @return int|null
1516+
*/
1517+
private function getExistingOptionTypeId($optionId, $storeId, $optionTypeTitle)
1518+
{
1519+
if (!isset($this->optionTypeTitles[$storeId])) {
1520+
/** @var ProductOptionValueCollection $optionTypeCollection */
1521+
$optionTypeCollection = $this->productOptionValueCollectionFactory->create();
1522+
$optionTypeCollection->addTitleToResult($storeId);
1523+
/** @var \Magento\Catalog\Model\Product\Option\Value $type */
1524+
foreach ($optionTypeCollection as $type) {
1525+
$this->optionTypeTitles[$storeId][$type->getOptionId()][$type->getId()] = $type->getTitle();
1526+
}
1527+
}
1528+
if (isset($this->optionTypeTitles[$storeId][$optionId])
1529+
&& is_array($this->optionTypeTitles[$storeId][$optionId])
1530+
) {
1531+
foreach ($this->optionTypeTitles[$storeId][$optionId] as $optionTypeId => $currentTypeTitle) {
1532+
if ($optionTypeTitle === $currentTypeTitle) {
1533+
return $optionTypeId;
1534+
}
1535+
}
1536+
}
1537+
return null;
1538+
}
1539+
14191540
/**
14201541
* Parse required data from current row and store to class internal variables some data
14211542
* for underlying dependent rows
@@ -1547,13 +1668,13 @@ protected function _getOptionData(array $rowData, $productId, $optionId, $type)
15471668
protected function _getPriceData(array $rowData, $optionId, $type)
15481669
{
15491670
if (in_array(
1550-
'price',
1551-
$this->_specificTypes[$type]
1552-
) && isset(
1553-
$rowData[self::COLUMN_PREFIX . 'price']
1554-
) && strlen(
1555-
$rowData[self::COLUMN_PREFIX . 'price']
1556-
) > 0
1671+
'price',
1672+
$this->_specificTypes[$type]
1673+
) && isset(
1674+
$rowData[self::COLUMN_PREFIX . 'price']
1675+
) && strlen(
1676+
$rowData[self::COLUMN_PREFIX . 'price']
1677+
) > 0
15571678
) {
15581679
$priceData = [
15591680
'option_id' => $optionId,
@@ -1803,13 +1924,17 @@ protected function _updateProducts(array $data)
18031924
* @return array
18041925
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
18051926
*/
1806-
protected function _parseCustomOptions($rowData)
1927+
protected function _parseCustomOptions($rowData)
18071928
{
18081929
$beforeOptionValueSkuDelimiter = ';';
18091930
if (empty($rowData['custom_options'])) {
18101931
return $rowData;
18111932
}
1812-
$rowData['custom_options'] = str_replace($beforeOptionValueSkuDelimiter, $this->_productEntity->getMultipleValueSeparator(), $rowData['custom_options']);
1933+
$rowData['custom_options'] = str_replace(
1934+
$beforeOptionValueSkuDelimiter,
1935+
$this->_productEntity->getMultipleValueSeparator(),
1936+
$rowData['custom_options']
1937+
);
18131938
$options = [];
18141939
$optionValues = explode(Product::PSEUDO_MULTI_LINE_SEPARATOR, $rowData['custom_options']);
18151940
$k = 0;
@@ -1821,7 +1946,7 @@ protected function _parseCustomOptions($rowData)
18211946
if (!empty($nameAndValue)) {
18221947
$value = isset($nameAndValue[1]) ? $nameAndValue[1] : '';
18231948
$value = trim($value);
1824-
$fieldName = trim($nameAndValue[0]);
1949+
$fieldName = trim($nameAndValue[0]);
18251950
if ($value && ($fieldName == 'name')) {
18261951
if ($name != $value) {
18271952
$name = $value;

0 commit comments

Comments
 (0)