Mass Action: Bulk invoice - Shipping charges issueMass action in widgetsAdd mass action in order grid to exportRemove Mass action from Sales/Order GridChange updated_at date on mass actionProductController for Mass ActionMass Action in Order GridMass Action not sending all dataValidate mass action columnMagento 2 add conditional mass action in sales order gridCreate shipment and invoice in mass action
Jem'Hadar, something strange about their life expectancy
How to test the sharpness of a knife?
Why is indicated airspeed rather than ground speed used during the takeoff roll?
Isn't the word "experience" wrongly used in this context?
Norwegian Refugee travel document
Does fire aspect on a sword, destroy mob drops?
How can I create URL shortcuts/redirects for task/diff IDs in Phabricator?
Can "few" be used as a subject? If so, what is the rule?
What (if any) is the reason to buy in small local stores?
Is there any common country to visit for uk and schengen visa?
How do researchers send unsolicited emails asking for feedback on their works?
Single word to change groups
Difficulty understanding group delay concept
Unfrosted light bulb
How are passwords stolen from companies if they only store hashes?
Justification failure in beamer enumerate list
TDE Master Key Rotation
Help with identifying unique aircraft over NE Pennsylvania
Can other pieces capture a threatening piece and prevent a checkmate?
Have any astronauts/cosmonauts died in space?
Print last inputted byte
Exit shell with shortcut (not typing exit) that closes session properly
The English Debate
How to balance a monster modification (zombie)?
Mass Action: Bulk invoice - Shipping charges issue
Mass action in widgetsAdd mass action in order grid to exportRemove Mass action from Sales/Order GridChange updated_at date on mass actionProductController for Mass ActionMass Action in Order GridMass Action not sending all dataValidate mass action columnMagento 2 add conditional mass action in sales order gridCreate shipment and invoice in mass action
I have created mass action in order grid to create bulk invoice. And after successfully creating invoice on multiple orders I am facing issue with shipping charges.
i.e, for first order it is adding shipping amount in invoice and for other orders it is excluding shipping amount.
Here is my code for mass invoice:
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if ($loadedOrder->canInvoice())
$invoice = $this->_invoiceService->prepareInvoice($loadedOrder);
if ($loadedOrder->getPayment()->getMethod() != "cashondelivery")
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
$invoice->save();
$transactionSave = $this->_transaction->addObject($invoice)->addObject($invoice->getOrder());
$transactionSave->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. ' . $appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . $loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . ", " . $loadedOrder->getIncrementId();
magento2 sales-order magento2.2.2 massaction
add a comment |
I have created mass action in order grid to create bulk invoice. And after successfully creating invoice on multiple orders I am facing issue with shipping charges.
i.e, for first order it is adding shipping amount in invoice and for other orders it is excluding shipping amount.
Here is my code for mass invoice:
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if ($loadedOrder->canInvoice())
$invoice = $this->_invoiceService->prepareInvoice($loadedOrder);
if ($loadedOrder->getPayment()->getMethod() != "cashondelivery")
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
$invoice->save();
$transactionSave = $this->_transaction->addObject($invoice)->addObject($invoice->getOrder());
$transactionSave->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. ' . $appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . $loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . ", " . $loadedOrder->getIncrementId();
magento2 sales-order magento2.2.2 massaction
add a comment |
I have created mass action in order grid to create bulk invoice. And after successfully creating invoice on multiple orders I am facing issue with shipping charges.
i.e, for first order it is adding shipping amount in invoice and for other orders it is excluding shipping amount.
Here is my code for mass invoice:
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if ($loadedOrder->canInvoice())
$invoice = $this->_invoiceService->prepareInvoice($loadedOrder);
if ($loadedOrder->getPayment()->getMethod() != "cashondelivery")
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
$invoice->save();
$transactionSave = $this->_transaction->addObject($invoice)->addObject($invoice->getOrder());
$transactionSave->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. ' . $appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . $loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . ", " . $loadedOrder->getIncrementId();
magento2 sales-order magento2.2.2 massaction
I have created mass action in order grid to create bulk invoice. And after successfully creating invoice on multiple orders I am facing issue with shipping charges.
i.e, for first order it is adding shipping amount in invoice and for other orders it is excluding shipping amount.
Here is my code for mass invoice:
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if ($loadedOrder->canInvoice())
$invoice = $this->_invoiceService->prepareInvoice($loadedOrder);
if ($loadedOrder->getPayment()->getMethod() != "cashondelivery")
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
$invoice->save();
$transactionSave = $this->_transaction->addObject($invoice)->addObject($invoice->getOrder());
$transactionSave->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. ' . $appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . $loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers . ", " . $loadedOrder->getIncrementId();
magento2 sales-order magento2.2.2 massaction
magento2 sales-order magento2.2.2 massaction
edited 12 hours ago
Muhammad Hasham
2,5581731
2,5581731
asked Jan 31 at 8:03
Shoaib MunirShoaib Munir
2,1101828
2,1101828
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Replace your foreach loop with this
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if($loadedOrder->canInvoice())
// Create invoice for this order
$invoice = $this->_objectManager->create('MagentoSalesModelServiceInvoiceService')->prepareInvoice($loadedOrder);
//$invoice->getOrder()->setIsInProcess(true);
$invoice->setShippingAmount($loadedOrder->getShippingAmount());
$invoice->setBaseShippingAmount($loadedOrder->getBaseShippingAmount());
$invoice->setTaxAmount($loadedOrder->getTaxAmount());
$invoice->setBaseTaxAmount($loadedOrder->getBaseTaxAmount());
$invoice->setSubtotal($loadedOrder->getSubtotal());
$invoice->setBaseSubtotal($loadedOrder->getBaseSubtotal());
$invoice->setGrandTotal($loadedOrder->getGrandTotal());
$invoice->setBaseGrandTotal($loadedOrder->getBaseGrandTotal());
// Register as invoice item
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
// Save the invoice to the order
$transaction = $this->_objectManager->create('MagentoFrameworkDBTransaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transaction->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. '.$appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.$loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.", ".$loadedOrder->getIncrementId();
In above code the only difference is, I assign shipping amount, tax amount, subtotal and grandtotal during invoice creation
I hope this will help
Thanks @Muhammad Hasham for the answer, let me try this code
– Shoaib Munir
Feb 1 at 7:12
It worked perfectly. Thanks mate :)
– Shoaib Munir
Feb 1 at 7:22
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f259934%2fmass-action-bulk-invoice-shipping-charges-issue%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
Replace your foreach loop with this
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if($loadedOrder->canInvoice())
// Create invoice for this order
$invoice = $this->_objectManager->create('MagentoSalesModelServiceInvoiceService')->prepareInvoice($loadedOrder);
//$invoice->getOrder()->setIsInProcess(true);
$invoice->setShippingAmount($loadedOrder->getShippingAmount());
$invoice->setBaseShippingAmount($loadedOrder->getBaseShippingAmount());
$invoice->setTaxAmount($loadedOrder->getTaxAmount());
$invoice->setBaseTaxAmount($loadedOrder->getBaseTaxAmount());
$invoice->setSubtotal($loadedOrder->getSubtotal());
$invoice->setBaseSubtotal($loadedOrder->getBaseSubtotal());
$invoice->setGrandTotal($loadedOrder->getGrandTotal());
$invoice->setBaseGrandTotal($loadedOrder->getBaseGrandTotal());
// Register as invoice item
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
// Save the invoice to the order
$transaction = $this->_objectManager->create('MagentoFrameworkDBTransaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transaction->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. '.$appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.$loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.", ".$loadedOrder->getIncrementId();
In above code the only difference is, I assign shipping amount, tax amount, subtotal and grandtotal during invoice creation
I hope this will help
Thanks @Muhammad Hasham for the answer, let me try this code
– Shoaib Munir
Feb 1 at 7:12
It worked perfectly. Thanks mate :)
– Shoaib Munir
Feb 1 at 7:22
add a comment |
Replace your foreach loop with this
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if($loadedOrder->canInvoice())
// Create invoice for this order
$invoice = $this->_objectManager->create('MagentoSalesModelServiceInvoiceService')->prepareInvoice($loadedOrder);
//$invoice->getOrder()->setIsInProcess(true);
$invoice->setShippingAmount($loadedOrder->getShippingAmount());
$invoice->setBaseShippingAmount($loadedOrder->getBaseShippingAmount());
$invoice->setTaxAmount($loadedOrder->getTaxAmount());
$invoice->setBaseTaxAmount($loadedOrder->getBaseTaxAmount());
$invoice->setSubtotal($loadedOrder->getSubtotal());
$invoice->setBaseSubtotal($loadedOrder->getBaseSubtotal());
$invoice->setGrandTotal($loadedOrder->getGrandTotal());
$invoice->setBaseGrandTotal($loadedOrder->getBaseGrandTotal());
// Register as invoice item
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
// Save the invoice to the order
$transaction = $this->_objectManager->create('MagentoFrameworkDBTransaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transaction->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. '.$appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.$loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.", ".$loadedOrder->getIncrementId();
In above code the only difference is, I assign shipping amount, tax amount, subtotal and grandtotal during invoice creation
I hope this will help
Thanks @Muhammad Hasham for the answer, let me try this code
– Shoaib Munir
Feb 1 at 7:12
It worked perfectly. Thanks mate :)
– Shoaib Munir
Feb 1 at 7:22
add a comment |
Replace your foreach loop with this
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if($loadedOrder->canInvoice())
// Create invoice for this order
$invoice = $this->_objectManager->create('MagentoSalesModelServiceInvoiceService')->prepareInvoice($loadedOrder);
//$invoice->getOrder()->setIsInProcess(true);
$invoice->setShippingAmount($loadedOrder->getShippingAmount());
$invoice->setBaseShippingAmount($loadedOrder->getBaseShippingAmount());
$invoice->setTaxAmount($loadedOrder->getTaxAmount());
$invoice->setBaseTaxAmount($loadedOrder->getBaseTaxAmount());
$invoice->setSubtotal($loadedOrder->getSubtotal());
$invoice->setBaseSubtotal($loadedOrder->getBaseSubtotal());
$invoice->setGrandTotal($loadedOrder->getGrandTotal());
$invoice->setBaseGrandTotal($loadedOrder->getBaseGrandTotal());
// Register as invoice item
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
// Save the invoice to the order
$transaction = $this->_objectManager->create('MagentoFrameworkDBTransaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transaction->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. '.$appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.$loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.", ".$loadedOrder->getIncrementId();
In above code the only difference is, I assign shipping amount, tax amount, subtotal and grandtotal during invoice creation
I hope this will help
Replace your foreach loop with this
foreach ($collection->getItems() as $order)
if (!$order->getEntityId())
continue;
$loadedOrder = $model->load($order->getEntityId());
if($loadedOrder->canInvoice())
// Create invoice for this order
$invoice = $this->_objectManager->create('MagentoSalesModelServiceInvoiceService')->prepareInvoice($loadedOrder);
//$invoice->getOrder()->setIsInProcess(true);
$invoice->setShippingAmount($loadedOrder->getShippingAmount());
$invoice->setBaseShippingAmount($loadedOrder->getBaseShippingAmount());
$invoice->setTaxAmount($loadedOrder->getTaxAmount());
$invoice->setBaseTaxAmount($loadedOrder->getBaseTaxAmount());
$invoice->setSubtotal($loadedOrder->getSubtotal());
$invoice->setBaseSubtotal($loadedOrder->getBaseSubtotal());
$invoice->setGrandTotal($loadedOrder->getGrandTotal());
$invoice->setBaseGrandTotal($loadedOrder->getBaseGrandTotal());
// Register as invoice item
$invoice->setRequestedCaptureCase(MagentoSalesModelOrderInvoice::CAPTURE_OFFLINE);
$invoice->register();
// Save the invoice to the order
$transaction = $this->_objectManager->create('MagentoFrameworkDBTransaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transaction->save();
//send notification code
$loadedOrder->addStatusHistoryComment(
__('Notified customer about invoice #%1. '.$appendusername, $invoice->getId())
)->setIsCustomerNotified(false)->save();
$countInvoiceOrder++;
else
if (empty($NonInvoiceOrdernuumbers))
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.$loadedOrder->getIncrementId();
else
$NonInvoiceOrdernuumbers = $NonInvoiceOrdernuumbers.", ".$loadedOrder->getIncrementId();
In above code the only difference is, I assign shipping amount, tax amount, subtotal and grandtotal during invoice creation
I hope this will help
answered Feb 1 at 7:11
Muhammad HashamMuhammad Hasham
2,5581731
2,5581731
Thanks @Muhammad Hasham for the answer, let me try this code
– Shoaib Munir
Feb 1 at 7:12
It worked perfectly. Thanks mate :)
– Shoaib Munir
Feb 1 at 7:22
add a comment |
Thanks @Muhammad Hasham for the answer, let me try this code
– Shoaib Munir
Feb 1 at 7:12
It worked perfectly. Thanks mate :)
– Shoaib Munir
Feb 1 at 7:22
Thanks @Muhammad Hasham for the answer, let me try this code
– Shoaib Munir
Feb 1 at 7:12
Thanks @Muhammad Hasham for the answer, let me try this code
– Shoaib Munir
Feb 1 at 7:12
It worked perfectly. Thanks mate :)
– Shoaib Munir
Feb 1 at 7:22
It worked perfectly. Thanks mate :)
– Shoaib Munir
Feb 1 at 7:22
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f259934%2fmass-action-bulk-invoice-shipping-charges-issue%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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