Skip to content

Commit a034337

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-59' into PR_L3_18_04_2022
2 parents 96790ee + 4c1266c commit a034337

File tree

3 files changed

+70
-30
lines changed

3 files changed

+70
-30
lines changed

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

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
2-
32
/**
4-
* Import entity of bundle product type
5-
*
63
* Copyright © Magento, Inc. All rights reserved.
74
* See COPYING.txt for license details.
85
*/
@@ -29,25 +26,25 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
2926
/**
3027
* Delimiter before product option value.
3128
*/
32-
const BEFORE_OPTION_VALUE_DELIMITER = ';';
29+
public const BEFORE_OPTION_VALUE_DELIMITER = ';';
3330

34-
const PAIR_VALUE_SEPARATOR = '=';
31+
public const PAIR_VALUE_SEPARATOR = '=';
3532

3633
/**
3734
* Dynamic value.
3835
*/
39-
const VALUE_DYNAMIC = 'dynamic';
36+
public const VALUE_DYNAMIC = 'dynamic';
4037

4138
/**
4239
* Fixed value.
4340
*/
44-
const VALUE_FIXED = 'fixed';
41+
public const VALUE_FIXED = 'fixed';
4542

46-
const NOT_FIXED_DYNAMIC_ATTRIBUTE = 'price_view';
43+
public const NOT_FIXED_DYNAMIC_ATTRIBUTE = 'price_view';
4744

48-
const SELECTION_PRICE_TYPE_FIXED = 0;
45+
public const SELECTION_PRICE_TYPE_FIXED = 0;
4946

50-
const SELECTION_PRICE_TYPE_PERCENT = 1;
47+
public const SELECTION_PRICE_TYPE_PERCENT = 1;
5148

5249
/**
5350
* Array of cached options.
@@ -89,9 +86,9 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
8986
];
9087

9188
/**
92-
* Custom fields mapping.
89+
* Custom fields mapping for bundle product.
9390
*
94-
* @inherited
91+
* @var array
9592
*/
9693
protected $_customFieldsMapping = [
9794
'price_type' => 'bundle_price_type',
@@ -102,7 +99,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
10299
];
103100

104101
/**
105-
* Bundle field mapping.
102+
* Bundle field mapping for bundle product with selection.
106103
*
107104
* @var array
108105
*/
@@ -113,7 +110,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
113110
];
114111

115112
/**
116-
* Option type mapping.
113+
* Option type mapping for bundle product.
117114
*
118115
* @var array
119116
*/
@@ -202,11 +199,7 @@ protected function parseSelections($rowData, $entityId)
202199
$this->_cachedOptions[$entityId][$option['name']]['selections'] = [];
203200
}
204201
$this->_cachedOptions[$entityId][$option['name']]['selections'][] = $option;
205-
$this->_cachedOptionSelectQuery[] =
206-
$this->connection->quoteInto(
207-
'(parent_id = ' . (int)$entityId . ' AND title = ?)',
208-
$option['name']
209-
);
202+
$this->_cachedOptionSelectQuery[] = [(int)$entityId, $option['name']];
210203
}
211204
}
212205
return $selections;
@@ -477,18 +470,24 @@ protected function transformBundleCustomAttributes($rowData)
477470
*/
478471
protected function populateExistingOptions()
479472
{
480-
$existingOptions = $this->connection->fetchAssoc(
481-
$this->connection->select()->from(
482-
['bo' => $this->_resource->getTableName('catalog_product_bundle_option')],
483-
['option_id', 'parent_id', 'required', 'position', 'type']
484-
)->joinLeft(
485-
['bov' => $this->_resource->getTableName('catalog_product_bundle_option_value')],
486-
'bo.option_id = bov.option_id',
487-
['value_id', 'title']
488-
)->where(
489-
implode(' OR ', $this->_cachedOptionSelectQuery)
490-
)
473+
$select = $this->connection->select()->from(
474+
['bo' => $this->_resource->getTableName('catalog_product_bundle_option')],
475+
['option_id', 'parent_id', 'required', 'position', 'type']
476+
)->joinLeft(
477+
['bov' => $this->_resource->getTableName('catalog_product_bundle_option_value')],
478+
'bo.option_id = bov.option_id',
479+
['value_id', 'title']
491480
);
481+
$orWhere = false;
482+
foreach ($this->_cachedOptionSelectQuery as $item) {
483+
if ($orWhere) {
484+
$select->orWhere('parent_id = '.$item[0].' AND title = ?', $item[1]);
485+
} else {
486+
$select->where('parent_id = '.$item[0].' AND title = ?', $item[1]);
487+
$orWhere = true;
488+
}
489+
}
490+
$existingOptions = $this->connection->fetchAssoc($select);
492491
foreach ($existingOptions as $optionId => $option) {
493492
$this->_cachedOptions[$option['parent_id']][$option['title']]['option_id'] = $optionId;
494493
foreach ($option as $key => $value) {

dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Import/Product/Type/BundleTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,44 @@ public function testBundleImportUpdateValues(array $expectedValues): void
184184
$this->importedProductSkus = ['Simple 1', 'Simple 2', 'Simple 3', 'Bundle 1'];
185185
}
186186

187+
/**
188+
* Test that Bundle options with question mark are updated correctly by import
189+
*
190+
*
191+
* @magentoAppArea adminhtml
192+
* @magentoDbIsolation enabled
193+
* @magentoAppIsolation enabled
194+
* @return void
195+
*/
196+
public function testBundleImportUpdateValuesWithQuestionMark(): void
197+
{
198+
// import data from CSV file
199+
$pathToFile = __DIR__ . '/../../_files/import_bundle_with_question_mark.csv';
200+
$errors = $this->doImport($pathToFile, Import::BEHAVIOR_APPEND);
201+
$this->assertEquals(0, $errors->getErrorsCount());
202+
203+
// import data from CSV file to update values
204+
$pathToFile2 = __DIR__ . '/../../_files/import_bundle_with_question_mark.csv';
205+
$errors = $this->doImport($pathToFile2, Import::BEHAVIOR_APPEND);
206+
$this->assertEquals(0, $errors->getErrorsCount());
207+
208+
$resource = $this->objectManager->get(ProductResource::class);
209+
$productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME);
210+
$this->assertIsNumeric($productId);
211+
/** @var Product $product */
212+
$product = $this->objectManager->create(ProductRepositoryInterface::class);
213+
$ProductRepository = $product->get(self::TEST_PRODUCT_NAME);
214+
215+
$this->assertEquals(self::TEST_PRODUCT_NAME, $ProductRepository->getName());
216+
$this->assertEquals(self::TEST_PRODUCT_TYPE, $ProductRepository->getTypeId());
217+
$this->assertEquals(1, $ProductRepository->getShipmentType());
218+
219+
$bundleOptionCollection = $ProductRepository->getExtensionAttributes()->getBundleProductOptions();
220+
$this->assertCount(1, $bundleOptionCollection);
221+
222+
$this->importedProductSkus = ['Simple 1', 'Bundle 1'];
223+
}
224+
187225
/**
188226
* @magentoDataFixture Magento/Store/_files/second_store.php
189227
* @magentoDbIsolation disabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sku,store_view_code,attribute_set_code,product_type,product_websites,name,product_online,price,additional_attributes,qty,out_of_stock_qty,website_id,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values
2+
Simple 1,,Default,simple,base,Simple 1,1,100,,1000,0,1,,,,,
3+
Bundle 1,,Default,bundle,base,Bundle 1,1,,shipment_type=separately,0,0,1,dynamic,dynamic,Price range,dynamic,"name=Option?,type=checkbox,required=1,sku=Simple 1,price=0.0000,default=0,default_qty=1.0000,price_type=fixed,can_change_qty=1"

0 commit comments

Comments
 (0)