3

I have two Modules in app/code.

  1. Xyz_Xyz - Module that already exists. I can't change its file.
  2. Abc_Abc - Module that I creating to override Xyz_Xyz Model.

The code I try is here.

app/code/Abc/Abc/etc/module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Abc_Abc" schema_version="1.0.0" setup_version="1.0.0" >
        <sequence>
            <module name="Xyz_Xyz" />
        </sequence>
    </module>
</config>

app/code/Abc/Abc/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">  
    <preference for="Xyz\Xyz\Model\Payment\PaymentAbstract" type="Abc\Abc\Model\Payment\PaymentAbstract" />
</config>

app/code/Abc/Abc/Model/Payment/PaymentAbstract.php

<?php
namespace Abc\Abc\Model\Payment;

class PaymentAbstract extends \Xyz\Xyz\Model\Payment\PaymentAbstract
{
    public function getFormFields($order, $requestParams, $isRequest = true)
    {
        \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class)->debug("Works ");
    }
}

Then I am going to cmd and run this commands :

rm -rf var/cache var/generation var/page_cache var/view_preprocessed var/composer_home var/di

Then

php bin/magento setup:di:compile

There is no error in di: compile.

So, can anyone tell me what to do ??

  • You haven't enabled your module? bin/magento module:enable Abc_Abc then do your compile. – andy jones Sep 22 '17 at 11:07
  • Thanks for that. But my module is enabled.Because this is only sample code actual module have more files and that all works so module is enabled. – jaydip sinh Parmar Sep 22 '17 at 11:40
0

It's impossible to rewrite (in the Magento sense) classes that are used as superclasses, including abstract classes (by definition). So, you can't rewrite an abstract class. The rewrite system works because Magento uses a factory pattern to instantiate model, blocks, and helpers. Since an abstract class is never instantiated, it can never be rewritten. Solution for you problem is you should rewrite the derive class that extends this abstract class.

  • Big thank you for that and You are right. We can't override abstract class. But I not sure which class I override is an abstract class.So here is the link to that module marketplace.magento.com/ingenico-ingenico-epayments-ogn2.html and here is the path to that file which I try to override "ingenico-ingenico_epayments_ogn2-2.3.0/Model/Payment/PaymentAbstract.php". Please look once and tell me this class is an abstract class or not. – jaydip sinh Parmar Sep 23 '17 at 10:02

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.