Skip to content

Commit 926bf64

Browse files
committed
Merge remote-tracking branch 'origin/develop' into PR-copy1
2 parents e4121e1 + 255ceb2 commit 926bf64

File tree

9 files changed

+43
-63
lines changed

9 files changed

+43
-63
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __construct(
8787
*/
8888
public function getChildren($productSku, $optionId = null)
8989
{
90-
$product = $this->productRepository->get($productSku);
90+
$product = $this->productRepository->get($productSku, true);
9191
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
9292
throw new InputException(__('Only implemented for bundle product'));
9393
}
@@ -111,7 +111,7 @@ public function getChildren($productSku, $optionId = null)
111111
public function addChildByProductSku($sku, $optionId, \Magento\Bundle\Api\Data\LinkInterface $linkedProduct)
112112
{
113113
/** @var \Magento\Catalog\Model\Product $product */
114-
$product = $this->productRepository->get($sku);
114+
$product = $this->productRepository->get($sku, true);
115115
return $this->addChild($product, $optionId, $linkedProduct);
116116
}
117117

@@ -124,7 +124,7 @@ public function saveChild(
124124
$sku,
125125
\Magento\Bundle\Api\Data\LinkInterface $linkedProduct
126126
) {
127-
$product = $this->productRepository->get($sku);
127+
$product = $this->productRepository->get($sku, true);
128128
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
129129
throw new InputException(
130130
__('Product with specified sku: "%1" is not a bundle product', [$product->getSku()])
@@ -277,7 +277,7 @@ public function addChild(
277277
*/
278278
public function removeChild($sku, $optionId, $childSku)
279279
{
280-
$product = $this->productRepository->get($sku);
280+
$product = $this->productRepository->get($sku, true);
281281

282282
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
283283
throw new InputException(__('Product with specified sku: %1 is not a bundle product', $sku));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
*/
3838
public function save(\Magento\Bundle\Api\Data\OptionInterface $option)
3939
{
40-
$product = $this->productRepository->get($option->getSku());
40+
$product = $this->productRepository->get($option->getSku(), true);
4141
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
4242
throw new InputException(__('Only implemented for bundle product'));
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ protected function updateOptionSelection(
250250
*/
251251
private function getProduct($sku)
252252
{
253-
$product = $this->productRepository->get($sku);
253+
$product = $this->productRepository->get($sku, true);
254254
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
255255
throw new InputException(__('Only implemented for bundle product'));
256256
}

app/code/Magento/Bundle/Model/Product/SaveHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function execute($entityType, $entity)
6464
$this->optionRepository->delete($option);
6565
}
6666

67-
$options = $entity->getExtensionAttributes()->getBundleProductOptions() ?: [];
67+
$options = $bundleProductOptions ?: [];
6868
foreach ($options as $option) {
6969
$option->setOptionId(null);
7070
$this->optionRepository->save($entity, $option);

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function getChildrenIds($parentId, $required = true)
247247
return $this->_bundleSelection->getChildrenIds($parentId, $required);
248248
}
249249

250-
/**
250+
/**
251251
* Retrieve parent ids array by required child
252252
*
253253
* @param int|array $childId

app/code/Magento/Bundle/Model/ResourceModel/Option/Collection.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,29 @@ public function setProductIdFilter($productId)
8585
'cpe.'.$linkField.' = main_table.parent_id',
8686
[]
8787
)->where(
88-
'cpe.entity_id = ?',
88+
"cpe.entity_id = ?",
8989
$productId
9090
);
9191

9292
return $this;
9393
}
9494

95+
/**
96+
* Set product link filter
97+
*
98+
* @param int $productLinkFieldValue
99+
*
100+
* @return $this
101+
*/
102+
public function setProductLinkFilter($productLinkFieldValue)
103+
{
104+
$this->getSelect()->where(
105+
'main_table.parent_id = ?',
106+
$productLinkFieldValue
107+
);
108+
return $this;
109+
}
110+
95111
/**
96112
* Sets order by position
97113
*

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class TypeTest extends \PHPUnit_Framework_TestCase
2020
* @var \Magento\Bundle\Model\ResourceModel\BundleFactory|\PHPUnit_Framework_MockObject_MockObject
2121
*/
2222
private $bundleFactory;
23+
2324
/**
2425
* @var \Magento\Bundle\Model\SelectionFactory|\PHPUnit_Framework_MockObject_MockObject
2526
*/
2627
private $bundleModelSelection;
28+
2729
/**
2830
* @var \Magento\Bundle\Model\Product\Type
2931
*/
@@ -2447,59 +2449,6 @@ protected function parentClass($group, $option, $buyRequest, $product)
24472449
->willReturn(false);
24482450
}
24492451

2450-
public function testGetOptionsCollection()
2451-
{
2452-
$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
2453-
->disableOriginalConstructor()
2454-
->setMethods(
2455-
[
2456-
'_wakeup',
2457-
'getStoreId',
2458-
'getData',
2459-
'hasData',
2460-
'setData',
2461-
'getEntityId'
2462-
]
2463-
)
2464-
->getMock();
2465-
$option = $this->getMockBuilder('\Magento\Bundle\Model\Option')
2466-
->disableOriginalConstructor()
2467-
->getMock();
2468-
$resourceClassName = 'Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection';
2469-
$dbResourceMock = $this->getMockBuilder($resourceClassName)
2470-
->setMethods(['setProductIdFilter', 'setPositionOrder', 'joinValues'])
2471-
->disableOriginalConstructor()
2472-
->getMock();
2473-
$store = $this->getMockBuilder('\Magento\Store\Model\Store')
2474-
->disableOriginalConstructor()
2475-
->setMethods(['getId'])
2476-
->getMock();
2477-
2478-
$product->expects($this->once())
2479-
->method('hasData')
2480-
->with('_cache_instance_options_collection')
2481-
->willReturn(false);
2482-
$this->bundleOptionFactory->expects($this->once())->method('create')->willReturn($option);
2483-
$option->expects($this->once())->method('getResourceCollection')->willReturn($dbResourceMock);
2484-
$product->expects($this->once())->method('getEntityId')->willReturn('prod_id');
2485-
$dbResourceMock->expects($this->once())->method('setProductIdFilter')->with('prod_id')->willReturnSelf();
2486-
$product->expects($this->once())->method('getStoreId')->willReturn('store_id');
2487-
$product->expects($this->at(3))->method('setData')->willReturnSelf();
2488-
$dbResourceMock->expects($this->once())->method('setPositionOrder')->willReturnSelf();
2489-
$product->expects($this->at(4))->method('getData')->with('_cache_instance_store_filter')->willReturn($store);
2490-
$store->expects($this->once())->method('getId')->willReturn('store_id');
2491-
$dbResourceMock->expects($this->once())->method('joinValues')->with('store_id')->willReturnSelf();
2492-
$product->expects($this->at(5))
2493-
->method('setData')
2494-
->with('_cache_instance_options_collection', $dbResourceMock)
2495-
->willReturnSelf();
2496-
$product->expects($this->at(6))->method('getData')->with('_cache_instance_options_collection')->willReturn(
2497-
'result_data'
2498-
);
2499-
2500-
$this->assertEquals('result_data', $this->model->getOptionsCollection($product));
2501-
}
2502-
25032452
public function testGetSelectionsCollection()
25042453
{
25052454
$optionIds = [1, 2, 3];

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/TypeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,19 @@ public function testPrepareProductIndexForBundleProduct()
6262
$result = $this->connectionMock->fetchAll($select);
6363
$this->assertCount(1, $result);
6464
}
65+
66+
/**
67+
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options.php
68+
* @covers \Magento\Bundle\Model\Product\Type::getOptionsCollection
69+
*/
70+
public function testGetOptionsCollection()
71+
{
72+
$productRepository = $this->objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
73+
/** @var \Magento\Catalog\Model\Product $bundleProduct */
74+
$bundleProduct = $productRepository->get('bundle-product');
75+
$bundleType = $bundleProduct->getTypeInstance();
76+
/** @var \Magento\Bundle\Model\Product\Type $bundleType */
77+
$options = $bundleType->getOptionsCollection($bundleProduct);
78+
$this->assertCount(5, $options->getItems());
79+
}
6580
}

dev/tests/integration/testsuite/Magento/Sales/Model/AbstractCollectorPositionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class AbstractCollectorPositionsTest extends \PHPUnit_Framework_TestCas
2121
*/
2222
public function testCollectorPosition($collectorCode, $configType, array $before, array $after)
2323
{
24-
$allCollectors = $this->_getConfigCollectors($configType);
24+
$allCollectors = self::_getConfigCollectors($configType);
2525
$collectorCodes = array_keys($allCollectors);
2626
$collectorPos = array_search($collectorCode, $collectorCodes);
2727
$this->assertNotSame(false, $collectorPos, "'{$collectorCode}' total collector is not found");

0 commit comments

Comments
 (0)