/**
  * Adds new attribute value using ajax request
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function ajaxAddAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         return $this->redirectToAction('index');
     }
     $attributeValueName = $request->request->get('name');
     $attributeId = (int) $request->request->get('attribute');
     $value = $this->manager->addAttributeValue($attributeValueName, $attributeId);
     return $this->jsonResponse(['id' => $value->getId()]);
 }
 /**
  * {@inheritdoc}
  */
 public function findOrCreate($data, AttributeGroupInterface $group)
 {
     $id = $this->propertyAccessor->getValue($data, '[id]');
     $name = $this->propertyAccessor->getValue($data, '[name]');
     $values = $this->propertyAccessor->getValue($data, '[values]');
     $attribute = $this->attributeManager->getAttribute($id, $name, $group);
     if (!empty($values)) {
         $valuesCollection = new ArrayCollection();
         foreach ($values as $value) {
             $attributeValue = $this->attributeValueManager->getAttributeValue($value['id'], $value['name'], $attribute);
             $valuesCollection->add($attributeValue);
         }
         $this->synchronizeCollection($attribute->getValues(), $valuesCollection);
         $attribute->setValues($valuesCollection);
     }
     return $attribute;
 }