Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magento/magento2#25540: Products are not displaying infront end after updating product via importing CSV. #25664

Merged
merged 5 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,31 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\BundleImportExport\Model\Import\Product\Type;

use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Bundle\Model\Product\Price as BundlePrice;
use Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributeCollectionFactory;
use Magento\CatalogImportExport\Model\Import\Product;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory as AttributeSetCollectionFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class Bundle
* Import entity Bundle product type.
*
* @package Magento\BundleImportExport\Model\Import\Product\Type
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
{

/**
* Delimiter before product option value.
*/
const BEFORE_OPTION_VALUE_DELIMITER = ';';

/**
* Pair value separator.
*/
const PAIR_VALUE_SEPARATOR = '=';

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

/**
* Not fixed dynamic attribute.
*/
const NOT_FIXED_DYNAMIC_ATTRIBUTE = 'price_view';

/**
* Selection price type fixed.
*/
const SELECTION_PRICE_TYPE_FIXED = 0;

/**
* Selection price type percent.
*/
const SELECTION_PRICE_TYPE_PERCENT = 1;

/**
Expand Down Expand Up @@ -133,7 +120,7 @@ class Bundle extends \Magento\CatalogImportExport\Model\Import\Product\Type\Abst
protected $_optionTypeMapping = [
'dropdown' => 'select',
'radiobutton' => 'radio',
'checkbox' => 'checkbox',
'checkbox' => 'checkbox',
'multiselect' => 'multi',
];

Expand Down Expand Up @@ -543,7 +530,7 @@ protected function populateExistingSelections($existingOptions)
? $this->_bundleFieldMapping[$origKey]
: $origKey;
if (
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
!isset($this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key])
) {
$this->_cachedOptions[$existingSelection['parent_product_id']][$optionTitle]['selections'][$selectIndex][$key] =
$existingSelection[$origKey];
Expand Down Expand Up @@ -616,6 +603,7 @@ protected function populateInsertOptionValues(array $optionIds): array
if ($assoc['position'] == $this->_cachedOptions[$entityId][$key]['index']
&& $assoc['parent_id'] == $entityId) {
$option['parent_id'] = $entityId;
//phpcs:ignore Magento2.Performance.ForeachArrayMerge
$optionValues = array_merge(
$optionValues,
$this->populateOptionValueTemplate($option, $optionId)
Expand Down Expand Up @@ -675,10 +663,7 @@ private function insertParentChildRelations()
$childIds = [];
foreach ($options as $option) {
foreach ($option['selections'] as $selection) {
if (!isset($selection['parent_product_id'])) {
if (!isset($this->_cachedSkuToProducts[$selection['sku']])) {
continue;
}
if (isset($this->_cachedSkuToProducts[$selection['sku']])) {
$childIds[] = $this->_cachedSkuToProducts[$selection['sku']];
}
}
Expand Down Expand Up @@ -717,6 +702,8 @@ protected function _initAttributes()
}
}
}

return $this;
}

/**
Expand All @@ -735,17 +722,19 @@ protected function deleteOptionsAndSelections($productIds)
$optionTable = $this->_resource->getTableName('catalog_product_bundle_option');
$optionValueTable = $this->_resource->getTableName('catalog_product_bundle_option_value');
$selectionTable = $this->_resource->getTableName('catalog_product_bundle_selection');
$valuesIds = $this->connection->fetchAssoc($this->connection->select()->from(
['bov' => $optionValueTable],
['value_id']
)->joinLeft(
['bo' => $optionTable],
'bo.option_id = bov.option_id',
['option_id']
)->where(
'parent_id IN (?)',
$productIds
));
$valuesIds = $this->connection->fetchAssoc(
$this->connection->select()->from(
['bov' => $optionValueTable],
['value_id']
)->joinLeft(
['bo' => $optionTable],
'bo.option_id = bov.option_id',
['option_id']
)->where(
'parent_id IN (?)',
$productIds
)
);
$this->connection->delete(
$optionValueTable,
$this->connection->quoteInto('value_id IN (?)', array_keys($valuesIds))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="UpdateBundleProductViaImportTest">
<annotations>
<features value="Import/Export"/>
<title value="Update Bundle product via import"/>
<description
value="Check that Bundle products are displaying on the storefront after updating product via importing CSV"/>
<severity value="MAJOR"/>
<group value="importExport"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>
<after>
<!-- Delete products created via import -->
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteBundleProduct">
<argument name="sku" value="Bundle"/>
</actionGroup>
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteSimpleProduct">
<argument name="sku" value="Simple"/>
</actionGroup>
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
</after>

<!-- Create Bundle product via import -->
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsCreate">
<argument name="behavior" value="Add/Update"/>
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
<argument name="importNoticeMessage" value="Created: 2, Updated: 0, Deleted: 0"/>
</actionGroup>
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterCreate"/>
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterCreate"/>

<!-- Check Bundle product is visible on the storefront-->
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterCreation">
<argument name="categoryName" value="New"/>
</actionGroup>
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
stepKey="assertBundleProductInStockAfterCreation">
<argument name="productName" value="Bundle"/>
</actionGroup>

<!-- Update Bundle product via import -->
<actionGroup ref="AdminImportProductsActionGroup" stepKey="adminImportProductsUpdate">
<argument name="behavior" value="Add/Update"/>
<argument name="importFile" value="catalog_product_import_bundle.csv"/>
<argument name="importNoticeMessage" value="Created: 0, Updated: 2, Deleted: 0"/>
</actionGroup>
<magentoCLI command="cache:flush" arguments="full_page" stepKey="flushCacheAfterUpdate"/>
<magentoCLI command="indexer:reindex" stepKey="indexerReindexAfterUpdate"/>

<!-- Check Bundle product is still visible on the storefront-->
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPageAfterUpdate">
<argument name="categoryName" value="New"/>
</actionGroup>
<actionGroup ref="AssertStorefrontProductIsPresentOnCategoryPageActionGroup"
stepKey="assertBundleProductInStockAfterUpdate">
<argument name="productName" value="Bundle"/>
</actionGroup>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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
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,,,,,,,,,,,,,,,,,,,,,
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,,,,,