Skip to main content
Magento

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Magento 2: New module causing crash

I'm trying to override the module-catalog/Block/Product/View/Options/Type/Select.php class with a new version which includes a few other bits of custom php. I have done the below and then run the php bin/magento setup:upgrade and php cache:clean commands but the product page is showing a blank/white page.

I created a 'code' folder and placed it here:

/app/code/

I created a Vendor folder titled 'Mike' and placed it here:

/app/code/Mike/

Within the new Mike vendor folder, I created an etc folder: /app/code/Mike/etc/. Within this etc folder, I have added a di.xml file containing the below:

<?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="Mike\NewSelect\Block\Product\View\Options\Type\Select" />
</config>

I then created a Module folder titled NewSelect and placed it in the Mike vendor folder:

/app/code/Mike/NewSelect/

I then just copied over the directory structure (without the containing files, except for Select.php) of the core Select class and placed it in the NewSelect module folder, resulting in the below:

app/
├── Mike/
│ ├── NewSelect/
│ │ ├── Block/
│ │ │ ├── Product/
│ │ │ │ ├── View/
│ │ │ │ │ ├── Options/
│ │ │ │ │ │ ├── Type/
│ │ │ │ │ │ │ ├── Select.php
│ │ ├── etc/
│ │ │ ├── di.xml

Within my new Select class (app/code/Mike\NewSelect\Block\Product\View\Options\Type\Select.php), I have extended the core Select class with the following:

namespace Mike\NewSelect\Block\Product\View\Options\Type;
class Select extends \Magento\Catalog\Block\Product\View\Options\Type\Select
{
 /**
 * Return html for control element
 *
 * @return string
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
etc etc...

In my Mike/MyTheme/Magento_Catalog/catalog_product_view.xml file, I have updated the calling block:

<block class="Magento\Catalog\Block\Product\View\Options\Type\Select" as="select" template="product/view/options/type/select_hamper.phtml"/>

and changed it to:

<block class="Mike\NewSelect\Block\Product\View\Options\Type\Select" as="select" template="product/view/options/type/select.phtml"/>

Can anyone see where I'm going wrong?

Thank you

Answer*

Draft saved
Draft discarded
Cancel

default

AltStyle によって変換されたページ (->オリジナル) /