I am trying to override the Magento\ConfigurableProduct\Block\Product\View\Type\Configurable class.

I have added a preference in app/code/vendor/module/etc/di.xml file.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" type="vendor\ConfigurableProduct\Block\Product\View\Type\Configurable" />

After running the setup:di:compile command, I noticed that Magento is still using the old one.

I have added preferences number of times but had experienced such behavior.

  • is worth mentioning if you haven't done so run setup:upgrade, clear:cache, cache:flush, setup:static there is a good blog here just in case:magenticians.com/magento-2-override-block – Juliano Vargas Jul 2 '18 at 8:38
  • @JulianoVargas I had run all the commands. – Wasim Bajwa Jul 2 '18 at 9:08
  • you have to change functionality by plugin method preference not works all time – Ketan Borada Jul 2 '18 at 10:18

Try the below code and replace the vendor and module name with your vendor name and module name:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" type="[Vendor]\[Module]\Block\Product\View\Type\Configurable" />
  • Is it different from the one i have mentioned? – Wasim Bajwa Jul 2 '18 at 9:10
  • Did you created any module with namespace vendor and module name ConfigurableProduct? – Sukumar Gorai Jul 2 '18 at 9:11
  • Ofcourse, i have it in a separate module. – Wasim Bajwa Jul 2 '18 at 9:15
  • What is the name of that module? Can you give me the exact path of that module? – Sukumar Gorai Jul 2 '18 at 9:16
  • I have updated the module and vendor name on my end in di.xml. – Wasim Bajwa Jul 2 '18 at 9:17

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.