Skip to content

Commit addb913

Browse files
committed
MAGETWO-95653: Product positions are incorrect after import
1 parent 65c9a58 commit addb913

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
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()) {

0 commit comments

Comments
 (0)