1

I want to override the "Select.php" file at: /vendor/magento/module-catalog/Block/Product/View/Options/Type/ but I'm not sure where to put the modified "Select.php" file. The only thing I changed was commenting out the "--Please Select--" line 47.

Where do I put the modified "Select.php" file?

I am using stock Magento theme.

Thank you.

asked Sep 19, 2017 at 0:27

1 Answer 1

0

You need to write a small module to override this file.

  1. Create a module under

    app/code//Catalog/

  2. Create module.xml under app/code/<vendor_name>/Catalog/etc:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
     <module name="<vendor_name>_Catalog" setup_version="1.0.0"/>
    </config>
    
  3. Create registraion.php on module root folder, that is app/code/<vendor_name>/Catalog/:

    <?php
    \Magento\Framework\Component\ComponentRegistrar::register(
     \Magento\Framework\Component\ComponentRegistrar::MODULE,
     '<vendor_name>_Catalog',
     __DIR__
    );
    ?>
    
  4. Create di.xml under app/code/<vendor_name>/Catalog/etc:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Catalog\Block\Product\View\Options\Type\Select" type="<vendor_name>\Catalog\Block\Product\View\Options\Type\Select" />
    </config>
    
  5. Finally, create Select.php under app/code/<vendor_name>/Catalog/Block/Product/View/Options/Type. The file should be look like this:

    <?php
    namespace <vendor_name>\Catalog\Block\Product\View\Options\Type;
    class Select extends \Magento\Catalog\Block\Product\View\Options\Type\Select
    {
     public function getValuesHtml()
     {
     //do your stuff
     }
    }
    

You should able to override the getValuesHtml functions on template file.

answered Sep 19, 2017 at 2:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.