Skip to content

Commit adf67e7

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95653' into 2.2-develop-pr61
2 parents 4f63342 + 32405ba commit adf67e7

File tree

6 files changed

+51
-3
lines changed

6 files changed

+51
-3
lines changed

app/code/Magento/Catalog/Model/Category/Product/PositionResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function getPositions(int $categoryId)
5252
$categoryId
5353
)->order(
5454
'ccp.position ' . \Magento\Framework\DB\Select::SQL_ASC
55+
)->order(
56+
'ccp.product_id ' . \Magento\Framework\DB\Select::SQL_DESC
5557
);
5658

5759
return array_flip($connection->fetchCol($select));

app/code/Magento/Catalog/Test/Unit/Model/Category/Product/PositionResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testGetPositions()
105105
$this->select->expects($this->once())
106106
->method('where')
107107
->willReturnSelf();
108-
$this->select->expects($this->once())
108+
$this->select->expects($this->exactly(2))
109109
->method('order')
110110
->willReturnSelf();
111111
$this->select->expects($this->once())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ protected function _saveProductCategories(array $categoriesData)
13721372
$delProductId[] = $productId;
13731373

13741374
foreach (array_keys($categories) as $categoryId) {
1375-
$categoriesIn[] = ['product_id' => $productId, 'category_id' => $categoryId, 'position' => 1];
1375+
$categoriesIn[] = ['product_id' => $productId, 'category_id' => $categoryId, 'position' => 0];
13761376
}
13771377
}
13781378
if (Import::BEHAVIOR_APPEND != $this->getBehavior()) {

dev/tests/integration/testsuite/Magento/Catalog/_files/category_product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)->setParentId(
1616
2
1717
)->setPath(
18-
'1/2/3'
18+
'1/2/333'
1919
)->setLevel(
2020
2
2121
)->setAvailableSortBy(

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class ProductTest extends \Magento\TestFramework\Indexer\TestCase
6969
*/
7070
private $logger;
7171

72+
/**
73+
* @inheritdoc
74+
*/
7275
protected function setUp()
7376
{
7477
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -79,6 +82,7 @@ protected function setUp()
7982
\Magento\CatalogImportExport\Model\Import\Product::class,
8083
['logger' => $this->logger]
8184
);
85+
8286
parent::setUp();
8387
}
8488

@@ -1278,6 +1282,46 @@ public function testProductPositionInCategory()
12781282
}
12791283
}
12801284

1285+
/**
1286+
* @magentoAppArea adminhtml
1287+
* @magentoDbIsolation enabled
1288+
* @magentoAppIsolation enabled
1289+
* @magentoDataFixture Magento/Catalog/_files/category_product.php
1290+
*/
1291+
public function testNewProductPositionInCategory()
1292+
{
1293+
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
1294+
1295+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
1296+
$source = $this->objectManager->create(
1297+
\Magento\ImportExport\Model\Import\Source\Csv::class,
1298+
[
1299+
'file' => __DIR__ . '/_files/product_to_import_with_category.csv',
1300+
'directory' => $directory,
1301+
]
1302+
);
1303+
$errors = $this->_model->setSource(
1304+
$source
1305+
)->setParameters(
1306+
[
1307+
'behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND,
1308+
'entity' => 'catalog_product',
1309+
]
1310+
)->validateData();
1311+
1312+
$this->assertTrue($errors->getErrorsCount() === 0);
1313+
$this->_model->importData();
1314+
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);
1323+
}
1324+
12811325
/**
12821326
* @return array
12831327
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,product_type,store_view_code,name,price,attribute_set_code,categories
2+
simpleImported,simple,,"simple Imported",25,Default,"Default Category/Category 1"

0 commit comments

Comments
 (0)