Create module config file : app\etc\modules\Magespy_Autoinvoice.xml
<config>
<modules>
<Magespy_Autoinvoice>
<active>true</active>
<codePool>local</codePool>
</Magespy_Autoinvoice>
</modules>
</config>
I'd go the creating an event observer for sales_order_shipment_save_after:
File path: app/code/local/Magespy/Autoinvoice/etc/config.xml
<? xml version = "1.0" ?>
<config>
<modules>
<Magespy_Autoinvoice>
<version>0.1.0</version>
</Magespy_Autoinvoice>
</modules>
<global>
<events>
<sales_order_shipment_save_after>
<observers>
<magespy_autoinvoice>
<type>singleton</type>
<class>Magespy_Autoinvoice_Model_Observer</class>
<method>autoInvoice</method>
</magespy_autoinvoice>
</observers>
</sales_order_shipment_save_after>
</events>
</global>
</config>
Now, we create one observer file : app\code\local\Magespy\Autoinvoice\Model\Observer.php
<?php
class Magespy_Autoinvoice_Model_Observer {
public function autoInvoice($observer) {
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
if ($order->canInvoice()) {
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
}
}
<config>
<modules>
<Magespy_Autoinvoice>
<active>true</active>
<codePool>local</codePool>
</Magespy_Autoinvoice>
</modules>
</config>
I'd go the creating an event observer for sales_order_shipment_save_after:
File path: app/code/local/Magespy/Autoinvoice/etc/config.xml
<? xml version = "1.0" ?>
<config>
<modules>
<Magespy_Autoinvoice>
<version>0.1.0</version>
</Magespy_Autoinvoice>
</modules>
<global>
<events>
<sales_order_shipment_save_after>
<observers>
<magespy_autoinvoice>
<type>singleton</type>
<class>Magespy_Autoinvoice_Model_Observer</class>
<method>autoInvoice</method>
</magespy_autoinvoice>
</observers>
</sales_order_shipment_save_after>
</events>
</global>
</config>
Now, we create one observer file : app\code\local\Magespy\Autoinvoice\Model\Observer.php
<?php
class Magespy_Autoinvoice_Model_Observer {
public function autoInvoice($observer) {
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
if ($order->canInvoice()) {
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
}
}
No comments:
Post a Comment