private function processAttributes(ProductInterface $variant, array $variantData, $locale)
    {
        $parent = $variant->getParent();

        // Number of attributes in variantData and parents variant-attributes need to match and must not be 0.
        $sizeOfVariantAttributes = count($this->getProperty($variantData, 'attributes'));
        $sizeOfParentAttributes = $parent->getVariantAttributes()->count();
        if (!$sizeOfVariantAttributes
            || !$sizeOfParentAttributes
            || $sizeOfVariantAttributes != $sizeOfParentAttributes
        ) {
            throw new ProductException('Invalid number of attributes for variant provided.');
        }

        $attributesDataCopy = $variantData['attributes'];

        // For all variants of parent, find corresponding attribute in variant-data.
        foreach ($parent->getVariantAttributes() as $variantAttribute) {
            foreach ($attributesDataCopy as $index => $attributeData) {
                if ($variantAttribute->getId() === $attributeData['attributeId']) {
                    // Update or create ProductAttribute for variant.
                    $this->productAttributeManager->updateOrCreateProductAttributeForProduct(
                        $variant,
                        $variantAttribute,
                        $attributeData,
                        $locale
                    );

                    unset($attributesDataCopy[$index]);
                }
            }
        }

        // Not all necessary variant attributes were defined in data array.
        if (count($attributesDataCopy)) {
            throw new ProductException('Invalid attributes for variant provided.');
        }
    }