Skip to content

Commit 0f00630

Browse files
author
Michael Logvin
committed
MAGETWO-46472: Prepare pull request
1 parent bf4e733 commit 0f00630

File tree

372 files changed

+13250
-6684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+13250
-6684
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
9595
* @param \Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory
9696
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
9797
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
98+
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
9899
* @param ImportProduct\StoreResolver $storeResolver
99100
* @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
100101
* @throws \Magento\Framework\Exception\LocalizedException
@@ -117,6 +118,7 @@ public function __construct(
117118
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
118119
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
119120
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
121+
\Magento\Framework\Model\Entity\MetadataPool $metadataPool,
120122
\Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver,
121123
\Magento\Customer\Api\GroupRepositoryInterface $groupRepository
122124
) {
@@ -139,7 +141,8 @@ public function __construct(
139141
$attributeColFactory,
140142
$_typeFactory,
141143
$linkTypeProvider,
142-
$rowCustomizer
144+
$rowCustomizer,
145+
$metadataPool
143146
);
144147
}
145148

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Export/AdvancedPricingTest.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class AdvancedPricingTest extends \PHPUnit_Framework_TestCase
107107
*/
108108
protected $groupRepository;
109109

110+
/**
111+
* @var \Magento\Framework\Model\Entity\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
112+
*/
113+
protected $metadataPool;
114+
110115
/**
111116
* @var \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter| \PHPUnit_Framework_MockObject_MockObject
112117
*/
@@ -285,6 +290,13 @@ protected function setUp()
285290
'',
286291
false
287292
);
293+
$this->metadataPool = $this->getMock(
294+
'\Magento\Framework\Model\Entity\MetadataPool',
295+
[],
296+
[],
297+
'',
298+
false
299+
);
288300
$this->writer = $this->getMock(
289301
'Magento\ImportExport\Model\Export\Adapter\AbstractAdapter',
290302
[
@@ -344,7 +356,8 @@ protected function setUp()
344356
$this->linkTypeProvider,
345357
$this->rowCustomizer,
346358
$this->storeResolver,
347-
$this->groupRepository
359+
$this->groupRepository,
360+
$this->metadataPool
348361
);
349362
}
350363

app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php

+79-8
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,59 @@
55
*/
66
namespace Magento\Bundle\Controller\Adminhtml\Product\Initialization\Helper\Plugin;
77

8+
use \Magento\Bundle\Api\Data\OptionInterfaceFactory as OptionFactory;
9+
use \Magento\Bundle\Api\Data\LinkInterfaceFactory as LinkFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
11+
use Magento\Store\Model\StoreManagerInterface as StoreManager;
12+
use Magento\Framework\App\RequestInterface;
13+
14+
815
class Bundle
916
{
1017
/**
11-
* @var \Magento\Framework\App\RequestInterface
18+
* @var RequestInterface
1219
*/
1320
protected $request;
1421

1522
/**
16-
* @param \Magento\Framework\App\RequestInterface $request
23+
* @var OptionFactory
24+
*/
25+
protected $optionFactory;
26+
27+
/**
28+
* @var LinkFactory
29+
*/
30+
protected $linkFactory;
31+
32+
/**
33+
* @var ProductRepository
34+
*/
35+
protected $productRepository;
36+
37+
/**
38+
* @var StoreManager
39+
*/
40+
protected $storeManager;
41+
42+
/**
43+
* @param RequestInterface $request
44+
* @param OptionFactory $optionFactory
45+
* @param LinkFactory $linkFactory
46+
* @param ProductRepository $productRepository
47+
* @param StoreManager $storeManager
1748
*/
18-
public function __construct(\Magento\Framework\App\RequestInterface $request)
19-
{
49+
public function __construct(
50+
RequestInterface $request,
51+
OptionFactory $optionFactory,
52+
LinkFactory $linkFactory,
53+
ProductRepository $productRepository,
54+
StoreManager $storeManager
55+
) {
2056
$this->request = $request;
57+
$this->optionFactory = $optionFactory;
58+
$this->linkFactory = $linkFactory;
59+
$this->productRepository = $productRepository;
60+
$this->storeManager =$storeManager;
2161
}
2262

2363
/**
@@ -34,15 +74,47 @@ public function afterInitialize(
3474
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject,
3575
\Magento\Catalog\Model\Product $product
3676
) {
77+
if (($selections = $this->request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
78+
$product->setBundleSelectionsData($selections);
79+
}
3780
if (($items = $this->request->getPost('bundle_options')) && !$product->getCompositeReadonly()) {
3881
$product->setBundleOptionsData($items);
3982
}
4083

41-
if (($selections = $this->request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
42-
$product->setBundleSelectionsData($selections);
84+
if ($product->getBundleOptionsData()) {
85+
$options = [];
86+
foreach ($product->getBundleOptionsData() as $key => $optionData) {
87+
if (!(bool)$optionData['delete']) {
88+
$option = $this->optionFactory->create(['data' => $optionData]);
89+
$option->setSku($product->getSku());
90+
$option->setOptionId(null);
91+
92+
$links = [];
93+
$bundleLinks = $product->getBundleSelectionsData();
94+
if (!empty($bundleLinks[$key])) {
95+
foreach ($bundleLinks[$key] as $linkData) {
96+
if (!(bool)$linkData['delete']) {
97+
$link = $this->linkFactory->create(['data' => $linkData]);
98+
$linkProduct = $this->productRepository->getById($linkData['product_id']);
99+
$link->setSku($linkProduct->getSku());
100+
$link->setQty($linkData['selection_qty']);
101+
$links[] = $link;
102+
}
103+
}
104+
$option->setProductLinks($links);
105+
$options[] = $option;
106+
}
107+
}
108+
}
109+
$extension = $product->getExtensionAttributes();
110+
$extension->setBundleProductOptions($options);
111+
$product->setExtensionAttributes($extension);
43112
}
44113

45-
if ($product->getPriceType() == '0' && !$product->getOptionsReadonly()) {
114+
if (
115+
$product->getPriceType() === \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC
116+
&& !$product->getOptionsReadonly()
117+
) {
46118
$product->setCanSaveCustomOptions(true);
47119
if ($customOptions = $product->getProductOptions()) {
48120
foreach (array_keys($customOptions) as $key) {
@@ -55,7 +127,6 @@ public function afterInitialize(
55127
$product->setCanSaveBundleSelections(
56128
(bool)$this->request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly()
57129
);
58-
59130
return $product;
60131
}
61132
}

app/code/Magento/Bundle/Model/OptionRepository.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class OptionRepository implements \Magento\Bundle\Api\ProductOptionRepositoryInt
6060
*/
6161
protected $dataObjectHelper;
6262

63+
/**
64+
* @var \Magento\Framework\Model\Entity\MetadataPool
65+
*/
66+
protected $metadataPool;
67+
6368
/**
6469
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
6570
* @param Product\Type $type
@@ -80,8 +85,10 @@ public function __construct(
8085
\Magento\Bundle\Api\ProductLinkManagementInterface $linkManagement,
8186
\Magento\Bundle\Model\Product\OptionList $productOptionList,
8287
\Magento\Bundle\Model\Product\LinksList $linkList,
83-
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
88+
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
89+
\Magento\Framework\Model\Entity\MetadataPool $metadataPool
8490
) {
91+
$this->metadataPool = $metadataPool;
8592
$this->productRepository = $productRepository;
8693
$this->type = $type;
8794
$this->optionFactory = $optionFactory;
@@ -166,8 +173,12 @@ public function save(
166173
\Magento\Catalog\Api\Data\ProductInterface $product,
167174
\Magento\Bundle\Api\Data\OptionInterface $option
168175
) {
169-
$option->setStoreId($this->storeManager->getStore()->getId());
170-
$option->setParentId($product->getId());
176+
$option->getResource()->removeOptionSelections($option->getOptionId());
177+
$metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
178+
179+
180+
$option->setStoreId($product->getStoreId());
181+
$option->setParentId($product->getData($metadata->getLinkField()));
171182

172183
$optionId = $option->getOptionId();
173184
if (!$optionId) {

app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php

-65
This file was deleted.

app/code/Magento/Bundle/Model/Plugin/BundleSaveOptions.php

-82
This file was deleted.

0 commit comments

Comments
 (0)