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.

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.

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.