Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the error that is wrong link title of a downloadable product when enabling "Use Default Value" #27295

Merged
6 changes: 5 additions & 1 deletion app/code/Magento/Downloadable/Model/Link/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
$link->setLinkFile($linkFileName);
$link->setLinkUrl(null);
}

if (isset($this->data['sample'])) {
$link = $this->buildSample($link, $this->data['sample']);
}
Expand All @@ -132,6 +132,10 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
if (isset($this->data['is_unlimited']) && $this->data['is_unlimited']) {
$link->setNumberOfDownloads(0);
}

if (isset($this->data['use_default_title']) && $this->data['use_default_title'] == '1') {
$link->setTitle(null);
}
$this->resetData();

return $link;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function setUp()
$this->linkMock = $this->getMockBuilder(LinkInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->service = $objectManagerHelper->getObject(
Builder::class,
[
Expand Down Expand Up @@ -160,6 +160,9 @@ public function testBuild($data, $expectedPrice)
if (isset($data['is_unlimited'])) {
$this->linkMock->expects($this->once())->method('setNumberOfDownloads')->with(0);
}
if (isset($data['use_default_title']) && $data['use_default_title'] == '1') {
$this->linkMock->expects($this->once())->method('getTitle')->with(null);
}
if (isset($data['price'])) {
$this->linkMock->expects($this->once())->method('getPrice')->willReturn($data['price']);
} else {
Expand Down