Skip to content

Commit bc77c1f

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'mainline/develop' into pull-request
2 parents e3bb6a4 + 0dfd558 commit bc77c1f

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,11 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
8888
'to_link',
8989
$this->data
9090
);
91-
$downloadableLinkSampleData = $this->objectCopyService->getDataFromFieldset(
92-
'downloadable_link_sample_data',
93-
'to_link_sample',
94-
$this->data['sample']
95-
);
9691
$this->dataObjectHelper->populateWithArray(
9792
$link,
9893
array_merge(
9994
$this->data,
100-
$downloadableData,
101-
$downloadableLinkSampleData
95+
$downloadableData
10296
),
10397
\Magento\Downloadable\Api\Data\LinkInterface::class
10498
);
@@ -114,8 +108,10 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
114108
$link->setLinkFile($linkFileName);
115109
$link->setLinkUrl(null);
116110
}
117-
118-
$link = $this->buildSample($link, $this->data['sample']);
111+
112+
if (isset($this->data['sample'])) {
113+
$link = $this->buildSample($link, $this->data['sample']);
114+
}
119115

120116
if (!$link->getSortOrder()) {
121117
$link->setSortOrder(1);
@@ -161,6 +157,19 @@ private function getComponent()
161157
private function buildSample(\Magento\Downloadable\Api\Data\LinkInterface $link, array $sample)
162158
{
163159
if (!empty($sample['url']) || !empty($sample['file'])) {
160+
$downloadableLinkSampleData = $this->objectCopyService->getDataFromFieldset(
161+
'downloadable_link_sample_data',
162+
'to_link_sample',
163+
$this->data['sample']
164+
);
165+
$this->dataObjectHelper->populateWithArray(
166+
$link,
167+
array_merge(
168+
$this->data,
169+
$downloadableLinkSampleData
170+
),
171+
\Magento\Downloadable\Api\Data\LinkInterface::class
172+
);
164173
if ($link->getSampleType() === \Magento\Downloadable\Helper\Download::LINK_TYPE_FILE) {
165174
$linkSampleFileName = $this->downloadableFile->moveFileFromTmp(
166175
$this->getComponent()->getBaseSampleTmpPath(),

app/code/Magento/Downloadable/Test/Unit/Model/Link/BuilderTest.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,24 @@ public function testBuild($data, $expectedPrice)
108108
)->willReturn($downloadableData);
109109
$this->service->setData($data);
110110
$this->dataObjectHelperMock->method('populateWithArray')
111-
->with(
112-
$this->linkMock,
113-
array_merge(
114-
$data,
115-
$downloadableData
116-
),
117-
LinkInterface::class
111+
->withConsecutive(
112+
[
113+
$this->linkMock,
114+
array_merge(
115+
$data,
116+
$downloadableData
117+
),
118+
LinkInterface::class
119+
],
120+
[
121+
$this->linkMock,
122+
array_merge(
123+
$data,
124+
$downloadableData,
125+
$data['sample']
126+
),
127+
LinkInterface::class
128+
]
118129
)->willReturn($this->linkMock);
119130
$this->linkMock->expects($this->once())->method('getLinkType')->willReturn(Download::LINK_TYPE_FILE);
120131
$linkModel = $this->getMockBuilder(Link::class)
@@ -172,16 +183,11 @@ public function testBuildFileNotProvided()
172183
]
173184
];
174185
$downloadableData = ['sort_order' => 1];
175-
$this->objectCopyServiceMock->expects($this->exactly(2))->method('getDataFromFieldset')->withConsecutive(
186+
$this->objectCopyServiceMock->expects($this->once())->method('getDataFromFieldset')->withConsecutive(
176187
[
177188
'downloadable_data',
178189
'to_link',
179190
$data
180-
],
181-
[
182-
'downloadable_link_sample_data',
183-
'to_link_sample',
184-
$data['sample']
185191
]
186192
)->willReturn($downloadableData);
187193
$this->service->setData($data);

0 commit comments

Comments
 (0)