-1

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

}

  • Please run bin/magento setup:di:compile then check. – Charul Tyagi Oct 3 '18 at 4:23
  • after run this command still getting this issue – jhon jhon doe Oct 3 '18 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. – Charul Tyagi Oct 3 '18 at 4:29
0

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.

  • 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 – jhon jhon doe Oct 3 '18 at 4:37
  • Remove your generated and cache folders and check again. – Dinesh Yadav Oct 3 '18 at 4:40
  • Check my updated answer – Dinesh Yadav Oct 3 '18 at 4:42
  • Check and let me know if you still face any error. – Dinesh Yadav Oct 3 '18 at 4:43
  • now i am not able to login my admin panel – jhon jhon doe Oct 3 '18 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.

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

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.