I'm trying to get a configuration for my custom module

My Custom module overrides \Magento\Swatches\Block\Product\Renderer\Configurable

With the following Code:

namespace Vendor\swatchExtender\Block;

use Magento\Catalog\Block\Product\Context;
use Magento\Catalog\Helper\Product as CatalogProduct;
use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Helper\Data;
use Magento\ConfigurableProduct\Model\ConfigurableAttributeData;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Stdlib\ArrayUtils;
use Magento\Store\Model\ScopeInterface;
use Magento\Swatches\Helper\Data as SwatchData;
use Magento\Swatches\Helper\Media;
use Magento\Swatches\Model\Swatch;
use Magento\Framework\App\ObjectManager;
use Magento\Swatches\Model\SwatchAttributesProvider;

class Configurable extends \Magento\Swatches\Block\Product\Renderer\Configurable
    protected function extractNecessarySwatchData(array $swatchDataArray)
        $result['type'] = $swatchDataArray['type'];

        if ($result['type'] == Swatch::SWATCH_TYPE_VISUAL_IMAGE && !empty($swatchDataArray['value'])) {
            $result['value'] = $this->swatchMediaHelper->getSwatchAttributeImage(
            $result['thumb'] = $this->swatchMediaHelper->getSwatchAttributeImage(
        } else {
            $result['value'] = $swatchDataArray['value'];
        $result['custom_parameter'] = 'value';


But now i want to read the configuation parameters from the admin-panel.

I have created a Helper data Class:

namespace Vendor\swatchExtender\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
    public function getConfig($config_path)
        return $this->scopeConfig->getValue(

But i have no idea how to access the Helper/data, everything i tried will brake the Configurable class, because of the parent __Construct,

How can i Access my Helper/Data class ?

  • you want use helper function inside block file? – Abhishek Panchal Jan 10 '18 at 17:24
  • @AbhishekPanchal I have extend / replaced the original function, to add some extra output, but now i want to get some parameters from the configuration in the admin – Trickster Jan 10 '18 at 17:41

Your constructor should like this:

public function __construct(
    Context $context,
    ArrayUtils $arrayUtils,
    EncoderInterface $jsonEncoder,
    Data $helper,
    CatalogProduct $catalogProduct,
    CurrentCustomer $currentCustomer,
    PriceCurrencyInterface $priceCurrency,
    ConfigurableAttributeData $configurableAttributeData,
    SwatchData $swatchHelper,
    Media $swatchMediaHelper,
    array $data = [],
    SwatchAttributesProvider $swatchAttributesProvider = null,
    \Vendor\Module\Helper\Data $helper
) {
    $this->helper = $helper;

Now you can use $this->helper to call helper function

class Configurable extends \Magento\Swatches\Block\Product\Renderer\Configurable
    protected function extractNecessarySwatchData(array $swatchDataArray)
         * Yout Code


Remove var/generation folder for Magento 2.2 remove /generated folder

  • Thank you, The Biggest problem for me with all the Trying was Removing the /generated folder – Trickster Jan 10 '18 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.