Skip to content

Commit 07c08e9

Browse files
committed
Merge remote-tracking branch 'falcon/MAGETWO-59743' into MAGETWO-59974
2 parents 24b9d20 + 9574e6e commit 07c08e9

File tree

2 files changed

+111
-2
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import

2 files changed

+111
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ public function validateRow(array $rowData, $rowNum)
23042304

23052305
$sku = $rowData[self::COL_SKU];
23062306

2307-
if (isset($this->_oldSku[$sku])) {
2307+
if (isset($this->_oldSku[$sku]) && Import::BEHAVIOR_REPLACE !== $this->getBehavior()) {
23082308
// can we get all necessary data from existent DB product?
23092309
// check for supported type of existing product
23102310
if (isset($this->_productTypeModels[$this->_oldSku[$sku]['type_id']])) {
@@ -2356,7 +2356,7 @@ public function validateRow(array $rowData, $rowNum)
23562356
$rowAttributesValid = $productTypeValidator->isRowValid(
23572357
$rowData,
23582358
$rowNum,
2359-
!isset($this->_oldSku[$sku])
2359+
!(isset($this->_oldSku[$sku]) && Import::BEHAVIOR_REPLACE !== $this->getBehavior())
23602360
);
23612361
if (!$rowAttributesValid && self::SCOPE_DEFAULT == $rowScope) {
23622362
// mark SCOPE_DEFAULT row as invalid for future child rows if product not in DB already

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,4 +1431,113 @@ public function testProductWithWrappedAdditionalAttributes()
14311431
$this->assertEquals(implode(',', [$multiselectOptions[1]->getValue(), $multiselectOptions[2]->getValue()]),
14321432
$product2->getData('multiselect_attribute'));
14331433
}
1434+
1435+
/**
1436+
* @param array $row
1437+
* @param string|null $behavior
1438+
* @param bool $expectedResult
1439+
* @magentoAppArea adminhtml
1440+
* @magentoAppIsolation enabled
1441+
* @magentoDbIsolation enabled
1442+
* @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/product_simple.php
1443+
* @dataProvider validateRowDataProvider
1444+
*/
1445+
public function testValidateRow(array $row, $behavior, $expectedResult)
1446+
{
1447+
$this->_model->setParameters(['behavior' => $behavior, 'entity' => 'catalog_product']);
1448+
$this->assertSame($expectedResult, $this->_model->validateRow($row, 1));
1449+
}
1450+
1451+
/**
1452+
* @return array
1453+
*/
1454+
public function validateRowDataProvider()
1455+
{
1456+
return [
1457+
[
1458+
'row' => ['sku' => 'simple products'],
1459+
'behavior' => null,
1460+
'expectedResult' => true,
1461+
],
1462+
[
1463+
'row' => ['sku' => 'simple products absent'],
1464+
'behavior' => null,
1465+
'expectedResult' => false,
1466+
],
1467+
[
1468+
'row' => [
1469+
'sku' => 'simple products absent',
1470+
'name' => 'Test',
1471+
'product_type' => 'simple',
1472+
'_attribute_set' => 'Default',
1473+
'price' => 10.20,
1474+
],
1475+
'behavior' => null,
1476+
'expectedResult' => true,
1477+
],
1478+
[
1479+
'row' => ['sku' => 'simple products'],
1480+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
1481+
'expectedResult' => true,
1482+
],
1483+
[
1484+
'row' => ['sku' => 'simple products absent'],
1485+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
1486+
'expectedResult' => false,
1487+
],
1488+
[
1489+
'row' => [
1490+
'sku' => 'simple products absent',
1491+
'name' => 'Test',
1492+
'product_type' => 'simple',
1493+
'_attribute_set' => 'Default',
1494+
'price' => 10.20,
1495+
],
1496+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
1497+
'expectedResult' => true,
1498+
],
1499+
[
1500+
'row' => ['sku' => 'simple products'],
1501+
'behavior' => Import::BEHAVIOR_DELETE,
1502+
'expectedResult' => true,
1503+
],
1504+
[
1505+
'row' => ['sku' => 'simple products absent'],
1506+
'behavior' => Import::BEHAVIOR_DELETE,
1507+
'expectedResult' => false,
1508+
],
1509+
[
1510+
'row' => ['sku' => 'simple products'],
1511+
'behavior' => Import::BEHAVIOR_REPLACE,
1512+
'expectedResult' => false,
1513+
],
1514+
[
1515+
'row' => ['sku' => 'simple products absent'],
1516+
'behavior' => Import::BEHAVIOR_REPLACE,
1517+
'expectedResult' => false,
1518+
],
1519+
[
1520+
'row' => [
1521+
'sku' => 'simple products absent',
1522+
'name' => 'Test',
1523+
'product_type' => 'simple',
1524+
'_attribute_set' => 'Default',
1525+
'price' => 10.20,
1526+
],
1527+
'behavior' => Import::BEHAVIOR_REPLACE,
1528+
'expectedResult' => false,
1529+
],
1530+
[
1531+
'row' => [
1532+
'sku' => 'simple products',
1533+
'name' => 'Test',
1534+
'product_type' => 'simple',
1535+
'_attribute_set' => 'Default',
1536+
'price' => 10.20,
1537+
],
1538+
'behavior' => Import::BEHAVIOR_REPLACE,
1539+
'expectedResult' => true,
1540+
],
1541+
];
1542+
}
14341543
}

0 commit comments

Comments
 (0)