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 ??

2
  • You haven't enabled your module? bin/magento module:enable Abc_Abc then do your compile. Commented Sep 22, 2017 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. Commented Sep 22, 2017 at 11:40

1 Answer 1

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.

answered Sep 23, 2017 at 9:33
1
  • 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. Commented Sep 23, 2017 at 10:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.