Fix configurable product type conversion when variants are removed#40391
Fix configurable product type conversion when variants are removed#40391koushikch7 wants to merge 9 commits intomagento:2.4-developfrom
Conversation
When a configurable product has all its variants removed and saved, it was incorrectly being converted to a simple product. This fix ensures that a configurable product preserves its type even when all variants are removed. Changes: 1. Modified Builder Plugin to check if product is already configurable before converting to simple type. Only converts to simple if the product was not previously a configurable product. 2. Modified TypeTransitionManager Plugin to preserve configurable type when attributes are empty if the product is already configurable. 3. Added unit tests: - Builder Plugin: testAfterBuildPreservesConfigurableTypeWhenAttributesAreEmpty() - TypeTransitionManager: testAroundProcessProductPreservesConfigurableTypeWhenAttributesEmpty() 4. Created integration tests to verify the fix works end-to-end for both existing and new configurable products. This allows users to: - Remove incorrect variants and re-add correct ones - Import configurable products multiple times - Manage variants without product type conversion Fixes magento#2703
|
Hi @koushikch7. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
@magento run all tests |
|
@magento run all tests |
- Refactored Plugin.php afterBuild() method to reduce NPath complexity (220 -> <200) * Extracted setProductType() private method * Extracted setRequiredAttributes() private method * Extracted copyAttributesFromConfigurable() private method * Added variable extraction for line length fix (131 -> 116 chars) - Fixed namespace in TypeTransitionTest.php to match file location * Changed from Magento\ConfigurableProduct\Test\Integration\Model\Product * To: Magento\ConfigurableProduct\Model\Product\TypeTransition - Fixed PluginTest.php mock configuration * Changed mock class from ProductTestHelper to Product * Added getOrigData to mocked methods list - Fixed ConfigurableTest.php mock configuration * Added getTypeId to mocked methods list Fixes magento#2703 - Ensures configurable product type is preserved when variants are removed Resolves PR magento#40391 test failures
|
@magento run all tests |
- Fixed namespace in TypeTransitionTest.php to match file location * Changed from: Magento\ConfigurableProduct\Model\Product\TypeTransition * Changed to: Magento\ConfigurableProduct\Model\Product - Fixed Cyclomatic Complexity in copyAttributesFromConfigurable() method * Extracted shouldCopyAttributes() private method * Extracted isAttributeValuable() private method * Reduced complexity from 11 to <10 Fixes integration test failures and code mess detector warnings
|
@magento run Static Tests |
|
@magento run Static Tests |
|
@magento run all tests |
…ay/month in dates" This reverts commit f5a2acc.
|
@magento run all tests |
|
@magento run Unit Tests |
|
@magento run all tests |
Issue #2703: Configurable product incorrectly converts to simple when all variants are removed
This PR fixes the type transition logic to preserve the configurable product type even when all variants are removed.
Changes:
Fixes #2703