Skip to content

Commit

Permalink
Merge pull request #612 from magento-okapis/MAGETWO-60479-Import-Prod…
Browse files Browse the repository at this point in the history
…ucts

[Okapis] MAGETWO-60479: Importing existing products with 'Replace' behavior
  • Loading branch information
Joan He authored Nov 21, 2016
2 parents 056ffbe + f4b1eeb commit 7186af8
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,8 @@ public function validateRow(array $rowData, $rowNum)

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

if (isset($this->_oldSku[$sku])) {
$isNewProduct = !isset($this->_oldSku[$sku]) || (Import::BEHAVIOR_REPLACE == $this->getBehavior());
if (!$isNewProduct) {
// can we get all necessary data from existent DB product?
// check for supported type of existing product
if (isset($this->_productTypeModels[$this->_oldSku[$sku]['type_id']])) {
Expand Down Expand Up @@ -2346,7 +2347,7 @@ public function validateRow(array $rowData, $rowNum)
$rowAttributesValid = $this->_productTypeModels[$newSku['type_id']]->isRowValid(
$rowData,
$rowNum,
!isset($this->_oldSku[$sku])
$isNewProduct
);
if (!$rowAttributesValid && self::SCOPE_DEFAULT == $rowScope) {
// mark SCOPE_DEFAULT row as invalid for future child rows if product not in DB already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,4 +1383,168 @@ public function testProductWithWrappedAdditionalAttributes()
$this->assertEquals(implode(',', [$multiselectOptions[1]->getValue(), $multiselectOptions[2]->getValue()]),
$product2->getData('multiselect_attribute'));
}

/**
* @param array $row
* @param string|null $behavior
* @param bool $expectedResult
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/product_simple.php
* @dataProvider validateRowDataProvider
*/
public function testValidateRow(array $row, $behavior, $expectedResult)
{
$this->_model->setParameters(['behavior' => $behavior, 'entity' => 'catalog_product']);
$this->assertSame($expectedResult, $this->_model->validateRow($row, 1));
}

/**
* @return array
*/
public function validateRowDataProvider()
{
return [
[
'row' => ['sku' => 'simple products'],
'behavior' => null,
'expectedResult' => true,
],
[
'row' => ['sku' => 'simple products absent'],
'behavior' => null,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products absent',
'name' => 'Test',
'product_type' => 'simple',
'_attribute_set' => 'Default',
'price' => 10.20,
],
'behavior' => null,
'expectedResult' => true,
],
[
'row' => ['sku' => 'simple products'],
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
'expectedResult' => true,
],
[
'row' => ['sku' => 'simple products absent'],
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products absent',
'name' => 'Test',
'product_type' => 'simple',
'_attribute_set' => 'Default',
'price' => 10.20,
],
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
'expectedResult' => true,
],
[
'row' => ['sku' => 'simple products'],
'behavior' => Import::BEHAVIOR_DELETE,
'expectedResult' => true,
],
[
'row' => ['sku' => 'simple products absent'],
'behavior' => Import::BEHAVIOR_DELETE,
'expectedResult' => false,
],
[
'row' => ['sku' => 'simple products'],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
[
'row' => ['sku' => 'simple products absent'],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products absent',
'name' => 'Test',
'product_type' => 'simple',
'_attribute_set' => 'Default',
'price' => 10.20,
],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products',
'name' => 'Test',
'product_type' => 'simple',
'_attribute_set' => 'Default',
'price' => 10.20,
],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => true,
],
[
'row' => [
'sku' => null,
'name' => 'Test',
'product_type' => 'simple',
'_attribute_set' => 'Default',
'price' => 10.20,
],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products',
'name' => null,
'product_type' => 'simple',
'_attribute_set' => 'Default',
'price' => 10.20,
],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products',
'name' => 'Test',
'product_type' => null,
'_attribute_set' => 'Default',
'price' => 10.20,
],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products',
'name' => 'Test',
'product_type' => 'simple',
'_attribute_set' => null,
'price' => 10.20,
],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
[
'row' => [
'sku' => 'simple products',
'name' => 'Test',
'product_type' => 'simple',
'_attribute_set' => 'Default',
'price' => null,
],
'behavior' => Import::BEHAVIOR_REPLACE,
'expectedResult' => false,
],
];
}
}

0 comments on commit 7186af8

Please sign in to comment.