Skip to content

Commit 35081f3

Browse files
committed
Merge branch 'ACP2E-1345' of https://github.com/magento-l3/magento2ce into PR01262023
2 parents 90a2a74 + bdfdd01 commit 35081f3

File tree

2 files changed

+96
-6
lines changed

2 files changed

+96
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
namespace Magento\Bundle\Model\ResourceModel;
77

8-
use Magento\Framework\App\ObjectManager;
98
use Magento\Catalog\Api\Data\ProductInterface;
10-
use Magento\Framework\EntityManager\MetadataPool;
9+
use Magento\Framework\App\ObjectManager;
1110
use Magento\Framework\EntityManager\EntityManager;
11+
use Magento\Framework\EntityManager\MetadataPool;
1212
use Magento\Framework\Model\ResourceModel\Db\Context;
1313

1414
/**
@@ -141,7 +141,7 @@ public function getParentIdsByChild($childId)
141141
''
142142
)->join(
143143
['e' => $this->metadataPool->getMetadata(ProductInterface::class)->getEntityTable()],
144-
'e.' . $metadata->getLinkField() . ' = ' . $this->getMainTable() . '.parent_product_id',
144+
'e.' . $metadata->getLinkField() . ' = ' . $this->getMainTable() . '.parent_product_id',
145145
['e.entity_id as parent_product_id']
146146
)->where(
147147
$this->getMainTable() . '.product_id IN(?)',
@@ -174,10 +174,11 @@ public function saveSelectionPrice($item)
174174
$values = [
175175
'selection_id' => $item->getSelectionId(),
176176
'website_id' => $item->getWebsiteId(),
177-
'selection_price_type' => $item->getSelectionPriceType(),
178-
'selection_price_value' => $item->getSelectionPriceValue(),
177+
'selection_price_type' => $item->getSelectionPriceType() ?? 0,
178+
'selection_price_value' => $item->getSelectionPriceValue() ?? 0,
179179
'parent_product_id' => $item->getParentProductId(),
180180
];
181+
181182
$connection->insertOnDuplicate(
182183
$this->getTable('catalog_product_bundle_selection_price'),
183184
$values,
@@ -187,7 +188,8 @@ public function saveSelectionPrice($item)
187188
}
188189

189190
/**
190-
* {@inheritdoc}
191+
* @inheritdoc
192+
*
191193
* @since 100.2.0
192194
*/
193195
public function save(\Magento\Framework\Model\AbstractModel $object)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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\Test\Unit\Model\ResourceModel;
9+
10+
use Codeception\PHPUnit\TestCase;
11+
use Magento\Bundle\Model\ResourceModel\Selection as ResourceSelection;
12+
use Magento\Bundle\Model\Selection;
13+
use Magento\Framework\App\ResourceConnection;
14+
use Magento\Framework\DB\Adapter\AdapterInterface;
15+
use Magento\Framework\EntityManager\MetadataPool;
16+
use Magento\Framework\Model\ResourceModel\Db\Context;
17+
18+
class SelectionTest extends TestCase
19+
{
20+
/**
21+
* @var Context|Context&\PHPUnit\Framework\MockObject\MockObject|\PHPUnit\Framework\MockObject\MockObject
22+
*/
23+
private Context $context;
24+
25+
/**
26+
* @var MetadataPool|MetadataPool&\PHPUnit\Framework\MockObject\MockObject|\PHPUnit\Framework\MockObject\MockObject
27+
*/
28+
private MetadataPool $metadataPool;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
protected function setUp(): void
34+
{
35+
parent::setUp();
36+
37+
$this->context = $this->createMock(Context::class);
38+
$this->metadataPool = $this->createMock(MetadataPool::class);
39+
}
40+
41+
public function testSaveSelectionPrice()
42+
{
43+
$item = $this->getMockBuilder(Selection::class)
44+
->disableOriginalConstructor()
45+
->addMethods([
46+
'getSelectionId',
47+
'getWebsiteId',
48+
'getSelectionPriceType',
49+
'getSelectionPriceValue',
50+
'getParentProductId',
51+
'getDefaultPriceScope'])
52+
->getMock();
53+
$values = [
54+
'selection_id' => 1,
55+
'website_id' => 1,
56+
'selection_price_type' => null,
57+
'selection_price_value' => null,
58+
'parent_product_id' => 1,
59+
];
60+
$item->expects($this->once())->method('getDefaultPriceScope')->willReturn(false);
61+
$item->expects($this->once())->method('getSelectionId')->willReturn($values['selection_id']);
62+
$item->expects($this->once())->method('getWebsiteId')->willReturn($values['website_id']);
63+
$item->expects($this->once())->method('getSelectionPriceType')->willReturn($values['selection_price_type']);
64+
$item->expects($this->once())->method('getSelectionPriceValue')->willReturn($values['selection_price_value']);
65+
$item->expects($this->once())->method('getParentProductId')->willReturn($values['parent_product_id']);
66+
67+
$connection = $this->createMock(AdapterInterface::class);
68+
$connection->expects($this->once())
69+
->method('insertOnDuplicate')
70+
->with(
71+
'catalog_product_bundle_selection_price',
72+
$this->callback(function ($insertValues) {
73+
return $insertValues['selection_price_type'] === 0 && $insertValues['selection_price_value'] === 0;
74+
}),
75+
['selection_price_type', 'selection_price_value']
76+
);
77+
78+
$parentResources = $this->createMock(ResourceConnection::class);
79+
$parentResources->expects($this->once())->method('getConnection')->willReturn($connection);
80+
$parentResources->expects($this->once())->method('getTableName')
81+
->with('catalog_product_bundle_selection_price', 'test_connection_name')
82+
->willReturn('catalog_product_bundle_selection_price');
83+
$this->context->expects($this->once())->method('getResources')->willReturn($parentResources);
84+
85+
$selection = new ResourceSelection($this->context, $this->metadataPool, 'test_connection_name');
86+
$selection->saveSelectionPrice($item);
87+
}
88+
}

0 commit comments

Comments
 (0)