Skip to content

Commit 98e22fd

Browse files
author
Anna Bukatar
committed
ACP2E-779: Configurable products can be associated with the grouped products during product import
1 parent 7cb6736 commit 98e22fd

File tree

2 files changed

+66
-12
lines changed

2 files changed

+66
-12
lines changed

app/code/Magento/GroupedImportExport/Model/Import/Product/Type/Grouped.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Import entity of grouped product type
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -12,12 +10,15 @@
1210
use Magento\Framework\App\ObjectManager;
1311
use Magento\ImportExport\Model\Import;
1412

13+
/**
14+
* Import entity of grouped product type
15+
*/
1516
class Grouped extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
1617
{
1718
/**
1819
* Default delimiter for sku and qty.
1920
*/
20-
const SKU_QTY_DELIMITER = '=';
21+
public const SKU_QTY_DELIMITER = '=';
2122

2223
/**
2324
* Column names that holds values with particular meaning.
@@ -42,8 +43,6 @@ class Grouped extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abs
4243
private $allowedProductTypes;
4344

4445
/**
45-
* Product entity identifier field
46-
*
4746
* @var string
4847
*/
4948
private $productEntityIdentifierField;
@@ -111,7 +110,7 @@ public function saveData()
111110
) {
112111
$linkedProductId = $newSku[$associatedSku][$this->getProductEntityIdentifierField()];
113112
} elseif (isset($oldSku[$associatedSku]) &&
114-
in_array($newSku[$associatedSku]['type_id'], $this->allowedProductTypes)
113+
in_array($oldSku[$associatedSku]['type_id'], $this->allowedProductTypes)
115114
) {
116115
$linkedProductId = $oldSku[$associatedSku][$this->getProductEntityIdentifierField()];
117116
} else {

app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\GroupedImportExport;
2121
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped;
2222
use Magento\GroupedImportExport\Model\Import\Product\Type\Grouped\Links;
23+
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
2324
use Magento\ImportExport\Test\Unit\Model\Import\AbstractImportTestCase;
2425
use PHPUnit\Framework\MockObject\MockObject;
2526

@@ -73,6 +74,11 @@ class GroupedTest extends AbstractImportTestCase
7374
*/
7475
protected $links;
7576

77+
/**
78+
* @var ConfigInterface|MockObject
79+
*/
80+
private $configMock;
81+
7682
/**
7783
* @var Product|MockObject
7884
*/
@@ -117,6 +123,10 @@ protected function setUp(): void
117123
1 => 'grouped'
118124
];
119125
$this->links = $this->createMock(Links::class);
126+
$this->configMock = $this->getMockForAbstractClass(ConfigInterface::class);
127+
$this->configMock->expects($this->once())
128+
->method('getComposableTypes')
129+
->willReturn(['simple', 'virtual', 'downloadable']);
120130
$entityAttributes = [
121131
[
122132
'attribute_set_name' => 'attribute_id',
@@ -156,7 +166,8 @@ protected function setUp(): void
156166
'prodAttrColFac' => $this->attrCollectionFactory,
157167
'resource' => $this->resource,
158168
'params' => $this->params,
159-
'links' => $this->links
169+
'links' => $this->links,
170+
'config' => $this->configMock
160171
]
161172
);
162173
$metadataPoolMock = $this->createMock(MetadataPool::class);
@@ -214,10 +225,10 @@ public function saveDataProvider(): array
214225
[
215226
'skus' => [
216227
'newSku' => [
217-
'sku_assoc1' => ['entity_id' => 1],
228+
'sku_assoc1' => ['entity_id' => 1, 'type_id' => 'simple'],
218229
'productsku' => ['entity_id' => 3, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
219230
],
220-
'oldSku' => ['sku_assoc2' => ['entity_id' => 2]]
231+
'oldSku' => ['sku_assoc2' => ['entity_id' => 2, 'type_id' => 'simple']]
221232
],
222233
'bunch' => [
223234
'associated_skus' => 'sku_assoc1=1, sku_assoc2=2',
@@ -249,7 +260,7 @@ public function saveDataProvider(): array
249260
[
250261
'skus' => [
251262
'newSku' => [
252-
'sku_assoc1' => ['entity_id' => 1],
263+
'sku_assoc1' => ['entity_id' => 1, 'type_id' => 'simple'],
253264
'productsku' => ['entity_id' => 3, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
254265
],
255266
'oldSku' => []
@@ -272,13 +283,13 @@ public function testSaveDataScopeStore(): void
272283
{
273284
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn(
274285
[
275-
'sku_assoc1' => ['entity_id' => 1],
286+
'sku_assoc1' => ['entity_id' => 1, 'type_id' => 'simple'],
276287
'productsku' => ['entity_id' => 2, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
277288
]
278289
);
279290
$this->entityModel->expects($this->once())->method('getOldSku')->willReturn(
280291
[
281-
'sku_assoc2' => ['entity_id' => 3]
292+
'sku_assoc2' => ['entity_id' => 3, 'type_id' => 'simple']
282293
]
283294
);
284295
$attributes = ['position' => ['id' => 0], 'qty' => ['id' => 0]];
@@ -302,4 +313,48 @@ public function testSaveDataScopeStore(): void
302313
$this->links->expects($this->once())->method('saveLinksData');
303314
$this->grouped->saveData();
304315
}
316+
317+
/**
318+
* Test saveData() with composite product associated with a grouped product
319+
*
320+
* @return void
321+
*/
322+
public function testSaveDataAssociatedComposite(): void
323+
{
324+
$this->entityModel->expects($this->once())->method('getNewSku')->willReturn(
325+
[
326+
'sku_assoc1' => ['entity_id' => 1, 'type_id' => 'configurable'],
327+
'productsku' => ['entity_id' => 2, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
328+
]
329+
);
330+
$this->entityModel->expects($this->once())->method('getOldSku')->willReturn([]);
331+
$attributes = ['position' => ['id' => 0], 'qty' => ['id' => 0]];
332+
$this->links->expects($this->once())->method('getAttributes')->willReturn($attributes);
333+
334+
$bunch = [
335+
[
336+
'associated_skus' => 'sku_assoc1=1',
337+
'sku' => 'productsku',
338+
'product_type' => 'grouped'
339+
]
340+
];
341+
342+
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->willReturn(true);
343+
$this->entityModel
344+
->method('getNextBunch')
345+
->willReturnOnConsecutiveCalls($bunch);
346+
$this->entityModel
347+
->method('getRowScope')
348+
->willReturnOnConsecutiveCalls(Product::SCOPE_DEFAULT, Product::SCOPE_STORE);
349+
350+
$expectedLinkData = [
351+
'product_ids' => [],
352+
'attr_product_ids' => [],
353+
'position' => [],
354+
'qty' => [],
355+
'relation' => []
356+
];
357+
$this->links->expects($this->once())->method('saveLinksData')->with($expectedLinkData);
358+
$this->grouped->saveData();
359+
}
305360
}

0 commit comments

Comments
 (0)