/**
  * Filters the item to keep only association related fields
  *
  * @param array $item
  *
  * @return array
  */
 protected function filter(array $item)
 {
     $requiredFields = $this->assocColumnsResolver->resolveAssociationColumns();
     $requiredFields[] = $this->attrColumnsResolver->resolveIdentifierField();
     foreach (array_keys($item) as $fieldName) {
         if (!in_array($fieldName, $requiredFields)) {
             unset($item[$fieldName]);
         }
     }
     return $item;
 }
 /**
  * Returns associations fields (resolves once)
  *
  * @return array
  */
 protected function getOptionalAssociationFields()
 {
     if (empty($this->optionalAssociationFields)) {
         $this->optionalAssociationFields = $this->assocColumnsResolver->resolveAssociationColumns();
     }
     return $this->optionalAssociationFields;
 }
 /**
  * Denormalize product associations
  *
  * @param string           &$data
  * @param string           $format
  * @param array            $context
  * @param ProductInterface $product
  *
  * @throws \RuntimeException
  */
 protected function denormalizeAssociations(&$data, $format, array $context, ProductInterface $product)
 {
     foreach ($product->getAssociations() as $association) {
         foreach ($association->getGroups() as $group) {
             $association->removeGroup($group);
         }
         foreach ($association->getProducts() as $prod) {
             $association->removeProduct($prod);
         }
     }
     // Get association field names and add associations
     $assocFieldNames = $this->assocFieldResolver->resolveAssociationColumns();
     foreach ($assocFieldNames as $assocFieldName) {
         if (isset($data[$assocFieldName])) {
             if (strlen($data[$assocFieldName]) > 0) {
                 list($associationTypeCode, $part) = explode('-', $assocFieldName);
                 $association = $product->getAssociationForTypeCode($associationTypeCode);
                 $association = $this->serializer->denormalize($data[$assocFieldName], $this->associationClass, $format, ['entity' => $association, 'association_type_code' => $associationTypeCode, 'part' => $part] + $context);
                 if (!$product->getAssociationForTypeCode($associationTypeCode)) {
                     $product->addAssociation($association);
                 }
             }
             unset($data[$assocFieldName]);
         }
     }
     foreach (array_keys($data) as $fieldName) {
         if (null !== ($matches = $this->extractAssociationFieldNameInfos($fieldName))) {
             throw new \RuntimeException(sprintf('Association type "%s" does not exist anymore', $matches['assoc_type_code']));
         }
     }
 }
 /**
  * Get the association field names
  *
  * @return array
  */
 public function getAssociationFieldNames()
 {
     return $this->associationColumnsResolver->resolveAssociationColumns();
 }
 /**
  * @param string $column
  *
  * @return bool
  */
 public function supportsColumn($column)
 {
     $associationFields = $this->assocFieldResolver->resolveAssociationColumns();
     $fields = array_merge(['categories', 'groups', 'enabled', 'family'], $associationFields);
     return in_array($column, $fields);
 }