How to create invoices for more than one order via mass action? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Magento 2 Mass shipmentAdd mass action in order grid to exportNew Order statuses in the mass action update menu in Orders / Sales?Forwarding post parametersAdmin grid massaction checkboxes default checked & option set to action I wantAdding new custom mass order status actionHow to add a mass action via xml in Magento 2?Add new mass action in order grid in magento 1.9Mass creation of invoice in magento 1.9Mass Action: Bulk invoice - Shipping charges issue
Why is std::move not [[nodiscard]] in C++20?
The test team as an enemy of development? And how can this be avoided?
Is there hard evidence that the grant peer review system performs significantly better than random?
How much damage would a cupful of neutron star matter do to the Earth?
In musical terms, what properties are varied by the human voice to produce different words / syllables?
Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?
Why is a lens darker than other ones when applying the same settings?
Is multiple magic items in one inherently imbalanced?
How to change the tick of the color bar legend to black
Caught masturbating at work
One-one communication
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
Is it possible for SQL statements to execute concurrently within a single session in SQL Server?
What is the "studentd" process?
Should a wizard buy fine inks every time he want to copy spells into his spellbook?
How to ask rejected full-time candidates to apply to teach individual courses?
Monty Hall Problem-Probability Paradox
What order were files/directories output in dir?
What does Turing mean by this statement?
Trying to understand entropy as a novice in thermodynamics
Can you force honesty by using the Speak with Dead and Zone of Truth spells together?
What does it mean that physics no longer uses mechanical models to describe phenomena?
Special flights
AppleTVs create a chatty alternate WiFi network
How to create invoices for more than one order via mass action?
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Magento 2 Mass shipmentAdd mass action in order grid to exportNew Order statuses in the mass action update menu in Orders / Sales?Forwarding post parametersAdmin grid massaction checkboxes default checked & option set to action I wantAdding new custom mass order status actionHow to add a mass action via xml in Magento 2?Add new mass action in order grid in magento 1.9Mass creation of invoice in magento 1.9Mass Action: Bulk invoice - Shipping charges issue
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
for creating an invoice normally you have to open the order an create the invoice for that one order.
But is it possible to select more than one order in the overview grid and create the invoices for the selected orders in one mass action. Like you can do for e.g. printing invoices?
Or do we have to use an extension for such a mass action? Can you recommend any extension for that problem?
invoice massaction
add a comment |
for creating an invoice normally you have to open the order an create the invoice for that one order.
But is it possible to select more than one order in the overview grid and create the invoices for the selected orders in one mass action. Like you can do for e.g. printing invoices?
Or do we have to use an extension for such a mass action? Can you recommend any extension for that problem?
invoice massaction
add a comment |
for creating an invoice normally you have to open the order an create the invoice for that one order.
But is it possible to select more than one order in the overview grid and create the invoices for the selected orders in one mass action. Like you can do for e.g. printing invoices?
Or do we have to use an extension for such a mass action? Can you recommend any extension for that problem?
invoice massaction
for creating an invoice normally you have to open the order an create the invoice for that one order.
But is it possible to select more than one order in the overview grid and create the invoices for the selected orders in one mass action. Like you can do for e.g. printing invoices?
Or do we have to use an extension for such a mass action? Can you recommend any extension for that problem?
invoice massaction
invoice massaction
edited Jul 5 '18 at 4:55
Teja Bhagavan Kollepara
2,99241949
2,99241949
asked Sep 2 '15 at 14:41
runi0011runi0011
12
12
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You have 2 options:
Make a script to create invoices programmaticaly
(http://inchoo.net/magento/how-to-create-magento-invoice-from-order/)Buy a extension with massaction invoice
(http://www.magentocommerce.com/magento-connect/mass-order-actions-by-amasty.html)
I recommend you this extensions. Works fine!
Neither of these answer the op.
– Si Griffiths
Sep 22 '16 at 16:12
add a comment |
Since there's still no default way in Magento 2.2.x to accomplish this, I've created a basic mass action that will create an invoice for each selected order, which:
- Will be set to "Capture offline"
- Change the order status to "Processing"
- (Optional) Sends out the invoice e-mail (see commented code)
Of course this can also be extended upon to meet your wishes.
Assuming that you know how to create a custom module (Remember to change all instances of Vendor and Module with your own module details):
VendorModuleviewadminhtmlui_componentsales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="vendor_module_mass_invoice">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">vendor_module_mass_invoice</item>
<item name="label" xsi:type="string" translate="true">Invoice</item>
<item name="url" xsi:type="url" path="myroute/order/massInvoice"/>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</listing>
VendorModuleetcadminhtmlroutes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="myroute" frontName="myroute">
<module name="Vendor_Module" />
</route>
</router>
</config>
**VendorModuleControllerAdminhtmlOrderMassInvoice.php**
<?php
namespace VendorModuleControllerAdminhtmlOrder;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use MagentoSalesModelResourceModelOrderCollectionFactory;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderInvoice;
use MagentoSalesModelOrder;
class MassInvoice extends MagentoSalesControllerAdminhtmlOrderAbstractMassAction
/**
* @var InvoiceSender
*/
protected $_invoiceSender;
/**
* @var object
*/
protected $collectionFactory;
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory,
InvoiceSender $invoiceSender
)
parent::__construct($context, $filter);
$this->collectionFactory = $collectionFactory;
$this->_invoiceSender = $invoiceSender;
protected function massAction(AbstractCollection $collection)
$countInvoice = 0;
foreach ($collection->getItems() as $order)
// Check if order can be invoiced
if (!$order->canInvoice())
$this->messageManager->addError(__('Cannot create invoice for order %1', $order->getIncrementId()));
continue;
try
$invoice = $order->prepareInvoice();
$invoice->getOrder()->setIsInProcess(true);
// Offline only
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_OFFLINE);
// Save & set paid
$invoice->register()->pay();
$invoice->save();
// Uncomment if you also want to send an e-mail
//$this->_invoiceSender->send($invoice);
// Change order status
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$order->save();
$countInvoice++;
catch (Exception $e)
$this->messageManager->addError(__('Error creating invoice for order %1', $order->getIncrementId()));
if ($countInvoice)
$this->messageManager->addSuccess(__('Created invoice for %1 order(s)', $countInvoice));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
Be sure to run php bin/magento cache:clean
after making these changes to your module. You should now have an "Invoice" option available in your order grid. This text can be changed in sales_order_grid.xml if you so desire.
It added shipping charges on the first order in invoice, ignore shipping charges for other orders in bulk orders
– Muhammad Hasham
Jan 31 at 10:14
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%2f80710%2fhow-to-create-invoices-for-more-than-one-order-via-mass-action%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have 2 options:
Make a script to create invoices programmaticaly
(http://inchoo.net/magento/how-to-create-magento-invoice-from-order/)Buy a extension with massaction invoice
(http://www.magentocommerce.com/magento-connect/mass-order-actions-by-amasty.html)
I recommend you this extensions. Works fine!
Neither of these answer the op.
– Si Griffiths
Sep 22 '16 at 16:12
add a comment |
You have 2 options:
Make a script to create invoices programmaticaly
(http://inchoo.net/magento/how-to-create-magento-invoice-from-order/)Buy a extension with massaction invoice
(http://www.magentocommerce.com/magento-connect/mass-order-actions-by-amasty.html)
I recommend you this extensions. Works fine!
Neither of these answer the op.
– Si Griffiths
Sep 22 '16 at 16:12
add a comment |
You have 2 options:
Make a script to create invoices programmaticaly
(http://inchoo.net/magento/how-to-create-magento-invoice-from-order/)Buy a extension with massaction invoice
(http://www.magentocommerce.com/magento-connect/mass-order-actions-by-amasty.html)
I recommend you this extensions. Works fine!
You have 2 options:
Make a script to create invoices programmaticaly
(http://inchoo.net/magento/how-to-create-magento-invoice-from-order/)Buy a extension with massaction invoice
(http://www.magentocommerce.com/magento-connect/mass-order-actions-by-amasty.html)
I recommend you this extensions. Works fine!
answered Sep 2 '15 at 15:31
osrecioosrecio
1,410516
1,410516
Neither of these answer the op.
– Si Griffiths
Sep 22 '16 at 16:12
add a comment |
Neither of these answer the op.
– Si Griffiths
Sep 22 '16 at 16:12
Neither of these answer the op.
– Si Griffiths
Sep 22 '16 at 16:12
Neither of these answer the op.
– Si Griffiths
Sep 22 '16 at 16:12
add a comment |
Since there's still no default way in Magento 2.2.x to accomplish this, I've created a basic mass action that will create an invoice for each selected order, which:
- Will be set to "Capture offline"
- Change the order status to "Processing"
- (Optional) Sends out the invoice e-mail (see commented code)
Of course this can also be extended upon to meet your wishes.
Assuming that you know how to create a custom module (Remember to change all instances of Vendor and Module with your own module details):
VendorModuleviewadminhtmlui_componentsales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="vendor_module_mass_invoice">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">vendor_module_mass_invoice</item>
<item name="label" xsi:type="string" translate="true">Invoice</item>
<item name="url" xsi:type="url" path="myroute/order/massInvoice"/>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</listing>
VendorModuleetcadminhtmlroutes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="myroute" frontName="myroute">
<module name="Vendor_Module" />
</route>
</router>
</config>
**VendorModuleControllerAdminhtmlOrderMassInvoice.php**
<?php
namespace VendorModuleControllerAdminhtmlOrder;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use MagentoSalesModelResourceModelOrderCollectionFactory;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderInvoice;
use MagentoSalesModelOrder;
class MassInvoice extends MagentoSalesControllerAdminhtmlOrderAbstractMassAction
/**
* @var InvoiceSender
*/
protected $_invoiceSender;
/**
* @var object
*/
protected $collectionFactory;
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory,
InvoiceSender $invoiceSender
)
parent::__construct($context, $filter);
$this->collectionFactory = $collectionFactory;
$this->_invoiceSender = $invoiceSender;
protected function massAction(AbstractCollection $collection)
$countInvoice = 0;
foreach ($collection->getItems() as $order)
// Check if order can be invoiced
if (!$order->canInvoice())
$this->messageManager->addError(__('Cannot create invoice for order %1', $order->getIncrementId()));
continue;
try
$invoice = $order->prepareInvoice();
$invoice->getOrder()->setIsInProcess(true);
// Offline only
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_OFFLINE);
// Save & set paid
$invoice->register()->pay();
$invoice->save();
// Uncomment if you also want to send an e-mail
//$this->_invoiceSender->send($invoice);
// Change order status
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$order->save();
$countInvoice++;
catch (Exception $e)
$this->messageManager->addError(__('Error creating invoice for order %1', $order->getIncrementId()));
if ($countInvoice)
$this->messageManager->addSuccess(__('Created invoice for %1 order(s)', $countInvoice));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
Be sure to run php bin/magento cache:clean
after making these changes to your module. You should now have an "Invoice" option available in your order grid. This text can be changed in sales_order_grid.xml if you so desire.
It added shipping charges on the first order in invoice, ignore shipping charges for other orders in bulk orders
– Muhammad Hasham
Jan 31 at 10:14
add a comment |
Since there's still no default way in Magento 2.2.x to accomplish this, I've created a basic mass action that will create an invoice for each selected order, which:
- Will be set to "Capture offline"
- Change the order status to "Processing"
- (Optional) Sends out the invoice e-mail (see commented code)
Of course this can also be extended upon to meet your wishes.
Assuming that you know how to create a custom module (Remember to change all instances of Vendor and Module with your own module details):
VendorModuleviewadminhtmlui_componentsales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="vendor_module_mass_invoice">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">vendor_module_mass_invoice</item>
<item name="label" xsi:type="string" translate="true">Invoice</item>
<item name="url" xsi:type="url" path="myroute/order/massInvoice"/>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</listing>
VendorModuleetcadminhtmlroutes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="myroute" frontName="myroute">
<module name="Vendor_Module" />
</route>
</router>
</config>
**VendorModuleControllerAdminhtmlOrderMassInvoice.php**
<?php
namespace VendorModuleControllerAdminhtmlOrder;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use MagentoSalesModelResourceModelOrderCollectionFactory;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderInvoice;
use MagentoSalesModelOrder;
class MassInvoice extends MagentoSalesControllerAdminhtmlOrderAbstractMassAction
/**
* @var InvoiceSender
*/
protected $_invoiceSender;
/**
* @var object
*/
protected $collectionFactory;
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory,
InvoiceSender $invoiceSender
)
parent::__construct($context, $filter);
$this->collectionFactory = $collectionFactory;
$this->_invoiceSender = $invoiceSender;
protected function massAction(AbstractCollection $collection)
$countInvoice = 0;
foreach ($collection->getItems() as $order)
// Check if order can be invoiced
if (!$order->canInvoice())
$this->messageManager->addError(__('Cannot create invoice for order %1', $order->getIncrementId()));
continue;
try
$invoice = $order->prepareInvoice();
$invoice->getOrder()->setIsInProcess(true);
// Offline only
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_OFFLINE);
// Save & set paid
$invoice->register()->pay();
$invoice->save();
// Uncomment if you also want to send an e-mail
//$this->_invoiceSender->send($invoice);
// Change order status
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$order->save();
$countInvoice++;
catch (Exception $e)
$this->messageManager->addError(__('Error creating invoice for order %1', $order->getIncrementId()));
if ($countInvoice)
$this->messageManager->addSuccess(__('Created invoice for %1 order(s)', $countInvoice));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
Be sure to run php bin/magento cache:clean
after making these changes to your module. You should now have an "Invoice" option available in your order grid. This text can be changed in sales_order_grid.xml if you so desire.
It added shipping charges on the first order in invoice, ignore shipping charges for other orders in bulk orders
– Muhammad Hasham
Jan 31 at 10:14
add a comment |
Since there's still no default way in Magento 2.2.x to accomplish this, I've created a basic mass action that will create an invoice for each selected order, which:
- Will be set to "Capture offline"
- Change the order status to "Processing"
- (Optional) Sends out the invoice e-mail (see commented code)
Of course this can also be extended upon to meet your wishes.
Assuming that you know how to create a custom module (Remember to change all instances of Vendor and Module with your own module details):
VendorModuleviewadminhtmlui_componentsales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="vendor_module_mass_invoice">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">vendor_module_mass_invoice</item>
<item name="label" xsi:type="string" translate="true">Invoice</item>
<item name="url" xsi:type="url" path="myroute/order/massInvoice"/>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</listing>
VendorModuleetcadminhtmlroutes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="myroute" frontName="myroute">
<module name="Vendor_Module" />
</route>
</router>
</config>
**VendorModuleControllerAdminhtmlOrderMassInvoice.php**
<?php
namespace VendorModuleControllerAdminhtmlOrder;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use MagentoSalesModelResourceModelOrderCollectionFactory;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderInvoice;
use MagentoSalesModelOrder;
class MassInvoice extends MagentoSalesControllerAdminhtmlOrderAbstractMassAction
/**
* @var InvoiceSender
*/
protected $_invoiceSender;
/**
* @var object
*/
protected $collectionFactory;
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory,
InvoiceSender $invoiceSender
)
parent::__construct($context, $filter);
$this->collectionFactory = $collectionFactory;
$this->_invoiceSender = $invoiceSender;
protected function massAction(AbstractCollection $collection)
$countInvoice = 0;
foreach ($collection->getItems() as $order)
// Check if order can be invoiced
if (!$order->canInvoice())
$this->messageManager->addError(__('Cannot create invoice for order %1', $order->getIncrementId()));
continue;
try
$invoice = $order->prepareInvoice();
$invoice->getOrder()->setIsInProcess(true);
// Offline only
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_OFFLINE);
// Save & set paid
$invoice->register()->pay();
$invoice->save();
// Uncomment if you also want to send an e-mail
//$this->_invoiceSender->send($invoice);
// Change order status
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$order->save();
$countInvoice++;
catch (Exception $e)
$this->messageManager->addError(__('Error creating invoice for order %1', $order->getIncrementId()));
if ($countInvoice)
$this->messageManager->addSuccess(__('Created invoice for %1 order(s)', $countInvoice));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
Be sure to run php bin/magento cache:clean
after making these changes to your module. You should now have an "Invoice" option available in your order grid. This text can be changed in sales_order_grid.xml if you so desire.
Since there's still no default way in Magento 2.2.x to accomplish this, I've created a basic mass action that will create an invoice for each selected order, which:
- Will be set to "Capture offline"
- Change the order status to "Processing"
- (Optional) Sends out the invoice e-mail (see commented code)
Of course this can also be extended upon to meet your wishes.
Assuming that you know how to create a custom module (Remember to change all instances of Vendor and Module with your own module details):
VendorModuleviewadminhtmlui_componentsales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="vendor_module_mass_invoice">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">vendor_module_mass_invoice</item>
<item name="label" xsi:type="string" translate="true">Invoice</item>
<item name="url" xsi:type="url" path="myroute/order/massInvoice"/>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</listing>
VendorModuleetcadminhtmlroutes.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="myroute" frontName="myroute">
<module name="Vendor_Module" />
</route>
</router>
</config>
**VendorModuleControllerAdminhtmlOrderMassInvoice.php**
<?php
namespace VendorModuleControllerAdminhtmlOrder;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use MagentoSalesModelResourceModelOrderCollectionFactory;
use MagentoSalesModelOrderEmailSenderInvoiceSender;
use MagentoSalesModelOrderInvoice;
use MagentoSalesModelOrder;
class MassInvoice extends MagentoSalesControllerAdminhtmlOrderAbstractMassAction
/**
* @var InvoiceSender
*/
protected $_invoiceSender;
/**
* @var object
*/
protected $collectionFactory;
public function __construct(
Context $context,
Filter $filter,
CollectionFactory $collectionFactory,
InvoiceSender $invoiceSender
)
parent::__construct($context, $filter);
$this->collectionFactory = $collectionFactory;
$this->_invoiceSender = $invoiceSender;
protected function massAction(AbstractCollection $collection)
$countInvoice = 0;
foreach ($collection->getItems() as $order)
// Check if order can be invoiced
if (!$order->canInvoice())
$this->messageManager->addError(__('Cannot create invoice for order %1', $order->getIncrementId()));
continue;
try
$invoice = $order->prepareInvoice();
$invoice->getOrder()->setIsInProcess(true);
// Offline only
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_OFFLINE);
// Save & set paid
$invoice->register()->pay();
$invoice->save();
// Uncomment if you also want to send an e-mail
//$this->_invoiceSender->send($invoice);
// Change order status
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$order->save();
$countInvoice++;
catch (Exception $e)
$this->messageManager->addError(__('Error creating invoice for order %1', $order->getIncrementId()));
if ($countInvoice)
$this->messageManager->addSuccess(__('Created invoice for %1 order(s)', $countInvoice));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
Be sure to run php bin/magento cache:clean
after making these changes to your module. You should now have an "Invoice" option available in your order grid. This text can be changed in sales_order_grid.xml if you so desire.
edited Apr 17 at 7:34
answered Oct 11 '18 at 8:48
sduifsduif
51519
51519
It added shipping charges on the first order in invoice, ignore shipping charges for other orders in bulk orders
– Muhammad Hasham
Jan 31 at 10:14
add a comment |
It added shipping charges on the first order in invoice, ignore shipping charges for other orders in bulk orders
– Muhammad Hasham
Jan 31 at 10:14
It added shipping charges on the first order in invoice, ignore shipping charges for other orders in bulk orders
– Muhammad Hasham
Jan 31 at 10:14
It added shipping charges on the first order in invoice, ignore shipping charges for other orders in bulk orders
– Muhammad Hasham
Jan 31 at 10:14
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%2f80710%2fhow-to-create-invoices-for-more-than-one-order-via-mass-action%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