Magento 2 - while saving product from admin getting error as Class Magento\ConfigurableProduct\Model\Product\VariationHandler does not exist
-
19-12-2020 - |
Question
Magento 2 while saving product from admin getting error as "Class Magento\ConfigurableProduct\Model\Product\VariationHandler does not exist". But this class is there in Vendor folder.
There is no use even after clearing generation files and re-compiling the code.
Solution
This is a strange issue.
Override getConstructor method in vendor/magento/framework/Code/Reader/ClassReader.php and change it to below
public function getConstructor($className)
{
$class = new \ReflectionClass($className);
$result = null;
$constructor = $class->getConstructor();
if ($constructor) {
$result = [];
/** @var $parameter \ReflectionParameter */
foreach ($constructor->getParameters() as $parameter) {
try {
$result[] = [
$parameter->getName(),
$parameter->getClass() !== null ? $parameter->getClass()->getName() : null,
!$parameter->isOptional(),
$parameter->isOptional()
? ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null)
: null,
];
} catch (\ReflectionException $e) {
if($parameter->getName() == 'variationHandler' ) {
$result[] = [
$parameter->getName(),
$parameter->getClass() !== null ? $parameter->getClass()->getName() : null,
!$parameter->isOptional(),
$parameter->isOptional()
? ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null)
: null,
];
continue;
}
$message = $e->getMessage();
throw new \ReflectionException($message, 0, $e);
}
}
}
return $result;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange