Hello @dipind4u. Thanks for reporting. Probably we've missed something but currently we are not able to reproduce Your issue. Here is what we did in order to get it reproduced.
We had 16 products called S1, S2,...,S16. Then we related to some of them three others to each as follows:
S1 - related S16, S15, S14
S2 - related S15, S14, S13
S5 - related S12, S11, S10.
Then exported these products to CSV.
Then in CSV file we changed the names of S10-S16 to S10name-S16name relatively. So we updated a bit those products.
Then re-imported them. As a result all the products in both areas were correctly displayed.
So please tell us where we have misunderstand You.
I will explain the issue with example .
Suppose i have 100 products named s1,s2,s3,s4 ...s100 .
I have to add related products to all of these products .For example ,s1's related products are s2,s3,s4,s5,s6 and s2's related products are s1,s3,s4,s5,s6 .For bulk update i am using default import option .If i am updating the related products using csv ,then only 2 related products will be shown in the backend (product edit page)and all 5 products will display in front end(product detail view page) .
Ok @dipind4u, We have recorded three videos where we were trying to reproduce Your issue. Sorry for its bad quality, but we hope You won't miss the essential things in it. As You will see we are still not able to reproduce Your issue. So please after You have watched the videos tell us what we do incorrectly not as You mean or what we've missed. Thank You.
@dipind4u, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.
I have the same issue: only 2 related products are shown in admin. Below steps to reproduce:
After that only 2 products related to P1 will be shown in admin (in frontend everything is ok).
Bug is in class Magento\Catalog\Model\ProductLink\CollectionProvider on method getCollection
foreach ($output as $item) {
$itemPosition = $item['position'];
if (!isset($sorterItems[$itemPosition])) {
$sorterItems[$itemPosition] = $item;
} else {
$newPosition = $itemPosition + 1;
$sorterItems[$newPosition] = $item;
}
}
@magento-engcom-team Could you reopen this issue?
I have the same issue. I have migrated the data from M1 to M2.
@KrzysztofMoskalik is right. The problem is +1 that overrides value in the array $sorterItems.
Let me explain with example
P1 R1 0
P1 R2 1
P1 R3 1
P1 R4 2
P1 R5 2
Where P1 is main product R1-R5 is related product and numbers in last column is sort position.
And i am missing related product R4 in magento admin. By the logic in the code shown by @KrzysztofMoskalik $sorterItems array will look like at the end [0 => R1, 1=> R2, 2=> R3, 3=> R5]
@magento-engcom-team please reopen this issue.
@magento-engcom-team: I've reopened the issue, since there is an update and some good information pointing towards the cause of this bug (I've seen this thing happen myself, but hadn't had the change yet to look into the problem, so thanks to @KrzysztofMoskalik & @gulshan-streammarket for the extra info!)
I fixed this by doing this in the function @KrzysztofMoskalik said:
foreach ($output as $item) {
$itemPosition = (int)$item['position'];
while(true) {
if (!isset($sorterItems[$itemPosition])) {
break;
}
$itemPosition += 1;
}
$sorterItems[$itemPosition] = $item;
}
@hostep @gulshan-streammarket @dipind4u
What is the current status of this issue? Will it ever be merged into core?
I believe https://github.com/magento/magento2/pull/15251 should be re-opened and re-evaluated because it was closed for an incorrect reason.
@dipind4u, thank you for your report.
We've acknowledged the issue and added to our backlog.
I think the problem here is that the import behavior will only add related skus, never remove them.
Let's start with 2 related skus already in the database:
SKU | Position
------------ | -------------
OLD-1 | 1
OLD-2 | 2
If I upload this:
sku,related_skus,related_position
MYSKU,"NEW-1,NEW-2","1,2"
I expect that the new skus would overwrite the old skus in their positions, like:
SKU | Position
------------ | -------------
NEW-1 | 1
NEW-2 | 2
Instead it will only add skus to the list and trigger this bug, like:
SKU | Position
------------ | -------------
OLD-1 | 1
OLD-2 | 2
NEW-1 | 1
NEW-2 | 2
Likewise, if I upload:
sku,related_skus,related_position
MYSKU,"","1,2"
I'd expect the empty field to cause Magento to remove the related skus at positions 1 and 2. Instead, this simply does nothing.
Hi @dipind4u. Thank you for your report.
The issue has been fixed in magento/magento2#17885 by @hostep in 2.2-develop branch
Related commit(s):
The fix will be available with the upcoming 2.2.8 release.
Hi @dipind4u. Thank you for your report.
The issue has been fixed in magento/magento2#18207 by @hostep in 2.3-develop branch
Related commit(s):
The fix will be available with the upcoming 2.3.1 release.
After i have added this fix in my Magento2.2.6 version all the related products are showing, but i cannot properly sort the related products from backend. Unable to move the position of related products.
@ameshca: indeed, you are correct, if some positions of those linked products in the database are non-unique you might have problems dragging the products in the grid correctly. But what can help is just randomly dragging multiple products in all kind of positions in the grid, until the grid has generated enough unique sorting positions that it starts working properly again. Which is a bit tedious to do, but it seems to work when I'm quickly trying this.
Or you can try to update the positions directly in your database so they are unique per linked product (but make sure you test this first on a local/staging environment and don't do this directly on production without proper testing).
@ameshca: indeed, you are correct, if some positions of those linked products in the database are non-unique you might have problems dragging the products in the grid correctly. But what can help is just randomly dragging multiple products in all kind of positions in the grid, until the grid has generated enough unique sorting positions that it starts working properly again. Which is a bit tedious to do, but it seems to work when I'm quickly trying this.
Or you can try to update the positions directly in your database so they are unique per linked product (but make sure you test this first on a local/staging environment and don't do this directly on production without proper testing).
Yes, your are correct. I have updated the positions directly from database and now its working fine. Thanks @hostep
I fixed this by doing this in the function @KrzysztofMoskalik said:
foreach ($output as $item) { $itemPosition = (int)$item['position']; while(true) { if (!isset($sorterItems[$itemPosition])) { break; } $itemPosition += 1; } $sorterItems[$itemPosition] = $item; }
@hostep @gulshan-streammarket @dipind4u
@robbertstevens Is this solution is safe to implement? Will it effect other data in admin?
@ChintanKaneriya havent noticed any side effects
Most helpful comment
I have the same issue: only 2 related products are shown in admin. Below steps to reproduce:
After that only 2 products related to P1 will be shown in admin (in frontend everything is ok).
Bug is in class Magento\Catalog\Model\ProductLink\CollectionProvider on method getCollection
foreach ($output as $item) { $itemPosition = $item['position']; if (!isset($sorterItems[$itemPosition])) { $sorterItems[$itemPosition] = $item; } else { $newPosition = $itemPosition + 1; $sorterItems[$newPosition] = $item; } }
@magento-engcom-team Could you reopen this issue?