Skip to content

Commit b72077e

Browse files
author
Yaroslav Onischenko
committed
Merge remote-tracking branch 'origin/MAGETWO-50649' into develop
2 parents 6b62a79 + 72e3546 commit b72077e

File tree

1 file changed

+113
-0
lines changed
  • app/code/Magento/DownloadableSampleData/Model

1 file changed

+113
-0
lines changed

app/code/Magento/DownloadableSampleData/Model/Product.php

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
namespace Magento\DownloadableSampleData\Model;
77

88
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
9+
use Magento\Downloadable\Api\Data\SampleInterfaceFactory as SampleFactory;
10+
use Magento\Downloadable\Api\Data\LinkInterfaceFactory as LinkFactory;
11+
use \Magento\Framework\App\ObjectManager;
912

1013
/**
1114
* Setup downloadable product
@@ -27,6 +30,16 @@ class Product extends \Magento\CatalogSampleData\Model\Product
2730
*/
2831
protected $downloadableData = [];
2932

33+
/**
34+
* @var SampleFactory
35+
*/
36+
protected $sampleFactory;
37+
38+
/**
39+
* @var LinkFactory
40+
*/
41+
protected $linkFactory;
42+
3043
/**
3144
* Product constructor.
3245
* @param SampleDataContext $sampleDataContext
@@ -96,9 +109,109 @@ public function install(array $productFixtures, array $galleryFixtures, array $d
96109
protected function prepareProduct($product, $data)
97110
{
98111
if (isset($this->downloadableData[$data['sku']])) {
112+
$extension = $product->getExtensionAttributes();
113+
$links = [];
114+
foreach ($this->downloadableData[$data['sku']]['link'] as $linkData) {
115+
$link = $this->getLinkFactory()->create(['data' => $linkData]);
116+
if (isset($linkData['type'])) {
117+
$link->setLinkType($linkData['type']);
118+
}
119+
if (isset($linkData['file'])) {
120+
$link->setFile($linkData['file']);
121+
}
122+
if (isset($linkData['file_content'])) {
123+
$link->setLinkFileContent($linkData['file_content']);
124+
}
125+
$link->setId(null);
126+
if (isset($linkData['sample']['type'])) {
127+
$link->setSampleType($linkData['sample']['type']);
128+
}
129+
if (isset($linkData['sample']['file'])) {
130+
$link->setSampleFileData($linkData['sample']['file']);
131+
}
132+
if (isset($linkData['sample']['url'])) {
133+
$link->setSampleUrl($linkData['sample']['url']);
134+
}
135+
if (isset($linkData['sample']['file_content'])) {
136+
$link->setSampleFileContent($linkData['file_content']);
137+
}
138+
$link->setStoreId($product->getStoreId());
139+
$link->setWebsiteId($product->getStore()->getWebsiteId());
140+
$link->setProductWebsiteIds($product->getWebsiteIds());
141+
if (!$link->getSortOrder()) {
142+
$link->setSortOrder(1);
143+
}
144+
if (null === $link->getPrice()) {
145+
$link->setPrice(0);
146+
}
147+
if ($link->getIsUnlimited()) {
148+
$link->setNumberOfDownloads(0);
149+
}
150+
$links[] = $link;
151+
}
152+
$extension->setDownloadableProductLinks($links);
153+
154+
$samples = [];
155+
foreach ($this->downloadableData[$data['sku']]['sample'] as $sampleData) {
156+
$sample = $this->getSampleFactory()->create(['data' => $sampleData]);
157+
$sample->setId(null);
158+
$sample->setStoreId($product->getStoreId());
159+
if (isset($sampleData['type'])) {
160+
$sample->setSampleType($sampleData['type']);
161+
}
162+
if (isset($sampleData['file'])) {
163+
$sample->setFile($sampleData['file']);
164+
}
165+
if (isset($sampleData['sample_url'])) {
166+
$sample->setSampleUrl($sampleData['sample_url']);
167+
}
168+
if (!$sample->getSortOrder()) {
169+
$sample->setSortOrder(1);
170+
}
171+
$samples[] = $sample;
172+
}
173+
$extension->setDownloadableProductSamples($samples);
174+
99175
$product->setDownloadableData($this->downloadableData[$data['sku']]);
176+
$product->setExtensionAttributes($extension);
100177
}
101178
$this->setVirtualStockData($product);
102179
return $this;
103180
}
181+
182+
/**
183+
* Get link interface factory
184+
*
185+
* @deprecated
186+
* @return \Magento\Downloadable\Api\Data\LinkInterfaceFactory
187+
*/
188+
private function getLinkFactory()
189+
{
190+
191+
if (!($this->linkFactory)) {
192+
return ObjectManager::getInstance()->get(
193+
'\Magento\Downloadable\Api\Data\LinkInterfaceFactory'
194+
);
195+
} else {
196+
return $this->linkFactory;
197+
}
198+
}
199+
200+
/**
201+
* Get sample interface factory
202+
*
203+
* @deprecated
204+
* @return \Magento\Downloadable\Api\Data\SampleInterfaceFactory
205+
*/
206+
private function getSampleFactory()
207+
{
208+
209+
if (!($this->sampleFactory)) {
210+
return ObjectManager::getInstance()->get(
211+
'\Magento\Downloadable\Api\Data\SampleInterfaceFactory'
212+
);
213+
} else {
214+
return $this->sampleFactory;
215+
}
216+
}
104217
}

0 commit comments

Comments
 (0)