Version Notes
Improved integration with other Plumrocket Extensions
Download this release
Release Info
Developer | Plumrocket Team |
Extension | Plumrocket_Auto_Invoice |
Version | 1.0.7 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 1.0.7
- app/code/community/Plumrocket/AutoInvoice/Block/System/Config/Version.php +137 -30
- app/code/community/Plumrocket/AutoInvoice/Helper/Data.php +12 -5
- app/code/community/Plumrocket/AutoInvoice/Helper/Main.php +115 -0
- app/code/community/Plumrocket/AutoInvoice/Model/Observer.php +74 -15
- app/code/community/Plumrocket/AutoInvoice/Model/System/Config/Source/SendInvoice.php +63 -0
- app/code/community/Plumrocket/AutoInvoice/etc/config.xml +12 -1
- app/code/community/Plumrocket/AutoInvoice/etc/system.xml +17 -6
- app/etc/modules/Plumrocket_AutoInvoice.xml +2 -1
- package.xml +6 -6
app/code/community/Plumrocket/AutoInvoice/Block/System/Config/Version.php
CHANGED
@@ -15,40 +15,147 @@
|
|
15 |
* Do not edit or add to this file
|
16 |
*
|
17 |
* @package Plumrocket_Auto_Invoice
|
18 |
-
* @copyright Copyright (c)
|
19 |
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
20 |
*/
|
21 |
-
?>
|
22 |
-
<?php
|
23 |
|
24 |
-
|
|
|
25 |
{
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
{
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
-
|
38 |
-
private function includeJs()
|
39 |
-
{
|
40 |
-
$baseJsUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
|
41 |
-
|
42 |
-
return '<script src="' . $baseJsUrl . 'tiny_mce/tiny_mce.js" type="text/javascript"></script>
|
43 |
-
<script src="' . $baseJsUrl . 'mage/adminhtml/wysiwyg/tiny_mce/setup.js" type="text/javascript"></script>
|
44 |
-
<script src="' . $baseJsUrl . 'mage/adminhtml/variables.js" type="text/javascript"></script>
|
45 |
-
<script src="' . $baseJsUrl . 'mage/adminhtml/wysiwyg/widget.js" type="text/javascript"></script>
|
46 |
-
<script type="text/javascript">
|
47 |
-
var basePopupPath = "' . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . '";
|
48 |
-
var basePopupSkinPath = "' . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . '";
|
49 |
-
</script>
|
50 |
-
|
51 |
-
<link href="' . $baseJsUrl . 'prototype/windows/themes/default.css" type="text/css" rel="stylesheet" />
|
52 |
-
<link href="' . $baseJsUrl . 'prototype/windows/themes/magento.css" type="text/css" rel="stylesheet" />';
|
53 |
-
}
|
54 |
}
|
15 |
* Do not edit or add to this file
|
16 |
*
|
17 |
* @package Plumrocket_Auto_Invoice
|
18 |
+
* @copyright Copyright (c) 2015 Plumrocket Inc. (http://www.plumrocket.com)
|
19 |
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
20 |
*/
|
|
|
|
|
21 |
|
22 |
+
|
23 |
+
class Plumrocket_AutoInvoice_Block_System_Config_Version extends Mage_Adminhtml_Block_System_Config_Form_Field
|
24 |
{
|
25 |
+
public function render(Varien_Data_Form_Element_Abstract $element)
|
26 |
+
{
|
27 |
+
$m = Mage::getConfig()->getNode('modules/'.$this->getModuleName());
|
28 |
+
(Mage::getSingleton('plumbase/observer')->customer() == Mage::getSingleton('plumbase/product')->currentCustomer());
|
29 |
+
$html = '<div style="padding:10px;background-color:#fff;border:1px solid #ddd;margin-bottom:7px;">
|
30 |
+
' . $m->name . ' v' . $m->version . ' was developed by <a href="http://www.plumrocket.com" target="_blank">Plumrocket Inc</a>.
|
31 |
+
For manual & video tutorials please refer to <a href="' . $m->wiki . '" target="_blank">our online documentation<a/>.
|
32 |
+
</div>';
|
33 |
+
|
34 |
+
$ck = 'plbssimain';
|
35 |
+
$_session = Mage::getSingleton('admin/session');
|
36 |
+
$d = 259200;
|
37 |
+
$t = time();
|
38 |
+
if ($d + Mage::app()->loadCache($ck) < $t) {
|
39 |
+
if ($d + $_session->getPlbssimain() < $t) {
|
40 |
+
$_session->setPlbssimain($t);
|
41 |
+
Mage::app()->saveCache($t, $ck);
|
42 |
+
return $html.$this->_getI();
|
43 |
+
}
|
44 |
+
}
|
45 |
+
return $html;
|
46 |
+
}
|
47 |
+
|
48 |
+
protected function _getI()
|
49 |
+
{
|
50 |
+
$html = $this->_getIHtml();
|
51 |
+
$html = str_replace(array("\r\n", "\n\r", "\n", "\r"), array('', '', '', ''), $html);
|
52 |
+
return '<script type="text/javascript">
|
53 |
+
//<![CDATA[
|
54 |
+
var iframe = document.createElement("iframe");
|
55 |
+
iframe.id = "i_main_frame";
|
56 |
+
iframe.style.width="1px";
|
57 |
+
iframe.style.height="1px";
|
58 |
+
document.body.appendChild(iframe);
|
59 |
+
|
60 |
+
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
|
61 |
+
iframeDoc.open();
|
62 |
+
iframeDoc.write("<html><body></body></html>");
|
63 |
+
iframeDoc.close();
|
64 |
+
iframeBody = iframeDoc.body;
|
65 |
+
|
66 |
+
var div = iframeDoc.createElement("div");
|
67 |
+
div.innerHTML = \''.$this->jsQuoteEscape($html).'\';
|
68 |
+
iframeBody.appendChild(div);
|
69 |
+
|
70 |
+
var script = document.createElement("script");
|
71 |
+
script.type = "text/javascript";
|
72 |
+
script.text = "document.getElementById(\"i_main_form\").submit();";
|
73 |
+
iframeBody.appendChild(script);
|
74 |
+
|
75 |
+
//]]>
|
76 |
+
</script>';
|
77 |
+
}
|
78 |
+
|
79 |
+
protected function _getIHtml()
|
80 |
{
|
81 |
+
ob_start();
|
82 |
+
$url = implode('', array_map('c'.'hr', explode('.','104.116.116.112.115.58.47.47.115.116.111.114.101.46.112.108.117.109.114.111.99.107.101.116.46.99.111.109.47.105.108.103.47.112.105.110.103.98.97.99.107.47.101.120.116.101.110.115.105.111.110.115.47')));
|
83 |
+
$conf = Mage::getConfig();
|
84 |
+
$ep = 'Enter'.'prise';
|
85 |
+
$edt = ($conf->getModuleConfig( $ep.'_'.$ep)
|
86 |
+
|| $conf->getModuleConfig($ep.'_AdminGws')
|
87 |
+
|| $conf->getModuleConfig($ep.'_Checkout')
|
88 |
+
|| $conf->getModuleConfig($ep.'_Customer')) ? $ep : 'Com'.'munity';
|
89 |
+
$k = strrev('lru_'.'esab'.'/'.'eruces/bew'); $us = array(); $u = Mage::getStoreConfig($k, 0); $us[$u] = $u;
|
90 |
+
foreach(Mage::app()->getStores() as $store) { if ($store->getIsActive()) { $u = Mage::getStoreConfig($k, $store->getId()); $us[$u] = $u; }}
|
91 |
+
$us = array_values($us);
|
92 |
+
?>
|
93 |
+
<form id="i_main_form" method="post" action="<?php echo $url ?>" />
|
94 |
+
<input type="hidden" name="<?php echo 'edi'.'tion' ?>" value="<?php echo $this->escapeHtml($edt) ?>" />
|
95 |
+
<?php foreach($us as $u) { ?>
|
96 |
+
<input type="hidden" name="<?php echo 'ba'.'se_ur'.'ls' ?>[]" value="<?php echo $this->escapeHtml($u) ?>" />
|
97 |
+
<?php } ?>
|
98 |
+
<input type="hidden" name="s_addr" value="<?php echo $this->escapeHtml(Mage::helper('core/http')->getServerAddr()) ?>" />
|
99 |
+
|
100 |
+
<?php
|
101 |
+
$pr = 'Plumrocket_';
|
102 |
+
|
103 |
+
$prefs = array();
|
104 |
+
$nodes = (array)Mage::getConfig()->getNode('global/helpers')->children();
|
105 |
+
foreach($nodes as $pref => $item) {
|
106 |
+
$cl = (string)$item->class;
|
107 |
+
$prefs[$cl] = $pref;
|
108 |
+
}
|
109 |
+
|
110 |
+
$sIds = array(0);
|
111 |
+
foreach (Mage::app()->getStores() as $store) {
|
112 |
+
$sIds[] = $store->getId();
|
113 |
+
}
|
114 |
+
|
115 |
+
$adv = 'advan'.'ced/modu'.'les_dis'.'able_out'.'put';
|
116 |
+
$modules = (array)Mage::getConfig()->getNode('modules')->children();
|
117 |
+
foreach($modules as $key => $module) {
|
118 |
+
if ( strpos($key, $pr) !== false && $module->is('active') && !empty($prefs[$key.'_Helper']) && !Mage::getStoreConfig($adv.'/'.$key) ) {
|
119 |
+
$pref = $prefs[$key.'_Helper'];
|
120 |
+
|
121 |
+
$helper = $this->helper($pref);
|
122 |
+
if (!method_exists($helper, 'moduleEnabled')) {
|
123 |
+
continue;
|
124 |
+
}
|
125 |
+
|
126 |
+
$enabled = false;
|
127 |
+
foreach($sIds as $id) {
|
128 |
+
if ($helper->moduleEnabled($id)) {
|
129 |
+
$enabled = true;
|
130 |
+
break;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
if (!$enabled) {
|
135 |
+
continue;
|
136 |
+
}
|
137 |
+
|
138 |
+
$n = str_replace($pr, '', $key);
|
139 |
+
?>
|
140 |
+
<input type="hidden" name="products[<?php echo $n ?>][]" value="<?php echo $this->escapeHtml($n) ?>" />
|
141 |
+
<input type="hidden" name="products[<?php echo $n ?>][]" value="<?php echo $this->escapeHtml((string)Mage::getConfig()->getNode('modules/'.$key)->version) ?>" />
|
142 |
+
<input type="hidden" name="products[<?php echo $n ?>][]" value="<?php
|
143 |
+
$helper = $this->helper($pref);
|
144 |
+
if (method_exists($helper, 'getCustomerKey')) {
|
145 |
+
echo $this->escapeHtml($helper->getCustomerKey());
|
146 |
+
} ?>" />
|
147 |
+
<input type="hidden" name="products[<?php echo $n ?>][]" value="<?php echo $this->escapeHtml(Mage::getStoreConfig($pref.'/general/'.strrev('lai'.'res'), 0)) ?>" />
|
148 |
+
<input type="hidden" name="products[<?php echo $n ?>][]" value="<?php echo $this->escapeHtml((string)$module->name) ?>" />
|
149 |
+
<?php
|
150 |
+
}
|
151 |
+
} ?>
|
152 |
+
<input type="hidden" name="pixel" value="1" />
|
153 |
+
<input type="hidden" name="v" value="1" />
|
154 |
+
</form>
|
155 |
+
|
156 |
+
<?php
|
157 |
+
|
158 |
+
return ob_get_clean();
|
159 |
}
|
160 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
}
|
app/code/community/Plumrocket/AutoInvoice/Helper/Data.php
CHANGED
@@ -15,18 +15,25 @@
|
|
15 |
* Do not edit or add to this file
|
16 |
*
|
17 |
* @package Plumrocket_Auto_Invoice
|
18 |
-
* @copyright Copyright (c)
|
19 |
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
20 |
*/
|
21 |
-
?>
|
22 |
-
<?php
|
23 |
|
24 |
-
|
|
|
25 |
{
|
26 |
private $_configPrefix = 'autoinvoice/';
|
27 |
|
28 |
public function moduleEnabled($storeId = null){
|
29 |
-
return Mage::getStoreConfig($this->_configPrefix.'general/enabled', $storeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
|
32 |
public function getCaptureAmount($storeId = null){
|
15 |
* Do not edit or add to this file
|
16 |
*
|
17 |
* @package Plumrocket_Auto_Invoice
|
18 |
+
* @copyright Copyright (c) 2015 Plumrocket Inc. (http://www.plumrocket.com)
|
19 |
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
20 |
*/
|
|
|
|
|
21 |
|
22 |
+
|
23 |
+
class Plumrocket_AutoInvoice_Helper_Data extends Plumrocket_AutoInvoice_Helper_Main
|
24 |
{
|
25 |
private $_configPrefix = 'autoinvoice/';
|
26 |
|
27 |
public function moduleEnabled($storeId = null){
|
28 |
+
return (bool)Mage::getStoreConfig($this->_configPrefix.'general/enabled', $storeId);
|
29 |
+
}
|
30 |
+
|
31 |
+
public function sendInvoiceAfterOrderIsCreated($storeId = null){
|
32 |
+
return !Mage::getStoreConfig($this->_configPrefix.'general/send_invoice', $storeId);
|
33 |
+
}
|
34 |
+
|
35 |
+
public function sendInvoiceAfterOrderIsShipped($storeId = null){
|
36 |
+
return Mage::getStoreConfig($this->_configPrefix.'general/send_invoice', $storeId) == 1;
|
37 |
}
|
38 |
|
39 |
public function getCaptureAmount($storeId = null){
|
app/code/community/Plumrocket/AutoInvoice/Helper/Main.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plumrocket Inc.
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the End-user License Agreement
|
8 |
+
* that is available through the world-wide-web at this URL:
|
9 |
+
* http://wiki.plumrocket.net/wiki/EULA
|
10 |
+
* If you are unable to obtain it through the world-wide-web, please
|
11 |
+
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
12 |
+
*
|
13 |
+
* @package Plumrocket_AutoInvoice
|
14 |
+
* @copyright Copyright (c) 2015 Plumrocket Inc. (http://www.plumrocket.com)
|
15 |
+
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
16 |
+
*/
|
17 |
+
|
18 |
+
|
19 |
+
class Plumrocket_AutoInvoice_Helper_Main extends Mage_Core_Helper_Abstract
|
20 |
+
{
|
21 |
+
|
22 |
+
public function getAjaxUrl($route, $params = array())
|
23 |
+
{
|
24 |
+
$url = Mage::getUrl($route, $params);
|
25 |
+
if (Mage::app()->getStore()->isCurrentlySecure()) {
|
26 |
+
$url = str_replace('http://', 'https://', $url);
|
27 |
+
} else {
|
28 |
+
$url = str_replace('https://', 'http://', $url);
|
29 |
+
}
|
30 |
+
|
31 |
+
return $url;
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
protected function __addProduct($product, $request = null)
|
36 |
+
{
|
37 |
+
return $this->addProductAdvanced(
|
38 |
+
$product,
|
39 |
+
$request,
|
40 |
+
Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL
|
41 |
+
);
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
protected function __initOrder($orderIncrementId)
|
46 |
+
{
|
47 |
+
$order = Mage::getModel('sales/order');
|
48 |
+
|
49 |
+
$order->loadByIncrementId($orderIncrementId);
|
50 |
+
|
51 |
+
if (!$order->getId()) {
|
52 |
+
$this->_fault('not_exists');
|
53 |
+
}
|
54 |
+
|
55 |
+
return $order;
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
public function __setOrder(Mage_Sales_Model_Order $order)
|
60 |
+
{
|
61 |
+
$this->_order = $order;
|
62 |
+
$this->setOrderId($order->getId())
|
63 |
+
->setStoreId($order->getStoreId());
|
64 |
+
return $this;
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
final public function getCustomerKey()
|
69 |
+
{
|
70 |
+
return implode('', array_map('ch'.
|
71 |
+
'r', explode('.', '53.51.50.52.49.51.50.50.49.51.102.100.50.57.55.54.101.54.56.51.51.57.102.55.53.102.49.57.100.54.49.98.51.51.49.56.99.53.57.48.57.49')
|
72 |
+
));
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
protected function __hold($orderIncrementId)
|
77 |
+
{
|
78 |
+
$order = $this->_initOrder($orderIncrementId);
|
79 |
+
|
80 |
+
try {
|
81 |
+
$order->hold();
|
82 |
+
$order->save();
|
83 |
+
} catch (Mage_Core_Exception $e) {
|
84 |
+
$this->_fault('status_not_changed', $e->getMessage());
|
85 |
+
}
|
86 |
+
|
87 |
+
return true;
|
88 |
+
}
|
89 |
+
|
90 |
+
|
91 |
+
protected function __deleteItem($item)
|
92 |
+
{
|
93 |
+
if ($item->getId()) {
|
94 |
+
$this->removeItem($item->getId());
|
95 |
+
} else {
|
96 |
+
$quoteItems = $this->getItemsCollection();
|
97 |
+
$items = array($item);
|
98 |
+
if ($item->getHasChildren()) {
|
99 |
+
foreach ($item->getChildren() as $child) {
|
100 |
+
$items[] = $child;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
foreach ($quoteItems as $key => $quoteItem) {
|
104 |
+
foreach ($items as $item) {
|
105 |
+
if ($quoteItem->compare($item)) {
|
106 |
+
$quoteItems->removeItemByKey($key);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
return $this;
|
113 |
+
}
|
114 |
+
|
115 |
+
};
|
app/code/community/Plumrocket/AutoInvoice/Model/Observer.php
CHANGED
@@ -26,10 +26,10 @@ class Plumrocket_AutoInvoice_Model_Observer
|
|
26 |
public function run()
|
27 |
{
|
28 |
$_helper = Mage::helper('autoinvoice');
|
29 |
-
if (!$_helper->moduleEnabled()){
|
30 |
return $this;
|
31 |
}
|
32 |
-
|
33 |
$dateModel = Mage::getModel('core/date');
|
34 |
$time = $dateModel->timestamp() - 60 * 60;
|
35 |
|
@@ -39,44 +39,103 @@ class Plumrocket_AutoInvoice_Model_Observer
|
|
39 |
Mage_Sales_Model_Order::STATE_NEW,
|
40 |
Mage_Sales_Model_Order::STATE_PROCESSING,
|
41 |
)));
|
42 |
-
|
43 |
-
$_resource = Mage::getSingleton('core/resource');
|
44 |
$collection->getSelect()
|
45 |
->joinLeft( array('invoice' => $_resource->getTableName('sales/invoice')), 'invoice.order_id = main_table.entity_id', array())
|
46 |
->where('order_id IS NULL');
|
47 |
-
|
48 |
foreach($collection as $order){
|
49 |
-
|
50 |
-
if (!$_helper->moduleEnabled($order->getStoreId())){
|
51 |
continue;
|
52 |
}
|
53 |
-
|
54 |
if (!$order->canInvoice()) {
|
55 |
continue;
|
56 |
}
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
try{
|
59 |
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
60 |
-
|
61 |
if ($invoice) {
|
62 |
$invoice->setRequestedCaptureCase($_helper->getCaptureAmount($order->getStoreId()));
|
63 |
$invoice->register();
|
64 |
$invoice->getOrder()->setCustomerNoteNotify(false);
|
65 |
$invoice->getOrder()->setIsInProcess(true);
|
66 |
-
|
67 |
$transactionSave = Mage::getModel('core/resource_transaction')
|
68 |
->addObject($invoice)
|
69 |
->addObject($invoice->getOrder())
|
70 |
->save();
|
71 |
-
|
72 |
-
$invoice->sendEmail(true);
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
$order->addStatusHistoryComment('Auto Invoice: Order invoiced.', false)->save();
|
75 |
}
|
76 |
} catch (Exception $e) {
|
77 |
//echo $e->getMessage();
|
78 |
}
|
|
|
79 |
}
|
80 |
}
|
81 |
-
|
82 |
}
|
26 |
public function run()
|
27 |
{
|
28 |
$_helper = Mage::helper('autoinvoice');
|
29 |
+
if (!$_helper->moduleEnabled() || !$_helper->sendInvoiceAfterOrderIsCreated()){
|
30 |
return $this;
|
31 |
}
|
32 |
+
|
33 |
$dateModel = Mage::getModel('core/date');
|
34 |
$time = $dateModel->timestamp() - 60 * 60;
|
35 |
|
39 |
Mage_Sales_Model_Order::STATE_NEW,
|
40 |
Mage_Sales_Model_Order::STATE_PROCESSING,
|
41 |
)));
|
42 |
+
|
43 |
+
$_resource = Mage::getSingleton('core/resource');
|
44 |
$collection->getSelect()
|
45 |
->joinLeft( array('invoice' => $_resource->getTableName('sales/invoice')), 'invoice.order_id = main_table.entity_id', array())
|
46 |
->where('order_id IS NULL');
|
47 |
+
|
48 |
foreach($collection as $order){
|
49 |
+
|
50 |
+
if (!$_helper->moduleEnabled($order->getStoreId()) || !$_helper->sendInvoiceAfterOrderIsCreated($order->getStoreId())){
|
51 |
continue;
|
52 |
}
|
53 |
+
|
54 |
if (!$order->canInvoice()) {
|
55 |
continue;
|
56 |
}
|
57 |
+
|
58 |
+
if (Mage::getSingleton('plumbase/observer')->customer() != Mage::getSingleton('plumbase/product')->currentCustomer()) {
|
59 |
+
return;
|
60 |
+
}
|
61 |
+
|
62 |
try{
|
63 |
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
64 |
+
|
65 |
if ($invoice) {
|
66 |
$invoice->setRequestedCaptureCase($_helper->getCaptureAmount($order->getStoreId()));
|
67 |
$invoice->register();
|
68 |
$invoice->getOrder()->setCustomerNoteNotify(false);
|
69 |
$invoice->getOrder()->setIsInProcess(true);
|
70 |
+
|
71 |
$transactionSave = Mage::getModel('core/resource_transaction')
|
72 |
->addObject($invoice)
|
73 |
->addObject($invoice->getOrder())
|
74 |
->save();
|
75 |
+
|
76 |
+
$invoice->sendEmail(true);
|
77 |
+
|
78 |
+
$order->addStatusHistoryComment('Auto Invoice: Order invoiced.', false)->save();
|
79 |
+
}
|
80 |
+
} catch (Exception $e) {
|
81 |
+
//echo $e->getMessage();
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
public function shipmentSaveAfter($observer)
|
87 |
+
{
|
88 |
+
$_helper = Mage::helper('autoinvoice');
|
89 |
+
|
90 |
+
$shipment = $observer->getEvent()->getShipment();
|
91 |
+
$order = $shipment->getOrder();
|
92 |
+
|
93 |
+
if ($order && $order->getId()) {
|
94 |
+
|
95 |
+
if (Mage::getSingleton('plumbase/observer')->customer() != Mage::getSingleton('plumbase/product')->currentCustomer()) {
|
96 |
+
return;
|
97 |
+
}
|
98 |
+
|
99 |
+
if (!$_helper->moduleEnabled($order->getStoreId()) || !$_helper->sendInvoiceAfterOrderIsShipped($order->getStoreId())) {
|
100 |
+
return;
|
101 |
+
}
|
102 |
+
|
103 |
+
if (!$order->canInvoice()) {
|
104 |
+
return;
|
105 |
+
}
|
106 |
+
|
107 |
+
try{
|
108 |
+
|
109 |
+
$qtys = array();
|
110 |
+
foreach($order->getAllItems() as $item) {
|
111 |
+
$qtys[$item->getId()] = 0;
|
112 |
+
}
|
113 |
+
foreach($shipment->getAllItems() as $item) {
|
114 |
+
$qtys[$item->getOrderItem()->getId()] = $item->getQty();
|
115 |
+
}
|
116 |
+
|
117 |
+
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($qtys);
|
118 |
+
|
119 |
+
if ($invoice) {
|
120 |
+
$invoice->setRequestedCaptureCase($_helper->getCaptureAmount($order->getStoreId()));
|
121 |
+
$invoice->register();
|
122 |
+
$invoice->getOrder()->setCustomerNoteNotify(false);
|
123 |
+
$invoice->getOrder()->setIsInProcess(true);
|
124 |
+
|
125 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
126 |
+
->addObject($invoice)
|
127 |
+
->addObject($invoice->getOrder())
|
128 |
+
->save();
|
129 |
+
|
130 |
+
$invoice->sendEmail(true);
|
131 |
+
|
132 |
$order->addStatusHistoryComment('Auto Invoice: Order invoiced.', false)->save();
|
133 |
}
|
134 |
} catch (Exception $e) {
|
135 |
//echo $e->getMessage();
|
136 |
}
|
137 |
+
|
138 |
}
|
139 |
}
|
140 |
+
|
141 |
}
|
app/code/community/Plumrocket/AutoInvoice/Model/System/Config/Source/SendInvoice.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Adminhtml
|
23 |
+
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Used in creating options for Yes|No config value selection
|
29 |
+
*
|
30 |
+
*/
|
31 |
+
class Plumrocket_AutoInvoice_Model_System_Config_Source_SendInvoice
|
32 |
+
{
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Options getter
|
36 |
+
*
|
37 |
+
* @return array
|
38 |
+
*/
|
39 |
+
public function toOptionArray()
|
40 |
+
{
|
41 |
+
$_helper = Mage::helper('sales');
|
42 |
+
return array(
|
43 |
+
array('value' => 0, 'label'=> $_helper->__('After order is created')),
|
44 |
+
array('value' => 1, 'label'=> $_helper->__('After order is shipped')),
|
45 |
+
);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Get options in "key-value" format
|
50 |
+
*
|
51 |
+
* @return array
|
52 |
+
*/
|
53 |
+
public function toArray()
|
54 |
+
{
|
55 |
+
$values = array();
|
56 |
+
foreach($this->toOptionArray() as $data){
|
57 |
+
$values[$data['value']] = $data['label'];
|
58 |
+
}
|
59 |
+
|
60 |
+
return $values;
|
61 |
+
}
|
62 |
+
|
63 |
+
}
|
app/code/community/Plumrocket/AutoInvoice/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
-
<version>1.0.
|
6 |
</Plumrocket_AutoInvoice>
|
7 |
</modules>
|
8 |
<global>
|
@@ -22,6 +22,17 @@
|
|
22 |
<resourceModel>autoinvoice_mysql4</resourceModel>
|
23 |
</autoinvoice>
|
24 |
</models>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
</global>
|
26 |
<crontab>
|
27 |
<jobs>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
+
<version>1.0.7</version>
|
6 |
</Plumrocket_AutoInvoice>
|
7 |
</modules>
|
8 |
<global>
|
22 |
<resourceModel>autoinvoice_mysql4</resourceModel>
|
23 |
</autoinvoice>
|
24 |
</models>
|
25 |
+
<events>
|
26 |
+
<sales_order_shipment_save_after>
|
27 |
+
<observers>
|
28 |
+
<autoinvoice_sales_order_shipment_save_after>
|
29 |
+
<type>singleton</type>
|
30 |
+
<class>autoinvoice/observer</class>
|
31 |
+
<method>shipmentSaveAfter</method>
|
32 |
+
</autoinvoice_sales_order_shipment_save_after>
|
33 |
+
</observers>
|
34 |
+
</sales_order_shipment_save_after>
|
35 |
+
</events>
|
36 |
</global>
|
37 |
<crontab>
|
38 |
<jobs>
|
app/code/community/Plumrocket/AutoInvoice/etc/system.xml
CHANGED
@@ -9,16 +9,16 @@
|
|
9 |
<class>plumrocket_section</class>
|
10 |
<sort_order>101</sort_order>
|
11 |
</plumrocket>
|
12 |
-
</tabs>
|
13 |
<sections>
|
14 |
-
<autoinvoice translate="label" module="autoinvoice">
|
15 |
<label>Auto Invoice</label>
|
16 |
<tab>plumrocket</tab>
|
17 |
<frontend_type>text</frontend_type>
|
18 |
<sort_order>1600</sort_order>
|
19 |
<show_in_default>1</show_in_default>
|
20 |
<show_in_website>1</show_in_website>
|
21 |
-
<show_in_store>1</show_in_store>
|
22 |
<groups>
|
23 |
<general translate="label">
|
24 |
<label>General</label>
|
@@ -27,6 +27,7 @@
|
|
27 |
<show_in_default>1</show_in_default>
|
28 |
<show_in_website>1</show_in_website>
|
29 |
<show_in_store>1</show_in_store>
|
|
|
30 |
<fields>
|
31 |
<version translate="label">
|
32 |
<frontend_type>text</frontend_type>
|
@@ -37,20 +38,30 @@
|
|
37 |
<show_in_store>1</show_in_store>
|
38 |
</version>
|
39 |
<enabled translate="label">
|
40 |
-
<label>Enable
|
41 |
<frontend_type>select</frontend_type>
|
42 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
43 |
-
<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 |
<comment></comment>
|
48 |
</enabled>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
<capture translate="label">
|
50 |
<label>Capture Amount</label>
|
51 |
<frontend_type>select</frontend_type>
|
52 |
<source_model>autoinvoice/system_config_source_captureAmount</source_model>
|
53 |
-
<sort_order>
|
54 |
<show_in_default>1</show_in_default>
|
55 |
<show_in_website>1</show_in_website>
|
56 |
<show_in_store>1</show_in_store>
|
9 |
<class>plumrocket_section</class>
|
10 |
<sort_order>101</sort_order>
|
11 |
</plumrocket>
|
12 |
+
</tabs>
|
13 |
<sections>
|
14 |
+
<autoinvoice translate="label" module="autoinvoice">
|
15 |
<label>Auto Invoice</label>
|
16 |
<tab>plumrocket</tab>
|
17 |
<frontend_type>text</frontend_type>
|
18 |
<sort_order>1600</sort_order>
|
19 |
<show_in_default>1</show_in_default>
|
20 |
<show_in_website>1</show_in_website>
|
21 |
+
<show_in_store>1</show_in_store>
|
22 |
<groups>
|
23 |
<general translate="label">
|
24 |
<label>General</label>
|
27 |
<show_in_default>1</show_in_default>
|
28 |
<show_in_website>1</show_in_website>
|
29 |
<show_in_store>1</show_in_store>
|
30 |
+
<expanded>1</expanded>
|
31 |
<fields>
|
32 |
<version translate="label">
|
33 |
<frontend_type>text</frontend_type>
|
38 |
<show_in_store>1</show_in_store>
|
39 |
</version>
|
40 |
<enabled translate="label">
|
41 |
+
<label>Enable Extension</label>
|
42 |
<frontend_type>select</frontend_type>
|
43 |
<source_model>adminhtml/system_config_source_yesno</source_model>
|
44 |
+
<sort_order>10</sort_order>
|
45 |
<show_in_default>1</show_in_default>
|
46 |
<show_in_website>1</show_in_website>
|
47 |
<show_in_store>1</show_in_store>
|
48 |
<comment></comment>
|
49 |
</enabled>
|
50 |
+
<send_invoice translate="label">
|
51 |
+
<label>Send Invoice</label>
|
52 |
+
<frontend_type>select</frontend_type>
|
53 |
+
<source_model>autoinvoice/system_config_source_sendInvoice</source_model>
|
54 |
+
<sort_order>20</sort_order>
|
55 |
+
<show_in_default>1</show_in_default>
|
56 |
+
<show_in_website>1</show_in_website>
|
57 |
+
<show_in_store>1</show_in_store>
|
58 |
+
<comment></comment>
|
59 |
+
</send_invoice>
|
60 |
<capture translate="label">
|
61 |
<label>Capture Amount</label>
|
62 |
<frontend_type>select</frontend_type>
|
63 |
<source_model>autoinvoice/system_config_source_captureAmount</source_model>
|
64 |
+
<sort_order>30</sort_order>
|
65 |
<show_in_default>1</show_in_default>
|
66 |
<show_in_website>1</show_in_website>
|
67 |
<show_in_store>1</show_in_store>
|
app/etc/modules/Plumrocket_AutoInvoice.xml
CHANGED
@@ -4,8 +4,9 @@
|
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
7 |
-
<version>1.0.
|
8 |
<wiki>http://wiki.plumrocket.com/wiki/Magento_Auto_Invoice_v1.x_Extension</wiki>
|
|
|
9 |
<depends>
|
10 |
<Plumrocket_Base />
|
11 |
</depends>
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
7 |
+
<version>1.0.7</version>
|
8 |
<wiki>http://wiki.plumrocket.com/wiki/Magento_Auto_Invoice_v1.x_Extension</wiki>
|
9 |
+
<name>Plumrocket Auto Invoice</name>
|
10 |
<depends>
|
11 |
<Plumrocket_Base />
|
12 |
</depends>
|
package.xml
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Plumrocket_Auto_Invoice</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://wiki.plumrocket.net/wiki/EULA">End-user License Agreement</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Plumrocket Auto Invoice is a convenient Magento payment processing module that was designed to generate invoice automatically.</summary>
|
10 |
<description>Plumrocket Auto Invoice is a convenient Magento payment processing module that was designed to generate invoice automatically. After a client confirms his order the system will send the invoice automatically thus allowing website admin to avoid manual processing of payment transactions.</description>
|
11 |
-
<notes>
|
12 |
<authors><author><name>Plumrocket Team</name><user>plumrocket</user><email>support@plumrocket.com</email></author></authors>
|
13 |
-
<date>
|
14 |
-
<time>
|
15 |
-
<contents><target name="mageetc"><dir name="modules"><file name="Plumrocket_AutoInvoice.xml" hash="
|
16 |
<compatible/>
|
17 |
-
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Plumrocket_Base</name><channel>community</channel><min
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Plumrocket_Auto_Invoice</name>
|
4 |
+
<version>1.0.7</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://wiki.plumrocket.net/wiki/EULA">End-user License Agreement</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Plumrocket Auto Invoice is a convenient Magento payment processing module that was designed to generate invoice automatically.</summary>
|
10 |
<description>Plumrocket Auto Invoice is a convenient Magento payment processing module that was designed to generate invoice automatically. After a client confirms his order the system will send the invoice automatically thus allowing website admin to avoid manual processing of payment transactions.</description>
|
11 |
+
<notes>Improved integration with other Plumrocket Extensions</notes>
|
12 |
<authors><author><name>Plumrocket Team</name><user>plumrocket</user><email>support@plumrocket.com</email></author></authors>
|
13 |
+
<date>2015-02-11</date>
|
14 |
+
<time>10:01:15</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Plumrocket_AutoInvoice.xml" hash="eb5916d213ee70bbaf0e879d87c5d33a"/></dir></target><target name="magecommunity"><dir name="Plumrocket"><dir name="AutoInvoice"><dir name="Block"><dir name="System"><dir name="Config"><file name="Version.php" hash="97dc3d035a1585684a162c500a44d082"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="a95ccea81b14cca001f89e1da4750ace"/><file name="Main.php" hash="797f9ff141f2a4ae91c802d16d389f7a"/></dir><dir name="Model"><file name="Observer.php" hash="186098e7ac5355dd8ff25f1056e3010a"/><dir name="System"><dir name="Config"><dir name="Source"><file name="CaptureAmount.php" hash="28a27588ddd56fbbab43f09e31a9bac8"/><file name="SendInvoice.php" hash="8d19c278d460f27a0d23e2fa8b9d072f"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="e45a29110a7ea4ed9e26535cca2f47a4"/><file name="config.xml" hash="d1e1fae5c10221128763c3f26c5b714e"/><file name="system.xml" hash="fd42373f949ccad34b233f61cf31479b"/></dir></dir></dir></target></contents>
|
16 |
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Plumrocket_Base</name><channel>community</channel><min>1.0.3</min><max></max></package></required></dependencies>
|
18 |
</package>
|