0

Exception #0 (Exception): Notice: Undefined variable: context in /home/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php on line 37

<?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(
        \Sugarcode\Test\Model\Total\FeeFactory $feeFactory
        ) {
              parent::__construct($context);

    $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');
}

}

3
  • Please run bin/magento setup:di:compile then check. Commented Oct 3, 2018 at 4:23
  • after run this command still getting this issue Commented Oct 3, 2018 at 4:26
  • I think you did not use Magento\Framework\App\Action\Context $context in your constructor if not please do and try again. Commented Oct 3, 2018 at 4:29

2 Answers 2

1

You have to add parent dependencies in your public function __construct()

public function __construct(
    \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
    \Magento\Authorization\Model\ResourceModel\Role $resource,
    \Magento\Authorization\Model\ResourceModel\Role\Collection $resourceCollection,
    \Sugarcode\Test\Model\Total\FeeFactory $feeFactory,
    array $data = []
) {
    parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    $this->_feeFactory = $feeFactory;
}

Then remove your generated folder, clean cache and check again.

9
  • facing this error Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Framework\Model\AbstractModel::__construct() must be an instance of Magento\Framework\Registry, none given, called in /home/dukaania/public_html/testing2/app/code/Sugarcode/Test/Model/Total/Fee.php on line 37 and defined in Commented Oct 3, 2018 at 4:37
  • Remove your generated and cache folders and check again. Commented Oct 3, 2018 at 4:40
  • Check my updated answer Commented Oct 3, 2018 at 4:42
  • Check and let me know if you still face any error. Commented Oct 3, 2018 at 4:43
  • now i am not able to login my admin panel Commented Oct 3, 2018 at 4:47
0

You just need to replace your constructor and need to clear generation. Below I have added constructor code please update it in your file and check after that.

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 = array()
    ) {
        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    }

Still you have any query let me know.

5
  • facing this issue Exception #0 (ReflectionException): Class Sugarcode\Test\Model\ResourceModel\Fee.php does not exist Commented Oct 3, 2018 at 8:45
  • when you getting this error ? Commented Oct 3, 2018 at 9:18
  • on login admin panel or add product in shopping cart Commented Oct 3, 2018 at 9:35
  • have you define any resourse model for it ? if no then you have to create resourse model for it Commented Oct 3, 2018 at 9:43
  • i have created module for it Commented Oct 3, 2018 at 9:44

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.