Skip to content

Commit

Permalink
Add Create Invoice Option
Browse files Browse the repository at this point in the history
Add ability to configure that a cash on delivery order automatically
create an invoice.
  • Loading branch information
Laurie Barker committed Mar 2, 2015
1 parent 89fa562 commit 8ae36cf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
34 changes: 33 additions & 1 deletion app/code/community/Phoenix/CashOnDelivery/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function sales_order_payment_place_end(Varien_Event_Observer $observer)
{
$payment = $observer->getPayment();
if ($payment->getMethodInstance()->getCode() != 'phoenix_cashondelivery') {
return $this;;
return $this;
}

$order = $payment->getOrder();
Expand Down Expand Up @@ -139,4 +139,36 @@ public function order_cancel_after(Varien_Event_Observer $observer)

return $this;
}


/**
* Invoice and set status to Cash On Delivery if order payment type is Cash on Delivery
*
* @param Varien_Event_Observer $observer
* @return void
*/
public function invoice_cashondelivery($observer)
{
// Get order
$order = $observer->getEvent()->getOrder();

// If order is instance of Phoenix_CashOnDelivery_Model_CashOnDelivery
if ($order->getPayment()->getMethodInstance()->getCode() == 'phoenix_cashondelivery' &&
// Can be invoiced
$order->canInvoice() &&
// order_invoice is true
Mage::getStoreConfig('payment/phoenix_cashondelivery/order_invoice')) {
// Prepare invoice
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
// Set capture case - OFFLINE
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();
//
// Save transaction
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
}
}
9 changes: 9 additions & 0 deletions app/code/community/Phoenix/CashOnDelivery/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@
</phoenix_cashondelivery>
</observers>
</order_cancel_after>
<sales_order_place_after>
<observers>
<phoenix_cashondelivery>
<type>singleton</type>
<class>phoenix_cashondelivery/observer</class>
<method>invoice_cashondelivery</method>
</phoenix_cashondelivery>
</observers>
</sales_order_place_after>
</events>
<pdf>
<totals>
Expand Down
9 changes: 9 additions & 0 deletions app/code/community/Phoenix/CashOnDelivery/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</order_status>
<order_invoice translate="label">
<label>Invoice Order</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>45</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</order_invoice>
<sort_order translate="label">
<label>Sort order</label>
<frontend_type>text</frontend_type>
Expand Down

0 comments on commit 8ae36cf

Please sign in to comment.