Skip to content

Commit 5cc28b8

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into MCP-218
2 parents 53a3c6d + 2e2af0a commit 5cc28b8

File tree

175 files changed

+2652
-1083
lines changed

Some content is hidden

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

175 files changed

+2652
-1083
lines changed

app/code/Magento/Backend/Test/Mftf/Test/AdminLoginAfterChangeCookieDomainTest.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@
2121
</annotations>
2222
<before>
2323
<magentoCLI command="config:set {{ChangedCookieDomainForMainWebsiteConfigData.path}} --scope={{ChangedCookieDomainForMainWebsiteConfigData.scope}} --scope-code={{ChangedCookieDomainForMainWebsiteConfigData.scope_code}} {{ChangedCookieDomainForMainWebsiteConfigData.value}}" stepKey="changeDomainForMainWebsiteBeforeTestRun"/>
24-
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheBeforeTestRun">
25-
<argument name="tags" value="config"/>
26-
</actionGroup>
24+
<comment userInput="Adding the comment to replace CliCacheFlushActionGroup action group ('cache:flush' command) for preserving Backward Compatibility" stepKey="flushCacheBeforeTestRun"/>
2725
</before>
2826
<after>
2927
<magentoCLI command="config:set {{EmptyCookieDomainForMainWebsiteConfigData.path}} --scope={{EmptyCookieDomainForMainWebsiteConfigData.scope}} --scope-code={{EmptyCookieDomainForMainWebsiteConfigData.scope_code}} {{EmptyCookieDomainForMainWebsiteConfigData.value}}" stepKey="changeDomainForMainWebsiteAfterTestComplete"/>
30-
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCacheAfterTestComplete">
31-
<argument name="tags" value="config"/>
32-
</actionGroup>
28+
<comment userInput="Adding the comment to replace CliCacheFlushActionGroup action group ('cache:flush' command) for preserving Backward Compatibility" stepKey="flushCacheAfterTestComplete"/>
3329
</after>
3430
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
3531
<actionGroup ref="AssertAdminDashboardPageIsVisibleActionGroup" stepKey="seeDashboardPage"/>

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

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
use Magento\Catalog\Api\ProductRepositoryInterface;
2020
use Magento\Catalog\Model\Product;
2121
use Magento\Framework\Api\DataObjectHelper;
22+
use Magento\Framework\EntityManager\MetadataPool;
2223
use Magento\Framework\Exception\CouldNotSaveException;
2324
use Magento\Framework\Exception\InputException;
24-
use Magento\Framework\EntityManager\MetadataPool;
2525
use Magento\Framework\Exception\NoSuchEntityException;
2626
use Magento\Store\Model\StoreManagerInterface;
2727

@@ -173,12 +173,11 @@ public function saveChild(
173173
)
174174
);
175175
}
176-
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
177-
$selectionModel = $this->mapProductLinkToSelectionModel(
176+
$selectionModel = $this->mapProductLinkToBundleSelectionModel(
178177
$selectionModel,
179178
$linkedProduct,
180-
$linkProductModel->getId(),
181-
$product->getData($linkField)
179+
$product,
180+
(int)$linkProductModel->getId()
182181
);
183182

184183
try {
@@ -202,6 +201,7 @@ public function saveChild(
202201
*
203202
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
204203
* @SuppressWarnings(PHPMD.NPathComplexity)
204+
* @deprecated use mapProductLinkToBundleSelectionModel
205205
*/
206206
protected function mapProductLinkToSelectionModel(
207207
Selection $selectionModel,
@@ -239,6 +239,55 @@ protected function mapProductLinkToSelectionModel(
239239
return $selectionModel;
240240
}
241241

242+
/**
243+
* Fill selection model with product link data.
244+
*
245+
* @param Selection $selectionModel
246+
* @param LinkInterface $productLink
247+
* @param ProductInterface $parentProduct
248+
* @param int $linkedProductId
249+
* @param string $linkField
250+
* @return Selection
251+
* @throws NoSuchEntityException
252+
*/
253+
private function mapProductLinkToBundleSelectionModel(
254+
Selection $selectionModel,
255+
LinkInterface $productLink,
256+
ProductInterface $parentProduct,
257+
int $linkedProductId
258+
): Selection {
259+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
260+
$selectionModel->setProductId($linkedProductId);
261+
$selectionModel->setParentProductId($parentProduct->getData($linkField));
262+
if ($productLink->getSelectionId() !== null) {
263+
$selectionModel->setSelectionId($productLink->getSelectionId());
264+
}
265+
if ($productLink->getOptionId() !== null) {
266+
$selectionModel->setOptionId($productLink->getOptionId());
267+
}
268+
if ($productLink->getPosition() !== null) {
269+
$selectionModel->setPosition($productLink->getPosition());
270+
}
271+
if ($productLink->getQty() !== null) {
272+
$selectionModel->setSelectionQty($productLink->getQty());
273+
}
274+
if ($productLink->getPriceType() !== null) {
275+
$selectionModel->setSelectionPriceType($productLink->getPriceType());
276+
}
277+
if ($productLink->getPrice() !== null) {
278+
$selectionModel->setSelectionPriceValue($productLink->getPrice());
279+
}
280+
if ($productLink->getCanChangeQuantity() !== null) {
281+
$selectionModel->setSelectionCanChangeQty($productLink->getCanChangeQuantity());
282+
}
283+
if ($productLink->getIsDefault() !== null) {
284+
$selectionModel->setIsDefault($productLink->getIsDefault());
285+
}
286+
$selectionModel->setWebsiteId((int)$this->storeManager->getStore($parentProduct->getStoreId())->getWebsiteId());
287+
288+
return $selectionModel;
289+
}
290+
242291
/**
243292
* @inheritDoc
244293
*
@@ -302,12 +351,13 @@ public function addChild(
302351
}
303352

304353
$selectionModel = $this->bundleSelection->create();
305-
$selectionModel = $this->mapProductLinkToSelectionModel(
354+
$selectionModel = $this->mapProductLinkToBundleSelectionModel(
306355
$selectionModel,
307356
$linkedProduct,
308-
$linkProductModel->getEntityId(),
309-
$product->getData($linkField)
357+
$product,
358+
(int)$linkProductModel->getEntityId()
310359
);
360+
311361
$selectionModel->setOptionId($optionId);
312362

313363
try {

app/code/Magento/Bundle/Model/Option/SaveAction.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
namespace Magento\Bundle\Model\Option;
99

10+
use Magento\Bundle\Api\Data\LinkInterface;
1011
use Magento\Bundle\Api\Data\OptionInterface;
1112
use Magento\Bundle\Model\ResourceModel\Option;
1213
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Framework\App\ObjectManager;
1315
use Magento\Framework\EntityManager\MetadataPool;
1416
use Magento\Framework\Exception\CouldNotSaveException;
1517
use Magento\Bundle\Model\Product\Type;
1618
use Magento\Bundle\Api\ProductLinkManagementInterface;
19+
use Magento\Framework\Exception\NoSuchEntityException;
20+
use Magento\Store\Model\StoreManagerInterface;
1721

1822
/**
1923
* Encapsulates logic for saving a bundle option, including coalescing the parent product's data.
@@ -45,12 +49,14 @@ class SaveAction
4549
* @param MetadataPool $metadataPool
4650
* @param Type $type
4751
* @param ProductLinkManagementInterface $linkManagement
52+
* @param StoreManagerInterface|null $storeManager
4853
*/
4954
public function __construct(
5055
Option $optionResource,
5156
MetadataPool $metadataPool,
5257
Type $type,
53-
ProductLinkManagementInterface $linkManagement
58+
ProductLinkManagementInterface $linkManagement,
59+
?StoreManagerInterface $storeManager = null
5460
) {
5561
$this->optionResource = $optionResource;
5662
$this->metadataPool = $metadataPool;
@@ -69,7 +75,7 @@ public function __construct(
6975
*/
7076
public function save(ProductInterface $bundleProduct, OptionInterface $option)
7177
{
72-
$metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
78+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
7379

7480
$option->setStoreId($bundleProduct->getStoreId());
7581
$parentId = $bundleProduct->getData($metadata->getLinkField());
@@ -108,7 +114,7 @@ public function save(ProductInterface $bundleProduct, OptionInterface $option)
108114
throw new CouldNotSaveException(__("The option couldn't be saved."), $e);
109115
}
110116

111-
/** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */
117+
/** @var LinkInterface $linkedProduct */
112118
foreach ($linksToAdd as $linkedProduct) {
113119
$this->linkManagement->addChild($bundleProduct, $option->getOptionId(), $linkedProduct);
114120
}
@@ -121,8 +127,8 @@ public function save(ProductInterface $bundleProduct, OptionInterface $option)
121127
/**
122128
* Update option selections
123129
*
124-
* @param \Magento\Catalog\Api\Data\ProductInterface $product
125-
* @param \Magento\Bundle\Api\Data\OptionInterface $option
130+
* @param ProductInterface $product
131+
* @param OptionInterface $option
126132
* @return void
127133
*/
128134
private function updateOptionSelection(ProductInterface $product, OptionInterface $option)
@@ -141,7 +147,7 @@ private function updateOptionSelection(ProductInterface $product, OptionInterfac
141147
$linksToUpdate[] = $productLink;
142148
}
143149
}
144-
/** @var \Magento\Bundle\Api\Data\LinkInterface[] $linksToDelete */
150+
/** @var LinkInterface[] $linksToDelete */
145151
$linksToDelete = $this->compareLinks($existingLinks, $linksToUpdate);
146152
}
147153
foreach ($linksToUpdate as $linkedProduct) {
@@ -162,8 +168,8 @@ private function updateOptionSelection(ProductInterface $product, OptionInterfac
162168
/**
163169
* Compute the difference between given arrays.
164170
*
165-
* @param \Magento\Bundle\Api\Data\LinkInterface[] $firstArray
166-
* @param \Magento\Bundle\Api\Data\LinkInterface[] $secondArray
171+
* @param LinkInterface[] $firstArray
172+
* @param LinkInterface[] $secondArray
167173
*
168174
* @return array
169175
*/

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,42 @@ private function getBaseBundleSelectionPriceSelect(): Select
463463
return $select;
464464
}
465465

466+
/**
467+
* Get base select for bundle selection price update
468+
*
469+
* @return Select
470+
* @throws \Exception
471+
*/
472+
private function getBaseBundleSelectionPriceUpdateSelect(): Select
473+
{
474+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
475+
$linkField = $metadata->getLinkField();
476+
$bundleSelectionTable = $this->getBundleSelectionTable();
477+
478+
$select = $this->getConnection()->select()
479+
->join(
480+
['i' => $this->getBundlePriceTable()],
481+
"i.entity_id = $bundleSelectionTable.entity_id
482+
AND i.customer_group_id = $bundleSelectionTable.customer_group_id
483+
AND i.website_id = $bundleSelectionTable.website_id",
484+
[]
485+
)->join(
486+
['parent_product' => $this->getTable('catalog_product_entity')],
487+
'parent_product.entity_id = i.entity_id',
488+
[]
489+
)->join(
490+
['bo' => $this->getTable('catalog_product_bundle_option')],
491+
"bo.parent_id = parent_product.$linkField AND bo.option_id = $bundleSelectionTable.option_id",
492+
['option_id']
493+
)->join(
494+
['bs' => $this->getTable('catalog_product_bundle_selection')],
495+
"bs.option_id = bo.option_id AND bs.selection_id = $bundleSelectionTable.selection_id",
496+
['selection_id']
497+
);
498+
499+
return $select;
500+
}
501+
466502
/**
467503
* Apply selections price for fixed bundles
468504
*
@@ -506,7 +542,7 @@ private function applyFixedBundleSelectionPrice()
506542
]
507543
);
508544

509-
$select = $this->getBaseBundleSelectionPriceSelect();
545+
$select = $this->getBaseBundleSelectionPriceUpdateSelect();
510546
$select->joinInner(
511547
['bsp' => $this->getTable('catalog_product_bundle_selection_price')],
512548
'bs.selection_id = bsp.selection_id AND bsp.website_id = i.website_id',

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @method \Magento\Bundle\Model\Selection setPosition(int $value)
2121
* @method int getIsDefault()
2222
* @method \Magento\Bundle\Model\Selection setIsDefault(int $value)
23+
* @method int getWebsiteId()
24+
* @method \Magento\Bundle\Model\Selection setWebsiteId(int $value)
2325
* @method int getSelectionPriceType()
2426
* @method \Magento\Bundle\Model\Selection setSelectionPriceType(int $value)
2527
* @method float getSelectionPriceValue()
@@ -74,18 +76,35 @@ protected function _construct()
7476
/**
7577
* Processing object before save data
7678
*
79+
* @return void
80+
*/
81+
public function beforeSave()
82+
{
83+
if (!$this->_catalogData->isPriceGlobal() && $this->getWebsiteId()) {
84+
$this->setData('tmp_selection_price_value', $this->getSelectionPriceValue());
85+
$this->setSelectionPriceValue($this->getOrigData('selection_price_value'));
86+
}
87+
parent::beforeSave();
88+
}
89+
90+
/**
91+
* Processing object after save data
92+
*
7793
* @return $this
7894
*/
7995
public function afterSave()
8096
{
8197
if (!$this->_catalogData->isPriceGlobal() && $this->getWebsiteId()) {
98+
if (null !== $this->getData('tmp_selection_price_value')) {
99+
$this->setSelectionPriceValue($this->getData('tmp_selection_price_value'));
100+
}
82101
$this->getResource()->saveSelectionPrice($this);
83102

84103
if (!$this->getDefaultPriceScope()) {
85104
$this->unsSelectionPriceValue();
86105
$this->unsSelectionPriceType();
87106
}
88107
}
89-
parent::afterSave();
108+
return parent::afterSave();
90109
}
91110
}

app/code/Magento/Bundle/Test/Mftf/Data/BundleLinkData.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@
1717
<data key="price_type">1</data>
1818
<data key="can_change_quantity">1</data>
1919
</entity>
20+
<entity name="ApiBundleLinkFixed" type="bundle_link">
21+
<var key="option_id" entityKey="return" entityType="bundle_option"/>
22+
<var key="sku" entityKey="sku" entityType="product"/>
23+
<data key="qty">1</data>
24+
<data key="is_default">1</data>
25+
<data key="price">30</data>
26+
<data key="price_type">0</data>
27+
<data key="can_change_quantity">1</data>
28+
</entity>
2029
</entities>

app/code/Magento/Bundle/Test/Mftf/Test/MassEnableDisableBundleProductsTest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@
134134

135135
<!--Clear Cache - reindex - resets products according to enabled/disabled view-->
136136
<comment userInput="Adding the comment to replace CliIndexerReindexActionGroup action group ('indexer:reindex' commands) for preserving Backward Compatibility" stepKey="reindex"/>
137-
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache">
138-
<argument name="tags" value=""/>
139-
</actionGroup>
137+
<comment userInput="Adding the comment to replace CliCacheFlushActionGroup action group ('cache:flush' command) for preserving Backward Compatibility" stepKey="flushCache"/>
140138

141139
<!--Confirm bundle products have been enabled-->
142140
<amOnPage url="{{BundleProduct.urlKey2}}.html" stepKey="GoToProductPageEnabled"/>

0 commit comments

Comments
 (0)