Zend certified PHP/Magento developer

Magento 2.3 – Swatches Helper override

I’m trying to override a function in the Helper of the Swatches module of Magento 2. The function resides in the Data.php file. As some of you may know in specific versions of Magento 2 the text swatch values fall back to the default Admin value due to a bug.

A fix was issued here: https://github.com/magento/magento2/pull/15960

I am trying to implement this fix by overriding the function in Data.php using preference.

Since the Porto theme that I’m using is already overriding some other functions I decided to add my override there.

app/code/Smartwave/Porto/etc/di.xml

< ?xml version="1.0"?>



    
        
            MagentoFrameworkViewElementTemplateContext
            MagentoFrameworkRegistry
        
    


    
        
            MagentoFrameworkViewElementTemplateContext
            MagentoCatalogHelperCategory
            MagentoCatalogModelIndexerCategoryFlatState
            MagentoThemeBlockHtmlTopmenu
        
    





As you can see I added the preference on the last line.

app/code/Smartwave/Porto/Helper/Swatches/Data.php

namespace SmartwavePortoHelperSwatches;

class Data extends MagentoSwatchesHelperData
{

/**
 * @param array $fallbackValues
 * @param array $swatches
 * @return array
 */
public function addFallbackOptions(array $fallbackValues, array $swatches)
{
    $currentStoreId = $this->storeManager->getStore()->getId();
    foreach ($fallbackValues as $optionId => $optionsArray) {
        if (isset($optionsArray[$currentStoreId]['type'], $swatches[$optionId]['type'])
            && $swatches[$optionId]['type'] === $optionsArray[$currentStoreId]['type']
        ) {
            $swatches[$optionId] = $optionsArray[$currentStoreId];
        } elseif (isset($optionsArray[$currentStoreId])) {
            $swatches[$optionId] = $optionsArray[$currentStoreId];
        } elseif (isset($optionsArray[self::DEFAULT_STORE_ID])) {
            $swatches[$optionId] = $optionsArray[self::DEFAULT_STORE_ID];
        }
    }

    return $swatches;
}

}

However this doesn’t seem to work. Is there anyone that can tell me why this is the case.