“Undefined property: Interceptor::$invoiceService” while overriding controller in magento2Magento 2 error...

Asserting that Atheism and Theism are both faith based positions

Have the tides ever turned twice on any open problem?

PTIJ: Which Dr. Seuss books should one obtain?

Unfrosted light bulb

What is the difference between something being completely legal and being completely decriminalized?

How to test the sharpness of a knife?

How can a new country break out from a developed country without war?

How can an organ that provides biological immortality be unable to regenerate?

Why is there so much iron?

Is xar preinstalled on macOS?

Output visual diagram of picture

Determine voltage drop over 10G resistors with cheap multimeter

Can "few" be used as a subject? If so, what is the rule?

Why is this tree refusing to shed its dead leaves?

How to find the largest number(s) in a list of elements, possibly non-unique?

Is this Pascal's Matrix?

Why do I have a large white artefact on the rendered image?

Are hand made posters acceptable in Academia?

Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?

Emojional cryptic crossword

Have any astronauts/cosmonauts died in space?

How to balance a monster modification (zombie)?

label a part of commutative diagram

Was World War I a war of liberals against authoritarians?



“Undefined property: Interceptor::$invoiceService” while overriding controller in magento2


Magento 2 error while adding new order statusMagento 2 Service Contract API Example For Creating A Shipment and Adding ItemsMagento 2: How to override newsletter Subscriber modelMagento 2 - Can't access to products with direct urlMagento 2: Shipment Email gives Missing required argument $debugHintsPathDI not working in ControllerError when i clicked on ship button inside a orderMagento 2.2.5: Overriding Admin Controller sales/orderhow to capture cybersource echeck programtically













0















I am trying to override "AdminhtmlOrderInvoiceSave" controller, So I made changes in di.xml as below -



<preference for="MagentoSalesControllerAdminhtmlOrderInvoiceSave" type="CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave" />


And create as save.php controller at location -
CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave.php



and overide its execute function like below -



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{

public function execute()
{
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
====
....................
........................
default code............
......................

try {
$invoiceData = $this->getRequest()->getParam('invoice', []);
$invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : [];

/** @var MagentoSalesModelOrder $order */
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($orderId);
if (!$order->getId()) {
throw new MagentoFrameworkExceptionLocalizedException(__('The order no longer exists.'));
}

if (!$order->canInvoice()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('The order does not allow an invoice to be created.')
);
}
//====on below line its giving error========
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);

if (!$invoice) {
throw new LocalizedException(__('We can't save the invoice right now.'));
}

if (!$invoice->getTotalQty()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('You can't create an invoice without products.')
);
}
$this->registry->register('current_invoice', $invoice);
if (!empty($data['capture_case'])) {
$invoice->setRequestedCaptureCase($data['capture_case']);
}

if (!empty($data['comment_text'])) {
$invoice->addComment(
$data['comment_text'],
isset($data['comment_customer_notify']),
isset($data['is_visible_on_front'])
);

$invoice->setCustomerNote($data['comment_text']);
$invoice->setCustomerNoteNotify(isset($data['comment_customer_notify']));
}

$invoice->register();

$invoice->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
$invoice->getOrder()->setIsInProcess(true);

$transactionSave = $this->_objectManager->create(
'MagentoFrameworkDBTransaction'
)->addObject(
$invoice
)->addObject(
$invoice->getOrder()
);
$shipment = false;
if (!empty($data['do_shipment']) || (int)$invoice->getOrder()->getForcedShipmentWithInvoice()) {
$shipment = $this->_prepareShipment($invoice);
if ($shipment) {
$transactionSave->addObject($shipment);
}
}
$transactionSave->save();
//=================
//===My custom code========
//=================
//....................
........................
default code............
......................

return $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (Exception $e) {
echo "<pre>";
print_r($e->getMessage()); die;
$this->messageManager->addError(__('We can't save the invoice right now.'));
$this->_objectManager->get('PsrLogLoggerInterface')->critical($e);
}
return $resultRedirect->setPath('sales/*/new', ['order_id' => $orderId]);
}
}


On this line its giving me error -



$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);


Error - : Notice: Undefined property: CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSaveInterceptor::$invoiceService in /var/www/html/git_projects/testbeat/app/code/Customcode/Productserialno/Controller/Sales/Adminhtml/Order/Invoice/Save.php on line 51



Please let me know what I am doing wrong .



Thanks










share|improve this question














bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • remvoe var folder and check

    – Rakesh Jesadiya
    Sep 1 '17 at 8:30











  • Hi Rakesh, I removed all directories of var, pub/static then again run upgrade, content deploy n flush cache but still giving same issue....

    – Atul
    Sep 1 '17 at 10:41


















0















I am trying to override "AdminhtmlOrderInvoiceSave" controller, So I made changes in di.xml as below -



<preference for="MagentoSalesControllerAdminhtmlOrderInvoiceSave" type="CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave" />


And create as save.php controller at location -
CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave.php



and overide its execute function like below -



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{

public function execute()
{
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
====
....................
........................
default code............
......................

try {
$invoiceData = $this->getRequest()->getParam('invoice', []);
$invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : [];

/** @var MagentoSalesModelOrder $order */
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($orderId);
if (!$order->getId()) {
throw new MagentoFrameworkExceptionLocalizedException(__('The order no longer exists.'));
}

if (!$order->canInvoice()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('The order does not allow an invoice to be created.')
);
}
//====on below line its giving error========
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);

if (!$invoice) {
throw new LocalizedException(__('We can't save the invoice right now.'));
}

if (!$invoice->getTotalQty()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('You can't create an invoice without products.')
);
}
$this->registry->register('current_invoice', $invoice);
if (!empty($data['capture_case'])) {
$invoice->setRequestedCaptureCase($data['capture_case']);
}

if (!empty($data['comment_text'])) {
$invoice->addComment(
$data['comment_text'],
isset($data['comment_customer_notify']),
isset($data['is_visible_on_front'])
);

$invoice->setCustomerNote($data['comment_text']);
$invoice->setCustomerNoteNotify(isset($data['comment_customer_notify']));
}

$invoice->register();

$invoice->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
$invoice->getOrder()->setIsInProcess(true);

$transactionSave = $this->_objectManager->create(
'MagentoFrameworkDBTransaction'
)->addObject(
$invoice
)->addObject(
$invoice->getOrder()
);
$shipment = false;
if (!empty($data['do_shipment']) || (int)$invoice->getOrder()->getForcedShipmentWithInvoice()) {
$shipment = $this->_prepareShipment($invoice);
if ($shipment) {
$transactionSave->addObject($shipment);
}
}
$transactionSave->save();
//=================
//===My custom code========
//=================
//....................
........................
default code............
......................

return $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (Exception $e) {
echo "<pre>";
print_r($e->getMessage()); die;
$this->messageManager->addError(__('We can't save the invoice right now.'));
$this->_objectManager->get('PsrLogLoggerInterface')->critical($e);
}
return $resultRedirect->setPath('sales/*/new', ['order_id' => $orderId]);
}
}


On this line its giving me error -



$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);


Error - : Notice: Undefined property: CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSaveInterceptor::$invoiceService in /var/www/html/git_projects/testbeat/app/code/Customcode/Productserialno/Controller/Sales/Adminhtml/Order/Invoice/Save.php on line 51



Please let me know what I am doing wrong .



Thanks










share|improve this question














bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • remvoe var folder and check

    – Rakesh Jesadiya
    Sep 1 '17 at 8:30











  • Hi Rakesh, I removed all directories of var, pub/static then again run upgrade, content deploy n flush cache but still giving same issue....

    – Atul
    Sep 1 '17 at 10:41
















0












0








0








I am trying to override "AdminhtmlOrderInvoiceSave" controller, So I made changes in di.xml as below -



<preference for="MagentoSalesControllerAdminhtmlOrderInvoiceSave" type="CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave" />


And create as save.php controller at location -
CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave.php



and overide its execute function like below -



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{

public function execute()
{
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
====
....................
........................
default code............
......................

try {
$invoiceData = $this->getRequest()->getParam('invoice', []);
$invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : [];

/** @var MagentoSalesModelOrder $order */
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($orderId);
if (!$order->getId()) {
throw new MagentoFrameworkExceptionLocalizedException(__('The order no longer exists.'));
}

if (!$order->canInvoice()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('The order does not allow an invoice to be created.')
);
}
//====on below line its giving error========
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);

if (!$invoice) {
throw new LocalizedException(__('We can't save the invoice right now.'));
}

if (!$invoice->getTotalQty()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('You can't create an invoice without products.')
);
}
$this->registry->register('current_invoice', $invoice);
if (!empty($data['capture_case'])) {
$invoice->setRequestedCaptureCase($data['capture_case']);
}

if (!empty($data['comment_text'])) {
$invoice->addComment(
$data['comment_text'],
isset($data['comment_customer_notify']),
isset($data['is_visible_on_front'])
);

$invoice->setCustomerNote($data['comment_text']);
$invoice->setCustomerNoteNotify(isset($data['comment_customer_notify']));
}

$invoice->register();

$invoice->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
$invoice->getOrder()->setIsInProcess(true);

$transactionSave = $this->_objectManager->create(
'MagentoFrameworkDBTransaction'
)->addObject(
$invoice
)->addObject(
$invoice->getOrder()
);
$shipment = false;
if (!empty($data['do_shipment']) || (int)$invoice->getOrder()->getForcedShipmentWithInvoice()) {
$shipment = $this->_prepareShipment($invoice);
if ($shipment) {
$transactionSave->addObject($shipment);
}
}
$transactionSave->save();
//=================
//===My custom code========
//=================
//....................
........................
default code............
......................

return $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (Exception $e) {
echo "<pre>";
print_r($e->getMessage()); die;
$this->messageManager->addError(__('We can't save the invoice right now.'));
$this->_objectManager->get('PsrLogLoggerInterface')->critical($e);
}
return $resultRedirect->setPath('sales/*/new', ['order_id' => $orderId]);
}
}


On this line its giving me error -



$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);


Error - : Notice: Undefined property: CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSaveInterceptor::$invoiceService in /var/www/html/git_projects/testbeat/app/code/Customcode/Productserialno/Controller/Sales/Adminhtml/Order/Invoice/Save.php on line 51



Please let me know what I am doing wrong .



Thanks










share|improve this question














I am trying to override "AdminhtmlOrderInvoiceSave" controller, So I made changes in di.xml as below -



<preference for="MagentoSalesControllerAdminhtmlOrderInvoiceSave" type="CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave" />


And create as save.php controller at location -
CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave.php



and overide its execute function like below -



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{

public function execute()
{
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
====
....................
........................
default code............
......................

try {
$invoiceData = $this->getRequest()->getParam('invoice', []);
$invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : [];

/** @var MagentoSalesModelOrder $order */
$order = $this->_objectManager->create('MagentoSalesModelOrder')->load($orderId);
if (!$order->getId()) {
throw new MagentoFrameworkExceptionLocalizedException(__('The order no longer exists.'));
}

if (!$order->canInvoice()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('The order does not allow an invoice to be created.')
);
}
//====on below line its giving error========
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);

if (!$invoice) {
throw new LocalizedException(__('We can't save the invoice right now.'));
}

if (!$invoice->getTotalQty()) {
throw new MagentoFrameworkExceptionLocalizedException(
__('You can't create an invoice without products.')
);
}
$this->registry->register('current_invoice', $invoice);
if (!empty($data['capture_case'])) {
$invoice->setRequestedCaptureCase($data['capture_case']);
}

if (!empty($data['comment_text'])) {
$invoice->addComment(
$data['comment_text'],
isset($data['comment_customer_notify']),
isset($data['is_visible_on_front'])
);

$invoice->setCustomerNote($data['comment_text']);
$invoice->setCustomerNoteNotify(isset($data['comment_customer_notify']));
}

$invoice->register();

$invoice->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
$invoice->getOrder()->setIsInProcess(true);

$transactionSave = $this->_objectManager->create(
'MagentoFrameworkDBTransaction'
)->addObject(
$invoice
)->addObject(
$invoice->getOrder()
);
$shipment = false;
if (!empty($data['do_shipment']) || (int)$invoice->getOrder()->getForcedShipmentWithInvoice()) {
$shipment = $this->_prepareShipment($invoice);
if ($shipment) {
$transactionSave->addObject($shipment);
}
}
$transactionSave->save();
//=================
//===My custom code========
//=================
//....................
........................
default code............
......................

return $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (Exception $e) {
echo "<pre>";
print_r($e->getMessage()); die;
$this->messageManager->addError(__('We can't save the invoice right now.'));
$this->_objectManager->get('PsrLogLoggerInterface')->critical($e);
}
return $resultRedirect->setPath('sales/*/new', ['order_id' => $orderId]);
}
}


On this line its giving me error -



$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);


Error - : Notice: Undefined property: CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSaveInterceptor::$invoiceService in /var/www/html/git_projects/testbeat/app/code/Customcode/Productserialno/Controller/Sales/Adminhtml/Order/Invoice/Save.php on line 51



Please let me know what I am doing wrong .



Thanks







magento2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 1 '17 at 8:06









AtulAtul

470822




470822





bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • remvoe var folder and check

    – Rakesh Jesadiya
    Sep 1 '17 at 8:30











  • Hi Rakesh, I removed all directories of var, pub/static then again run upgrade, content deploy n flush cache but still giving same issue....

    – Atul
    Sep 1 '17 at 10:41





















  • remvoe var folder and check

    – Rakesh Jesadiya
    Sep 1 '17 at 8:30











  • Hi Rakesh, I removed all directories of var, pub/static then again run upgrade, content deploy n flush cache but still giving same issue....

    – Atul
    Sep 1 '17 at 10:41



















remvoe var folder and check

– Rakesh Jesadiya
Sep 1 '17 at 8:30





remvoe var folder and check

– Rakesh Jesadiya
Sep 1 '17 at 8:30













Hi Rakesh, I removed all directories of var, pub/static then again run upgrade, content deploy n flush cache but still giving same issue....

– Atul
Sep 1 '17 at 10:41







Hi Rakesh, I removed all directories of var, pub/static then again run upgrade, content deploy n flush cache but still giving same issue....

– Atul
Sep 1 '17 at 10:41












1 Answer
1






active

oldest

votes


















0














The scope of this variable is private. Hence you can't use this in your overriding (inherited) class. please inject MagentoSalesModelServiceInvoiceService class for this variable in your constructor as it is injected into the main class.



Don't forget to run upgrade and di:compile commands after DI.



Edit: try this in your class



<?php

namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;


use MagentoBackendAppAction;
use MagentoFrameworkRegistry;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderEmailSenderShipmentSender;
use MagentoSalesModelOrderShipmentFactory;
use MagentoSalesModelServiceInvoiceService;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct
(
ActionContext $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
)
{
$this->invoiceService = $invoiceService;
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

/**
* Save invoice
* We can save only new invoice. Existing invoices are not editable
*
* @return MagentoFrameworkControllerResultInterface
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
..........................
.......All code with customization------
}
}


=================My Code is this ===================



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct(
MagentoBackendAppAction $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
) {
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

public function execute() {
..........................
.......All code with customization------
}

}


Plz check because my code still giving same error.
Recoverable Error: Argument 1 passed to CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoBackendAppAction,



Plz let me know what I m doing wrong.






share|improve this answer


























  • I tried like this inside class - private $invoiceService; public function __construct( MagentoSalesModelServiceInvoiceService $invoiceService ) { $this->invoiceService = $invoiceService; } but its giving 500 error ....

    – Atul
    Sep 2 '17 at 10:16











  • did you run upgrade and compile commands afterwards??

    – Yogesh Agarwal
    Sep 2 '17 at 10:36











  • yes I have run Upgrade command but not compile because i m already in developer mode, >>>> now defined it as - public function __construct( MagentoFrameworkAppActionContext $context, MagentoSalesModelServiceInvoiceService $invoiceService, array $data = [] ) { $this->invoiceService = $invoiceService; parent::__construct($context, $data); } Now its giving - Argument 2 passed to MagentoSalesControllerAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoFrameworkRegistry, error...

    – Atul
    Sep 2 '17 at 10:46













  • -> can you plz add respective live of code via update your answer.

    – Atul
    Sep 2 '17 at 11:39











  • @Atul I have made an edit. please give it a shot.

    – Yogesh Agarwal
    Sep 2 '17 at 12:13











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f191550%2fundefined-property-interceptorinvoiceservice-while-overriding-controller-i%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The scope of this variable is private. Hence you can't use this in your overriding (inherited) class. please inject MagentoSalesModelServiceInvoiceService class for this variable in your constructor as it is injected into the main class.



Don't forget to run upgrade and di:compile commands after DI.



Edit: try this in your class



<?php

namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;


use MagentoBackendAppAction;
use MagentoFrameworkRegistry;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderEmailSenderShipmentSender;
use MagentoSalesModelOrderShipmentFactory;
use MagentoSalesModelServiceInvoiceService;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct
(
ActionContext $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
)
{
$this->invoiceService = $invoiceService;
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

/**
* Save invoice
* We can save only new invoice. Existing invoices are not editable
*
* @return MagentoFrameworkControllerResultInterface
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
..........................
.......All code with customization------
}
}


=================My Code is this ===================



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct(
MagentoBackendAppAction $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
) {
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

public function execute() {
..........................
.......All code with customization------
}

}


Plz check because my code still giving same error.
Recoverable Error: Argument 1 passed to CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoBackendAppAction,



Plz let me know what I m doing wrong.






share|improve this answer


























  • I tried like this inside class - private $invoiceService; public function __construct( MagentoSalesModelServiceInvoiceService $invoiceService ) { $this->invoiceService = $invoiceService; } but its giving 500 error ....

    – Atul
    Sep 2 '17 at 10:16











  • did you run upgrade and compile commands afterwards??

    – Yogesh Agarwal
    Sep 2 '17 at 10:36











  • yes I have run Upgrade command but not compile because i m already in developer mode, >>>> now defined it as - public function __construct( MagentoFrameworkAppActionContext $context, MagentoSalesModelServiceInvoiceService $invoiceService, array $data = [] ) { $this->invoiceService = $invoiceService; parent::__construct($context, $data); } Now its giving - Argument 2 passed to MagentoSalesControllerAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoFrameworkRegistry, error...

    – Atul
    Sep 2 '17 at 10:46













  • -> can you plz add respective live of code via update your answer.

    – Atul
    Sep 2 '17 at 11:39











  • @Atul I have made an edit. please give it a shot.

    – Yogesh Agarwal
    Sep 2 '17 at 12:13
















0














The scope of this variable is private. Hence you can't use this in your overriding (inherited) class. please inject MagentoSalesModelServiceInvoiceService class for this variable in your constructor as it is injected into the main class.



Don't forget to run upgrade and di:compile commands after DI.



Edit: try this in your class



<?php

namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;


use MagentoBackendAppAction;
use MagentoFrameworkRegistry;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderEmailSenderShipmentSender;
use MagentoSalesModelOrderShipmentFactory;
use MagentoSalesModelServiceInvoiceService;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct
(
ActionContext $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
)
{
$this->invoiceService = $invoiceService;
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

/**
* Save invoice
* We can save only new invoice. Existing invoices are not editable
*
* @return MagentoFrameworkControllerResultInterface
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
..........................
.......All code with customization------
}
}


=================My Code is this ===================



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct(
MagentoBackendAppAction $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
) {
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

public function execute() {
..........................
.......All code with customization------
}

}


Plz check because my code still giving same error.
Recoverable Error: Argument 1 passed to CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoBackendAppAction,



Plz let me know what I m doing wrong.






share|improve this answer


























  • I tried like this inside class - private $invoiceService; public function __construct( MagentoSalesModelServiceInvoiceService $invoiceService ) { $this->invoiceService = $invoiceService; } but its giving 500 error ....

    – Atul
    Sep 2 '17 at 10:16











  • did you run upgrade and compile commands afterwards??

    – Yogesh Agarwal
    Sep 2 '17 at 10:36











  • yes I have run Upgrade command but not compile because i m already in developer mode, >>>> now defined it as - public function __construct( MagentoFrameworkAppActionContext $context, MagentoSalesModelServiceInvoiceService $invoiceService, array $data = [] ) { $this->invoiceService = $invoiceService; parent::__construct($context, $data); } Now its giving - Argument 2 passed to MagentoSalesControllerAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoFrameworkRegistry, error...

    – Atul
    Sep 2 '17 at 10:46













  • -> can you plz add respective live of code via update your answer.

    – Atul
    Sep 2 '17 at 11:39











  • @Atul I have made an edit. please give it a shot.

    – Yogesh Agarwal
    Sep 2 '17 at 12:13














0












0








0







The scope of this variable is private. Hence you can't use this in your overriding (inherited) class. please inject MagentoSalesModelServiceInvoiceService class for this variable in your constructor as it is injected into the main class.



Don't forget to run upgrade and di:compile commands after DI.



Edit: try this in your class



<?php

namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;


use MagentoBackendAppAction;
use MagentoFrameworkRegistry;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderEmailSenderShipmentSender;
use MagentoSalesModelOrderShipmentFactory;
use MagentoSalesModelServiceInvoiceService;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct
(
ActionContext $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
)
{
$this->invoiceService = $invoiceService;
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

/**
* Save invoice
* We can save only new invoice. Existing invoices are not editable
*
* @return MagentoFrameworkControllerResultInterface
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
..........................
.......All code with customization------
}
}


=================My Code is this ===================



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct(
MagentoBackendAppAction $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
) {
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

public function execute() {
..........................
.......All code with customization------
}

}


Plz check because my code still giving same error.
Recoverable Error: Argument 1 passed to CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoBackendAppAction,



Plz let me know what I m doing wrong.






share|improve this answer















The scope of this variable is private. Hence you can't use this in your overriding (inherited) class. please inject MagentoSalesModelServiceInvoiceService class for this variable in your constructor as it is injected into the main class.



Don't forget to run upgrade and di:compile commands after DI.



Edit: try this in your class



<?php

namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;


use MagentoBackendAppAction;
use MagentoFrameworkRegistry;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderEmailSenderShipmentSender;
use MagentoSalesModelOrderShipmentFactory;
use MagentoSalesModelServiceInvoiceService;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct
(
ActionContext $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
)
{
$this->invoiceService = $invoiceService;
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

/**
* Save invoice
* We can save only new invoice. Existing invoices are not editable
*
* @return MagentoFrameworkControllerResultInterface
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
..........................
.......All code with customization------
}
}


=================My Code is this ===================



namespace CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoice;

class Save extends MagentoSalesControllerAdminhtmlOrderInvoiceSave
{
/**
* @var InvoiceService
*/
private $invoiceService;

public function __construct(
MagentoBackendAppAction $context,
Registry $registry,
InvoiceSender $invoiceSender,
ShipmentSender $shipmentSender,
ShipmentFactory $shipmentFactory,
InvoiceService $invoiceService
) {
parent::__construct($context, $registry, $invoiceSender, $shipmentSender, $shipmentFactory, $invoiceService);
}

public function execute() {
..........................
.......All code with customization------
}

}


Plz check because my code still giving same error.
Recoverable Error: Argument 1 passed to CustomcodeProductserialnoControllerSalesAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoBackendAppAction,



Plz let me know what I m doing wrong.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 6 '17 at 5:46

























answered Sep 2 '17 at 5:48









Yogesh AgarwalYogesh Agarwal

712316




712316













  • I tried like this inside class - private $invoiceService; public function __construct( MagentoSalesModelServiceInvoiceService $invoiceService ) { $this->invoiceService = $invoiceService; } but its giving 500 error ....

    – Atul
    Sep 2 '17 at 10:16











  • did you run upgrade and compile commands afterwards??

    – Yogesh Agarwal
    Sep 2 '17 at 10:36











  • yes I have run Upgrade command but not compile because i m already in developer mode, >>>> now defined it as - public function __construct( MagentoFrameworkAppActionContext $context, MagentoSalesModelServiceInvoiceService $invoiceService, array $data = [] ) { $this->invoiceService = $invoiceService; parent::__construct($context, $data); } Now its giving - Argument 2 passed to MagentoSalesControllerAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoFrameworkRegistry, error...

    – Atul
    Sep 2 '17 at 10:46













  • -> can you plz add respective live of code via update your answer.

    – Atul
    Sep 2 '17 at 11:39











  • @Atul I have made an edit. please give it a shot.

    – Yogesh Agarwal
    Sep 2 '17 at 12:13



















  • I tried like this inside class - private $invoiceService; public function __construct( MagentoSalesModelServiceInvoiceService $invoiceService ) { $this->invoiceService = $invoiceService; } but its giving 500 error ....

    – Atul
    Sep 2 '17 at 10:16











  • did you run upgrade and compile commands afterwards??

    – Yogesh Agarwal
    Sep 2 '17 at 10:36











  • yes I have run Upgrade command but not compile because i m already in developer mode, >>>> now defined it as - public function __construct( MagentoFrameworkAppActionContext $context, MagentoSalesModelServiceInvoiceService $invoiceService, array $data = [] ) { $this->invoiceService = $invoiceService; parent::__construct($context, $data); } Now its giving - Argument 2 passed to MagentoSalesControllerAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoFrameworkRegistry, error...

    – Atul
    Sep 2 '17 at 10:46













  • -> can you plz add respective live of code via update your answer.

    – Atul
    Sep 2 '17 at 11:39











  • @Atul I have made an edit. please give it a shot.

    – Yogesh Agarwal
    Sep 2 '17 at 12:13

















I tried like this inside class - private $invoiceService; public function __construct( MagentoSalesModelServiceInvoiceService $invoiceService ) { $this->invoiceService = $invoiceService; } but its giving 500 error ....

– Atul
Sep 2 '17 at 10:16





I tried like this inside class - private $invoiceService; public function __construct( MagentoSalesModelServiceInvoiceService $invoiceService ) { $this->invoiceService = $invoiceService; } but its giving 500 error ....

– Atul
Sep 2 '17 at 10:16













did you run upgrade and compile commands afterwards??

– Yogesh Agarwal
Sep 2 '17 at 10:36





did you run upgrade and compile commands afterwards??

– Yogesh Agarwal
Sep 2 '17 at 10:36













yes I have run Upgrade command but not compile because i m already in developer mode, >>>> now defined it as - public function __construct( MagentoFrameworkAppActionContext $context, MagentoSalesModelServiceInvoiceService $invoiceService, array $data = [] ) { $this->invoiceService = $invoiceService; parent::__construct($context, $data); } Now its giving - Argument 2 passed to MagentoSalesControllerAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoFrameworkRegistry, error...

– Atul
Sep 2 '17 at 10:46







yes I have run Upgrade command but not compile because i m already in developer mode, >>>> now defined it as - public function __construct( MagentoFrameworkAppActionContext $context, MagentoSalesModelServiceInvoiceService $invoiceService, array $data = [] ) { $this->invoiceService = $invoiceService; parent::__construct($context, $data); } Now its giving - Argument 2 passed to MagentoSalesControllerAdminhtmlOrderInvoiceSave::__construct() must be an instance of MagentoFrameworkRegistry, error...

– Atul
Sep 2 '17 at 10:46















-> can you plz add respective live of code via update your answer.

– Atul
Sep 2 '17 at 11:39





-> can you plz add respective live of code via update your answer.

– Atul
Sep 2 '17 at 11:39













@Atul I have made an edit. please give it a shot.

– Yogesh Agarwal
Sep 2 '17 at 12:13





@Atul I have made an edit. please give it a shot.

– Yogesh Agarwal
Sep 2 '17 at 12:13


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f191550%2fundefined-property-interceptorinvoiceservice-while-overriding-controller-i%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

“%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...