/**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (null === $data || '' === $data) {
         return null;
     }
     $attribute = $context['attribute'];
     $code = $this->prepareOptionCode($attribute, $data);
     return $this->repository->findOneByIdentifier($code);
 }
 /**
  * {@inheritdoc}
  *
  * Expected data input format: ["option_code", "other_option_code"]
  */
 public function setAttributeData(ProductInterface $product, AttributeInterface $attribute, $data, array $options = [])
 {
     $this->checkLocaleAndScope($attribute, $options['locale'], $options['scope'], 'multi select');
     $this->checkData($attribute, $data);
     $attributeOptions = [];
     foreach ($data as $optionCode) {
         $option = $this->attrOptionRepository->findOneBy(['code' => $optionCode, 'attribute' => $attribute]);
         if (null === $option) {
             throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'code', 'The option does not exist', 'setter', 'multi select', $optionCode);
         }
         $attributeOptions[] = $option;
     }
     $this->setOptions($product, $attribute, $attributeOptions, $options['locale'], $options['scope']);
 }
 /**
  * {@inheritdoc}
  *
  * Expected data input format: "option_code"
  */
 public function setAttributeData(ProductInterface $product, AttributeInterface $attribute, $data, array $options = [])
 {
     $options = $this->resolver->resolve($options);
     $this->checkLocaleAndScope($attribute, $options['locale'], $options['scope'], 'text');
     $this->checkData($attribute, $data);
     if (null === $data) {
         $option = null;
     } else {
         $option = $this->attrOptionRepository->findOneBy(['code' => $data, 'attribute' => $attribute]);
         if (null === $option) {
             throw InvalidArgumentException::validEntityCodeExpected($attribute->getCode(), 'code', 'The option does not exist', 'setter', 'simple select', $data);
         }
     }
     $this->setOption($product, $attribute, $option, $options['locale'], $options['scope']);
 }
 /**
  * {@inheritdoc}
  */
 public function setValue(array $products, AttributeInterface $attribute, $data, $locale = null, $scope = null)
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'simple select');
     $this->checkData($attribute, $data);
     if (null === $data) {
         $option = null;
     } else {
         $option = $this->attrOptionRepository->findOneBy(['code' => $data, 'attribute' => $attribute]);
         if (null === $option) {
             throw InvalidArgumentException::arrayInvalidKey($attribute->getCode(), 'code', 'The option does not exist', 'setter', 'simple select', $data);
         }
     }
     foreach ($products as $product) {
         $this->setOption($attribute, $product, $option, $locale, $scope);
     }
 }
 /**
  * Find Option entity from identifier
  *
  * @param string $identifier
  *
  * @return AttributeOptionInterface
  */
 protected function findEntity($identifier)
 {
     return $this->repository->findOneByIdentifier($identifier);
 }