src/Callbacks/OptionValueAndSwatchHandler.php
public function createOptionSwatchIfNecessary($attributeCode, $storeId, $value, $type)
    {

        // try to load the attribute option value and add the option ID
        if ($this->loadAttributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType($entityTypeId = $this->getEntityTypeId(), $attributeCode, $attributeCode, $storeId, $value)) {
            return;
        }

        // initialize the option ID
        $optionId = $this->createOptionBySwatchIfNecessary($entityTypeId, $attributeCode, $storeId, $value, $type);

        // create the swatch for the option
        $this->persistAttributeOptionSwatch($this->prepareAttributeOptionSwatch($optionId, $storeId, $value, $type));

        // log a message that the swwatch has successfully been created
        $this->getSystemLogger()->info(sprintf('Successfully created option swatch for attribute with code "%s", store ID "%d" and value "%s"', $attributeCode, $storeId, $value));
    }
public function createOptionSwatchIfNecessary($attributeCode, $storeId, $value, $type)
    {

        // try to load the attribute option value and add the option ID
        if ($this->loadAttributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType($entityTypeId = $this->getEntityTypeId(), $attributeCode, $attributeCode, $storeId, $value)) {
            return;
        }

        // initialize the option ID
        $optionId = $this->createOptionBySwatchIfNecessary($entityTypeId, $attributeCode, $storeId, $value, $type);

        // create the swatch for the option
        $this->persistAttributeOptionSwatch($this->prepareAttributeOptionSwatch($optionId, $storeId, $value, $type));

        // log a message that the swwatch has successfully been created
        $this->getSystemLogger()->info(sprintf('Successfully created option swatch for attribute with code "%s", store ID "%d" and value "%s"', $attributeCode, $storeId, $value));
    }
Queries whether or not an option as well as its swatch/value for the attribute with the given code
already exists. If not the option and/or the swatch will be created dynamically.

@param string  $attributeCode The attribute code to create the option as well as the swatch for
@param integer $storeId       The store ID
@param mixed   $value         The store specific option swatch/value
@param string  $type          The type to create the swatch for

@return void