3

I have taken reference of an old module (Bannerslider) created for Magento 2 Beta version and I am trying to convert it to Magento 2 stable compatible (Mycompany_Bannerslider).

When I enable the module and run the following command it doesn't give errors:

bin/magento setup:upgrade

But when I run bin/magento setup:di:compile command then it shows following error in the terminal:

enter image description here

Below is the model-collection file I am using:

namespace Mycompany\Bannerslider\Model\Resource\Banner;
class Collection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
{
        public function __construct()
        {
                $this->_init('Mycompany\Bannerslider\Model\Banner', 'Mycompany\Bannerslider\Model\Resource\Banner');
        }
}
4
  • Are you installed magento 2 release 17/11 ?
    – LinoPham
    Commented Dec 5, 2015 at 10:27
  • Yes the 2.0.0 stable version.
    – Vicky Dev
    Commented Dec 5, 2015 at 10:28
  • You need refactor your module, it can work fine with this version
    – LinoPham
    Commented Dec 5, 2015 at 10:35
  • Please explain what should I do in detail for "refactoring", I recompiled but this error is persistent.
    – Vicky Dev
    Commented Dec 5, 2015 at 10:48

2 Answers 2

3

Change Resource to ResourceModel

namespace Mycompany\Bannerslider\Model\ResourceModel\Banner;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
        public function __construct()
        {
                $this->_init('Mycompany\Bannerslider\Model\Banner', 'Mycompany\Bannerslider\Model\ResourceModel\Banner');
        }
}
4
  • Did that but still same error, please explain what could be the issue, changed implementing class path still same error.
    – Vicky Dev
    Commented Dec 5, 2015 at 10:47
  • In magento2 there are no Resource concept. So use ResourceModel instead Resource. That means Resource folder should replace with ResourceModel and change namespace to. Clear?
    – Sohel Rana
    Commented Dec 5, 2015 at 12:16
  • Here is an example of using resource model github.com/sohelrana09/magento2-sample-module/tree/master/SR/…
    – Sohel Rana
    Commented Dec 5, 2015 at 12:18
  • Thanks, your hint fixed my plugin. Following this clue, I found this answer really helpful: stackoverflow.com/a/31984198/1903781 Commented Jan 15, 2017 at 16:24
2

You need refactor your module from Magento2 1.0.0 to Magento2 2.0.0. It included many change, i can list something in the following:

  1. You find and replace all namespace have contain Resource to ResourceModel
  2. Change name Resource folder to ResourceModel in Yourcompany/YourModule/Model
  3. Change all format(xsd) of .xml file in etc folder.
  4. Change Observer/Event(if it exist include: events.xml and path).

...

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.