public function validate($value, Constraint $constraint)
{
if (!$value instanceof ProductInterface) {
throw new UnexpectedTypeException($value, ProductInterface::class);
}
if (!$value->isSimple()) {
return;
}
if (null !== $this->productVariantRepository->findOneBy(['code' => $value->getCode()])) {
$this->context->buildViolation($constraint->message)->atPath('code')->addViolation();
}
}