Skip to content

Commit 8216ad4

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-pangolin/RE-develop
2 parents 2349014 + 4832a75 commit 8216ad4

File tree

70 files changed

+1878
-1289
lines changed

Some content is hidden

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

70 files changed

+1878
-1289
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ language: php
1818
php:
1919
- 7.1
2020
- 7.2
21+
git:
22+
depth: 5
2123
env:
2224
global:
2325
- COMPOSER_BIN_DIR=~/bin

app/code/Magento/Backend/Block/Template.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Backend\Block;
710

811
/**
@@ -17,10 +20,12 @@
1720
* Example:
1821
* <block name="my.block" class="Magento\Backend\Block\Template" template="My_Module::template.phtml" >
1922
* <arguments>
20-
* <argument name="viewModel" xsi:type="object">My\Module\ViewModel\Custom</argument>
23+
* <argument name="view_model" xsi:type="object">My\Module\ViewModel\Custom</argument>
2124
* </arguments>
2225
* </block>
2326
*
27+
* Your class object can then be accessed by doing $block->getViewModel()
28+
*
2429
* @api
2530
* @SuppressWarnings(PHPMD.NumberOfChildren)
2631
* @since 100.0.2

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
137137
</field>
138138
<field id="template_hints_blocks" translate="label" type="select" sortOrder="21" showInDefault="1" showInWebsite="1" showInStore="1">
139-
<label>Add Block Names to Hints</label>
139+
<label>Add Block Class Type to Hints</label>
140140
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
141141
</field>
142142
</group>
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Model\Option;
9+
10+
use Magento\Bundle\Api\Data\OptionInterface;
11+
use Magento\Bundle\Model\ResourceModel\Option;
12+
use Magento\Catalog\Api\Data\ProductInterface;
13+
use Magento\Framework\EntityManager\MetadataPool;
14+
use Magento\Framework\Exception\CouldNotSaveException;
15+
use Magento\Bundle\Model\Product\Type;
16+
use Magento\Bundle\Api\ProductLinkManagementInterface;
17+
18+
/**
19+
* Encapsulates logic for saving a bundle option, including coalescing the parent product's data.
20+
*/
21+
class SaveAction
22+
{
23+
/**
24+
* @var Option
25+
*/
26+
private $optionResource;
27+
28+
/**
29+
* @var MetadataPool
30+
*/
31+
private $metadataPool;
32+
33+
/**
34+
* @var Type
35+
*/
36+
private $type;
37+
38+
/**
39+
* @var ProductLinkManagementInterface
40+
*/
41+
private $linkManagement;
42+
43+
/**
44+
* @param Option $optionResource
45+
* @param MetadataPool $metadataPool
46+
* @param Type $type
47+
* @param ProductLinkManagementInterface $linkManagement
48+
*/
49+
public function __construct(
50+
Option $optionResource,
51+
MetadataPool $metadataPool,
52+
Type $type,
53+
ProductLinkManagementInterface $linkManagement
54+
) {
55+
$this->optionResource = $optionResource;
56+
$this->metadataPool = $metadataPool;
57+
$this->type = $type;
58+
$this->linkManagement = $linkManagement;
59+
}
60+
61+
/**
62+
* Manage the logic of saving a bundle option, including the coalescence of its parent product data.
63+
*
64+
* @param ProductInterface $bundleProduct
65+
* @param OptionInterface $option
66+
* @return OptionInterface
67+
* @throws CouldNotSaveException
68+
* @throws \Exception
69+
*/
70+
public function save(ProductInterface $bundleProduct, OptionInterface $option)
71+
{
72+
$metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
73+
74+
$option->setStoreId($bundleProduct->getStoreId());
75+
$parentId = $bundleProduct->getData($metadata->getLinkField());
76+
$option->setParentId($parentId);
77+
78+
$optionId = $option->getOptionId();
79+
$linksToAdd = [];
80+
$optionCollection = $this->type->getOptionsCollection($bundleProduct);
81+
$optionCollection->setIdFilter($option->getOptionId());
82+
$optionCollection->setProductLinkFilter($parentId);
83+
84+
/** @var \Magento\Bundle\Model\Option $existingOption */
85+
$existingOption = $optionCollection->getFirstItem();
86+
if (!$optionId || $existingOption->getParentId() != $parentId) {
87+
//If option ID is empty or existing option's parent ID is different
88+
//we'd need a new ID for the option.
89+
$option->setOptionId(null);
90+
$option->setDefaultTitle($option->getTitle());
91+
if (is_array($option->getProductLinks())) {
92+
$linksToAdd = $option->getProductLinks();
93+
}
94+
} else {
95+
if (!$existingOption->getOptionId()) {
96+
throw new NoSuchEntityException(
97+
__("The option that was requested doesn't exist. Verify the entity and try again.")
98+
);
99+
}
100+
101+
$option->setData(array_merge($existingOption->getData(), $option->getData()));
102+
$this->updateOptionSelection($bundleProduct, $option);
103+
}
104+
105+
try {
106+
$this->optionResource->save($option);
107+
} catch (\Exception $e) {
108+
throw new CouldNotSaveException(__("The option couldn't be saved."), $e);
109+
}
110+
111+
/** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */
112+
foreach ($linksToAdd as $linkedProduct) {
113+
$this->linkManagement->addChild($bundleProduct, $option->getOptionId(), $linkedProduct);
114+
}
115+
116+
$bundleProduct->setIsRelationsChanged(true);
117+
118+
return $option;
119+
}
120+
121+
/**
122+
* Update option selections
123+
*
124+
* @param \Magento\Catalog\Api\Data\ProductInterface $product
125+
* @param \Magento\Bundle\Api\Data\OptionInterface $option
126+
* @return void
127+
*/
128+
private function updateOptionSelection(ProductInterface $product, OptionInterface $option)
129+
{
130+
$optionId = $option->getOptionId();
131+
$existingLinks = $this->linkManagement->getChildren($product->getSku(), $optionId);
132+
$linksToAdd = [];
133+
$linksToUpdate = [];
134+
$linksToDelete = [];
135+
if (is_array($option->getProductLinks())) {
136+
$productLinks = $option->getProductLinks();
137+
foreach ($productLinks as $productLink) {
138+
if (!$productLink->getId() && !$productLink->getSelectionId()) {
139+
$linksToAdd[] = $productLink;
140+
} else {
141+
$linksToUpdate[] = $productLink;
142+
}
143+
}
144+
/** @var \Magento\Bundle\Api\Data\LinkInterface[] $linksToDelete */
145+
$linksToDelete = $this->compareLinks($existingLinks, $linksToUpdate);
146+
}
147+
foreach ($linksToUpdate as $linkedProduct) {
148+
$this->linkManagement->saveChild($product->getSku(), $linkedProduct);
149+
}
150+
foreach ($linksToDelete as $linkedProduct) {
151+
$this->linkManagement->removeChild(
152+
$product->getSku(),
153+
$option->getOptionId(),
154+
$linkedProduct->getSku()
155+
);
156+
}
157+
foreach ($linksToAdd as $linkedProduct) {
158+
$this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct);
159+
}
160+
}
161+
162+
/**
163+
* Compute the difference between given arrays.
164+
*
165+
* @param \Magento\Bundle\Api\Data\LinkInterface[] $firstArray
166+
* @param \Magento\Bundle\Api\Data\LinkInterface[] $secondArray
167+
*
168+
* @return array
169+
*/
170+
private function compareLinks(array $firstArray, array $secondArray)
171+
{
172+
$result = [];
173+
174+
$firstArrayIds = [];
175+
$firstArrayMap = [];
176+
177+
$secondArrayIds = [];
178+
179+
foreach ($firstArray as $item) {
180+
$firstArrayIds[] = $item->getId();
181+
182+
$firstArrayMap[$item->getId()] = $item;
183+
}
184+
185+
foreach ($secondArray as $item) {
186+
$secondArrayIds[] = $item->getId();
187+
}
188+
189+
foreach (array_diff($firstArrayIds, $secondArrayIds) as $id) {
190+
$result[] = $firstArrayMap[$id];
191+
}
192+
193+
return $result;
194+
}
195+
}

0 commit comments

Comments
 (0)