Skip to content

Commit af96016

Browse files
committed
ACP2E-4212: Bundle product with scheduled updates removes the bundle items option on product save action
1 parent 6cda09a commit af96016

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ private function processLinkedProduct(
252252
throw new CouldNotSaveException(__('Could not save child: "%1"', $e->getMessage()), $e);
253253
}
254254

255+
$linkedProduct->setId($selectionModel->getId());
256+
$linkedProduct->setSelectionId($selectionModel->getId());
257+
$linkedProduct->setOptionId($optionId);
255258
return (int)$selectionModel->getId();
256259
}
257260

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ private function saveOptionItem(
165165

166166
/** @var LinkInterface $linkedProduct */
167167
foreach ($linksToAdd as $linkedProduct) {
168+
$linkedProduct->setId(null);
169+
$linkedProduct->setSelectionId(null);
168170
$this->linkManagement->addChild($bundleProduct, $option->getOptionId(), $linkedProduct);
169171
}
170172
}

app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,11 @@ static function () {
639639
*/
640640
public function testAddChild(): void
641641
{
642+
$selectionId = 42;
643+
$optionId = 1;
642644
$productLink = $this->getMockBuilder(LinkInterface::class)
643-
->onlyMethods(['getSku', 'getOptionId'])
644-
->addMethods(['getSelectionId'])
645+
->onlyMethods(['getSku', 'getOptionId', 'setOptionId', 'setId'])
646+
->addMethods(['getSelectionId', 'setSelectionId'])
645647
->disableOriginalConstructor()
646648
->getMockForAbstractClass();
647649
$productLink->method('getSku')->willReturn('linked_product_sku');
@@ -698,10 +700,14 @@ public function testAddChild(): void
698700

699701
$selection = $this->createPartialMock(Selection::class, ['save', 'getId', 'load']);
700702
$selection->expects($this->once())->method('save');
701-
$selection->expects($this->once())->method('getId')->willReturn(42);
703+
$selection->expects($this->any())->method('getId')->willReturn($selectionId);
702704
$this->bundleSelectionMock->expects($this->once())->method('create')->willReturn($selection);
703-
$result = $this->model->addChild($productMock, 1, $productLink);
704-
$this->assertEquals(42, $result);
705+
$productLink->expects($this->once())->method('setSelectionId')->with($selectionId)->willReturnSelf();
706+
$productLink->expects($this->once())->method('setId')->with($selectionId)->willReturnSelf();
707+
$productLink->expects($this->once())->method('setOptionId')->with($optionId)->willReturnSelf();
708+
709+
$result = $this->model->addChild($productMock, $optionId, $productLink);
710+
$this->assertEquals($selectionId, $result);
705711
}
706712

707713
/**

setup/src/Magento/Setup/Model/FixtureGenerator/BundleProductGenerator.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2017 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Setup\Model\FixtureGenerator;
77

@@ -43,7 +43,7 @@ class BundleProductGenerator
4343

4444
/**
4545
* @param ProductGeneratorFactory $productGeneratorFactory
46-
* @param ResourceConnection $resource|null
46+
* @param ResourceConnection|null $resource
4747
*/
4848
public function __construct(
4949
ProductGeneratorFactory $productGeneratorFactory,
@@ -224,13 +224,9 @@ private function generateSequenceId($tableName)
224224
{
225225
if (!$this->sequenceValues[$tableName]) {
226226
$connection = $this->resource->getConnection();
227-
228-
$this->sequenceValues[$tableName] = $connection->fetchOne(
229-
$connection->select()->from(
230-
$this->resource->getTableName($tableName),
231-
'MAX(`sequence_value`)'
232-
)
233-
);
227+
$entityStatus = $connection->showTableStatus($tableName);
228+
$this->sequenceValues[$tableName] = $entityStatus['Auto_increment'];
229+
return $this->sequenceValues[$tableName];
234230
}
235231

236232
return ++$this->sequenceValues[$tableName];

0 commit comments

Comments
 (0)