Skip to content

Commit ab2e9f8

Browse files
committed
ACPT-1429: PR stabilization
1 parent a48c57b commit ab2e9f8

File tree

7 files changed

+83
-31
lines changed

7 files changed

+83
-31
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*
2323
* @SuppressWarnings(PHPMD.TooManyFields)
2424
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2526
* @since 100.0.2
2627
*/
2728
abstract class AbstractType

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,42 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
220220
return true;
221221
}
222222

223-
if ($rowData[$attrCode] === $this->context->getEmptyAttributeValueConstant() && !$attrParams['is_required']) {
223+
if ($rowData[$attrCode] === $this->context->getEmptyAttributeValueConstant()
224+
&& !$attrParams['is_required']) {
224225
return true;
225226
}
226227
}
227228

229+
$valid = $this->validateByAttributeType($attrCode, $attrParams, $rowData);
230+
231+
if ($valid && !empty($attrParams['is_unique'])) {
232+
if (isset($this->_uniqueAttributes[$attrCode][$rowData[$attrCode]])
233+
&& ($this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] != $rowData[Product::COL_SKU])) {
234+
$this->_addMessages([RowValidatorInterface::ERROR_DUPLICATE_UNIQUE_ATTRIBUTE]);
235+
return false;
236+
}
237+
$this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] = $rowData[Product::COL_SKU];
238+
}
239+
240+
if (!$valid) {
241+
$this->setInvalidAttribute($attrCode);
242+
}
243+
244+
return (bool)$valid;
245+
}
246+
247+
/**
248+
* Validates attribute type.
249+
*
250+
* @param string $attrCode
251+
* @param array $attrParams
252+
* @param array $rowData
253+
* @return bool
254+
*/
255+
private function validateByAttributeType(string $attrCode, array $attrParams, array $rowData): bool
256+
{
228257
$valid = false;
258+
229259
switch ($attrParams['type']) {
230260
case 'varchar':
231261
case 'text':
@@ -266,20 +296,7 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
266296
break;
267297
}
268298

269-
if ($valid && !empty($attrParams['is_unique'])) {
270-
if (isset($this->_uniqueAttributes[$attrCode][$rowData[$attrCode]])
271-
&& ($this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] != $rowData[Product::COL_SKU])) {
272-
$this->_addMessages([RowValidatorInterface::ERROR_DUPLICATE_UNIQUE_ATTRIBUTE]);
273-
return false;
274-
}
275-
$this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] = $rowData[Product::COL_SKU];
276-
}
277-
278-
if (!$valid) {
279-
$this->setInvalidAttribute($attrCode);
280-
}
281-
282-
return (bool)$valid;
299+
return $valid;
283300
}
284301

285302
/**

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Media.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class Media extends AbstractImportValidator implements RowValidatorInterface
1515
* @deprecated As this regexp doesn't give guarantee of correct url validation
1616
* @see \Magento\Framework\Url\Validator::isValid()
1717
*/
18-
const URL_REGEXP = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i';
18+
private const URL_REGEXP = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i';
1919

20-
const PATH_REGEXP = '#^(?!.*[\\/]\.{2}[\\/])(?!\.{2}[\\/])[-\w.\\/]+$#';
20+
private const PATH_REGEXP = '#^(?!.*[\\/]\.{2}[\\/])(?!\.{2}[\\/])[-\w.\\/]+$#';
2121

22-
const ADDITIONAL_IMAGES = 'additional_images';
22+
private const ADDITIONAL_IMAGES = 'additional_images';
2323

2424
/**
2525
* The url validator. Checks if given url is valid.
@@ -40,14 +40,16 @@ public function __construct(Validator $validator = null)
4040
* @deprecated
4141
* @see \Magento\CatalogImportExport\Model\Import\Product::getMultipleValueSeparator()
4242
*/
43-
const ADDITIONAL_IMAGES_DELIMITER = ',';
43+
private const ADDITIONAL_IMAGES_DELIMITER = ',';
4444

4545
/**
4646
* @var array
4747
*/
4848
protected $mediaAttributes = ['image', 'small_image', 'thumbnail'];
4949

5050
/**
51+
* Checks if the provided $string parameter is a valid URL or not.
52+
*
5153
* @param string $string
5254
* @return bool
5355
* @deprecated 100.2.0 As this method doesn't give guarantee of correct url validation.
@@ -59,6 +61,8 @@ protected function checkValidUrl($string)
5961
}
6062

6163
/**
64+
* Validates a provided string as a file or directory path.
65+
*
6266
* @param string $string
6367
* @return bool
6468
*/
@@ -68,6 +72,8 @@ protected function checkPath($string)
6872
}
6973

7074
/**
75+
* Checks whether a file or directory exists at a given path
76+
*
7177
* @param string $path
7278
* @return bool
7379
*/

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Website.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(\Magento\CatalogImportExport\Model\Import\Product\St
2424
}
2525

2626
/**
27-
* {@inheritdoc}
27+
* @inheritdoc
2828
*/
2929
public function isValid($value)
3030
{

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,18 @@ private function getFieldAndValuePairs(array|string $variation): array
612612
}
613613

614614
$fieldAndValuePairsText = explode($this->_entityModel->getMultipleValueSeparator(), $variation);
615+
616+
return $this->processFieldAndValuePairs($fieldAndValuePairsText);
617+
}
618+
619+
/**
620+
* Process field and value pairs.
621+
*
622+
* @param array $fieldAndValuePairsText
623+
* @return array
624+
*/
625+
private function processFieldAndValuePairs(array $fieldAndValuePairsText): array
626+
{
615627
$fieldAndValuePairs = [];
616628
$fieldName = null;
617629

app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,20 @@ protected function prepareSampleData($rowCol, $entityId = null)
837837
private function prepareStructuredSampleData(array $samples, $entityId = null): array
838838
{
839839
$result = [];
840+
840841
foreach ($samples as $sample) {
841-
$result[] = array_merge(
842-
$this->dataSample,
843-
['product_id' => $entityId],
844-
$this->parseStructuredSampleOption($sample)
845-
);
842+
$structuredSampleOption = $this->parseStructuredSampleOption($sample);
843+
844+
$temp = [];
845+
foreach ($this->dataSample as $key => $value) {
846+
$temp[$key] = $value;
847+
}
848+
$temp['product_id'] = $entityId;
849+
foreach ($structuredSampleOption as $key => $value) {
850+
$temp[$key] = $value;
851+
}
852+
853+
$result[] = $temp;
846854
}
847855

848856
return $result;
@@ -883,12 +891,17 @@ protected function prepareLinkData($rowCol, $entityId = null)
883891
private function prepareStructuredLinkData(array $links, $entityId = null): array
884892
{
885893
$result = [];
894+
886895
foreach ($links as $link) {
887-
$result[] = array_merge(
888-
$this->dataLink,
889-
['product_id' => $entityId],
890-
$this->parseStructuredLinkOption($link)
891-
);
896+
$linkOptions = $this->parseStructuredLinkOption($link);
897+
$newLink = $this->dataLink;
898+
899+
foreach ($linkOptions as $key => $value) {
900+
$newLink[$key] = $value;
901+
}
902+
903+
$newLink['product_id'] = $entityId;
904+
$result[] = $newLink;
892905
}
893906

894907
return $result;

app/code/Magento/ImportExport/Model/Import/Source/Json.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\ImportExport\Model\Import\Source;
79

810
use Magento\Framework\Exception\ValidatorException;
@@ -66,7 +68,7 @@ public function __construct(
6668
// convert all scalar values to strings
6769
$this->items = array_map(function ($item) {
6870
return array_map(function ($value) {
69-
return is_scalar($value) ? strval($value) : $value;
71+
return is_scalar($value) ? (string) $value : $value;
7072
}, $item);
7173
}, $this->items);
7274
if (isset($this->items[0])) {
@@ -106,6 +108,7 @@ public function rewind()
106108
* @param int $position
107109
* @return void
108110
*/
111+
#[\ReturnTypeWillChange]
109112
public function seek($position)
110113
{
111114
$this->position = $position;

0 commit comments

Comments
 (0)