Skip to content

Commit ebba9e7

Browse files
committed
Merge pull request #553 from magento-firedrakes/MAGETWO-51969
[Firedrakes] Bugfixes
2 parents a4dd876 + 5699064 commit ebba9e7

File tree

18 files changed

+1042
-707
lines changed

18 files changed

+1042
-707
lines changed

app/code/Magento/Downloadable/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Downloadable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function afterInitialize(
7777
if (!$linkData || (isset($linkData['is_delete']) && (bool)$linkData['is_delete'])) {
7878
continue;
7979
} else {
80-
//unset($linkData['link_id']);
8180
// TODO: need to implement setLinkFileContent()
8281
$link = $this->linkFactory->create(['data' => $linkData]);
8382
if (isset($linkData['type'])) {
@@ -89,6 +88,7 @@ public function afterInitialize(
8988
if (isset($linkData['file_content'])) {
9089
$link->setLinkFileContent($linkData['file_content']);
9190
}
91+
$link->setId(null);
9292
if (isset($linkData['link_id'])) {
9393
$link->setId($linkData['link_id']);
9494
}
@@ -128,10 +128,11 @@ public function afterInitialize(
128128
continue;
129129
} else {
130130
$sample = $this->sampleFactory->create(['data' => $sampleData]);
131-
$sample->setStoreId($product->getStoreId());
131+
$sample->setId(null);
132132
if (isset($sampleData['sample_id'])) {
133133
$sample->setId($sampleData['sample_id']);
134134
}
135+
$sample->setStoreId($product->getStoreId());
135136
if (isset($sampleData['type'])) {
136137
$sample->setSampleType($sampleData['type']);
137138
}

app/code/Magento/Downloadable/Model/Link/SaveHandler.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,24 @@ public function __construct(LinkRepository $linkRepository)
3636
*/
3737
public function execute($entityType, $entity, $arguments = [])
3838
{
39-
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
4039
if ($entity->getTypeId() !== 'downloadable') {
4140
return $entity;
4241
}
43-
44-
$oldLinks = $this->linkRepository->getList($entity->getSku());
4542
$links = $entity->getExtensionAttributes()->getDownloadableProductLinks() ?: [];
46-
$updatedLinkIds = [];
43+
$updatedLinks = [];
44+
$oldLinks = $this->linkRepository->getList($entity->getSku());
4745
foreach ($links as $link) {
4846
if ($link->getId()) {
49-
$updatedLinkIds[] = $link->getId();
47+
$updatedLinks[$link->getId()] = true;
5048
}
5149
$this->linkRepository->save($entity->getSku(), $link, !(bool)$entity->getStoreId());
5250
}
51+
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
5352
foreach ($oldLinks as $link) {
54-
if (!in_array($link->getId(), $updatedLinkIds)) {
53+
if (!isset($updatedLinks[$link->getId()])) {
5554
$this->linkRepository->delete($link->getId());
5655
}
5756
}
58-
5957
return $entity;
6058
}
6159
}

0 commit comments

Comments
 (0)