Version Notes
Developed By CueBlocks
Download this release
Release Info
Developer | Francesco Magazzu' |
Extension | CueBlocks_FreeAutoInvoice |
Version | 0.0.1 |
Comparing to | |
See all releases |
Version 0.0.1
- app/code/community/CueBlocks/FreeAutoInvoice/Helper/Data.php +22 -0
- app/code/community/CueBlocks/FreeAutoInvoice/Model/Observer.php +85 -0
- app/code/community/CueBlocks/FreeAutoInvoice/etc/config.xml +41 -0
- app/code/community/CueBlocks/FreeAutoInvoice/etc/system.xml +82 -0
- app/etc/modules/CueBlocks_FreeAutoInvoice.xml +9 -0
- package.xml +18 -0
app/code/community/CueBlocks/FreeAutoInvoice/Helper/Data.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Description of
|
4 |
+
* @package CueBlocks_
|
5 |
+
* @company CueBlocks - http://www.cueblocks.com/
|
6 |
+
* @author Francesco Magazzu' <francesco.magazzu at cueblocks.com>
|
7 |
+
* @support <magento at cueblocks.com>
|
8 |
+
*/
|
9 |
+
|
10 |
+
class CueBlocks_FreeAutoInvoice_Helper_Data extends Mage_Core_Helper_Abstract
|
11 |
+
{
|
12 |
+
const CONFIG_BASE_PATH = 'sales/auto_invoice';
|
13 |
+
|
14 |
+
public function getConfig($storeId = null)
|
15 |
+
{
|
16 |
+
$config = new Varien_Object(
|
17 |
+
Mage::getStoreConfig(self::CONFIG_BASE_PATH , $storeId
|
18 |
+
)
|
19 |
+
);
|
20 |
+
return $config;
|
21 |
+
}
|
22 |
+
}
|
app/code/community/CueBlocks/FreeAutoInvoice/Model/Observer.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Description of
|
4 |
+
* @package CueBlocks_
|
5 |
+
* @company CueBlocks - http://www.cueblocks.com/
|
6 |
+
* @author Francesco Magazzu' <francesco.magazzu at cueblocks.com>
|
7 |
+
* @support <magento at cueblocks.com>
|
8 |
+
*/
|
9 |
+
|
10 |
+
|
11 |
+
class CueBlocks_FreeAutoInvoice_Model_Observer
|
12 |
+
{
|
13 |
+
protected $_config = null;
|
14 |
+
|
15 |
+
public function getConfig($storeId = null)
|
16 |
+
{
|
17 |
+
if (!$this->_config) {
|
18 |
+
$this->_config = Mage::helper('freeAutoInvoice')->getConfig($storeId);
|
19 |
+
}
|
20 |
+
return $this->_config;
|
21 |
+
}
|
22 |
+
|
23 |
+
public function autoInvoice($event)
|
24 |
+
{
|
25 |
+
$order = $event->getOrder();
|
26 |
+
|
27 |
+
if ($enabled = $this->getConfig($order->getStoreId())->getEnabled()) {
|
28 |
+
|
29 |
+
if ($this->_getPaymentMethod($order) == 'free' && $order->getGrandTotal() == 0) {
|
30 |
+
if ($order->canInvoice()) {
|
31 |
+
$this->_processOrderStatus($order);
|
32 |
+
}
|
33 |
+
}
|
34 |
+
}
|
35 |
+
return $this;
|
36 |
+
}
|
37 |
+
|
38 |
+
private function _getPaymentMethod($order)
|
39 |
+
{
|
40 |
+
return $order->getPayment()->getMethodInstance()->getCode();
|
41 |
+
}
|
42 |
+
|
43 |
+
private function _processOrderStatus($order)
|
44 |
+
{
|
45 |
+
$config = $this->getConfig($order->getStoreId());
|
46 |
+
|
47 |
+
// Prepare Invoice
|
48 |
+
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
49 |
+
// Set invoice to Payment
|
50 |
+
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
|
51 |
+
// Process Invoice
|
52 |
+
$invoice->register();
|
53 |
+
|
54 |
+
// $state = Mage_Sales_Model_Order::ACTION_FLAG_INVOICE;
|
55 |
+
// $this->_changeOrderState($order, $state);
|
56 |
+
|
57 |
+
// Add note to Order/Invoice History
|
58 |
+
if ($orderNote = $config->getOrderNote()) {
|
59 |
+
$invoice->addComment($orderNote);
|
60 |
+
$order->addStatusHistoryComment($orderNote, null);
|
61 |
+
}
|
62 |
+
// Save Order And Invoice using a transaction
|
63 |
+
Mage::getModel('core/resource_transaction')
|
64 |
+
->addObject($invoice)
|
65 |
+
->addObject($invoice->getOrder())
|
66 |
+
->save();
|
67 |
+
|
68 |
+
// Send Invoice Mail to the Customer
|
69 |
+
if ($config->getEnabledEmail()) {
|
70 |
+
if ($emailComment = $config->getEmailMessage()) {
|
71 |
+
$invoice->sendEmail(true, $emailComment);
|
72 |
+
} else {
|
73 |
+
$invoice->sendEmail(true);
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
return true;
|
78 |
+
}
|
79 |
+
|
80 |
+
// private function _changeOrderState($order, $state)
|
81 |
+
// {
|
82 |
+
// $order->setState($state, true);
|
83 |
+
// $order->save();
|
84 |
+
// }
|
85 |
+
}
|
app/code/community/CueBlocks/FreeAutoInvoice/etc/config.xml
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<CueBlocks_FreeAutoInvoice>
|
5 |
+
<version>0.1.0</version>
|
6 |
+
</CueBlocks_FreeAutoInvoice>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<models>
|
10 |
+
<freeAutoInvoice>
|
11 |
+
<class>CueBlocks_FreeAutoInvoice_Model</class>
|
12 |
+
</freeAutoInvoice>
|
13 |
+
</models>
|
14 |
+
<helpers>
|
15 |
+
<freeAutoInvoice>
|
16 |
+
<class>CueBlocks_FreeAutoInvoice_Helper</class>
|
17 |
+
</freeAutoInvoice>
|
18 |
+
</helpers>
|
19 |
+
<events>
|
20 |
+
<sales_order_place_after>
|
21 |
+
<observers>
|
22 |
+
<auto_invoice_order>
|
23 |
+
<type>singleton</type>
|
24 |
+
<class>freeAutoInvoice/observer</class>
|
25 |
+
<method>autoInvoice</method>
|
26 |
+
</auto_invoice_order>
|
27 |
+
</observers>
|
28 |
+
</sales_order_place_after>
|
29 |
+
</events>
|
30 |
+
</global>
|
31 |
+
<default>
|
32 |
+
<sales>
|
33 |
+
<auto_invoice>
|
34 |
+
<enabled>1</enabled>
|
35 |
+
<enabled_email>1</enabled_email>
|
36 |
+
<email_message></email_message>
|
37 |
+
<order_note>No Payment Required: Automatically Invoiced !</order_note>
|
38 |
+
</auto_invoice>
|
39 |
+
</sales>
|
40 |
+
</default>
|
41 |
+
</config>
|
app/code/community/CueBlocks/FreeAutoInvoice/etc/system.xml
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<!--<tabs>-->
|
4 |
+
<!--<cueBlocks translate="label">-->
|
5 |
+
<!--<label>CueBlocks</label>-->
|
6 |
+
<!--<sort_order>100</sort_order>-->
|
7 |
+
<!--</cueBlocks>-->
|
8 |
+
<!--</tabs>-->
|
9 |
+
<sections>
|
10 |
+
<sales>
|
11 |
+
<!--<label>Custom Order ID</label>-->
|
12 |
+
<!--<tab>sales</tab>-->
|
13 |
+
<!--<frontend_type>text</frontend_type>-->
|
14 |
+
<!--<sort_order>300</sort_order>-->
|
15 |
+
<!--<show_in_default>1</show_in_default>-->
|
16 |
+
<!--<show_in_website>1</show_in_website>-->
|
17 |
+
<!--<show_in_store>1</show_in_store>-->
|
18 |
+
<groups>
|
19 |
+
<auto_invoice translate="label">
|
20 |
+
<label>Auto Invoice Free Product Options</label>
|
21 |
+
<frontend_type>text</frontend_type>
|
22 |
+
<sort_order>900</sort_order>
|
23 |
+
<show_in_default>1</show_in_default>
|
24 |
+
<show_in_website>1</show_in_website>
|
25 |
+
<show_in_store>1</show_in_store>
|
26 |
+
<fields>
|
27 |
+
<enabled translate="label">
|
28 |
+
<label>Enabled</label>
|
29 |
+
<frontend_type>select</frontend_type>
|
30 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
31 |
+
<comment>Enable Auto Invoice functionality for Free Products</comment>
|
32 |
+
<tooltip>Only order with 'free' payment method and grand total = '0' will be automatically invoiced</tooltip>
|
33 |
+
<sort_order>10</sort_order>
|
34 |
+
<show_in_default>1</show_in_default>
|
35 |
+
<show_in_website>1</show_in_website>
|
36 |
+
<show_in_store>1</show_in_store>
|
37 |
+
</enabled>
|
38 |
+
<enabled_email translate="label">
|
39 |
+
<label>Send Invoice Mail to Customer</label>
|
40 |
+
<frontend_type>select</frontend_type>
|
41 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
42 |
+
<comment>An Email invoice email will sent to the customer</comment>
|
43 |
+
<sort_order>20</sort_order>
|
44 |
+
<show_in_default>1</show_in_default>
|
45 |
+
<show_in_website>1</show_in_website>
|
46 |
+
<show_in_store>1</show_in_store>
|
47 |
+
<depends>
|
48 |
+
<enabled>1</enabled>
|
49 |
+
</depends>
|
50 |
+
</enabled_email>
|
51 |
+
<email_message translate="label">
|
52 |
+
<label>Custom Email Message</label>
|
53 |
+
<frontend_type>text</frontend_type>
|
54 |
+
<comment>Add a message to the email footer (empty message will be skipped) </comment>
|
55 |
+
<sort_order>30</sort_order>
|
56 |
+
<show_in_default>1</show_in_default>
|
57 |
+
<show_in_website>1</show_in_website>
|
58 |
+
<show_in_store>1</show_in_store>
|
59 |
+
<depends>
|
60 |
+
<enabled>1</enabled>
|
61 |
+
<enabled_email>1</enabled_email>
|
62 |
+
</depends>
|
63 |
+
</email_message>
|
64 |
+
<order_note translate="label">
|
65 |
+
<label>Add a note to the Order/Invoice History</label>
|
66 |
+
<frontend_type>text</frontend_type>
|
67 |
+
<comment>Empty note will be skipped</comment>
|
68 |
+
<sort_order>50</sort_order>
|
69 |
+
<show_in_default>1</show_in_default>
|
70 |
+
<show_in_website>1</show_in_website>
|
71 |
+
<show_in_store>1</show_in_store>
|
72 |
+
<depends>
|
73 |
+
<enabled>1</enabled>
|
74 |
+
<enabled_order_note>1</enabled_order_note>
|
75 |
+
</depends>
|
76 |
+
</order_note>
|
77 |
+
</fields>
|
78 |
+
</auto_invoice>
|
79 |
+
</groups>
|
80 |
+
</sales>
|
81 |
+
</sections>
|
82 |
+
</config>
|
app/etc/modules/CueBlocks_FreeAutoInvoice.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<CueBlocks_FreeAutoInvoice>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</CueBlocks_FreeAutoInvoice>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>CueBlocks_FreeAutoInvoice</name>
|
4 |
+
<version>0.0.1</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://store.cueblocks.com/LICENSE_STORE.txt">EULA</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Automatic Invoice Free Orders</summary>
|
10 |
+
<description>Automatic Invoice Free Orders</description>
|
11 |
+
<notes>Developed By CueBlocks</notes>
|
12 |
+
<authors><author><name>CueBlocks</name><user>Franky</user><email>magento@cueblocks.com</email></author></authors>
|
13 |
+
<date>2013-11-27</date>
|
14 |
+
<time>05:49:42</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="CueBlocks_FreeAutoInvoice.xml" hash="e8466ae582895091735f88b5be2a6360"/></dir></target><target name="magecommunity"><dir><dir name="CueBlocks"><dir name="FreeAutoInvoice"><dir name="Helper"><file name="Data.php" hash="0e3246e4148d012bbb64414288622f8e"/></dir><dir name="Model"><file name="Observer.php" hash="8158ec0ff6888f5c649f516aa30fa732"/></dir><dir name="etc"><file name="config.xml" hash="e05a03e0bfedc880ceb627a6af5cb16c"/><file name="system.xml" hash="fd48fb15259c551364990196b50b4f71"/></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.0.2</min><max>7.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|