10 use Magento\Downloadable\Model\LinkFactory;
29 private $downloadableFile;
34 private $objectCopyService;
39 private $dataObjectHelper;
44 private $componentFactory;
60 File $downloadableFile,
61 Copy $objectCopyService,
63 LinkFactory $componentFactory
65 $this->downloadableFile = $downloadableFile;
66 $this->objectCopyService = $objectCopyService;
68 $this->componentFactory = $componentFactory;
95 $this->dataObjectHelper->populateWithArray(
101 \
Magento\Downloadable\Api\Data\LinkInterface::class
104 if (!isset($this->data[
'file'])) {
105 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Link file not provided'));
107 $linkFileName = $this->downloadableFile->moveFileFromTmp(
112 $link->setLinkFile($linkFileName);
113 $link->setLinkUrl(
null);
116 if (isset($this->data[
'sample'])) {
117 $link = $this->buildSample(
$link, $this->data[
'sample']);
120 if (!
$link->getSortOrder()) {
121 $link->setSortOrder(1);
124 if (!is_numeric(
$link->getPrice())) {
128 if (isset($this->data[
'is_unlimited']) && $this->data[
'is_unlimited']) {
129 $link->setNumberOfDownloads(0);
139 private function resetData()
147 private function getComponent()
149 if (!$this->component) {
150 $this->component = $this->componentFactory->create();
152 return $this->component;
161 private function buildSample(\
Magento\Downloadable\Api\Data\LinkInterface
$link, array $sample)
163 if (!empty($sample[
'url']) || !empty($sample[
'file'])) {
164 $downloadableLinkSampleData = $this->objectCopyService->getDataFromFieldset(
165 'downloadable_link_sample_data',
167 $this->data[
'sample']
169 $this->dataObjectHelper->populateWithArray(
173 $downloadableLinkSampleData
175 \
Magento\Downloadable\Api\Data\LinkInterface::class
178 $linkSampleFileName = $this->downloadableFile->moveFileFromTmp(
183 $link->setSampleFile($linkSampleFileName);
__construct(File $downloadableFile, Copy $objectCopyService, DataObjectHelper $dataObjectHelper, LinkFactory $componentFactory)
build(\Magento\Downloadable\Api\Data\LinkInterface $link)