Skip to content

Commit f55e9fc

Browse files
committed
MAGETWO-95653: Product positions are incorrect after import
1 parent 1f5d708 commit f55e9fc

File tree

1 file changed

+11
-27
lines changed
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import

1 file changed

+11
-27
lines changed

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

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,18 +1290,14 @@ public function testProductPositionInCategory()
12901290
*/
12911291
public function testNewProductPositionInCategory()
12921292
{
1293-
$categoryId = 333;
1294-
1295-
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
1296-
\Magento\Framework\Filesystem::class
1297-
);
1293+
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
12981294

12991295
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
13001296
$source = $this->objectManager->create(
13011297
\Magento\ImportExport\Model\Import\Source\Csv::class,
13021298
[
13031299
'file' => __DIR__ . '/_files/product_to_import_with_category.csv',
1304-
'directory' => $directory
1300+
'directory' => $directory,
13051301
]
13061302
);
13071303
$errors = $this->_model->setSource(
@@ -1313,29 +1309,17 @@ public function testNewProductPositionInCategory()
13131309
]
13141310
)->validateData();
13151311

1316-
$this->assertTrue($errors->getErrorsCount() == 0);
1312+
$this->assertTrue($errors->getErrorsCount() === 0);
13171313
$this->_model->importData();
13181314

1319-
/** @var \Magento\Framework\App\ResourceConnection $resourceConnection */
1320-
$resourceConnection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
1321-
\Magento\Framework\App\ResourceConnection::class
1322-
);
1323-
$categoryProductstableName = $resourceConnection->getTableName('catalog_category_product');
1324-
$productEntitiesTableName = $resourceConnection->getTableName('catalog_product_entity');
1325-
$select = $resourceConnection->getConnection()
1326-
->select()
1327-
->from(['category_products' => $categoryProductstableName])
1328-
->join(
1329-
['product_entities' => $productEntitiesTableName],
1330-
'product_entities.entity_id = category_products.product_id',
1331-
''
1332-
)
1333-
->where('category_products.category_id = ?', $categoryId)
1334-
->where('product_entities.sku = "simpleImported"');
1335-
$importedItem = $resourceConnection->getConnection()->fetchRow($select);
1336-
$this->assertTrue(is_array($importedItem));
1337-
$this->assertNotEmpty($importedItem);
1338-
$this->assertEquals(0, $importedItem['position']);
1315+
/** @var ProductRepositoryInterface $productRepository */
1316+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
1317+
/** @var ProductInterface $product */
1318+
$product = $productRepository->get('simpleImported');
1319+
$categoryLinks = $product->getExtensionAttributes('category_links')->getCategoryLinks();
1320+
$position = $categoryLinks[0]->getPosition();
1321+
1322+
$this->assertEquals(0, $position);
13391323
}
13401324

13411325
/**

0 commit comments

Comments
 (0)