Skip to content

Commit 8c8397f

Browse files
authored
ENGCOM-7145: #25540: Products are not displaying infront end after updating product via importing CSV. #25664
2 parents 3126d65 + 23ab426 commit 8c8397f

File tree

3 files changed

+97
-35
lines changed

3 files changed

+97
-35
lines changed

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

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,31 @@
66
* Copyright © Magento, Inc. All rights reserved.
77
* See COPYING.txt for license details.
88
*/
9+
910
namespace Magento\BundleImportExport\Model\Import\Product\Type;
1011

11-
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
12-
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
13-
use Magento\Framework\App\ObjectManager;
1412
use Magento\Bundle\Model\Product\Price as BundlePrice;
1513
use Magento\Catalog\Model\Product\Type\AbstractType;
14+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
1615
use Magento\CatalogImportExport\Model\Import\Product;
16+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
17+
use Magento\Framework\App\ObjectManager;
1718
use Magento\Framework\App\ResourceConnection;
1819
use Magento\Framework\EntityManager\MetadataPool;
1920
use Magento\Store\Model\StoreManagerInterface;
2021

2122
/**
22-
* Class Bundle
23+
* Import entity Bundle product type.
2324
*
24-
* @package Magento\BundleImportExport\Model\Import\Product\Type
2525
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2626
*/
2727
class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
2828
{
29-
3029
/**
3130
* Delimiter before product option value.
3231
*/
3332
const BEFORE_OPTION_VALUE_DELIMITER = ';';
3433

35-
/**
36-
* Pair value separator.
37-
*/
3834
const PAIR_VALUE_SEPARATOR = '=';
3935

4036
/**
@@ -47,19 +43,10 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
4743
*/
4844
const VALUE_FIXED = 'fixed';
4945

50-
/**
51-
* Not fixed dynamic attribute.
52-
*/
5346
const NOT_FIXED_DYNAMIC_ATTRIBUTE = 'price_view';
5447

55-
/**
56-
* Selection price type fixed.
57-
*/
5848
const SELECTION_PRICE_TYPE_FIXED = 0;
5949

60-
/**
61-
* Selection price type percent.
62-
*/
6350
const SELECTION_PRICE_TYPE_PERCENT = 1;
6451

6552
/**
@@ -133,7 +120,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
133120
protected $_optionTypeMapping = [
134121
'dropdown' => 'select',
135122
'radiobutton' => 'radio',
136-
'checkbox' => 'checkbox',
123+
'checkbox' => 'checkbox',
137124
'multiselect' => 'multi',
138125
];
139126

@@ -543,7 +530,7 @@ protected function populateExistingSelections($existingOptions)
543530
? $this->_bundleFieldMapping[$origKey]
544531
: $origKey;
545532
if (
546-
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
533+
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
547534
) {
548535
$this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key] =
549536
$existingSelection[$origKey];
@@ -616,6 +603,7 @@ protected function populateInsertOptionValues(array $optionIds): array
616603
if ($assoc['position'] == $this->_cachedOptions[$entityId][$key]['index']
617604
&& $assoc['parent_id'] == $entityId) {
618605
$option['parent_id'] = $entityId;
606+
//phpcs:ignore Magento2.Performance.ForeachArrayMerge
619607
$optionValues = array_merge(
620608
$optionValues,
621609
$this->populateOptionValueTemplate($option, $optionId)
@@ -675,10 +663,7 @@ private function insertParentChildRelations()
675663
$childIds = [];
676664
foreach ($options as $option) {
677665
foreach ($option['selections'] as $selection) {
678-
if (!isset($selection['parent_product_id'])) {
679-
if (!isset($this->_cachedSkuToProducts[$selection['sku']])) {
680-
continue;
681-
}
666+
if (isset($this->_cachedSkuToProducts[$selection['sku']])) {
682667
$childIds[] = $this->_cachedSkuToProducts[$selection['sku']];
683668
}
684669
}
@@ -717,6 +702,8 @@ protected function _initAttributes()
717702
}
718703
}
719704
}
705+
706+
return $this;
720707
}
721708

722709
/**
@@ -735,17 +722,19 @@ protected function deleteOptionsAndSelections($productIds)
735722
$optionTable = $this->_resource->getTableName('catalog_product_bundle_option');
736723
$optionValueTable = $this->_resource->getTableName('catalog_product_bundle_option_value');
737724
$selectionTable = $this->_resource->getTableName('catalog_product_bundle_selection');
738-
$valuesIds = $this->connection->fetchAssoc($this->connection->select()->from(
739-
['bov' => $optionValueTable],
740-
['value_id']
741-
)->joinLeft(
742-
['bo' => $optionTable],
743-
'bo.option_id = bov.option_id',
744-
['option_id']
745-
)->where(
746-
'parent_id IN (?)',
747-
$productIds
748-
));
725+
$valuesIds = $this->connection->fetchAssoc(
726+
$this->connection->select()->from(
727+
['bov' => $optionValueTable],
728+
['value_id']
729+
)->joinLeft(
730+
['bo' => $optionTable],
731+
'bo.option_id = bov.option_id',
732+
['option_id']
733+
)->where(
734+
'parent_id IN (?)',
735+
$productIds
736+
)
737+
);
749738
$this->connection->delete(
750739
$optionValueTable,
751740
$this->connection->quoteInto('value_id IN (?)', array_keys($valuesIds))
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="UpdateBundleProductViaImportTest">
12+
<annotations>
13+
<features value="Import/Export"/>
14+
<title value="Update Bundle product via import"/>
15+
<description
16+
value="Check that Bundle products are displaying on the storefront after updating product via importing CSV"/>
17+
<severity value="MAJOR"/>
18+
<group value="importExport"/>
19+
</annotations>
20+
<before>
21+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
22+
</before>
23+
<after>
24+
<!-- Delete products created via import -->
25+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteBundleProduct">
26+
<argument name="sku" value="Bundle"/>
27+
</actionGroup>
28+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteSimpleProduct">
29+
<argument name="sku" value="Simple"/>
30+
</actionGroup>
31+
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
32+
</after>
33+
34+
<!-- Create Bundle product via import -->
35+
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsCreate">
36+
<argument name="behavior" value="Add/Update"/>
37+
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
38+
<argument name="importNoticeMessage" value="Created: 2, Updated: 0, Deleted: 0"/>
39+
</actionGroup>
40+
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterCreate"/>
41+
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterCreate"/>
42+
43+
<!-- Check Bundle product is visible on the storefront-->
44+
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterCreation">
45+
<argument name="categoryName" value="New"/>
46+
</actionGroup>
47+
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
48+
stepKey="assertBundleProductInStockAfterCreation">
49+
<argument name="productName" value="Bundle"/>
50+
</actionGroup>
51+
52+
<!-- Update Bundle product via import -->
53+
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsUpdate">
54+
<argument name="behavior" value="Add/Update"/>
55+
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
56+
<argument name="importNoticeMessage" value="Created: 0, Updated: 2, Deleted: 0"/>
57+
</actionGroup>
58+
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterUpdate"/>
59+
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterUpdate"/>
60+
61+
<!-- Check Bundle product is still visible on the storefront-->
62+
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterUpdate">
63+
<argument name="categoryName" value="New"/>
64+
</actionGroup>
65+
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
66+
stepKey="assertBundleProductInStockAfterUpdate">
67+
<argument name="productName" value="Bundle"/>
68+
</actionGroup>
69+
</test>
70+
</tests>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,related_position,crosssell_skus,crosssell_position,upsell_skus,upsell_position,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,bundle_shipment_type,associated_skus,downloadable_links,downloadable_samples,configurable_variations,configurable_variation_labels
2+
Simple,,Default,simple,"Default Category/New",base,Simple,,,1.000000,1,"Taxable Goods","Catalog, Search",100.000000,,,,simple,Simple,Simple,"Simple ",,,,,,,,,"3/18/20, 6:56 AM","3/18/20, 6:56 AM",,,"Block after Info Column",,,,"Use config",,,,,,,"Use config",,,1000.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,,,,
3+
Bundle,,Default,bundle,"Default Category/New",base,Bundle,,,,1,"Taxable Goods","Catalog, Search",,,,,bundle,Bundle,Bundle,"Bundle ",,,,,,,,,"3/18/20, 6:57 AM","3/18/20, 6:57 AM",,,"Block after Info Column",,,,"Use config",,,,,,,"Use config",,,0.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,dynamic,dynamic,"Price range",dynamic,"name=Test Option,type=select,required=1,sku=Simple,price=0.0000,default=1,default_qty=1.0000,price_type=fixed,can_change_qty=0",together,,,,,

0 commit comments

Comments
 (0)