0

Fatal error: Uncaught Error: Cannot instantiate abstract class Magento\Framework\Model\ResourceModel\AbstractResource in /home/dukaania/public_html/testing2/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50 Stack trace: #0

Here's my code:

/home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Sugarcode\Test\Model\Total;
class Fee extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface {
 const CACHE_TAG = 'mr_dukaaniatest';
protected $_cacheTag = 'mr_dukaaniatest';
protected $_eventPrefix = 'mr_dukaaniatest';



protected function _construct()
{
    $this->_init('Sugarcode\Test\Model\ResourceModel\Fee.php');
}

/**
 * Collect grand total address amount
 *
 * @param \Magento\Quote\Model\Quote $quote
 * @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
 * @param \Magento\Quote\Model\Quote\Address\Total $total
 * @return $this
 */

   protected $_feeFactory;



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,
            \Sugarcode\Test\Model\Total\FeeFactory $feeFactory,

        array $data = array()
    ) {
        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
            $this->_feeFactory = $feeFactory;

    }

public function collect(

) {
    parent::collect($quote, $shippingAssignment, $total);



}






public function getIdentities()
{
    $identities = [
        self::CACHE_TAG . '_' . $this->getId(),
    ];
    if ($this->hasDataChanges() || $this->isDeleted()) {
        $identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $this->getId();
    }
    return $identities;
}



 public function fetch() {      
    $fee = $this->_feeFactory->create();
    $collection = $fee->getCollection();
    foreach($collection as $item){
        \Zend_Debug::dump($item->getData());
    }
    exit();
}

  public function execute()
{
    $fee = $this->_feeFactory->create();
    $collection = $fee->getCollection();
    foreach($collection as $item){
        \Zend_Debug::dump($item->getData());
    }
    exit();
}

/**
 * Get Subtotal label
 *
 * @return \Magento\Framework\Phrase
 */
public function getLabel() {
    return __('Fee');
}
}

/home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/ResourceModel/Fee.php

<?php
namespace Sugarcode\Test\Model\ResourceModel;


class Fee extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{

    public function __construct(
        \Magento\Framework\Model\ResourceModel\Db\Context $context
    )
    {
        parent::__construct($context);
    }

    protected function _construct()
    {
        $this->_init('mr_dukaaniatest', 'dukaaniatest_id');
    }

}

/home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/ResourceModel/Fee/Collection.php

<?php
namespace Sugarcode\Test\Model\ResourceModel\Fee;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    protected $_idFieldName = 'dukaaniatest_id';
    protected $_eventPrefix = 'mr_dukaaniatest_collection';
    protected $_eventObject = 'fee_collection';

    /**
     * Define resource model
     *
     * @return void
     */
    protected function _construct()
    {
        $this->_init('Sugarcode\Test\Model\Total\Fee', 'Sugarcode\Test\Model\ResourceModel\Fee');
    }

}

/home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Block/Sales/Order/Fee.php

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * Tax totals modification block. Can be used just as subblock of \Magento\Sales\Block\Order\Totals
 */
namespace Sugarcode\Test\Block\Sales\Order;



class Fee extends \Magento\Framework\View\Element\Template
{
    /**
     * Tax configuration model
     *
     * @var \Magento\Tax\Model\Config
     */
    protected $_config;

    /**
     * @var Order
     */
    protected $_order;

    /**
     * @var \Magento\Framework\DataObject
     */
    protected $_source;

    /**
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Tax\Model\Config $taxConfig
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Tax\Model\Config $taxConfig,
        array $data = []
    ) {
        $this->_config = $taxConfig;
        parent::__construct($context, $data);
    }

    /**
     * Check if we nedd display full tax total info
     *
     * @return bool
     */
    public function displayFullSummary()
    {
        return true;
    }

    /**
     * Get data (totals) source model
     *
     * @return \Magento\Framework\DataObject
     */
    public function getSource()
    {
        return $this->_source;
    } 
    public function getStore()
    {
        return $this->_order->getStore();
    }

      /**
     * @return Order
     */
    public function getOrder()
    {
        return $this->_order;
    }

    /**
     * @return array
     */
    public function getLabelProperties()
    {
        return $this->getParentBlock()->getLabelProperties();
    }

    /**
     * @return array
     */
    public function getValueProperties()
    {
        return $this->getParentBlock()->getValueProperties();
    }

    /**
     * Initialize all order totals relates with tax
     *
     * @return \Magento\Tax\Block\Sales\Order\Tax
     */
     public function initTotals()
    {

        $parent = $this->getParentBlock();
        $this->_order = $parent->getOrder();
        $this->_source = $parent->getSource();

        $store = $this->getStore();

        $fee = new \Magento\Framework\DataObject(
                [
                    'code' => 'fee',
                    'strong' => false,
                    'value' => 120,
                    //'value' => $this->_source->getFee(),
                    'label' => __('Fee'),
                ]
            );

            $parent->addTotal($fee, 'fee');
           // $this->_addTax('grand_total');


            return $this;



    }


public function getIdentities()
{
    return $this->getCurrentCategory()->getIdentities();
}



}
  • which magento varsion you used ? – Dharmendra Jadav Oct 3 '18 at 9:55
  • magento 2.0 version – jhon jhon doe Oct 3 '18 at 9:56
  • Check constructor of this file "\Magento\Framework\Model\AbstractModel" and set that constructor here. – Dharmendra Jadav Oct 3 '18 at 9:57
  • please remove constructor from your resource model fee.php – Dharmendra Jadav Oct 3 '18 at 10:07
  • i removed constructor but nothing happen same issue – jhon jhon doe Oct 3 '18 at 10:24
0

please replace your consturct code in below file /home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php

       public function __construct(
    \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
     \Sugarcode\Test\Model\Total\FeeFactory $feeFactory,
    \Magento\Framework\Model\ResourceModel\AbstractResource $resource= null,
    \Magento\Framework\Data\Collection\AbstractDb $resourceCollection= null,
      array $data = array()
) {
    parent::__construct($context, $registry, $resource, $resourceCollection, 
      $data);
        $this->_feeFactory = $feeFactory;

}

after replacing run command : rm -rf generated/* and clear cache and check

  • still m getting this issue Exception #0 (ReflectionException): Class Sugarcode\Test\Model\ResourceModel\Fee.php does not exist – jhon jhon doe Oct 3 '18 at 10:03
  • please make sure your Fee.php in ResourceModel folder not in /Sugarcode/Test/Model/ResourceModel/Total/Fee.php – Rutvee Sojitra Oct 3 '18 at 10:25
  • /home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/ResourceModel/Fee.php /home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/ResourceModel/Fee/Collection.php /home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/ResourceModel/Fee.php /home1/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php – jhon jhon doe Oct 3 '18 at 10:32
  • @jhonjhondoe what you have asked in question is perfectly answered over here.if you have another issue you can asked another question. – Rutvee Sojitra Oct 4 '18 at 4:21
0

Please replace your this "Sugarcode/Test/Model/Total/Fee.php" model file function _construct.

protected function _construct()
{
    $this->_init('Sugarcode\Test\Model\ResourceModel\Fee');
}

and check after that.

  • after adding this or replace this code admin panel not login redirect to same admin panel login screen – jhon jhon doe Oct 3 '18 at 10:55
  • try to run command and clearing cache and then check it becuase your code issue has been fixed if you put above code – Dharmendra Jadav Oct 3 '18 at 10:56
  • i run all commands but still same issue my admin panel not login redirect to same login screen after login – jhon jhon doe Oct 3 '18 at 11:02
  • also product still not added in cart – jhon jhon doe Oct 3 '18 at 11:02
  • can we discuss in chat please – jhon jhon doe Oct 3 '18 at 11:03

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.