2

I use magento 2.3 and I can't see collectionFactory created in generated folder or inject to any class.

ModelFactory can create normally. There are my code:

Model file:

 <?php


namespace Lights\Magikfee\Model;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\DataObject\IdentityInterface;
use Lights\Magikfee\Api\Data\MagikfeeInterface;

class Magikfee extends AbstractModel implements IdentityInterface, MagikfeeInterface
{
    /**
     * magikfee type
     */
    const FIXED = '2';
    const PERCENT = '1';

    /**
     * status
     */
    const ENABLE = '1';
    const DISABLED ='0';

    const CACHE_TAG = 'magikfee_model';

    /**
     * Magikfee constructor.
     * @param \Magento\Framework\Model\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
     * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = []
    ) {
        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    }

    /**
     * Initialize model
     *
     */
    public function _construct()
    {
        $this->_init(\Lights\Magikfee\Model\ResourceModel\Magikfee::class);
    }

    public function getIdentities()
    {
        return [self::CACHE_TAG . '_' . $this->getId()];
    }

    public function getDefaultValues()
    {
        $values = [];

        return $values;
    }

Resource model:

<?php
/**
 * Created by PhpStorm.
 * User: thelight
 * Date: 1/19/19
 * Time: 11:23 PM
 */

namespace Lights\Magikfee\Model\ResourceModel;


class Magikfee extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
    const TABLENAME ='magikfee';
    protected $_idFieldName = 'magikfee_id';

    /**
     * Magikfee constructor.
     * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
     * @param null|string $connectionName
     */
    public function __construct(
        \Magento\Framework\Model\ResourceModel\Db\Context $context,
        ?string $connectionName = null)
    {
        parent::__construct($context, $connectionName);
    }

    /**
     * Resource initialization
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init(self::TABLENAME, 'magikfee_id');
    }

}

Collection:

<?php
/**
 * Created by PhpStorm.
 * User: thelight
 * Date: 1/19/19
 * Time: 11:24 PM
 */

namespace Lights\Magikfee\Model\ResourceModel\Magikfee;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;

class Collection extends AbstractCollection
{
    /**
     * primary key
     * @var string
     */
    protected $_idFieldName = 'magikfee_id';

    /**
     * capture event magikfee_load_before
     * capture event magikfee_load_after
     * @var string
     */
    protected $_eventPrefix = 'magikfee';

    /**
     * Collection constructor.
     * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
     * @param \Psr\Log\LoggerInterface $logger
     * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
     * @param \Magento\Framework\Event\ManagerInterface $eventManager
     * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
     * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
     */
    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {
        parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
    }


    protected function _construct()
    {
        $this->_init(\Lights\Magikfee\Model\Magikfee::class, \Lights\Magikfee\Model\ResourceModel\Magikfee::class);
//        $this->_setIdFieldName($this->getResource()->getIdFieldName());
    }
}

I 'm highly appreciate with any help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.