0

I am trying to import products into v2.2.7. Many products have many categories like:

Default Category/A1/A2/A3, Default Category/B1/B2/B3

When i check the product configuration, the product only has A3 and B3 checked as categories when it should have all the following categories checked for the product:

Default Category
Default Category/A1
Default Category/A1/A2
Default Category/A1/A2/A3

Default Category/B1
Default Category/B1/B2
Default Category/B1/B2/B3

I even tried sending the categories in like the following hoping it would add each of them as a category:

Default Category/A1,Default Category/A1/A2,Default Category/A1/A2/A3,Default Category/B1,Default Category/B1/B2,Default Category/B1/B2/B3

But that resulted in the following error:

1. Category " has not been created. URL key for specified store already exists. in row(s): 1
General system exception happened
Additional data:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`catalog_category_product`, CONSTRAINT `CAT_CTGR_PRD_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE), query was: INSERT INTO `catalog_category_product` (`product_id`,`category_id`,`position`) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?) ON DUPLICATE KEY UPDATE `product_id` = VALUES(`product_id`), `category_id` = VALUES(`category_id`)

And when i go to categories, I see it's created "Default Category" again instead of importing to the existing root "Default Category"! And it also created A1 and B1 in the others inside the root "Default Category".

test csv:

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,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,deferred_stock_update,use_config_deferred_stock_update,related_skus,crosssell_skus,upsell_skus,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,associated_skus
qqqq,,Default,simple,"Default Category/A1, Default Category/A1/A2, Default Category/A1/A2/A3",base,Cool sock,,test,1,1,Taxable Goods,"Catalog, Search",0,,,,test11,test meta title,,test meta description,,,,,Block after Info Column,,999,,,,,,,,,Use config,,"has_options=0,quantity_and_stock_status=In Stock,required_options=0",17,0,1,0,0,1,1,0,0,1,1,7,1,1,1,1,0,1,0,0,1,0,1,,,,,,,,,,,

Below is what my category directory looks like after the failure (Before test, I deleted all categories and sub-categories except "Default Category" since trying the import with categories already created still broke).

Default Category (0)
  A1 (0)
Default Category (0)

Maybe i shouldn't tell it the category belongs in Default Category? Nope, that just creates another root category and even then it doesn't check all categories. Here is test CSV:

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,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,deferred_stock_update,use_config_deferred_stock_update,related_skus,crosssell_skus,upsell_skus,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,associated_skus
qqqq,,Default,simple,"A1, A1/A2, A1/A2/A3",base,Cool sock,,test,1,1,Taxable Goods,"Catalog, Search",0,,,,test11,test meta title,,test meta description,,,,,Block after Info Column,,999,,,,,,,,,Use config,,"has_options=0,quantity_and_stock_status=In Stock,required_options=0",17,0,1,0,0,1,1,0,0,1,1,7,1,1,1,1,0,1,0,0,1,0,1,,,,,,,,,,,

Which results in the following category structure: enter image description here

What? two A1's? And didn't even check the A1 that is the parent of the checked A2.

How can i import products and make the product appear in the parent category as well as sub-categories instead of only the last child category?

0

Both test csv examples in the post have spaces after the comma in the categories. Brutal. Not sure why Magento doesn't trim white-space off beginning and end of field on import.

Try this:

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,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,deferred_stock_update,use_config_deferred_stock_update,related_skus,crosssell_skus,upsell_skus,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,associated_skus
qqqq,,Default,simple,"Default Category/A1,Default Category/A1/A2,Default Category/A1/A2/A3",base,Cool sock,,test,1,1,Taxable Goods,"Catalog, Search",0,,,,test11,test meta title,,test meta description,,,,,Block after Info Column,,999,,,,,,,,,Use config,,"has_options=0,quantity_and_stock_status=In Stock,required_options=0",17,0,1,0,0,1,1,0,0,1,1,7,1,1,1,1,0,1,0,0,1,0,1,,,,,,,,,,,

Results looking at categories in that product: enter image description here

Something else to look into if you want products to show up in parent category is checking Catalog > Categories > [your category] > Display Settings > Anchor = Yes. Do this for each of the categories that you want to inherit/show it's child category products .

Note that setting it to No has the side affect of removing the category "layered navigation" at that level. To get around this, setup attributes that match your categories and apply them to your products during on-boarding so you have more control over the way things show up.

Threads related to second idea:
Parent category is showing products in subcategories, even though product was not assigned to parent category

https://stackoverflow.com/questions/22990622/magento-stop-child-products-showing-in-anchor-category

Magento 2.2.6 Anchor setting (ON / OFF) does not work in category setting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.