Skip to content

Commit

Permalink
Merge branch 'Invoice-Order' of https://github.com/Flipmediaco/Magent…
Browse files Browse the repository at this point in the history
…o-CashOnDelivery into Flipmediaco-Invoice-Order
  • Loading branch information
PhoenixDev - JJ committed Apr 11, 2018
2 parents 1f66cac + 8ae36cf commit 95c6ea3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/code/community/Phoenix/CashOnDelivery/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,32 @@ 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)
{
$order = $observer->getEvent()->getOrder();

if ($order->getPayment()->getMethodInstance()->getCode() === 'phoenix_cashondelivery'
&& $order->canInvoice()
&& Mage::getStoreConfig('payment/phoenix_cashondelivery/order_invoice')
) {
$invoice = Mage::getModel('sales/service_order', $order)
->prepareInvoice();

$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();

$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 @@ -132,6 +132,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 95c6ea3

Please sign in to comment.