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 ) {
0 commit comments