I want to override Magento core block how can I do that
vendor\magento\module-catalog\view\frontend\templates\product\view\options\type\Select.php.
I want to remove -- before and after Please Select text as shown in the image below
So Far I have tried to create a Module to override the block in app/code, app/code/Abcd/Xyz but when i have enabled it it just removed the whole select box as shown in below image
[https://i.sstatic.net/gnJiP.png[2]
3 Answers 3
you can create you own module that contains a translation file i18n/en_US.csv with this content:
"-- Please Select --","Please Select"
 - 
 Ya, I thought that but now, I want to do something Like this insted of
Please SelectI wantSelect Size,Select ColorSo I have to override the view block.Arun Karnawat– Arun Karnawat2016年08月17日 08:33:03 +00:00Commented Aug 17, 2016 at 8:33 - 
 that is a totally different questions. please don't mix them.Marius– Marius2016年08月17日 08:57:53 +00:00Commented Aug 17, 2016 at 8:57
 - 
 I followed you advice and create a new question for it magento.stackexchange.com/questions/131762/…Arun Karnawat– Arun Karnawat2016年08月17日 09:44:38 +00:00Commented Aug 17, 2016 at 9:44
 
need to override the below block
<magento-root>/vendor/magento/module-catalog/Block/Product/View/Options/Type/Select.php
in the above file change the below line
 $select->setName('options[' . $_option->getid() . ']')->addOption('', __('-- Please Select --')); 
TO
 $select->setName('options[' . $_option->getid() . ']')->addOption('', __('Please Select'));
for override the block refer this answer
note: I am not tested but I hope it works
- 
 Hi, I have done the same. I have override the
Magento\Catalog\Block\Product\View\Options\Type\SelectBlock in my module, but doing so, Removed the select box from the view as in the above image[Refer Question]Arun Karnawat– Arun Karnawat2016年08月17日 08:36:20 +00:00Commented Aug 17, 2016 at 8:36 - 
 Do I have to override template file as well in the module
vendor\magento\module-catalog\view\frontend\templates\product\view\options\type\select.phtmlArun Karnawat– Arun Karnawat2016年08月17日 08:38:42 +00:00Commented Aug 17, 2016 at 8:38 - 
 for trial just directly change the text in vendor/magento/module-catalog/Block/Product/View/Options/Type/Select.php. after that clear cache then load page. If it worked, definitely you make mistake in override.Bilal Usean– Bilal Usean2016年08月17日 08:50:21 +00:00Commented Aug 17, 2016 at 8:50
 
given that Marius' solution is likely the most effective one, I take the chance to offer an alternative to avoid block rewrite. It is based on the usage of a plugin.
Assuming you know how to define your own module, you can declare the plugin in the <your_module_dir>/etc/di.xml file as follows:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 <type name="Magento\Framework\View\Element\Html\Select">
 <plugin name="vendorname_view_element_html_select"
 type="VendorName\ModuleName\Plugin\View\Element\Html\SelectPlugin" />
 </type>
</config>
Note: change VendorName and ModuleName according to your needs.
Then define the plugin in <your_module_dir>/Plugin/View/Element/Html/SelectPlugin.php:
<?php
namespace VendorName\ModuleName\Plugin\View\Element\Html;
class SelectPlugin
{
 public function beforeAddOption($subject, $value, $label) 
 {
 if ($value == '') {
 $label = __("Whatever you want");
 }
 return [$value, $label];
 }
}
Hope it helps.