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.Magento Dev– Magento Dev2018年10月03日 04:23:31 +00:00Commented Oct 3, 2018 at 4:23
-
after run this command still getting this issuejhon jhon doe– jhon jhon doe2018年10月03日 04:26:45 +00:00Commented 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.Magento Dev– Magento Dev2018年10月03日 04:29:55 +00:00Commented Oct 3, 2018 at 4:29
2 Answers 2
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 injhon jhon doe– jhon jhon doe2018年10月03日 04:37:17 +00:00Commented Oct 3, 2018 at 4:37
-
Remove your generated and cache folders and check again.Dinesh Yadav– Dinesh Yadav2018年10月03日 04:40:10 +00:00Commented Oct 3, 2018 at 4:40
-
Check my updated answerDinesh Yadav– Dinesh Yadav2018年10月03日 04:42:09 +00:00Commented Oct 3, 2018 at 4:42
-
Check and let me know if you still face any error.Dinesh Yadav– Dinesh Yadav2018年10月03日 04:43:33 +00:00Commented Oct 3, 2018 at 4:43
-
now i am not able to login my admin paneljhon jhon doe– jhon jhon doe2018年10月03日 04:47:26 +00:00Commented Oct 3, 2018 at 4:47
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 existjhon jhon doe– jhon jhon doe2018年10月03日 08:45:58 +00:00Commented Oct 3, 2018 at 8:45
-
when you getting this error ?Dharmendra Jadav– Dharmendra Jadav2018年10月03日 09:18:02 +00:00Commented Oct 3, 2018 at 9:18
-
on login admin panel or add product in shopping cartjhon jhon doe– jhon jhon doe2018年10月03日 09:35:35 +00:00Commented Oct 3, 2018 at 9:35
-
have you define any resourse model for it ? if no then you have to create resourse model for itDharmendra Jadav– Dharmendra Jadav2018年10月03日 09:43:08 +00:00Commented Oct 3, 2018 at 9:43
-
i have created module for itjhon jhon doe– jhon jhon doe2018年10月03日 09:44:31 +00:00Commented Oct 3, 2018 at 9:44