3

I have modules with inter-dependencies, such as

  • MyVendor_MyModule1: Account
  • MyVendor_MyModule2: Account

  • MyVendor_MyModule1: Auth

  • MyVendor_MyModule2: Auth

  • MyVendor_MyModule1: Config

  • MyVendor_MyModule2: Config

Accountnamespace contains common code for both MyModule1 and MyModule2.

Currently, I am having a duplicate code in both modules.

I want to make Account an independent module to reduce the code duplicacy.

How shall I move forward without messing with namespaces?

Edt:

To be exact: My current scenario is \Cj\Amazon is 1 module. I am planning to break it into two modules, i.e. Cj\Amazon\Importer and \Cj\Amazon\Integration.

Both uses the same authentication which is Cj\Amazon\Auth. But in Magento, we are restricted to use Vendor\Module pattern.

Is there any way two have multi modules with same namespaces i.e in \Cj\Amazon\ ?

1

You can create class Account in the MyVendor_MyModule1 and then extend from it in the MyVendor_MyModule2: Account.

for example

<?php
   namespace MyVendor\MyModule1;

   class Account 
   {
      public function someMethod() {}
   }


   namespace MyVendor\MyModule2;

   use MyVendor\MyModule1\Account as FirstAccount;

   class Account extends FirstAccount;
   {
      public function someMethod2() {}
   }
3
  • Yes sure I can do this, but both the module should independently also, which will fail the case. Jan 17 '19 at 16:25
  • You can create one more module that named as Base or Core and put all code that you want to use for both Module1 and Module2. If you want to provide Module1 independent of Module2 you can provide Base + Module1 or Base + Module 2
    – Anton
    Jan 18 '19 at 11:07
  • Yes, I was thinking about that, but my current scenario is \Cj\Amazon is 1 module. I am planning to break it into two modules, i.e. Cj\Amazon\Importer and \Cj\Amazon\Integration. Both uses the same authentication which is Cj\Amazon\Auth. But in Magento, we are restricted to Vendor\Module pattern. Is there any way two have multi modules with same namespaces i.e in \Cj\Amazon ? Jan 18 '19 at 13:40

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.