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
12 changes: 10 additions & 2 deletions app/code/Magento/Downloadable/Model/Link/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Downloadable\Model\Link;

use Magento\Downloadable\Helper\File;
Expand All @@ -12,7 +13,8 @@
use Magento\Framework\DataObject\Copy;

/**
* Class Builder
* Builder download link model for downloadable product
*
* @api
* @since 100.1.0
*/
Expand Down Expand Up @@ -116,7 +118,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 +134,12 @@ public function build(\Magento\Downloadable\Api\Data\LinkInterface $link)
if (isset($this->data['is_unlimited']) && $this->data['is_unlimited']) {
$link->setNumberOfDownloads(0);
}

$useDefaultTitle = $this->data['use_default_title'] ?? false;

if ($useDefaultTitle) {
$link->setTitle(null);
}
$this->resetData();

return $link;
Expand Down
14 changes: 12 additions & 2 deletions app/code/Magento/Downloadable/Model/Sample/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Downloadable\Model\Sample;

use Magento\Downloadable\Api\Data\SampleInterface;
Expand All @@ -14,7 +15,8 @@
use Magento\Framework\DataObject\Copy;

/**
* Class Builder
* Builder download sample link model for downloadable product
*
* @api
* @since 100.1.0
*/
Expand All @@ -24,7 +26,7 @@ class Builder
* @var Sample
*/
private $component;

/**
* @var File
*/
Expand Down Expand Up @@ -71,6 +73,8 @@ public function __construct(
}

/**
* Init data for builder
*
* @param array $data
* @return $this;
* @since 100.1.0
Expand All @@ -82,6 +86,8 @@ public function setData(array $data)
}

/**
* Build sample link
*
* @param SampleInterface $sample
* @return SampleInterface
* @throws \Magento\Framework\Exception\LocalizedException
Expand Down Expand Up @@ -122,6 +128,8 @@ public function build(SampleInterface $sample)
}

/**
* Reset data
*
* @return void
*/
private function resetData()
Expand All @@ -130,6 +138,8 @@ private function resetData()
}

/**
* Get component
*
* @return Sample
*/
private function getComponent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Downloadable\Test\Unit\Model\Link;

use Magento\Downloadable\Api\Data\LinkInterface;
Expand All @@ -11,7 +12,7 @@
use Magento\Downloadable\Helper\Download;

/**
* Class BuilderTest
* Unit test for downloadable products' builder link class
*/
class BuilderTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -68,7 +69,7 @@ protected function setUp()
$this->linkMock = $this->getMockBuilder(LinkInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->service = $objectManagerHelper->getObject(
Builder::class,
[
Expand Down Expand Up @@ -160,6 +161,10 @@ public function testBuild($data, $expectedPrice)
if (isset($data['is_unlimited'])) {
$this->linkMock->expects($this->once())->method('setNumberOfDownloads')->with(0);
}
$useDefaultTitle = $data['use_default_title'] ?? false;
if ($useDefaultTitle) {
$this->linkMock->expects($this->once())->method('setTitle')->with(null);
}
if (isset($data['price'])) {
$this->linkMock->expects($this->once())->method('getPrice')->willReturn($data['price']);
} else {
Expand Down Expand Up @@ -219,6 +224,7 @@ public function buildProvider()
[
'file' => 'cXVlIHRhbA==',
'type' => 'file',
'use_default_title' => '1',
'sample' => [
'file' => 'cXVlIHRhbA==',
'type' => 'file'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Downloadable\Test\Unit\Model\Sample;

use Magento\Downloadable\Api\Data\SampleInterface;
Expand All @@ -11,7 +12,7 @@
use Magento\Downloadable\Model\Sample\Builder;

/**
* Class BuilderTest
* Unit test for downloadable products' builder sample class
*/
class BuilderTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -123,7 +124,7 @@ public function testBuild()
$this->sampleMock->expects($this->once())->method('setSampleFile')->with($fileName);
$this->sampleMock->expects($this->once())->method('setSortOrder')->with(1);
$this->service->setData($data);

$this->service->build($this->sampleMock);
}
}