cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Module to overwrite vendor/magento/module-configurable-product

Custom Module to overwrite vendor/magento/module-configurable-product

Hi,

I had to fix a Fatal PHP Error in the Loader.php file to the path:

vendor/magento/module-configurable-product/Helper/Product/Options

 

I add this to line 52:

if (get_class($typeInstance) == 'Magento\Catalog\Model\Product\Type\Simple' || get_class($typeInstance) == 'Magento\Bundle\Model\Product\Type')
		{ return null;
		}

 

This is my question:

Is it possible to create a custom moldule to overwrite this file?

I don’t want to edit the file Loader.php under the vendor path.

 

many thanks

4 REPLIES 4

Re: Custom Module to overwrite vendor/magento/module-configurable-product

@iGniTioN3D 

Yes, you can create your custom module and override the file there.
 
Please refer to the example of creating a custom module here:
 
Here's the another example to override files from vendor:
 
You can try the below code for Helper:
<preference for="Magento\ConfigurableProduct\Helper\Product\Options\Loader" type="[Vendor]\[Extension]\Rewrite\Helper\Product\Options\Loader"/>
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: Custom Module to overwrite vendor/magento/module-configurable-product

Thank you for your help. I try to explain what I did:

I created a custom module in app/code/Develoweb/ShippingError

 

A registration.php file to /app/code/Develoweb/ShippingError/:

<?php
use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Develoweb_ShippingError', __DIR__);

A module.xml file to /app/code/Develoweb/ShippingError/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="Develoweb_ShippingError" setup_version="1.0.0">
            <sequence>
                <module name="ShippingError"/>
            </sequence>
        </module>
</config>

 

A di.xml file to /app/code/Develoweb/ShippingError/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\ConfigurableProduct\Helper\Product\Options\Loader" type="Develoweb\ShippingError\Rewrite\Helper\Product\Options\Loader"/>
</config>

 

A Loader.php file (to overwrite the original file in the vendor folder) to

/app/code/Develoweb/ShippingError/Helper/Product/Options:

(this is the part of the code I replaced by line 50 of the original file)

        /** @var Configurable $typeInstance */
        $typeInstance = $product->getTypeInstance();
		if (get_class($typeInstance) == 'Magento\Catalog\Model\Product\Type\Simple' || get_class($typeInstance) == 'Magento\Bundle\Model\Product\Type')
		{ return null;
		}
        $attributeCollection = $typeInstance->getConfigurableAttributeCollection($product);
        $this->extensionAttributesJoinProcessor->process($attributeCollection);

unfortunately it doesn’t work and now I get another error

Re: Custom Module to overwrite vendor/magento/module-configurable-product

Initially I’m trying to solve this problem:

Spoiler
Fatal error: Uncaught Error: Call to undefined method Magento\Catalog\Model\Product\Type\Simple::getConfigurableAttributeCollection() in /home/customer/www/develow9.sg-host.com/public_html/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php:52 Stack trace: #0 /home/customer/www/develow9.sg-host.com/public_html/vendor/magento/module-configurable-product/Model/Product/ReadHandler.php(48): Magento\ConfigurableProduct\Helper\Product\Options\Loader->load(Object(Magento\Catalog\Model\Product\Interceptor)) #1 /home/customer/www/develow9.sg-host.com/public_html/vendor/magento/framework/EntityManager/Operation/Read/ReadExtensions.php(48): Magento\ConfigurableProduct\Model\Product\ReadHandler->execute(Object(Magento\Catalog\Model\Product\Interceptor), Array) #2 /home/customer/www/develow9.sg-host.com/public_html/vendor/magento/framework/EntityManager/Operation/Read.php(112): Magento\Framework\EntityManager\Operation\Read\ReadExtensions->execute(Object(Magento\Catalog\Model\Product\Interceptor), Array) #3 /h in /home/customer/www/develow9.sg-host.com/public_html/vendor/magento/module-configurable-product/Helper/Product/Options/Loader.php on line 52

adding this code to the Loader.php file, the problem is solved:

if (get_class($typeInstance) == 'Magento\Catalog\Model\Product\Type\Simple' || get_class($typeInstance) == 'Magento\Bundle\Model\Product\Type')
		{ return null;
		}

but I don’t want to do this in the Loader.php file under the vendor directory...

 

many thanks

How to negotiate for salary

How to negotiate for salary we should wait for the employer to make an offer before they start negotiating. This can lead to a significantly lower starting salary since it leaves room for negotiation.