- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
After magento up-gradation to 2.4.6 one custom module arise some error but that module working fine in magento 2.4.3-p1
The error is
1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Ink\Returnrule\Helper\Returnrule, Plumrocket\RMA\Helper\Returnrule::__construct(): Argument #1 ($context) must be of type Magento\Framework\App\Helper\Context, Magento\Framework\App\ObjectManager given, called in /var/www/html/mage243p1/app/code/Ink/Returnrule/Helper/Returnrule.php on line 34
And my code ref is
<?php
namespace Ink\Returnrule\Helper;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Plumrocket\RMA\Model\Resolution;
use Plumrocket\RMA\Model\ResourceModel\Returnrule\CollectionFactory;
use Plumrocket\RMA\Model\ReturnruleFactory;
use Plumrocket\RMA\Model\Returnrule\SpaceFactory;
use Magento\Catalog\Model\ProductFactory;
class Returnrule extends \Plumrocket\RMA\Helper\Returnrule
{
public function __construct(
ObjectManagerInterface $objectManager,
Context $context,
StoreManagerInterface $storeManager,
ReturnruleFactory $returnruleFactory,
SpaceFactory $spaceFactory,
CollectionFactory $collectionFactory,
Resolution $resolution,
Session $session,
\Magento\Catalog\Helper\Product\Configuration $configurationHelper,
ProductFactory $productFactory,
SerializerInterface $serializer
) {
parent::__construct($objectManager, $context, $storeManager, $returnruleFactory,
$spaceFactory, $collectionFactory, $resolution, $session,
$configurationHelper, $productFactory, $serializer);
}
Please help to recognize the error
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error you are encountering is a "Type Error" that occurs when creating an object in your custom module after upgrading Magento to version 2.4.6. The error message indicates that there is an issue with the constructor of the Returnrule class in the Ink\Returnrule\Helper namespace.
The specific problem is with the argument $context in the constructor. In Magento 2.4.6, the Context class from the Magento\Framework\App\Helper namespace should be passed as the type for the $context argument. However, in your code, the ObjectManagerInterface is being passed instead.
To resolve this error, you need to update the constructor of the Returnrule class to use the correct type for the $context argument. Modify the constructor to match the following:
public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Plumrocket\RMA\Model\ReturnruleFactory $returnruleFactory, \Plumrocket\RMA\Model\Returnrule\SpaceFactory $spaceFactory, \Plumrocket\RMA\Model\ResourceModel\Returnrule\CollectionFactory $collectionFactory, \Plumrocket\RMA\Model\Resolution $resolution, \Magento\Customer\Model\Session $session, \Magento\Catalog\Helper\Product\Configuration $configurationHelper, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Framework\Serialize\SerializerInterface $serializer ) { parent::__construct( $context, $storeManager, $returnruleFactory, $spaceFactory, $collectionFactory, $resolution, $session, $configurationHelper, $productFactory, $serializer ); }
Make sure to update the namespace imports accordingly as well.
After making these changes, the error should be resolved, and your custom module should work properly with Magento 2.4.6.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have extended your class from Plumrocket\RMA\Helper\Returnrule, but since RMA 2.4.6 this helper has a different constructor. Therefore you have to remove the __construct method, if it just copies the parent method, or make replace this code with one provided below
parent::__construct($objectManager, $context, $storeManager, $returnruleFactory, $spaceFactory, $collectionFactory, $resolution, $session, $configurationHelper, $productFactory, $serializer);
parent::__construct($context, $storeManager, $returnruleFactory, $spaceFactory, $collectionFactory, $resolution, $session, $configurationHelper, $productFactory, $serializer);
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error you are encountering is a "Type Error" that occurs when creating an object in your custom module after upgrading Magento to version 2.4.6. The error message indicates that there is an issue with the constructor of the Returnrule class in the Ink\Returnrule\Helper namespace.
The specific problem is with the argument $context in the constructor. In Magento 2.4.6, the Context class from the Magento\Framework\App\Helper namespace should be passed as the type for the $context argument. However, in your code, the ObjectManagerInterface is being passed instead.
To resolve this error, you need to update the constructor of the Returnrule class to use the correct type for the $context argument. Modify the constructor to match the following:
public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Plumrocket\RMA\Model\ReturnruleFactory $returnruleFactory, \Plumrocket\RMA\Model\Returnrule\SpaceFactory $spaceFactory, \Plumrocket\RMA\Model\ResourceModel\Returnrule\CollectionFactory $collectionFactory, \Plumrocket\RMA\Model\Resolution $resolution, \Magento\Customer\Model\Session $session, \Magento\Catalog\Helper\Product\Configuration $configurationHelper, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Framework\Serialize\SerializerInterface $serializer ) { parent::__construct( $context, $storeManager, $returnruleFactory, $spaceFactory, $collectionFactory, $resolution, $session, $configurationHelper, $productFactory, $serializer ); }
Make sure to update the namespace imports accordingly as well.
After making these changes, the error should be resolved, and your custom module should work properly with Magento 2.4.6.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: After magento upgrade to 2.4.6 got Type Error occurred when creating object
Hello @rina_test
Try this
<?php namespace Ink\Returnrule\Helper; use Magento\Customer\Model\Session; use Magento\Framework\App\Helper\Context; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Serialize\SerializerInterface; use Magento\Store\Model\StoreManagerInterface; use Plumrocket\RMA\Model\Resolution; use Plumrocket\RMA\Model\ResourceModel\Returnrule\CollectionFactory; use Plumrocket\RMA\Model\ReturnruleFactory; use Plumrocket\RMA\Model\Returnrule\SpaceFactory; use Magento\Catalog\Model\ProductFactory; class Returnrule extends \Plumrocket\RMA\Helper\Returnrule { public function __construct( ObjectManagerInterface $objectManager, \Magento\Framework\App\Helper\Context $context, StoreManagerInterface $storeManager, ReturnruleFactory $returnruleFactory, SpaceFactory $spaceFactory, CollectionFactory $collectionFactory, Resolution $resolution, Session $session, \Magento\Catalog\Helper\Product\Configuration $configurationHelper, ProductFactory $productFactory, SerializerInterface $serializer ) { parent::__construct($objectManager, $context, $storeManager, $returnruleFactory, $spaceFactory, $collectionFactory, $resolution, $session, $configurationHelper, $productFactory, $serializer); } }
200+ Premium Magento 2 Extensions Need help? Hire Magento Developer
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have extended your class from Plumrocket\RMA\Helper\Returnrule, but since RMA 2.4.6 this helper has a different constructor. Therefore you have to remove the __construct method, if it just copies the parent method, or make replace this code with one provided below
parent::__construct($objectManager, $context, $storeManager, $returnruleFactory, $spaceFactory, $collectionFactory, $resolution, $session, $configurationHelper, $productFactory, $serializer);
parent::__construct($context, $storeManager, $returnruleFactory, $spaceFactory, $collectionFactory, $resolution, $session, $configurationHelper, $productFactory, $serializer);