Skip to content

Commit 44af415

Browse files
author
Leonid Poluyanov
committed
MAGETWO-50450: Bundle product has no products in sample data
1 parent 02b20cc commit 44af415

File tree

1 file changed

+61
-44
lines changed

1 file changed

+61
-44
lines changed

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

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
namespace Magento\BundleSampleData\Model;
77

8-
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
98
use Magento\Bundle\Api\Data\OptionInterfaceFactory as OptionFactory;
109
use Magento\Bundle\Api\Data\LinkInterfaceFactory as LinkFactory;
1110
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
11+
use \Magento\Framework\App\ObjectManager;
1212

1313
/**
1414
* Setup bundle product
@@ -23,54 +23,17 @@ class Product extends \Magento\CatalogSampleData\Model\Product
2323
/**
2424
* @var OptionFactory
2525
*/
26-
protected $optionFactory;
26+
private $optionFactory;
2727

2828
/**
2929
* @var LinkFactory
3030
*/
31-
protected $linkFactory;
31+
private $linkFactory;
3232

3333
/**
3434
* @var ProductRepository
3535
*/
36-
protected $productRepository;
37-
38-
/**
39-
* Product constructor.
40-
* @param SampleDataContext $sampleDataContext
41-
* @param \Magento\Catalog\Model\ProductFactory $productFactory
42-
* @param \Magento\Catalog\Model\ConfigFactory $catalogConfig
43-
* @param Product\Converter $converter
44-
* @param \Magento\CatalogSampleData\Model\Product\Gallery $gallery
45-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
46-
* @param \Magento\Eav\Model\Config $eavConfig
47-
*/
48-
public function __construct(
49-
SampleDataContext $sampleDataContext,
50-
\Magento\Catalog\Model\ProductFactory $productFactory,
51-
\Magento\Catalog\Model\ConfigFactory $catalogConfig,
52-
\Magento\BundleSampleData\Model\Product\Converter $converter,
53-
\Magento\CatalogSampleData\Model\Product\Gallery $gallery,
54-
\Magento\Store\Model\StoreManagerInterface $storeManager,
55-
\Magento\Eav\Model\Config $eavConfig,
56-
OptionFactory $optionFactory,
57-
LinkFactory $linkFactory,
58-
ProductRepository $productRepository
59-
) {
60-
$this->eavConfig = $eavConfig;
61-
parent::__construct(
62-
$sampleDataContext,
63-
$productFactory,
64-
$catalogConfig,
65-
$converter,
66-
$gallery,
67-
$storeManager,
68-
$eavConfig
69-
);
70-
$this->optionFactory = $optionFactory;
71-
$this->linkFactory = $linkFactory;
72-
$this->productRepository = $productRepository;
73-
}
36+
private $productRepository;
7437

7538
/**
7639
* @inheritdoc
@@ -85,15 +48,15 @@ protected function prepareProduct($product, $data)
8548
$options = [];
8649
foreach ($bundleOptionsData as $key => $optionData) {
8750

88-
$option = $this->optionFactory->create(['data' => $optionData]);
51+
$option = $this->getOptionFactory()->create(['data' => $optionData]);
8952
$option->setSku($product->getSku());
9053
$option->setOptionId(null);
9154

9255
$links = [];
9356
$bundleLinks = $product->getBundleSelectionsData();
9457
foreach ($bundleLinks[$key] as $linkData) {
95-
$linkProduct = $this->productRepository->getById($linkData['product_id']);
96-
$link = $this->linkFactory->create(['data' => $linkData]);
58+
$linkProduct = $this->getProductRepository()->getById($linkData['product_id']);
59+
$link = $this->getLinkFactory()->create(['data' => $linkData]);
9760
$link->setSku($linkProduct->getSku());
9861
$link->setQty($linkData['selection_qty']);
9962

@@ -112,4 +75,58 @@ protected function prepareProduct($product, $data)
11275

11376
return $this;
11477
}
78+
79+
/**
80+
* Get option interface factory
81+
*
82+
* @deprecated
83+
* @return \Magento\Bundle\Api\Data\OptionInterfaceFactory
84+
*/
85+
private function getOptionFactory()
86+
{
87+
88+
if (!($this->optionFactory)) {
89+
return ObjectManager::getInstance()->get(
90+
'\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks'
91+
);
92+
} else {
93+
return $this->optionFactory;
94+
}
95+
}
96+
97+
/**
98+
* Get bundle link interface factory
99+
*
100+
* @deprecated
101+
* @return \Magento\Bundle\Api\Data\LinkInterfaceFactory
102+
*/
103+
private function getLinkFactory()
104+
{
105+
106+
if (!($this->linkFactory)) {
107+
return ObjectManager::getInstance()->get(
108+
'\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks'
109+
);
110+
} else {
111+
return $this->linkFactory;
112+
}
113+
}
114+
115+
/**
116+
* Get product repository
117+
*
118+
* @deprecated
119+
* @return \Magento\Catalog\Api\ProductRepositoryInterface
120+
*/
121+
private function getProductRepository()
122+
{
123+
124+
if (!($this->productRepository)) {
125+
return ObjectManager::getInstance()->get(
126+
'\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks'
127+
);
128+
} else {
129+
return $this->productRepository;
130+
}
131+
}
115132
}

0 commit comments

Comments
 (0)