0

I'm trying to extend the class \Magento\Swatches\Block\Product\Renderer\Configurable to access session data. So I did this as proposed on so many stacks and tutorials.

class ExtendConfigurable extends \Magento\Swatches\Block\Product\Renderer\Configurable
{
    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 = []
    ) {
        parent::__construct($context, $arrayUtils, $jsonEncoder, $helper, $catalogProduct, $currentCustomer, $priceCurrency, $configurableAttributeData, $swatchHelper, $swatchMediaHelper, $data);
    }

This works. So now I want to inject the session data:

class ExtendConfigurable extends \Magento\Swatches\Block\Product\Renderer\Configurable
{
    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 = [],
        Magento\Customer\Model\Session $session
    ) {
        parent::__construct($context, $arrayUtils, $jsonEncoder, $helper, $catalogProduct, $currentCustomer, $priceCurrency, $configurableAttributeData, $swatchHelper, $swatchMediaHelper, $data);
        $this->customerSession = $session
    }

But all I get is:

must be an instance of Magento\Catalog\Model\Session, none given

How can I extend that class to access session data?

0

Can't confirm with this special case (getting session data) just yet. But in another case what was needed is recompiling di.

bin/magento setup:di:compile

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.