Skip to content

Commit 7228147

Browse files
Merge remote-tracking branch 'origin/MC-35484' into 2.3-develop-pr51
2 parents 98a29a4 + 5798334 commit 7228147

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
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
*/
6+
declare(strict_types=1);
7+
98
namespace Magento\BundleImportExport\Model\Import\Product\Type;
109

1110
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
@@ -19,13 +18,15 @@
1918
use Magento\Store\Model\StoreManagerInterface;
2019

2120
/**
22-
* Class Bundle
21+
* Import entity of bundle product type
2322
*
24-
* @package Magento\BundleImportExport\Model\Import\Product\Type
2523
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2624
*/
2725
class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
2826
{
27+
/**
28+
* phpcs:disable Magento2.Commenting.ConstantsPHPDocFormatting
29+
*/
2930

3031
/**
3132
* Delimiter before product option value.
@@ -62,6 +63,10 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
6263
*/
6364
const SELECTION_PRICE_TYPE_PERCENT = 1;
6465

66+
/**
67+
* phpcs:enable Magento2.Commenting.ConstantsPHPDocFormatting
68+
*/
69+
6570
/**
6671
* Array of cached options.
6772
*
@@ -616,6 +621,7 @@ protected function populateInsertOptionValues(array $optionIds): array
616621
if ($assoc['position'] == $this->_cachedOptions[$entityId][$key]['index']
617622
&& $assoc['parent_id'] == $entityId) {
618623
$option['parent_id'] = $entityId;
624+
//phpcs:ignore Magento2.Performance.ForeachArrayMerge
619625
$optionValues = array_merge(
620626
$optionValues,
621627
$this->populateOptionValueTemplate($option, $optionId)
@@ -675,10 +681,7 @@ private function insertParentChildRelations()
675681
$childIds = [];
676682
foreach ($options as $option) {
677683
foreach ($option['selections'] as $selection) {
678-
if (!isset($selection['parent_product_id'])) {
679-
if (!isset($this->_cachedSkuToProducts[$selection['sku']])) {
680-
continue;
681-
}
684+
if (isset($this->_cachedSkuToProducts[$selection['sku']])) {
682685
$childIds[] = $this->_cachedSkuToProducts[$selection['sku']];
683686
}
684687
}
@@ -717,6 +720,8 @@ protected function _initAttributes()
717720
}
718721
}
719722
}
723+
724+
return $this;
720725
}
721726

722727
/**
@@ -786,7 +791,7 @@ private function getStoreIdByCode(string $storeCode): int
786791
if (!isset($this->storeCodeToId[$storeCode])) {
787792
/** @var $store \Magento\Store\Model\Store */
788793
foreach ($this->storeManager->getStores() as $store) {
789-
$this->storeCodeToId[$store->getCode()] = $store->getId();
794+
$this->storeCodeToId[$store->getCode()] = (int)$store->getId();
790795
}
791796
}
792797

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
<stories value="Update Bundle product via import"/>
14+
<features value="Import/Export"/>
15+
<title value="Bundle relations is removed when products are re-imported"/>
16+
<description value="Bundle relations is removed when products are re-imported"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-35605"/>
19+
<useCaseId value="MC-35484"/>
20+
<group value="importExport"/>
21+
</annotations>
22+
<before>
23+
<actionGroup ref="LoginActionGroup" stepKey="loginAsAdmin"/>
24+
</before>
25+
<after>
26+
<!-- Delete products created via import -->
27+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteBundleProduct">
28+
<argument name="sku" value="Bundle"/>
29+
</actionGroup>
30+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteSimpleProduct">
31+
<argument name="sku" value="Simple"/>
32+
</actionGroup>
33+
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
34+
</after>
35+
36+
<!-- Create Bundle product via import -->
37+
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsCreate">
38+
<argument name="behavior" value="Add/Update"/>
39+
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
40+
<argument name="importNoticeMessage" value="Created: 2, Updated: 0, Deleted: 0"/>
41+
</actionGroup>
42+
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterCreate"/>
43+
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterCreate"/>
44+
45+
<!-- Check Bundle product is visible on the storefront-->
46+
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterCreation">
47+
<argument name="categoryName" value="New"/>
48+
</actionGroup>
49+
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
50+
stepKey="assertBundleProductInStockAfterCreation">
51+
<argument name="productName" value="Bundle"/>
52+
</actionGroup>
53+
54+
<!-- Update Bundle product via import -->
55+
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsUpdate">
56+
<argument name="behavior" value="Add/Update"/>
57+
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
58+
<argument name="importNoticeMessage" value="Created: 0, Updated: 2, Deleted: 0"/>
59+
</actionGroup>
60+
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterUpdate"/>
61+
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterUpdate"/>
62+
63+
<!-- Check Bundle product is still visible on the storefront-->
64+
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterUpdate">
65+
<argument name="categoryName" value="New"/>
66+
</actionGroup>
67+
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
68+
stepKey="assertBundleProductInStockAfterUpdate">
69+
<argument name="productName" value="Bundle"/>
70+
</actionGroup>
71+
</test>
72+
</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)