Skip to content

Commit 9b08b0b

Browse files
committed
Merge pull request #231 from magento-firedrakes/MAGETWO-46472
[Firedrakes] Sprint 53
2 parents 77988b6 + c78a700 commit 9b08b0b

File tree

454 files changed

+17810
-7395
lines changed

Some content is hidden

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

454 files changed

+17810
-7395
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ 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
101+
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
100102
* @throws \Magento\Framework\Exception\LocalizedException
101103
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
102104
*/
@@ -117,6 +119,7 @@ public function __construct(
117119
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
118120
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
119121
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
122+
\Magento\Framework\Model\Entity\MetadataPool $metadataPool,
120123
\Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver,
121124
\Magento\Customer\Api\GroupRepositoryInterface $groupRepository
122125
) {
@@ -139,7 +142,8 @@ public function __construct(
139142
$attributeColFactory,
140143
$_typeFactory,
141144
$linkTypeProvider,
142-
$rowCustomizer
145+
$rowCustomizer,
146+
$metadataPool
143147
);
144148
}
145149

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

Lines changed: 13 additions & 0 deletions
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
[
@@ -343,6 +355,7 @@ protected function setUp()
343355
$this->typeFactory,
344356
$this->linkTypeProvider,
345357
$this->rowCustomizer,
358+
$this->metadataPool,
346359
$this->storeResolver,
347360
$this->groupRepository
348361
);

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

Lines changed: 158 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,71 @@
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\Data\ProductCustomOptionInterfaceFactory;
11+
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
12+
use Magento\Store\Model\StoreManagerInterface as StoreManager;
13+
use Magento\Framework\App\RequestInterface;
14+
15+
/**
16+
* Class Bundle
17+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
*/
819
class Bundle
920
{
1021
/**
11-
* @var \Magento\Framework\App\RequestInterface
22+
* @var ProductCustomOptionInterfaceFactory
23+
*/
24+
protected $customOptionFactory;
25+
26+
/**
27+
* @var RequestInterface
1228
*/
1329
protected $request;
1430

1531
/**
16-
* @param \Magento\Framework\App\RequestInterface $request
32+
* @var OptionFactory
1733
*/
18-
public function __construct(\Magento\Framework\App\RequestInterface $request)
19-
{
34+
protected $optionFactory;
35+
36+
/**
37+
* @var LinkFactory
38+
*/
39+
protected $linkFactory;
40+
41+
/**
42+
* @var ProductRepository
43+
*/
44+
protected $productRepository;
45+
46+
/**
47+
* @var StoreManager
48+
*/
49+
protected $storeManager;
50+
51+
/**
52+
* @param RequestInterface $request
53+
* @param OptionFactory $optionFactory
54+
* @param LinkFactory $linkFactory
55+
* @param ProductRepository $productRepository
56+
* @param StoreManager $storeManager
57+
* @param ProductCustomOptionInterfaceFactory $customOptionFactory
58+
*/
59+
public function __construct(
60+
RequestInterface $request,
61+
OptionFactory $optionFactory,
62+
LinkFactory $linkFactory,
63+
ProductRepository $productRepository,
64+
StoreManager $storeManager,
65+
ProductCustomOptionInterfaceFactory $customOptionFactory
66+
) {
2067
$this->request = $request;
68+
$this->optionFactory = $optionFactory;
69+
$this->linkFactory = $linkFactory;
70+
$this->productRepository = $productRepository;
71+
$this->storeManager = $storeManager;
72+
$this->customOptionFactory = $customOptionFactory;
2173
}
2274

2375
/**
@@ -29,33 +81,122 @@ public function __construct(\Magento\Framework\App\RequestInterface $request)
2981
* @return \Magento\Catalog\Model\Product
3082
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3183
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
84+
* @SuppressWarnings(PHPMD.NPathComplexity)
3285
*/
3386
public function afterInitialize(
3487
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject,
3588
\Magento\Catalog\Model\Product $product
3689
) {
37-
if (($items = $this->request->getPost('bundle_options')) && !$product->getCompositeReadonly()) {
90+
$compositeReadonly = $product->getCompositeReadonly();
91+
$selections = $this->request->getPost('bundle_selections');
92+
if ($selections && !$compositeReadonly) {
93+
$product->setBundleSelectionsData($selections);
94+
}
95+
96+
$items = $this->request->getPost('bundle_options');
97+
if ($items && !$compositeReadonly) {
3898
$product->setBundleOptionsData($items);
3999
}
40100

41-
if (($selections = $this->request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
42-
$product->setBundleSelectionsData($selections);
101+
$this->processBundleOptionsData($product);
102+
103+
$this->processDynamicOptionsData($product);
104+
105+
$affectProductSelections = (bool)$this->request->getPost('affect_bundle_product_selections');
106+
$product->setCanSaveBundleSelections($affectProductSelections && !$compositeReadonly);
107+
return $product;
108+
}
109+
110+
/**
111+
* @param \Magento\Catalog\Model\Product $product
112+
* @return void
113+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
114+
*/
115+
protected function processBundleOptionsData(\Magento\Catalog\Model\Product $product)
116+
{
117+
$bundleOptionsData = $product->getBundleOptionsData();
118+
if (!$bundleOptionsData) {
119+
return;
43120
}
121+
$options = [];
122+
foreach ($bundleOptionsData as $key => $optionData) {
123+
if ((bool)$optionData['delete']) {
124+
continue;
125+
}
126+
$option = $this->optionFactory->create(['data' => $optionData]);
127+
$option->setSku($product->getSku());
128+
$option->setOptionId(null);
129+
130+
$links = [];
131+
$bundleLinks = $product->getBundleSelectionsData();
132+
if (empty($bundleLinks[$key])) {
133+
continue;
134+
}
135+
136+
foreach ($bundleLinks[$key] as $linkData) {
137+
if ((bool)$linkData['delete']) {
138+
continue;
139+
}
140+
$link = $this->linkFactory->create(['data' => $linkData]);
141+
142+
if (array_key_exists('selection_price_value', $linkData)) {
143+
$link->setPrice($linkData['selection_price_value']);
144+
}
145+
146+
if (array_key_exists('selection_price_type', $linkData)) {
147+
$link->setPriceType($linkData['selection_price_type']);
148+
}
44149

45-
if ($product->getPriceType() == '0' && !$product->getOptionsReadonly()) {
46-
$product->setCanSaveCustomOptions(true);
47-
if ($customOptions = $product->getProductOptions()) {
48-
foreach (array_keys($customOptions) as $key) {
49-
$customOptions[$key]['is_delete'] = 1;
150+
$linkProduct = $this->productRepository->getById($linkData['product_id']);
151+
$link->setSku($linkProduct->getSku());
152+
$link->setQty($linkData['selection_qty']);
153+
154+
if (array_key_exists('selection_can_change_qty', $linkData)) {
155+
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
50156
}
51-
$product->setProductOptions($customOptions);
157+
$links[] = $link;
52158
}
159+
$option->setProductLinks($links);
160+
$options[] = $option;
53161
}
54162

55-
$product->setCanSaveBundleSelections(
56-
(bool)$this->request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly()
57-
);
163+
$extension = $product->getExtensionAttributes();
164+
$extension->setBundleProductOptions($options);
165+
$product->setExtensionAttributes($extension);
166+
return;
167+
}
58168

59-
return $product;
169+
/**
170+
* @param \Magento\Catalog\Model\Product $product
171+
* @return void
172+
*/
173+
protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $product)
174+
{
175+
if ($product->getPriceType() !== \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
176+
return;
177+
}
178+
179+
if ($product->getOptionsReadonly()) {
180+
return;
181+
}
182+
$product->setCanSaveCustomOptions(true);
183+
$customOptions = $product->getProductOptions();
184+
if (!$customOptions) {
185+
return;
186+
}
187+
foreach (array_keys($customOptions) as $key) {
188+
$customOptions[$key]['is_delete'] = 1;
189+
}
190+
$newOptions = $product->getOptions();
191+
foreach ($customOptions as $customOptionData) {
192+
if ((bool)$customOptionData['is_delete']) {
193+
continue;
194+
}
195+
$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
196+
$customOption->setProductSku($product->getSku());
197+
$customOption->setOptionId(null);
198+
$newOptions[] = $customOption;
199+
}
200+
$product->setOptions($newOptions);
60201
}
61202
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public function addChild(
254254

255255
try {
256256
$selectionModel->save();
257-
$resource->addProductRelations($product->getId(), [$linkProductModel->getId()]);
257+
$resource->addProductRelation($product->getId(), $linkProductModel->getId());
258258
} catch (\Exception $e) {
259259
throw new CouldNotSaveException(__('Could not save child: "%1"', $e->getMessage()), $e);
260260
}
@@ -281,6 +281,7 @@ public function removeChild($sku, $optionId, $childSku)
281281
foreach ($option->getSelections() as $selection) {
282282
if ((strcasecmp($selection->getSku(), $childSku) == 0) && ($selection->getOptionId() == $optionId)) {
283283
$removeSelectionIds[] = $selection->getSelectionId();
284+
$usedProductIds[] = $selection->getProductId();
284285
continue;
285286
}
286287
$excludeSelectionIds[] = $selection->getSelectionId();

0 commit comments

Comments
 (0)