First of all, we need to add Constructor injection method to our custom select class: (Edit: we don't need to add Constructor Injection, we need to add the sequence module)
<?php
namespace Mike\Newselect\Block\Product\View\Options\Type;
class Select extends \Magento\Catalog\Block\Product\View\Options\Type\Select
{
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
\Magento\Catalog\Helper\Data $catalogData,
array $data = []
)
{
parent::__construct($context, $pricingHelper, $catalogData, $data);
}
.....
We need to add the :
<?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="Mike_Newselect" setup_version="1.0.0">
<sequence>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>
http://devdocs.magento.com/guides/v2.1/extension-dev-guide/build/module-load-order.html
Second, copy vendor/magento/module-catalog/view/frontend/templates/product/view/options/type/select.phtml
to our custom module app/code/Mike/Newselect/view/frontend/templates/product/view/options/type/select.phtml
You will have to create your custom module in "app/code/[VendorName]/[ModuleName]"
Here you will have to overwrite the block you would like to change using magento2's di.xml
.
Now for example you we can create a module "app/code/Foo/Bar".
Firstly you need a registration file which will register the new module. We need to create a file app/code/Foo/Bar/registration.php
, in which we add:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Foo_Bar',
__DIR__
);
Inside here you can create a di.xml
at "app/code/Foo/Bar/etc/di.xml". In the di.xml
we need to add a <preference/>
node to overwrite any core classes.
<preference for="Magento\Catalog\Block\Product\View\Options\Type\Select" type="Foo\Bar\Block\Product\View\Options\Type\Select"/>
So in my case the module will overwrite the class Magento\Catalog\Block\Product\View\Options\Type\Select
and instead the custom class will be loaded Foo\Bar\Block\Product\View\Options\Type\Select
Now we need to create a file at "app/code/Foo/Bar/Block/Product/View/Options/Type/Select.php" and our new class should extend the core class.
<?php
namespace Foo\Bar\Block\Product\View\Options\Type;
class Select extends \Magento\Catalog\Block\Product\View\Options\Type\Select
{
//method you would like to overwrite
}
Also you will have to run the following command to activate the new module:
php bin/magento setup:upgrade
If your thinking of file based overwriting as it was done in Magento
1, it is no longer possible in Magento 2
Best Answer
you can create you own module that contains a translation file
i18n/en_US.csv
with this content: