Skip to content

Commit 5a44486

Browse files
ENGCOM-7137: Fix the error that is wrong link title of a downloadable product when enabling 'Use Default Value' #27295
- Merge Pull Request #27295 from tna274/magento2:magento2.4/fixbug_default_link_title - Merged commits: 1. 4c40dad 2. 53136a2 3. 5a2c9b7 4. 2a2b98a 5. 7962557 6. e918d3b 7. d421504 8. a242e3a 9. 947eaed 10. 6cd3bf7
2 parents def8a07 + 6cd3bf7 commit 5a44486

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Downloadable\Model\Link;
78

89
use Magento\Downloadable\Helper\File;
@@ -12,7 +13,8 @@
1213
use Magento\Framework\DataObject\Copy;
1314

1415
/**
15-
* Class Builder
16+
* Builder download link model for downloadable product
17+
*
1618
* @api
1719
* @since 100.1.0
1820
*/
@@ -116,7 +118,7 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
116118
$link->setLinkFile($linkFileName);
117119
$link->setLinkUrl(null);
118120
}
119-
121+
120122
if (isset($this->data['sample'])) {
121123
$link = $this->buildSample($link, $this->data['sample']);
122124
}
@@ -132,6 +134,12 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
132134
if (isset($this->data['is_unlimited']) && $this->data['is_unlimited']) {
133135
$link->setNumberOfDownloads(0);
134136
}
137+
138+
$useDefaultTitle = $this->data['use_default_title'] ?? false;
139+
140+
if ($useDefaultTitle) {
141+
$link->setTitle(null);
142+
}
135143
$this->resetData();
136144

137145
return $link;

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Downloadable\Model\Sample;
78

89
use Magento\Downloadable\Api\Data\SampleInterface;
@@ -14,7 +15,8 @@
1415
use Magento\Framework\DataObject\Copy;
1516

1617
/**
17-
* Class Builder
18+
* Builder download sample link model for downloadable product
19+
*
1820
* @api
1921
* @since 100.1.0
2022
*/
@@ -24,7 +26,7 @@ class Builder
2426
* @var Sample
2527
*/
2628
private $component;
27-
29+
2830
/**
2931
* @var File
3032
*/
@@ -71,6 +73,8 @@ public function __construct(
7173
}
7274

7375
/**
76+
* Init data for builder
77+
*
7478
* @param array $data
7579
* @return $this;
7680
* @since 100.1.0
@@ -82,6 +86,8 @@ public function setData(array $data)
8286
}
8387

8488
/**
89+
* Build sample link
90+
*
8591
* @param SampleInterface $sample
8692
* @return SampleInterface
8793
* @throws \Magento\Framework\Exception\LocalizedException
@@ -116,12 +122,20 @@ public function build(SampleInterface $sample)
116122
if (!$sample->getSortOrder()) {
117123
$sample->setSortOrder(1);
118124
}
125+
126+
$useDefaultTitle = $this->data['use_default_title'] ?? false;
127+
128+
if ($useDefaultTitle) {
129+
$sample->setTitle(null);
130+
}
119131
$this->resetData();
120132

121133
return $sample;
122134
}
123135

124136
/**
137+
* Reset data
138+
*
125139
* @return void
126140
*/
127141
private function resetData()
@@ -130,6 +144,8 @@ private function resetData()
130144
}
131145

132146
/**
147+
* Get component
148+
*
133149
* @return Sample
134150
*/
135151
private function getComponent()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Downloadable\Test\Unit\Model\Link;
78

89
use Magento\Downloadable\Api\Data\LinkInterface;
@@ -11,7 +12,7 @@
1112
use Magento\Downloadable\Helper\Download;
1213

1314
/**
14-
* Class BuilderTest
15+
* Unit test for downloadable products' builder link class
1516
*/
1617
class BuilderTest extends \PHPUnit\Framework\TestCase
1718
{
@@ -68,7 +69,7 @@ protected function setUp()
6869
$this->linkMock = $this->getMockBuilder(LinkInterface::class)
6970
->disableOriginalConstructor()
7071
->getMockForAbstractClass();
71-
72+
7273
$this->service = $objectManagerHelper->getObject(
7374
Builder::class,
7475
[
@@ -160,6 +161,10 @@ public function testBuild($data, $expectedPrice)
160161
if (isset($data['is_unlimited'])) {
161162
$this->linkMock->expects($this->once())->method('setNumberOfDownloads')->with(0);
162163
}
164+
$useDefaultTitle = $data['use_default_title'] ?? false;
165+
if ($useDefaultTitle) {
166+
$this->linkMock->expects($this->once())->method('setTitle')->with(null);
167+
}
163168
if (isset($data['price'])) {
164169
$this->linkMock->expects($this->once())->method('getPrice')->willReturn($data['price']);
165170
} else {
@@ -219,6 +224,7 @@ public function buildProvider()
219224
[
220225
'file' => 'cXVlIHRhbA==',
221226
'type' => 'file',
227+
'use_default_title' => '1',
222228
'sample' => [
223229
'file' => 'cXVlIHRhbA==',
224230
'type' => 'file'

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Downloadable\Test\Unit\Model\Sample;
78

89
use Magento\Downloadable\Api\Data\SampleInterface;
@@ -11,7 +12,7 @@
1112
use Magento\Downloadable\Model\Sample\Builder;
1213

1314
/**
14-
* Class BuilderTest
15+
* Unit test for downloadable products' builder sample class
1516
*/
1617
class BuilderTest extends \PHPUnit\Framework\TestCase
1718
{
@@ -84,6 +85,7 @@ public function testBuild()
8485
{
8586
$data = [
8687
'file' => 'cXVlIHRhbA==',
88+
'use_default_title' => '1',
8789
'type' => 'file'
8890
];
8991
$downloadableData = ['sort_order' => 1];
@@ -122,8 +124,12 @@ public function testBuild()
122124
)->willReturn($fileName);
123125
$this->sampleMock->expects($this->once())->method('setSampleFile')->with($fileName);
124126
$this->sampleMock->expects($this->once())->method('setSortOrder')->with(1);
127+
$useDefaultTitle = $data['use_default_title'] ?? false;
128+
if ($useDefaultTitle) {
129+
$this->sampleMock->expects($this->once())->method('setTitle')->with(null);
130+
}
125131
$this->service->setData($data);
126-
132+
127133
$this->service->build($this->sampleMock);
128134
}
129135
}

0 commit comments

Comments
 (0)