Skip to content

Commit 77b74f7

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-borg/MAGETWO-91555
2 parents a90e08d + 2375461 commit 77b74f7

File tree

19 files changed

+209
-19
lines changed

19 files changed

+209
-19
lines changed

app/code/Magento/Catalog/Api/ProductAttributeOptionManagementInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getItems($attributeCode);
2929
* @param \Magento\Eav\Api\Data\AttributeOptionInterface $option
3030
* @throws \Magento\Framework\Exception\StateException
3131
* @throws \Magento\Framework\Exception\InputException
32-
* @return bool
32+
* @return string
3333
*/
3434
public function add($attributeCode, $option);
3535

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,19 @@ public function getMultipleValueSeparator()
909909
return Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
910910
}
911911

912+
/**
913+
* Return empty attribute value constant
914+
*
915+
* @return string
916+
*/
917+
public function getEmptyAttributeValueConstant()
918+
{
919+
if (!empty($this->_parameters[Import::FIELD_EMPTY_ATTRIBUTE_VALUE_CONSTANT])) {
920+
return $this->_parameters[Import::FIELD_EMPTY_ATTRIBUTE_VALUE_CONSTANT];
921+
}
922+
return Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT;
923+
}
924+
912925
/**
913926
* Retrieve instance of product custom options import entity
914927
*

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection as ProductOptionValueCollection;
1414
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory as ProductOptionValueCollectionFactory;
1515
use Magento\Store\Model\Store;
16+
use Magento\ImportExport\Model\Import;
1617

1718
/**
1819
* Entity class which provide possibility to import product custom options
@@ -1090,7 +1091,7 @@ protected function _getMultiRowFormat($rowData)
10901091
// Parse custom options.
10911092
$rowData = $this->_parseCustomOptions($rowData);
10921093
$multiRow = [];
1093-
if (empty($rowData['custom_options'])) {
1094+
if (empty($rowData['custom_options']) || !is_array($rowData['custom_options'])) {
10941095
return $multiRow;
10951096
}
10961097

@@ -1235,7 +1236,12 @@ protected function _importData()
12351236
$multiRowData = $this->_getMultiRowFormat($rowData);
12361237
if (!empty($rowData[self::COLUMN_SKU]) && isset($this->_productsSkuToId[$rowData[self::COLUMN_SKU]])) {
12371238
$this->_rowProductId = $this->_productsSkuToId[$rowData[self::COLUMN_SKU]];
1238-
if (array_key_exists('custom_options', $rowData) && trim($rowData['custom_options']) === '') {
1239+
if (array_key_exists('custom_options', $rowData)
1240+
&& (
1241+
trim($rowData['custom_options']) === '' ||
1242+
trim($rowData['custom_options']) === $this->_productEntity->getEmptyAttributeValueConstant()
1243+
)
1244+
) {
12391245
$optionsToRemove[] = $this->_rowProductId;
12401246
}
12411247
}
@@ -1923,7 +1929,8 @@ protected function _updateProducts(array $data)
19231929
protected function _parseCustomOptions($rowData)
19241930
{
19251931
$beforeOptionValueSkuDelimiter = ';';
1926-
if (empty($rowData['custom_options'])) {
1932+
if (empty($rowData['custom_options'])
1933+
|| $rowData['custom_options'] === Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT) {
19271934
return $rowData;
19281935
}
19291936
$rowData['custom_options'] = str_replace(

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ public function clearEmptyData(array $rowData)
537537
if (!$attrParams['is_static'] && !isset($rowData[$attrCode])) {
538538
unset($rowData[$attrCode]);
539539
}
540+
541+
if (isset($rowData[$attrCode])
542+
&& $rowData[$attrCode] === $this->_entityModel->getEmptyAttributeValueConstant()
543+
) {
544+
$rowData[$attrCode] = null;
545+
}
540546
}
541547
return $rowData;
542548
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ public function isRequiredAttributeValid($attrCode, array $attributeParams, arra
150150
$doCheck = true;
151151
}
152152

153-
return $doCheck ? isset($rowData[$attrCode]) && strlen(trim($rowData[$attrCode])) : true;
153+
if ($doCheck === true) {
154+
return isset($rowData[$attrCode])
155+
&& strlen(trim($rowData[$attrCode]))
156+
&& trim($rowData[$attrCode]) !== $this->context->getEmptyAttributeValueConstant();
157+
}
158+
return true;
154159
}
155160

156161
/**
@@ -188,6 +193,11 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData)
188193
if (!strlen(trim($rowData[$attrCode]))) {
189194
return true;
190195
}
196+
197+
if ($rowData[$attrCode] === $this->context->getEmptyAttributeValueConstant() && !$attrParams['is_required']) {
198+
return true;
199+
}
200+
191201
switch ($attrParams['type']) {
192202
case 'varchar':
193203
case 'text':

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ class Quantity extends AbstractImportValidator implements RowValidatorInterface
1818
public function isValid($value)
1919
{
2020
$this->_clearMessages();
21-
if (!empty($value['qty']) && !is_numeric($value['qty'])) {
21+
if (!empty($value['qty']) && (!is_numeric($value['qty'])
22+
&& $value['qty'] !== $this->context->getEmptyAttributeValueConstant())
23+
) {
2224
$this->_addMessages(
2325
[
2426
sprintf(

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class Weight extends AbstractImportValidator implements RowValidatorInterface
1515
public function isValid($value)
1616
{
1717
$this->_clearMessages();
18-
if (!empty($value['weight']) && (!is_numeric($value['weight']) || $value['weight'] < 0)) {
18+
if (!empty($value['weight']) && (!is_numeric($value['weight']) || $value['weight'] < 0)
19+
&& $value['weight'] !== $this->context->getEmptyAttributeValueConstant()
20+
) {
1921
$this->_addMessages(
2022
[
2123
sprintf(

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/QuantityTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\CatalogImportExport\Model\Import\Product;
99
use Magento\CatalogImportExport\Model\Import\Product\Validator\Quantity;
10+
use Magento\ImportExport\Model\Import;
1011

1112
/**
1213
* Class QuantityTest
@@ -25,6 +26,10 @@ protected function setUp()
2526
$contextStub = $this->getMockBuilder(Product::class)
2627
->disableOriginalConstructor()
2728
->getMock();
29+
$contextStub->expects($this->any())
30+
->method('getEmptyAttributeValueConstant')
31+
->willReturn(Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT);
32+
2833
$contextStub->method('retrieveMessageTemplate')->willReturn(null);
2934
$this->quantity->init($contextStub);
3035
}
@@ -54,6 +59,9 @@ public function isValidDataProvider()
5459
[true, ['qty' => '']],
5560
[false, ['qty' => 'abc']],
5661
[false, ['qty' => true]],
62+
[false, ['qty' => true]],
63+
[true, ['qty' => Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT]],
64+
[false, ['qty' => '__EMPTY__VALUE__TEST__']],
5765
];
5866
}
5967
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Test\Unit\Model\Import\Product\Validator;
9+
10+
use Magento\CatalogImportExport\Model\Import\Product;
11+
use Magento\CatalogImportExport\Model\Import\Product\Validator\Weight;
12+
use Magento\ImportExport\Model\Import;
13+
14+
/**
15+
* Class WeightTest
16+
*/
17+
class WeightTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var Weight
21+
*/
22+
private $weight;
23+
24+
protected function setUp()
25+
{
26+
$this->weight = new Weight();
27+
28+
$contextStub = $this->getMockBuilder(Product::class)
29+
->disableOriginalConstructor()
30+
->getMock();
31+
$contextStub->expects($this->any())
32+
->method('getEmptyAttributeValueConstant')
33+
->willReturn(Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT);
34+
35+
$contextStub->method('retrieveMessageTemplate')->willReturn(null);
36+
$this->weight->init($contextStub);
37+
}
38+
39+
/**
40+
* @param bool $expectedResult
41+
* @param array $value
42+
* @dataProvider isValidDataProvider
43+
*/
44+
public function testIsValid($expectedResult, $value)
45+
{
46+
$result = $this->weight->isValid($value);
47+
$this->assertEquals($expectedResult, $result);
48+
}
49+
50+
/**
51+
* @return array
52+
*/
53+
public function isValidDataProvider()
54+
{
55+
return [
56+
[true, ['weight' => 0]],
57+
[true, ['weight' => 1]],
58+
[true, ['weight' => 5]],
59+
[false, ['weight' => -1]],
60+
[false, ['weight' => -10]],
61+
[true, ['weight' => '']],
62+
[false, ['weight' => 'abc']],
63+
[false, ['weight' => true]],
64+
[false, ['weight' => true]],
65+
[true, ['weight' => Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT]],
66+
[false, ['weight' => '__EMPTY__VALUE__TEST__']],
67+
];
68+
}
69+
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,28 @@ public function testGetMultipleValueSeparatorFromParameters()
603603
);
604604
}
605605

606+
public function testGetEmptyAttributeValueConstantDefault()
607+
{
608+
$this->setPropertyValue($this->importProduct, '_parameters', null);
609+
$this->assertEquals(
610+
Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT,
611+
$this->importProduct->getEmptyAttributeValueConstant()
612+
);
613+
}
614+
615+
public function testGetEmptyAttributeValueConstantFromParameters()
616+
{
617+
$expectedSeparator = '__EMPTY__VALUE__TEST__';
618+
$this->setPropertyValue($this->importProduct, '_parameters', [
619+
\Magento\ImportExport\Model\Import::FIELD_EMPTY_ATTRIBUTE_VALUE_CONSTANT => $expectedSeparator,
620+
]);
621+
622+
$this->assertEquals(
623+
$expectedSeparator,
624+
$this->importProduct->getEmptyAttributeValueConstant()
625+
);
626+
}
627+
606628
public function testDeleteProductsForReplacement()
607629
{
608630
$importProduct = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Product::class)

0 commit comments

Comments
 (0)