It's caused by the fact that your model constructor does not match your original model constructor.
So this is the constructor from Magento\Newsletter\Model\Queue
:
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Newsletter\Model\Template\Filter $templateFilter,
\Magento\Framework\Stdlib\DateTime\DateTime $date,
\Magento\Newsletter\Model\TemplateFactory $templateFactory,
\Magento\Newsletter\Model\ProblemFactory $problemFactory,
\Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory $subscriberCollectionFactory,
\Magento\Newsletter\Model\Queue\TransportBuilder $transportBuilder,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct(
$context,
$registry,
$resource,
$resourceCollection,
$data
);
$this->_templateFilter = $templateFilter;
$this->_date = $date;
$this->_templateFactory = $templateFactory;
$this->_problemFactory = $problemFactory;
$this->_subscribersCollection = $subscriberCollectionFactory->create();
$this->_transportBuilder = $transportBuilder;
}
To fix your constructor it needs to be:
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Newsletter\Model\Template\Filter $templateFilter,
\Magento\Framework\Stdlib\DateTime\DateTime $date,
\Magento\Newsletter\Model\TemplateFactory $templateFactory,
\Magento\Newsletter\Model\ProblemFactory $problemFactory,
\Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory $subscriberCollectionFactory,
\Magento\Newsletter\Model\Queue\TransportBuilder $transportBuilder,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
\Vendor\Module\Block\Testing $customergroup,
\Magento\Customer\Model\ResourceModel\Group\Collection $customergroupdata,
array $data = []
)
{
$this->_customergroup = $customergroup;
$this->_customergroupdata = $customergroupdata;
parent::__construct(
$context,
$registry,
$templateFilter,
$date,
$templateFactory,
$problemFactory,
$subscriberCollectionFactory,
$transportBuilder,
$resource,
$resourceCollection,
$data
);
}
You cannot override classes which does not injected via DI. This class used only as parent and does not injected in any contructors and does not created via ObjectManager
.
To override this model you need to create preference on injected subtypes (\Magento\Customer\Model\Address
, ...).
But preference is not good way to add functionality. You can write plugin on \Magento\Customer\Model\Address\AbstractAddress
and easy solve your problem.
Best Answer
Create di.xml File
Path :
app/code/{vendorName}/{ModuleName}/etc/di.xml
Create Model file
Path :
app/code/{vendorName}/{ModuleName}/Model/Address/
AbstractAddres.php