Adventos_CustomizableId - Version 1.0.0

Version Notes

Init Extention

Download this release

Release Info

Developer Karsten Hoffmann
Extension Adventos_CustomizableId
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Adventos/CustomizableId/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Adventos_CustomizableId_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Adventos/CustomizableId/etc/config.xml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Adventos_CustomizableId>
5
+ <version>1.0.0</version>
6
+ </Adventos_CustomizableId>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <customizableid>
11
+ <class>Adventos_CustomizableId_Model</class>
12
+ </customizableid>
13
+ </models>
14
+ <helpers>
15
+ <customizableid>
16
+ <class>Adventos_CustomizableId_Helper</class>
17
+ </customizableid>
18
+ </helpers>
19
+ </global>
20
+ <adminhtml>
21
+ <acl>
22
+ <resources>
23
+ <all>
24
+ <title>Allow Everything</title>
25
+ </all>
26
+ <admin>
27
+ <children>
28
+ <system>
29
+ <children>
30
+ <config>
31
+ <children>
32
+ <adventos>
33
+ <title>Adventos Extentions</title>
34
+ </adventos>
35
+ </children>
36
+ </config>
37
+ </children>
38
+ </system>
39
+ </children>
40
+ </admin>
41
+ </resources>
42
+ </acl>
43
+ </adminhtml>
44
+ <default>
45
+ <adventos>
46
+ <customizableId>
47
+ <process>0</process>
48
+ <order_prefix></order_prefix>
49
+ <process_country>0</process_country>
50
+ </customizableId>
51
+ </adventos>
52
+ </default>
53
+ </config>
app/code/local/Adventos/CustomizableId/etc/system.xml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <adventos translate="label" module="customizableid">
5
+ <label>Adventos Extentions</label>
6
+ <sort_order>500</sort_order>
7
+ </adventos>
8
+ </tabs>
9
+ <sections>
10
+ <adventos translate="label" module="customizableid">
11
+ <label>Extensions</label>
12
+ <tab>adventos</tab>
13
+ <sort_order>1000</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <customizableId translate="label" module="customizableid">
19
+ <label>Custom Order Id</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>1000</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <process translate="label">
27
+ <label>Order Id customizable</label>
28
+ <frontend_type>select</frontend_type>
29
+ <source_model>adminhtml/system_config_source_yesno</source_model>
30
+ <sort_order>10</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>1</show_in_website>
33
+ <show_in_store>1</show_in_store>
34
+ </process>
35
+ <order_prefix translate="label">
36
+ <label>Order Prefix</label>
37
+ <frontend_type>text</frontend_type>
38
+ <sort_order>20</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>1</show_in_store>
42
+ </order_prefix>
43
+ <process_country translate="label">
44
+ <label>Include Country Code</label>
45
+ <comment>Add 2 digits Country Shortcut after Prefix</comment>
46
+ <frontend_type>select</frontend_type>
47
+ <source_model>adminhtml/system_config_source_yesno</source_model>
48
+ <sort_order>30</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>1</show_in_website>
51
+ <show_in_store>1</show_in_store>
52
+ </process_country>
53
+ </fields>
54
+ </customizableId>
55
+ </groups>
56
+ </adventos>
57
+ </sections>
58
+ </config>
app/code/local/Mage/Sales/Model/Order.php ADDED
@@ -0,0 +1,2254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Sales
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
+ * Order model
29
+ *
30
+ * Supported events:
31
+ * sales_order_load_after
32
+ * sales_order_save_before
33
+ * sales_order_save_after
34
+ * sales_order_delete_before
35
+ * sales_order_delete_after
36
+ *
37
+ * @method Mage_Sales_Model_Resource_Order _getResource()
38
+ * @method Mage_Sales_Model_Resource_Order getResource()
39
+ * @method string getState()
40
+ * @method string getStatus()
41
+ * @method Mage_Sales_Model_Order setStatus(string $value)
42
+ * @method string getCouponCode()
43
+ * @method Mage_Sales_Model_Order setCouponCode(string $value)
44
+ * @method string getProtectCode()
45
+ * @method Mage_Sales_Model_Order setProtectCode(string $value)
46
+ * @method string getShippingDescription()
47
+ * @method Mage_Sales_Model_Order setShippingDescription(string $value)
48
+ * @method int getIsVirtual()
49
+ * @method Mage_Sales_Model_Order setIsVirtual(int $value)
50
+ * @method int getStoreId()
51
+ * @method Mage_Sales_Model_Order setStoreId(int $value)
52
+ * @method int getCustomerId()
53
+ * @method Mage_Sales_Model_Order setCustomerId(int $value)
54
+ * @method float getBaseDiscountAmount()
55
+ * @method Mage_Sales_Model_Order setBaseDiscountAmount(float $value)
56
+ * @method float getBaseDiscountCanceled()
57
+ * @method Mage_Sales_Model_Order setBaseDiscountCanceled(float $value)
58
+ * @method float getBaseDiscountInvoiced()
59
+ * @method Mage_Sales_Model_Order setBaseDiscountInvoiced(float $value)
60
+ * @method float getBaseDiscountRefunded()
61
+ * @method Mage_Sales_Model_Order setBaseDiscountRefunded(float $value)
62
+ * @method float getBaseGrandTotal()
63
+ * @method Mage_Sales_Model_Order setBaseGrandTotal(float $value)
64
+ * @method float getBaseShippingAmount()
65
+ * @method Mage_Sales_Model_Order setBaseShippingAmount(float $value)
66
+ * @method float getBaseShippingCanceled()
67
+ * @method Mage_Sales_Model_Order setBaseShippingCanceled(float $value)
68
+ * @method float getBaseShippingInvoiced()
69
+ * @method Mage_Sales_Model_Order setBaseShippingInvoiced(float $value)
70
+ * @method float getBaseShippingRefunded()
71
+ * @method Mage_Sales_Model_Order setBaseShippingRefunded(float $value)
72
+ * @method float getBaseShippingTaxAmount()
73
+ * @method Mage_Sales_Model_Order setBaseShippingTaxAmount(float $value)
74
+ * @method float getBaseShippingTaxRefunded()
75
+ * @method Mage_Sales_Model_Order setBaseShippingTaxRefunded(float $value)
76
+ * @method float getBaseSubtotal()
77
+ * @method Mage_Sales_Model_Order setBaseSubtotal(float $value)
78
+ * @method float getBaseSubtotalCanceled()
79
+ * @method Mage_Sales_Model_Order setBaseSubtotalCanceled(float $value)
80
+ * @method float getBaseSubtotalInvoiced()
81
+ * @method Mage_Sales_Model_Order setBaseSubtotalInvoiced(float $value)
82
+ * @method float getBaseSubtotalRefunded()
83
+ * @method Mage_Sales_Model_Order setBaseSubtotalRefunded(float $value)
84
+ * @method float getBaseTaxAmount()
85
+ * @method Mage_Sales_Model_Order setBaseTaxAmount(float $value)
86
+ * @method float getBaseTaxCanceled()
87
+ * @method Mage_Sales_Model_Order setBaseTaxCanceled(float $value)
88
+ * @method float getBaseTaxInvoiced()
89
+ * @method Mage_Sales_Model_Order setBaseTaxInvoiced(float $value)
90
+ * @method float getBaseTaxRefunded()
91
+ * @method Mage_Sales_Model_Order setBaseTaxRefunded(float $value)
92
+ * @method float getBaseToGlobalRate()
93
+ * @method Mage_Sales_Model_Order setBaseToGlobalRate(float $value)
94
+ * @method float getBaseToOrderRate()
95
+ * @method Mage_Sales_Model_Order setBaseToOrderRate(float $value)
96
+ * @method float getBaseTotalCanceled()
97
+ * @method Mage_Sales_Model_Order setBaseTotalCanceled(float $value)
98
+ * @method float getBaseTotalInvoiced()
99
+ * @method Mage_Sales_Model_Order setBaseTotalInvoiced(float $value)
100
+ * @method float getBaseTotalInvoicedCost()
101
+ * @method Mage_Sales_Model_Order setBaseTotalInvoicedCost(float $value)
102
+ * @method float getBaseTotalOfflineRefunded()
103
+ * @method Mage_Sales_Model_Order setBaseTotalOfflineRefunded(float $value)
104
+ * @method float getBaseTotalOnlineRefunded()
105
+ * @method Mage_Sales_Model_Order setBaseTotalOnlineRefunded(float $value)
106
+ * @method float getBaseTotalPaid()
107
+ * @method Mage_Sales_Model_Order setBaseTotalPaid(float $value)
108
+ * @method float getBaseTotalQtyOrdered()
109
+ * @method Mage_Sales_Model_Order setBaseTotalQtyOrdered(float $value)
110
+ * @method float getBaseTotalRefunded()
111
+ * @method Mage_Sales_Model_Order setBaseTotalRefunded(float $value)
112
+ * @method float getDiscountAmount()
113
+ * @method Mage_Sales_Model_Order setDiscountAmount(float $value)
114
+ * @method float getDiscountCanceled()
115
+ * @method Mage_Sales_Model_Order setDiscountCanceled(float $value)
116
+ * @method float getDiscountInvoiced()
117
+ * @method Mage_Sales_Model_Order setDiscountInvoiced(float $value)
118
+ * @method float getDiscountRefunded()
119
+ * @method Mage_Sales_Model_Order setDiscountRefunded(float $value)
120
+ * @method float getGrandTotal()
121
+ * @method Mage_Sales_Model_Order setGrandTotal(float $value)
122
+ * @method float getShippingAmount()
123
+ * @method Mage_Sales_Model_Order setShippingAmount(float $value)
124
+ * @method float getShippingCanceled()
125
+ * @method Mage_Sales_Model_Order setShippingCanceled(float $value)
126
+ * @method float getShippingInvoiced()
127
+ * @method Mage_Sales_Model_Order setShippingInvoiced(float $value)
128
+ * @method float getShippingRefunded()
129
+ * @method Mage_Sales_Model_Order setShippingRefunded(float $value)
130
+ * @method float getShippingTaxAmount()
131
+ * @method Mage_Sales_Model_Order setShippingTaxAmount(float $value)
132
+ * @method float getShippingTaxRefunded()
133
+ * @method Mage_Sales_Model_Order setShippingTaxRefunded(float $value)
134
+ * @method float getStoreToBaseRate()
135
+ * @method Mage_Sales_Model_Order setStoreToBaseRate(float $value)
136
+ * @method float getStoreToOrderRate()
137
+ * @method Mage_Sales_Model_Order setStoreToOrderRate(float $value)
138
+ * @method float getSubtotal()
139
+ * @method Mage_Sales_Model_Order setSubtotal(float $value)
140
+ * @method float getSubtotalCanceled()
141
+ * @method Mage_Sales_Model_Order setSubtotalCanceled(float $value)
142
+ * @method float getSubtotalInvoiced()
143
+ * @method Mage_Sales_Model_Order setSubtotalInvoiced(float $value)
144
+ * @method float getSubtotalRefunded()
145
+ * @method Mage_Sales_Model_Order setSubtotalRefunded(float $value)
146
+ * @method float getTaxAmount()
147
+ * @method Mage_Sales_Model_Order setTaxAmount(float $value)
148
+ * @method float getTaxCanceled()
149
+ * @method Mage_Sales_Model_Order setTaxCanceled(float $value)
150
+ * @method float getTaxInvoiced()
151
+ * @method Mage_Sales_Model_Order setTaxInvoiced(float $value)
152
+ * @method float getTaxRefunded()
153
+ * @method Mage_Sales_Model_Order setTaxRefunded(float $value)
154
+ * @method float getTotalCanceled()
155
+ * @method Mage_Sales_Model_Order setTotalCanceled(float $value)
156
+ * @method float getTotalInvoiced()
157
+ * @method Mage_Sales_Model_Order setTotalInvoiced(float $value)
158
+ * @method float getTotalOfflineRefunded()
159
+ * @method Mage_Sales_Model_Order setTotalOfflineRefunded(float $value)
160
+ * @method float getTotalOnlineRefunded()
161
+ * @method Mage_Sales_Model_Order setTotalOnlineRefunded(float $value)
162
+ * @method float getTotalPaid()
163
+ * @method Mage_Sales_Model_Order setTotalPaid(float $value)
164
+ * @method float getTotalQtyOrdered()
165
+ * @method Mage_Sales_Model_Order setTotalQtyOrdered(float $value)
166
+ * @method float getTotalRefunded()
167
+ * @method Mage_Sales_Model_Order setTotalRefunded(float $value)
168
+ * @method int getCanShipPartially()
169
+ * @method Mage_Sales_Model_Order setCanShipPartially(int $value)
170
+ * @method int getCanShipPartiallyItem()
171
+ * @method Mage_Sales_Model_Order setCanShipPartiallyItem(int $value)
172
+ * @method int getCustomerIsGuest()
173
+ * @method Mage_Sales_Model_Order setCustomerIsGuest(int $value)
174
+ * @method int getCustomerNoteNotify()
175
+ * @method Mage_Sales_Model_Order setCustomerNoteNotify(int $value)
176
+ * @method int getBillingAddressId()
177
+ * @method Mage_Sales_Model_Order setBillingAddressId(int $value)
178
+ * @method int getCustomerGroupId()
179
+ * @method Mage_Sales_Model_Order setCustomerGroupId(int $value)
180
+ * @method int getEditIncrement()
181
+ * @method Mage_Sales_Model_Order setEditIncrement(int $value)
182
+ * @method int getEmailSent()
183
+ * @method Mage_Sales_Model_Order setEmailSent(int $value)
184
+ * @method int getForcedDoShipmentWithInvoice()
185
+ * @method Mage_Sales_Model_Order setForcedDoShipmentWithInvoice(int $value)
186
+ * @method int getGiftMessageId()
187
+ * @method Mage_Sales_Model_Order setGiftMessageId(int $value)
188
+ * @method int getPaymentAuthorizationExpiration()
189
+ * @method Mage_Sales_Model_Order setPaymentAuthorizationExpiration(int $value)
190
+ * @method int getPaypalIpnCustomerNotified()
191
+ * @method Mage_Sales_Model_Order setPaypalIpnCustomerNotified(int $value)
192
+ * @method int getQuoteAddressId()
193
+ * @method Mage_Sales_Model_Order setQuoteAddressId(int $value)
194
+ * @method int getQuoteId()
195
+ * @method Mage_Sales_Model_Order setQuoteId(int $value)
196
+ * @method int getShippingAddressId()
197
+ * @method Mage_Sales_Model_Order setShippingAddressId(int $value)
198
+ * @method float getAdjustmentNegative()
199
+ * @method Mage_Sales_Model_Order setAdjustmentNegative(float $value)
200
+ * @method float getAdjustmentPositive()
201
+ * @method Mage_Sales_Model_Order setAdjustmentPositive(float $value)
202
+ * @method float getBaseAdjustmentNegative()
203
+ * @method Mage_Sales_Model_Order setBaseAdjustmentNegative(float $value)
204
+ * @method float getBaseAdjustmentPositive()
205
+ * @method Mage_Sales_Model_Order setBaseAdjustmentPositive(float $value)
206
+ * @method float getBaseShippingDiscountAmount()
207
+ * @method Mage_Sales_Model_Order setBaseShippingDiscountAmount(float $value)
208
+ * @method float getBaseSubtotalInclTax()
209
+ * @method Mage_Sales_Model_Order setBaseSubtotalInclTax(float $value)
210
+ * @method Mage_Sales_Model_Order setBaseTotalDue(float $value)
211
+ * @method float getPaymentAuthorizationAmount()
212
+ * @method Mage_Sales_Model_Order setPaymentAuthorizationAmount(float $value)
213
+ * @method float getShippingDiscountAmount()
214
+ * @method Mage_Sales_Model_Order setShippingDiscountAmount(float $value)
215
+ * @method float getSubtotalInclTax()
216
+ * @method Mage_Sales_Model_Order setSubtotalInclTax(float $value)
217
+ * @method Mage_Sales_Model_Order setTotalDue(float $value)
218
+ * @method float getWeight()
219
+ * @method Mage_Sales_Model_Order setWeight(float $value)
220
+ * @method string getCustomerDob()
221
+ * @method Mage_Sales_Model_Order setCustomerDob(string $value)
222
+ * @method string getIncrementId()
223
+ * @method Mage_Sales_Model_Order setIncrementId(string $value)
224
+ * @method string getAppliedRuleIds()
225
+ * @method Mage_Sales_Model_Order setAppliedRuleIds(string $value)
226
+ * @method string getBaseCurrencyCode()
227
+ * @method Mage_Sales_Model_Order setBaseCurrencyCode(string $value)
228
+ * @method string getCustomerEmail()
229
+ * @method Mage_Sales_Model_Order setCustomerEmail(string $value)
230
+ * @method string getCustomerFirstname()
231
+ * @method Mage_Sales_Model_Order setCustomerFirstname(string $value)
232
+ * @method string getCustomerLastname()
233
+ * @method Mage_Sales_Model_Order setCustomerLastname(string $value)
234
+ * @method string getCustomerMiddlename()
235
+ * @method Mage_Sales_Model_Order setCustomerMiddlename(string $value)
236
+ * @method string getCustomerPrefix()
237
+ * @method Mage_Sales_Model_Order setCustomerPrefix(string $value)
238
+ * @method string getCustomerSuffix()
239
+ * @method Mage_Sales_Model_Order setCustomerSuffix(string $value)
240
+ * @method string getCustomerTaxvat()
241
+ * @method Mage_Sales_Model_Order setCustomerTaxvat(string $value)
242
+ * @method string getDiscountDescription()
243
+ * @method Mage_Sales_Model_Order setDiscountDescription(string $value)
244
+ * @method string getExtCustomerId()
245
+ * @method Mage_Sales_Model_Order setExtCustomerId(string $value)
246
+ * @method string getExtOrderId()
247
+ * @method Mage_Sales_Model_Order setExtOrderId(string $value)
248
+ * @method string getGlobalCurrencyCode()
249
+ * @method Mage_Sales_Model_Order setGlobalCurrencyCode(string $value)
250
+ * @method string getHoldBeforeState()
251
+ * @method Mage_Sales_Model_Order setHoldBeforeState(string $value)
252
+ * @method string getHoldBeforeStatus()
253
+ * @method Mage_Sales_Model_Order setHoldBeforeStatus(string $value)
254
+ * @method string getOrderCurrencyCode()
255
+ * @method Mage_Sales_Model_Order setOrderCurrencyCode(string $value)
256
+ * @method string getOriginalIncrementId()
257
+ * @method Mage_Sales_Model_Order setOriginalIncrementId(string $value)
258
+ * @method string getRelationChildId()
259
+ * @method Mage_Sales_Model_Order setRelationChildId(string $value)
260
+ * @method string getRelationChildRealId()
261
+ * @method Mage_Sales_Model_Order setRelationChildRealId(string $value)
262
+ * @method string getRelationParentId()
263
+ * @method Mage_Sales_Model_Order setRelationParentId(string $value)
264
+ * @method string getRelationParentRealId()
265
+ * @method Mage_Sales_Model_Order setRelationParentRealId(string $value)
266
+ * @method string getRemoteIp()
267
+ * @method Mage_Sales_Model_Order setRemoteIp(string $value)
268
+ * @method string getShippingMethod()
269
+ * @method Mage_Sales_Model_Order setShippingMethod(string $value)
270
+ * @method string getStoreCurrencyCode()
271
+ * @method Mage_Sales_Model_Order setStoreCurrencyCode(string $value)
272
+ * @method string getStoreName()
273
+ * @method Mage_Sales_Model_Order setStoreName(string $value)
274
+ * @method string getXForwardedFor()
275
+ * @method Mage_Sales_Model_Order setXForwardedFor(string $value)
276
+ * @method string getCustomerNote()
277
+ * @method Mage_Sales_Model_Order setCustomerNote(string $value)
278
+ * @method string getCreatedAt()
279
+ * @method Mage_Sales_Model_Order setCreatedAt(string $value)
280
+ * @method string getUpdatedAt()
281
+ * @method Mage_Sales_Model_Order setUpdatedAt(string $value)
282
+ * @method int getTotalItemCount()
283
+ * @method Mage_Sales_Model_Order setTotalItemCount(int $value)
284
+ * @method int getCustomerGender()
285
+ * @method Mage_Sales_Model_Order setCustomerGender(int $value)
286
+ * @method float getHiddenTaxAmount()
287
+ * @method Mage_Sales_Model_Order setHiddenTaxAmount(float $value)
288
+ * @method float getBaseHiddenTaxAmount()
289
+ * @method Mage_Sales_Model_Order setBaseHiddenTaxAmount(float $value)
290
+ * @method float getShippingHiddenTaxAmount()
291
+ * @method Mage_Sales_Model_Order setShippingHiddenTaxAmount(float $value)
292
+ * @method float getBaseShippingHiddenTaxAmount()
293
+ * @method Mage_Sales_Model_Order setBaseShippingHiddenTaxAmount(float $value)
294
+ * @method float getHiddenTaxInvoiced()
295
+ * @method Mage_Sales_Model_Order setHiddenTaxInvoiced(float $value)
296
+ * @method float getBaseHiddenTaxInvoiced()
297
+ * @method Mage_Sales_Model_Order setBaseHiddenTaxInvoiced(float $value)
298
+ * @method float getHiddenTaxRefunded()
299
+ * @method Mage_Sales_Model_Order setHiddenTaxRefunded(float $value)
300
+ * @method float getBaseHiddenTaxRefunded()
301
+ * @method Mage_Sales_Model_Order setBaseHiddenTaxRefunded(float $value)
302
+ * @method float getShippingInclTax()
303
+ * @method Mage_Sales_Model_Order setShippingInclTax(float $value)
304
+ * @method float getBaseShippingInclTax()
305
+ * @method Mage_Sales_Model_Order setBaseShippingInclTax(float $value)
306
+ *
307
+ * @category Mage
308
+ * @package Mage_Sales
309
+ * @author Magento Core Team <core@magentocommerce.com>
310
+ */
311
+ class Mage_Sales_Model_Order extends Mage_Sales_Model_Abstract
312
+ {
313
+ const ENTITY = 'order';
314
+ /**
315
+ * XML configuration paths
316
+ */
317
+ const XML_PATH_EMAIL_TEMPLATE = 'sales_email/order/template';
318
+ const XML_PATH_EMAIL_GUEST_TEMPLATE = 'sales_email/order/guest_template';
319
+ const XML_PATH_EMAIL_IDENTITY = 'sales_email/order/identity';
320
+ const XML_PATH_EMAIL_COPY_TO = 'sales_email/order/copy_to';
321
+ const XML_PATH_EMAIL_COPY_METHOD = 'sales_email/order/copy_method';
322
+ const XML_PATH_EMAIL_ENABLED = 'sales_email/order/enabled';
323
+
324
+ const XML_PATH_UPDATE_EMAIL_TEMPLATE = 'sales_email/order_comment/template';
325
+ const XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE = 'sales_email/order_comment/guest_template';
326
+ const XML_PATH_UPDATE_EMAIL_IDENTITY = 'sales_email/order_comment/identity';
327
+ const XML_PATH_UPDATE_EMAIL_COPY_TO = 'sales_email/order_comment/copy_to';
328
+ const XML_PATH_UPDATE_EMAIL_COPY_METHOD = 'sales_email/order_comment/copy_method';
329
+ const XML_PATH_UPDATE_EMAIL_ENABLED = 'sales_email/order_comment/enabled';
330
+
331
+ /**
332
+ * Order states
333
+ */
334
+ const STATE_NEW = 'new';
335
+ const STATE_PENDING_PAYMENT = 'pending_payment';
336
+ const STATE_PROCESSING = 'processing';
337
+ const STATE_COMPLETE = 'complete';
338
+ const STATE_CLOSED = 'closed';
339
+ const STATE_CANCELED = 'canceled';
340
+ const STATE_HOLDED = 'holded';
341
+ const STATE_PAYMENT_REVIEW = 'payment_review';
342
+
343
+ /**
344
+ * Order statuses
345
+ */
346
+ const STATUS_FRAUD = 'fraud';
347
+
348
+ /**
349
+ * Order flags
350
+ */
351
+ const ACTION_FLAG_CANCEL = 'cancel';
352
+ const ACTION_FLAG_HOLD = 'hold';
353
+ const ACTION_FLAG_UNHOLD = 'unhold';
354
+ const ACTION_FLAG_EDIT = 'edit';
355
+ const ACTION_FLAG_CREDITMEMO= 'creditmemo';
356
+ const ACTION_FLAG_INVOICE = 'invoice';
357
+ const ACTION_FLAG_REORDER = 'reorder';
358
+ const ACTION_FLAG_SHIP = 'ship';
359
+ const ACTION_FLAG_COMMENT = 'comment';
360
+
361
+ /**
362
+ * Report date types
363
+ */
364
+ const REPORT_DATE_TYPE_CREATED = 'created';
365
+ const REPORT_DATE_TYPE_UPDATED = 'updated';
366
+ /*
367
+ * Identifier for history item
368
+ */
369
+ const HISTORY_ENTITY_NAME = 'order';
370
+
371
+ protected $_eventPrefix = 'sales_order';
372
+ protected $_eventObject = 'order';
373
+
374
+ protected $_addresses = null;
375
+ protected $_items = null;
376
+ protected $_payments = null;
377
+ protected $_statusHistory = null;
378
+ protected $_invoices;
379
+ protected $_tracks;
380
+ protected $_shipments;
381
+ protected $_creditmemos;
382
+
383
+ protected $_relatedObjects = array();
384
+ protected $_orderCurrency = null;
385
+ protected $_baseCurrency = null;
386
+
387
+ /**
388
+ * Array of action flags for canUnhold, canEdit, etc.
389
+ *
390
+ * @var array
391
+ */
392
+ protected $_actionFlag = array();
393
+
394
+ /**
395
+ * Flag: if after order placing we can send new email to the customer.
396
+ *
397
+ * @var bool
398
+ */
399
+ protected $_canSendNewEmailFlag = true;
400
+
401
+ /*
402
+ * Identifier for history item
403
+ *
404
+ * @var string
405
+ */
406
+ protected $_historyEntityName = self::HISTORY_ENTITY_NAME;
407
+
408
+ /**
409
+ * Initialize resource model
410
+ */
411
+ protected function _construct()
412
+ {
413
+ $this->_init('sales/order');
414
+ }
415
+
416
+ /**
417
+ * Init mapping array of short fields to
418
+ * its full names
419
+ *
420
+ * @return Varien_Object
421
+ */
422
+ protected function _initOldFieldsMap()
423
+ {
424
+ $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order');
425
+ return $this;
426
+ }
427
+
428
+ /**
429
+ * Clear order object data
430
+ *
431
+ * @param string $key data key
432
+ * @return Mage_Sales_Model_Order
433
+ */
434
+ public function unsetData($key=null)
435
+ {
436
+ parent::unsetData($key);
437
+ if (is_null($key)) {
438
+ $this->_items = null;
439
+ }
440
+ return $this;
441
+ }
442
+
443
+ /**
444
+ * Retrieve can flag for action (edit, unhold, etc..)
445
+ *
446
+ * @param string $action
447
+ * @return boolean|null
448
+ */
449
+ public function getActionFlag($action)
450
+ {
451
+ if (isset($this->_actionFlag[$action])) {
452
+ return $this->_actionFlag[$action];
453
+ }
454
+ return null;
455
+ }
456
+
457
+ /**
458
+ * Set can flag value for action (edit, unhold, etc...)
459
+ *
460
+ * @param string $action
461
+ * @param boolean $flag
462
+ * @return Mage_Sales_Model_Order
463
+ */
464
+ public function setActionFlag($action, $flag)
465
+ {
466
+ $this->_actionFlag[$action] = (boolean) $flag;
467
+ return $this;
468
+ }
469
+
470
+ /**
471
+ * Return flag for order if it can sends new email to customer.
472
+ *
473
+ * @return bool
474
+ */
475
+ public function getCanSendNewEmailFlag()
476
+ {
477
+ return $this->_canSendNewEmailFlag;
478
+ }
479
+
480
+ /**
481
+ * Set flag for order if it can sends new email to customer.
482
+ *
483
+ * @param bool $flag
484
+ * @return Mage_Sales_Model_Order
485
+ */
486
+ public function setCanSendNewEmailFlag($flag)
487
+ {
488
+ $this->_canSendNewEmailFlag = (boolean) $flag;
489
+ return $this;
490
+ }
491
+
492
+ /**
493
+ * Load order by system increment identifier
494
+ *
495
+ * @param string $incrementId
496
+ * @return Mage_Sales_Model_Order
497
+ */
498
+ public function loadByIncrementId($incrementId)
499
+ {
500
+ return $this->loadByAttribute('increment_id', $incrementId);
501
+ }
502
+
503
+ /**
504
+ * Load order by custom attribute value. Attribute value should be unique
505
+ *
506
+ * @param string $attribute
507
+ * @param string $value
508
+ * @return Mage_Sales_Model_Order
509
+ */
510
+ public function loadByAttribute($attribute, $value)
511
+ {
512
+ $this->load($value, $attribute);
513
+ return $this;
514
+ }
515
+
516
+ /**
517
+ * Retrieve store model instance
518
+ *
519
+ * @return Mage_Core_Model_Store
520
+ */
521
+ public function getStore()
522
+ {
523
+ $storeId = $this->getStoreId();
524
+ if ($storeId) {
525
+ return Mage::app()->getStore($storeId);
526
+ }
527
+ return Mage::app()->getStore();
528
+ }
529
+
530
+ /**
531
+ * Retrieve order cancel availability
532
+ *
533
+ * @return bool
534
+ */
535
+ public function canCancel()
536
+ {
537
+ if ($this->canUnhold()) { // $this->isPaymentReview()
538
+ return false;
539
+ }
540
+
541
+ $allInvoiced = true;
542
+ foreach ($this->getAllItems() as $item) {
543
+ if ($item->getQtyToInvoice()) {
544
+ $allInvoiced = false;
545
+ break;
546
+ }
547
+ }
548
+ if ($allInvoiced) {
549
+ return false;
550
+ }
551
+
552
+ $state = $this->getState();
553
+ if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
554
+ return false;
555
+ }
556
+
557
+ if ($this->getActionFlag(self::ACTION_FLAG_CANCEL) === false) {
558
+ return false;
559
+ }
560
+
561
+ /**
562
+ * Use only state for availability detect
563
+ */
564
+ /*foreach ($this->getAllItems() as $item) {
565
+ if ($item->getQtyToCancel()>0) {
566
+ return true;
567
+ }
568
+ }
569
+ return false;*/
570
+ return true;
571
+ }
572
+
573
+ /**
574
+ * Getter whether the payment can be voided
575
+ * @return bool
576
+ */
577
+ public function canVoidPayment()
578
+ {
579
+ if ($this->canUnhold() || $this->isPaymentReview()) {
580
+ return false;
581
+ }
582
+ $state = $this->getState();
583
+ if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
584
+ return false;
585
+ }
586
+ return $this->getPayment()->canVoid(new Varien_Object);
587
+ }
588
+
589
+ /**
590
+ * Retrieve order invoice availability
591
+ *
592
+ * @return bool
593
+ */
594
+ public function canInvoice()
595
+ {
596
+ if ($this->canUnhold() || $this->isPaymentReview()) {
597
+ return false;
598
+ }
599
+ $state = $this->getState();
600
+ if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
601
+ return false;
602
+ }
603
+
604
+ if ($this->getActionFlag(self::ACTION_FLAG_INVOICE) === false) {
605
+ return false;
606
+ }
607
+
608
+ foreach ($this->getAllItems() as $item) {
609
+ if ($item->getQtyToInvoice()>0 && !$item->getLockedDoInvoice()) {
610
+ return true;
611
+ }
612
+ }
613
+ return false;
614
+ }
615
+
616
+ /**
617
+ * Retrieve order credit memo (refund) availability
618
+ *
619
+ * @return bool
620
+ */
621
+ public function canCreditmemo()
622
+ {
623
+ if ($this->hasForcedCanCreditmemo()) {
624
+ return $this->getForcedCanCreditmemo();
625
+ }
626
+
627
+ if ($this->canUnhold() || $this->isPaymentReview()) {
628
+ return false;
629
+ }
630
+
631
+ if ($this->isCanceled() || $this->getState() === self::STATE_CLOSED) {
632
+ return false;
633
+ }
634
+
635
+ /**
636
+ * We can have problem with float in php (on some server $a=762.73;$b=762.73; $a-$b!=0)
637
+ * for this we have additional diapason for 0
638
+ * TotalPaid - contains amount, that were not rounded.
639
+ */
640
+ if (abs($this->getStore()->roundPrice($this->getTotalPaid()) - $this->getTotalRefunded()) < .0001) {
641
+ return false;
642
+ }
643
+
644
+ if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
645
+ return false;
646
+ }
647
+ return true;
648
+ }
649
+
650
+ /**
651
+ * Retrieve order hold availability
652
+ *
653
+ * @return bool
654
+ */
655
+ public function canHold()
656
+ {
657
+ $state = $this->getState();
658
+ if ($this->isCanceled() || $this->isPaymentReview()
659
+ || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED || $state === self::STATE_HOLDED) {
660
+ return false;
661
+ }
662
+
663
+ if ($this->getActionFlag(self::ACTION_FLAG_HOLD) === false) {
664
+ return false;
665
+ }
666
+ return true;
667
+ }
668
+
669
+ /**
670
+ * Retrieve order unhold availability
671
+ *
672
+ * @return bool
673
+ */
674
+ public function canUnhold()
675
+ {
676
+ if ($this->getActionFlag(self::ACTION_FLAG_UNHOLD) === false || $this->isPaymentReview()) {
677
+ return false;
678
+ }
679
+ return $this->getState() === self::STATE_HOLDED;
680
+ }
681
+
682
+ /**
683
+ * Check if comment can be added to order history
684
+ *
685
+ * @return bool
686
+ */
687
+ public function canComment()
688
+ {
689
+ if ($this->getActionFlag(self::ACTION_FLAG_COMMENT) === false) {
690
+ return false;
691
+ }
692
+ return true;
693
+ }
694
+
695
+ /**
696
+ * Retrieve order shipment availability
697
+ *
698
+ * @return bool
699
+ */
700
+ public function canShip()
701
+ {
702
+ if ($this->canUnhold() || $this->isPaymentReview()) {
703
+ return false;
704
+ }
705
+
706
+ if ($this->getIsVirtual() || $this->isCanceled()) {
707
+ return false;
708
+ }
709
+
710
+ if ($this->getActionFlag(self::ACTION_FLAG_SHIP) === false) {
711
+ return false;
712
+ }
713
+
714
+ foreach ($this->getAllItems() as $item) {
715
+ if ($item->getQtyToShip()>0 && !$item->getIsVirtual()
716
+ && !$item->getLockedDoShip())
717
+ {
718
+ return true;
719
+ }
720
+ }
721
+ return false;
722
+ }
723
+
724
+ /**
725
+ * Retrieve order edit availability
726
+ *
727
+ * @return bool
728
+ */
729
+ public function canEdit()
730
+ {
731
+ if ($this->canUnhold()) {
732
+ return false;
733
+ }
734
+
735
+ $state = $this->getState();
736
+ if ($this->isCanceled() || $this->isPaymentReview()
737
+ || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
738
+ return false;
739
+ }
740
+
741
+ if (!$this->getPayment()->getMethodInstance()->canEdit()) {
742
+ return false;
743
+ }
744
+
745
+ if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
746
+ return false;
747
+ }
748
+
749
+ return true;
750
+ }
751
+
752
+ /**
753
+ * Retrieve order reorder availability
754
+ *
755
+ * @return bool
756
+ */
757
+ public function canReorder()
758
+ {
759
+ return $this->_canReorder(false);
760
+ }
761
+
762
+ /**
763
+ * Check the ability to reorder ignoring the availability in stock or status of the ordered products
764
+ *
765
+ * @return bool
766
+ */
767
+ public function canReorderIgnoreSalable()
768
+ {
769
+ return $this->_canReorder(true);
770
+ }
771
+
772
+ /**
773
+ * Retrieve order reorder availability
774
+ *
775
+ * @param bool $ignoreSalable
776
+ * @return bool
777
+ */
778
+ protected function _canReorder($ignoreSalable = false)
779
+ {
780
+ if ($this->canUnhold() || $this->isPaymentReview() || !$this->getCustomerId()) {
781
+ return false;
782
+ }
783
+
784
+ $products = array();
785
+ foreach ($this->getItemsCollection() as $item) {
786
+ $products[] = $item->getProductId();
787
+ }
788
+
789
+ if (!empty($products)) {
790
+ /*
791
+ * @TODO ACPAOC: Use product collection here, but ensure that product
792
+ * is loaded with order store id, otherwise there'll be problems with isSalable()
793
+ * for configurables, bundles and other composites
794
+ *
795
+ */
796
+ /*
797
+ $productsCollection = Mage::getModel('catalog/product')->getCollection()
798
+ ->setStoreId($this->getStoreId())
799
+ ->addIdFilter($products)
800
+ ->addAttributeToSelect('status')
801
+ ->load();
802
+
803
+ foreach ($productsCollection as $product) {
804
+ if (!$product->isSalable()) {
805
+ return false;
806
+ }
807
+ }
808
+ */
809
+
810
+ foreach ($products as $productId) {
811
+ $product = Mage::getModel('catalog/product')
812
+ ->setStoreId($this->getStoreId())
813
+ ->load($productId);
814
+ if (!$product->getId() || (!$ignoreSalable && !$product->isSalable())) {
815
+ return false;
816
+ }
817
+ }
818
+ }
819
+
820
+ if ($this->getActionFlag(self::ACTION_FLAG_REORDER) === false) {
821
+ return false;
822
+ }
823
+
824
+ return true;
825
+ }
826
+
827
+ /**
828
+ * Check whether the payment is in payment review state
829
+ * In this state order cannot be normally processed. Possible actions can be:
830
+ * - accept or deny payment
831
+ * - fetch transaction information
832
+ *
833
+ * @return bool
834
+ */
835
+ public function isPaymentReview()
836
+ {
837
+ return $this->getState() === self::STATE_PAYMENT_REVIEW;
838
+ }
839
+
840
+ /**
841
+ * Check whether payment can be accepted or denied
842
+ *
843
+ * @return bool
844
+ */
845
+ public function canReviewPayment()
846
+ {
847
+ return $this->isPaymentReview() && $this->getPayment()->canReviewPayment();
848
+ }
849
+
850
+ /**
851
+ * Check whether there can be a transaction update fetched for payment in review state
852
+ *
853
+ * @return bool
854
+ */
855
+ public function canFetchPaymentReviewUpdate()
856
+ {
857
+ return $this->isPaymentReview() && $this->getPayment()->canFetchTransactionInfo();
858
+ }
859
+
860
+ /**
861
+ * Retrieve order configuration model
862
+ *
863
+ * @return Mage_Sales_Model_Order_Config
864
+ */
865
+ public function getConfig()
866
+ {
867
+ return Mage::getSingleton('sales/order_config');
868
+ }
869
+
870
+ /**
871
+ * Place order payments
872
+ *
873
+ * @return Mage_Sales_Model_Order
874
+ */
875
+ protected function _placePayment()
876
+ {
877
+ $this->getPayment()->place();
878
+ return $this;
879
+ }
880
+
881
+ /**
882
+ * Retrieve order payment model object
883
+ *
884
+ * @return Mage_Sales_Model_Order_Payment
885
+ */
886
+ public function getPayment()
887
+ {
888
+ foreach ($this->getPaymentsCollection() as $payment) {
889
+ if (!$payment->isDeleted()) {
890
+ return $payment;
891
+ }
892
+ }
893
+ return false;
894
+ }
895
+
896
+ /**
897
+ * Declare order billing address
898
+ *
899
+ * @param Mage_Sales_Model_Order_Address $address
900
+ * @return Mage_Sales_Model_Order
901
+ */
902
+ public function setBillingAddress(Mage_Sales_Model_Order_Address $address)
903
+ {
904
+ $old = $this->getBillingAddress();
905
+ if (!empty($old)) {
906
+ $address->setId($old->getId());
907
+ }
908
+ $this->addAddress($address->setAddressType('billing'));
909
+ return $this;
910
+ }
911
+
912
+ /**
913
+ * Declare order shipping address
914
+ *
915
+ * @param Mage_Sales_Model_Order_Address $address
916
+ * @return Mage_Sales_Model_Order
917
+ */
918
+ public function setShippingAddress(Mage_Sales_Model_Order_Address $address)
919
+ {
920
+ $old = $this->getShippingAddress();
921
+ if (!empty($old)) {
922
+ $address->setId($old->getId());
923
+ }
924
+ $this->addAddress($address->setAddressType('shipping'));
925
+ return $this;
926
+ }
927
+
928
+ /**
929
+ * Retrieve order billing address
930
+ *
931
+ * @return Mage_Sales_Model_Order_Address
932
+ */
933
+ public function getBillingAddress()
934
+ {
935
+ foreach ($this->getAddressesCollection() as $address) {
936
+ if ($address->getAddressType()=='billing' && !$address->isDeleted()) {
937
+ return $address;
938
+ }
939
+ }
940
+ return false;
941
+ }
942
+
943
+ /**
944
+ * Retrieve order shipping address
945
+ *
946
+ * @return Mage_Sales_Model_Order_Address
947
+ */
948
+ public function getShippingAddress()
949
+ {
950
+ foreach ($this->getAddressesCollection() as $address) {
951
+ if ($address->getAddressType()=='shipping' && !$address->isDeleted()) {
952
+ return $address;
953
+ }
954
+ }
955
+ return false;
956
+ }
957
+
958
+ /**
959
+ * Order state setter.
960
+ * If status is specified, will add order status history with specified comment
961
+ * the setData() cannot be overriden because of compatibility issues with resource model
962
+ *
963
+ * @param string $state
964
+ * @param string|bool $status
965
+ * @param string $comment
966
+ * @param bool $isCustomerNotified
967
+ * @return Mage_Sales_Model_Order
968
+ */
969
+ public function setState($state, $status = false, $comment = '', $isCustomerNotified = null)
970
+ {
971
+ return $this->_setState($state, $status, $comment, $isCustomerNotified, true);
972
+ }
973
+
974
+ /**
975
+ * Order state protected setter.
976
+ * By default allows to set any state. Can also update status to default or specified value
977
+ * Сomplete and closed states are encapsulated intentionally, see the _checkState()
978
+ *
979
+ * @param string $state
980
+ * @param string|bool $status
981
+ * @param string $comment
982
+ * @param bool $isCustomerNotified
983
+ * @param $shouldProtectState
984
+ * @return Mage_Sales_Model_Order
985
+ */
986
+ protected function _setState($state, $status = false, $comment = '',
987
+ $isCustomerNotified = null, $shouldProtectState = false)
988
+ {
989
+ // attempt to set the specified state
990
+ if ($shouldProtectState) {
991
+ if ($this->isStateProtected($state)) {
992
+ Mage::throwException(
993
+ Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state)
994
+ );
995
+ }
996
+ }
997
+ $this->setData('state', $state);
998
+
999
+ // add status history
1000
+ if ($status) {
1001
+ if ($status === true) {
1002
+ $status = $this->getConfig()->getStateDefaultStatus($state);
1003
+ }
1004
+ $this->setStatus($status);
1005
+ $history = $this->addStatusHistoryComment($comment, false); // no sense to set $status again
1006
+ $history->setIsCustomerNotified($isCustomerNotified); // for backwards compatibility
1007
+ }
1008
+ return $this;
1009
+ }
1010
+
1011
+ /**
1012
+ * Whether specified state can be set from outside
1013
+ * @param $state
1014
+ * @return bool
1015
+ */
1016
+ public function isStateProtected($state)
1017
+ {
1018
+ if (empty($state)) {
1019
+ return false;
1020
+ }
1021
+ return self::STATE_COMPLETE == $state || self::STATE_CLOSED == $state;
1022
+ }
1023
+
1024
+ /**
1025
+ * Retrieve label of order status
1026
+ *
1027
+ * @return string
1028
+ */
1029
+ public function getStatusLabel()
1030
+ {
1031
+ return $this->getConfig()->getStatusLabel($this->getStatus());
1032
+ }
1033
+
1034
+ /**
1035
+ * Add status change information to history
1036
+ * @deprecated after 1.4.0.0-alpha3
1037
+ *
1038
+ * @param string $status
1039
+ * @param string $comment
1040
+ * @param bool $isCustomerNotified
1041
+ * @return Mage_Sales_Model_Order
1042
+ */
1043
+ public function addStatusToHistory($status, $comment = '', $isCustomerNotified = false)
1044
+ {
1045
+ $history = $this->addStatusHistoryComment($comment, $status)
1046
+ ->setIsCustomerNotified($isCustomerNotified);
1047
+ return $this;
1048
+ }
1049
+
1050
+ /*
1051
+ * Add a comment to order
1052
+ * Different or default status may be specified
1053
+ *
1054
+ * @param string $comment
1055
+ * @param string $status
1056
+ * @return Mage_Sales_Order_Status_History
1057
+ */
1058
+ public function addStatusHistoryComment($comment, $status = false)
1059
+ {
1060
+ if (false === $status) {
1061
+ $status = $this->getStatus();
1062
+ } elseif (true === $status) {
1063
+ $status = $this->getConfig()->getStateDefaultStatus($this->getState());
1064
+ } else {
1065
+ $this->setStatus($status);
1066
+ }
1067
+ $history = Mage::getModel('sales/order_status_history')
1068
+ ->setStatus($status)
1069
+ ->setComment($comment)
1070
+ ->setEntityName($this->_historyEntityName);
1071
+ $this->addStatusHistory($history);
1072
+ return $history;
1073
+ }
1074
+
1075
+ /**
1076
+ * Overrides entity id, which will be saved to comments history status
1077
+ *
1078
+ * @param string $status
1079
+ * @return Mage_Sales_Model_Order
1080
+ */
1081
+ public function setHistoryEntityName( $entityName )
1082
+ {
1083
+ $this->_historyEntityName = $entityName;
1084
+ return $this;
1085
+ }
1086
+
1087
+ /**
1088
+ * Place order
1089
+ *
1090
+ * @return Mage_Sales_Model_Order
1091
+ */
1092
+ public function place()
1093
+ {
1094
+ Mage::dispatchEvent('sales_order_place_before', array('order'=>$this));
1095
+ $this->_placePayment();
1096
+ Mage::dispatchEvent('sales_order_place_after', array('order'=>$this));
1097
+ return $this;
1098
+ }
1099
+
1100
+ public function hold()
1101
+ {
1102
+ if (!$this->canHold()) {
1103
+ Mage::throwException(Mage::helper('sales')->__('Hold action is not available.'));
1104
+ }
1105
+ $this->setHoldBeforeState($this->getState());
1106
+ $this->setHoldBeforeStatus($this->getStatus());
1107
+ $this->setState(self::STATE_HOLDED, true);
1108
+ return $this;
1109
+ }
1110
+
1111
+ /**
1112
+ * Attempt to unhold the order
1113
+ *
1114
+ * @return Mage_Sales_Model_Order
1115
+ * @throws Mage_Core_Exception
1116
+ */
1117
+ public function unhold()
1118
+ {
1119
+ if (!$this->canUnhold()) {
1120
+ Mage::throwException(Mage::helper('sales')->__('Unhold action is not available.'));
1121
+ }
1122
+ $this->setState($this->getHoldBeforeState(), $this->getHoldBeforeStatus());
1123
+ $this->setHoldBeforeState(null);
1124
+ $this->setHoldBeforeStatus(null);
1125
+ return $this;
1126
+ }
1127
+
1128
+ /**
1129
+ * Cancel order
1130
+ *
1131
+ * @return Mage_Sales_Model_Order
1132
+ */
1133
+ public function cancel()
1134
+ {
1135
+ if ($this->canCancel()) {
1136
+ $this->getPayment()->cancel();
1137
+ $this->registerCancellation();
1138
+
1139
+ Mage::dispatchEvent('order_cancel_after', array('order' => $this));
1140
+ }
1141
+
1142
+ return $this;
1143
+ }
1144
+
1145
+ /**
1146
+ * Prepare order totals to cancellation
1147
+ * @param string $comment
1148
+ * @param bool $graceful
1149
+ * @return Mage_Sales_Model_Order
1150
+ * @throws Mage_Core_Exception
1151
+ */
1152
+ public function registerCancellation($comment = '', $graceful = true)
1153
+ {
1154
+ if ($this->canCancel()) {
1155
+ $cancelState = self::STATE_CANCELED;
1156
+ foreach ($this->getAllItems() as $item) {
1157
+ if ($cancelState != self::STATE_PROCESSING && $item->getQtyToRefund()) {
1158
+ if ($item->getQtyToShip() > $item->getQtyToCancel()) {
1159
+ $cancelState = self::STATE_PROCESSING;
1160
+ } else {
1161
+ $cancelState = self::STATE_COMPLETE;
1162
+ }
1163
+ }
1164
+ $item->cancel();
1165
+ }
1166
+
1167
+ $this->setSubtotalCanceled($this->getSubtotal() - $this->getSubtotalInvoiced());
1168
+ $this->setBaseSubtotalCanceled($this->getBaseSubtotal() - $this->getBaseSubtotalInvoiced());
1169
+
1170
+ $this->setTaxCanceled($this->getTaxAmount() - $this->getTaxInvoiced());
1171
+ $this->setBaseTaxCanceled($this->getBaseTaxAmount() - $this->getBaseTaxInvoiced());
1172
+
1173
+ $this->setShippingCanceled($this->getShippingAmount() - $this->getShippingInvoiced());
1174
+ $this->setBaseShippingCanceled($this->getBaseShippingAmount() - $this->getBaseShippingInvoiced());
1175
+
1176
+ $this->setDiscountCanceled(abs($this->getDiscountAmount()) - $this->getDiscountInvoiced());
1177
+ $this->setBaseDiscountCanceled(abs($this->getBaseDiscountAmount()) - $this->getBaseDiscountInvoiced());
1178
+
1179
+ $this->setTotalCanceled($this->getGrandTotal() - $this->getTotalPaid());
1180
+ $this->setBaseTotalCanceled($this->getBaseGrandTotal() - $this->getBaseTotalPaid());
1181
+
1182
+ $this->_setState($cancelState, true, $comment);
1183
+ } elseif (!$graceful) {
1184
+ Mage::throwException(Mage::helper('sales')->__('Order does not allow to be canceled.'));
1185
+ }
1186
+ return $this;
1187
+ }
1188
+
1189
+ /**
1190
+ * Retrieve tracking numbers
1191
+ *
1192
+ * @return array
1193
+ */
1194
+ public function getTrackingNumbers()
1195
+ {
1196
+ if ($this->getData('tracking_numbers')) {
1197
+ return explode(',', $this->getData('tracking_numbers'));
1198
+ }
1199
+ return array();
1200
+ }
1201
+
1202
+ /**
1203
+ * Return model of shipping carrier
1204
+ *
1205
+ * @return bool|float|Mage_Shipping_Model_Carrier_Abstract
1206
+ */
1207
+ public function getShippingCarrier()
1208
+ {
1209
+ $carrierModel = $this->getData('shipping_carrier');
1210
+ if (is_null($carrierModel)) {
1211
+ $carrierModel = false;
1212
+ /**
1213
+ * $method - carrier_method
1214
+ */
1215
+ $method = $this->getShippingMethod(true);
1216
+ if ($method instanceof Varien_Object) {
1217
+ $className = Mage::getStoreConfig('carriers/' . $method->getCarrierCode() . '/model');
1218
+ if ($className) {
1219
+ $carrierModel = Mage::getModel($className);
1220
+ }
1221
+ }
1222
+ $this->setData('shipping_carrier', $carrierModel);
1223
+ }
1224
+ return $carrierModel;
1225
+ }
1226
+
1227
+ /**
1228
+ * Retrieve shipping method
1229
+ *
1230
+ * @param bool $asObject return carrier code and shipping method data as object
1231
+ * @return string|Varien_Object
1232
+ */
1233
+ public function getShippingMethod($asObject = false)
1234
+ {
1235
+ $shippingMethod = parent::getShippingMethod();
1236
+ if (!$asObject) {
1237
+ return $shippingMethod;
1238
+ } else {
1239
+ list($carrierCode, $method) = explode('_', $shippingMethod, 2);
1240
+ return new Varien_Object(array(
1241
+ 'carrier_code' => $carrierCode,
1242
+ 'method' => $method
1243
+ ));
1244
+ }
1245
+ }
1246
+
1247
+ /**
1248
+ * Send email with order data
1249
+ *
1250
+ * @return Mage_Sales_Model_Order
1251
+ */
1252
+ public function sendNewOrderEmail()
1253
+ {
1254
+ $storeId = $this->getStore()->getId();
1255
+
1256
+ if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) {
1257
+ return $this;
1258
+ }
1259
+ // Get the destination email addresses to send copies to
1260
+ $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
1261
+ $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
1262
+
1263
+ // Start store emulation process
1264
+ $appEmulation = Mage::getSingleton('core/app_emulation');
1265
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
1266
+
1267
+ try {
1268
+ // Retrieve specified view block from appropriate design package (depends on emulated store)
1269
+ $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
1270
+ ->setIsSecureMode(true);
1271
+ $paymentBlock->getMethod()->setStore($storeId);
1272
+ $paymentBlockHtml = $paymentBlock->toHtml();
1273
+ } catch (Exception $exception) {
1274
+ // Stop store emulation process
1275
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1276
+ throw $exception;
1277
+ }
1278
+
1279
+ // Stop store emulation process
1280
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1281
+
1282
+ // Retrieve corresponding email template id and customer name
1283
+ if ($this->getCustomerIsGuest()) {
1284
+ $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
1285
+ $customerName = $this->getBillingAddress()->getName();
1286
+ } else {
1287
+ $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
1288
+ $customerName = $this->getCustomerName();
1289
+ }
1290
+
1291
+ $mailer = Mage::getModel('core/email_template_mailer');
1292
+ $emailInfo = Mage::getModel('core/email_info');
1293
+ $emailInfo->addTo($this->getCustomerEmail(), $customerName);
1294
+ if ($copyTo && $copyMethod == 'bcc') {
1295
+ // Add bcc to customer email
1296
+ foreach ($copyTo as $email) {
1297
+ $emailInfo->addBcc($email);
1298
+ }
1299
+ }
1300
+ $mailer->addEmailInfo($emailInfo);
1301
+
1302
+ // Email copies are sent as separated emails if their copy method is 'copy'
1303
+ if ($copyTo && $copyMethod == 'copy') {
1304
+ foreach ($copyTo as $email) {
1305
+ $emailInfo = Mage::getModel('core/email_info');
1306
+ $emailInfo->addTo($email);
1307
+ $mailer->addEmailInfo($emailInfo);
1308
+ }
1309
+ }
1310
+
1311
+ // Set all required params and send emails
1312
+ $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
1313
+ $mailer->setStoreId($storeId);
1314
+ $mailer->setTemplateId($templateId);
1315
+ $mailer->setTemplateParams(array(
1316
+ 'order' => $this,
1317
+ 'billing' => $this->getBillingAddress(),
1318
+ 'payment_html' => $paymentBlockHtml
1319
+ )
1320
+ );
1321
+ $mailer->send();
1322
+
1323
+ $this->setEmailSent(true);
1324
+ $this->_getResource()->saveAttribute($this, 'email_sent');
1325
+
1326
+ return $this;
1327
+ }
1328
+
1329
+ /**
1330
+ * Send email with order update information
1331
+ *
1332
+ * @param boolean $notifyCustomer
1333
+ * @param string $comment
1334
+ * @return Mage_Sales_Model_Order
1335
+ */
1336
+ public function sendOrderUpdateEmail($notifyCustomer = true, $comment = '')
1337
+ {
1338
+ $storeId = $this->getStore()->getId();
1339
+
1340
+ if (!Mage::helper('sales')->canSendOrderCommentEmail($storeId)) {
1341
+ return $this;
1342
+ }
1343
+ // Get the destination email addresses to send copies to
1344
+ $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO);
1345
+ $copyMethod = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, $storeId);
1346
+ // Check if at least one recepient is found
1347
+ if (!$notifyCustomer && !$copyTo) {
1348
+ return $this;
1349
+ }
1350
+
1351
+ // Retrieve corresponding email template id and customer name
1352
+ if ($this->getCustomerIsGuest()) {
1353
+ $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, $storeId);
1354
+ $customerName = $this->getBillingAddress()->getName();
1355
+ } else {
1356
+ $templateId = Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, $storeId);
1357
+ $customerName = $this->getCustomerName();
1358
+ }
1359
+
1360
+ $mailer = Mage::getModel('core/email_template_mailer');
1361
+ if ($notifyCustomer) {
1362
+ $emailInfo = Mage::getModel('core/email_info');
1363
+ $emailInfo->addTo($this->getCustomerEmail(), $customerName);
1364
+ if ($copyTo && $copyMethod == 'bcc') {
1365
+ // Add bcc to customer email
1366
+ foreach ($copyTo as $email) {
1367
+ $emailInfo->addBcc($email);
1368
+ }
1369
+ }
1370
+ $mailer->addEmailInfo($emailInfo);
1371
+ }
1372
+
1373
+ // Email copies are sent as separated emails if their copy method is
1374
+ // 'copy' or a customer should not be notified
1375
+ if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) {
1376
+ foreach ($copyTo as $email) {
1377
+ $emailInfo = Mage::getModel('core/email_info');
1378
+ $emailInfo->addTo($email);
1379
+ $mailer->addEmailInfo($emailInfo);
1380
+ }
1381
+ }
1382
+
1383
+ // Set all required params and send emails
1384
+ $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_UPDATE_EMAIL_IDENTITY, $storeId));
1385
+ $mailer->setStoreId($storeId);
1386
+ $mailer->setTemplateId($templateId);
1387
+ $mailer->setTemplateParams(array(
1388
+ 'order' => $this,
1389
+ 'comment' => $comment,
1390
+ 'billing' => $this->getBillingAddress()
1391
+ )
1392
+ );
1393
+ $mailer->send();
1394
+
1395
+ return $this;
1396
+ }
1397
+
1398
+ protected function _getEmails($configPath)
1399
+ {
1400
+ $data = Mage::getStoreConfig($configPath, $this->getStoreId());
1401
+ if (!empty($data)) {
1402
+ return explode(',', $data);
1403
+ }
1404
+ return false;
1405
+ }
1406
+
1407
+ /*********************** ADDRESSES ***************************/
1408
+
1409
+ public function getAddressesCollection()
1410
+ {
1411
+ if (is_null($this->_addresses)) {
1412
+ $this->_addresses = Mage::getResourceModel('sales/order_address_collection')
1413
+ ->setOrderFilter($this);
1414
+
1415
+ if ($this->getId()) {
1416
+ foreach ($this->_addresses as $address) {
1417
+ $address->setOrder($this);
1418
+ }
1419
+ }
1420
+ }
1421
+
1422
+ return $this->_addresses;
1423
+ }
1424
+
1425
+ public function getAddressById($addressId)
1426
+ {
1427
+ foreach ($this->getAddressesCollection() as $address) {
1428
+ if ($address->getId()==$addressId) {
1429
+ return $address;
1430
+ }
1431
+ }
1432
+ return false;
1433
+ }
1434
+
1435
+ public function addAddress(Mage_Sales_Model_Order_Address $address)
1436
+ {
1437
+ $address->setOrder($this)->setParentId($this->getId());
1438
+ if (!$address->getId()) {
1439
+ $this->getAddressesCollection()->addItem($address);
1440
+ }
1441
+ return $this;
1442
+ }
1443
+
1444
+ public function getItemsCollection($filterByTypes = array(), $nonChildrenOnly = false)
1445
+ {
1446
+ if (is_null($this->_items)) {
1447
+ $this->_items = Mage::getResourceModel('sales/order_item_collection')
1448
+ ->setOrderFilter($this);
1449
+
1450
+ if ($filterByTypes) {
1451
+ $this->_items->filterByTypes($filterByTypes);
1452
+ }
1453
+ if ($nonChildrenOnly) {
1454
+ $this->_items->filterByParent();
1455
+ }
1456
+
1457
+ if ($this->getId()) {
1458
+ foreach ($this->_items as $item) {
1459
+ $item->setOrder($this);
1460
+ }
1461
+ }
1462
+ }
1463
+ return $this->_items;
1464
+ }
1465
+
1466
+ /**
1467
+ * Get random items collection with related children
1468
+ *
1469
+ * @param int $limit
1470
+ * @return Mage_Sales_Model_Mysql4_Order_Item_Collection
1471
+ */
1472
+ public function getItemsRandomCollection($limit = 1)
1473
+ {
1474
+ return $this->_getItemsRandomCollection($limit);
1475
+ }
1476
+
1477
+ /**
1478
+ * Get random items collection without related children
1479
+ *
1480
+ * @param int $limit
1481
+ * @return Mage_Sales_Model_Mysql4_Order_Item_Collection
1482
+ */
1483
+ public function getParentItemsRandomCollection($limit = 1)
1484
+ {
1485
+ return $this->_getItemsRandomCollection($limit, true);
1486
+ }
1487
+
1488
+ /**
1489
+ * Get random items collection with or without related children
1490
+ *
1491
+ * @param int $limit
1492
+ * @param bool $nonChildrenOnly
1493
+ * @return Mage_Sales_Model_Mysql4_Order_Item_Collection
1494
+ */
1495
+ protected function _getItemsRandomCollection($limit, $nonChildrenOnly = false)
1496
+ {
1497
+ $collection = Mage::getModel('sales/order_item')->getCollection()
1498
+ ->setOrderFilter($this)
1499
+ ->setRandomOrder();
1500
+
1501
+ if ($nonChildrenOnly) {
1502
+ $collection->filterByParent();
1503
+ }
1504
+ $products = array();
1505
+ foreach ($collection as $item) {
1506
+ $products[] = $item->getProductId();
1507
+ }
1508
+
1509
+ $productsCollection = Mage::getModel('catalog/product')
1510
+ ->getCollection()
1511
+ ->addIdFilter($products)
1512
+ ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds())
1513
+ /* Price data is added to consider item stock status using price index */
1514
+ ->addPriceData()
1515
+ ->setPageSize($limit)
1516
+ ->load();
1517
+
1518
+ foreach ($collection as $item) {
1519
+ $product = $productsCollection->getItemById($item->getProductId());
1520
+ if ($product) {
1521
+ $item->setProduct($product);
1522
+ }
1523
+ }
1524
+
1525
+ return $collection;
1526
+ }
1527
+
1528
+ public function getAllItems()
1529
+ {
1530
+ $items = array();
1531
+ foreach ($this->getItemsCollection() as $item) {
1532
+ if (!$item->isDeleted()) {
1533
+ $items[] = $item;
1534
+ }
1535
+ }
1536
+ return $items;
1537
+ }
1538
+
1539
+ public function getAllVisibleItems()
1540
+ {
1541
+ $items = array();
1542
+ foreach ($this->getItemsCollection() as $item) {
1543
+ if (!$item->isDeleted() && !$item->getParentItemId()) {
1544
+ $items[] = $item;
1545
+ }
1546
+ }
1547
+ return $items;
1548
+ }
1549
+
1550
+ public function getItemById($itemId)
1551
+ {
1552
+ return $this->getItemsCollection()->getItemById($itemId);
1553
+ }
1554
+
1555
+ public function getItemByQuoteItemId($quoteItemId)
1556
+ {
1557
+ foreach ($this->getItemsCollection() as $item) {
1558
+ if ($item->getQuoteItemId()==$quoteItemId) {
1559
+ return $item;
1560
+ }
1561
+ }
1562
+ return null;
1563
+ }
1564
+
1565
+ public function addItem(Mage_Sales_Model_Order_Item $item)
1566
+ {
1567
+ $item->setOrder($this);
1568
+ if (!$item->getId()) {
1569
+ $this->getItemsCollection()->addItem($item);
1570
+ }
1571
+ return $this;
1572
+ }
1573
+
1574
+ /**
1575
+ * Whether the order has nominal items only
1576
+ *
1577
+ * @return bool
1578
+ */
1579
+ public function isNominal()
1580
+ {
1581
+ foreach ($this->getAllVisibleItems() as $item) {
1582
+ if ('0' == $item->getIsNominal()) {
1583
+ return false;
1584
+ }
1585
+ }
1586
+ return true;
1587
+ }
1588
+
1589
+ /*********************** PAYMENTS ***************************/
1590
+
1591
+ public function getPaymentsCollection()
1592
+ {
1593
+ if (is_null($this->_payments)) {
1594
+ $this->_payments = Mage::getResourceModel('sales/order_payment_collection')
1595
+ ->setOrderFilter($this);
1596
+
1597
+ if ($this->getId()) {
1598
+ foreach ($this->_payments as $payment) {
1599
+ $payment->setOrder($this);
1600
+ }
1601
+ }
1602
+ }
1603
+ return $this->_payments;
1604
+ }
1605
+
1606
+ public function getAllPayments()
1607
+ {
1608
+ $payments = array();
1609
+ foreach ($this->getPaymentsCollection() as $payment) {
1610
+ if (!$payment->isDeleted()) {
1611
+ $payments[] = $payment;
1612
+ }
1613
+ }
1614
+ return $payments;
1615
+ }
1616
+
1617
+
1618
+ public function getPaymentById($paymentId)
1619
+ {
1620
+ foreach ($this->getPaymentsCollection() as $payment) {
1621
+ if ($payment->getId()==$paymentId) {
1622
+ return $payment;
1623
+ }
1624
+ }
1625
+ return false;
1626
+ }
1627
+
1628
+ public function addPayment(Mage_Sales_Model_Order_Payment $payment)
1629
+ {
1630
+ $payment->setOrder($this)
1631
+ ->setParentId($this->getId());
1632
+ if (!$payment->getId()) {
1633
+ $this->getPaymentsCollection()->addItem($payment);
1634
+ }
1635
+ return $this;
1636
+ }
1637
+
1638
+ public function setPayment(Mage_Sales_Model_Order_Payment $payment)
1639
+ {
1640
+ if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) {
1641
+ $payment->setId($old->getId());
1642
+ }
1643
+ $this->addPayment($payment);
1644
+ return $payment;
1645
+ }
1646
+
1647
+ /*********************** STATUSES ***************************/
1648
+
1649
+ /**
1650
+ * Enter description here...
1651
+ *
1652
+ * @return Mage_Sales_Model_Entity_Order_Status_History_Collection
1653
+ */
1654
+ public function getStatusHistoryCollection($reload=false)
1655
+ {
1656
+ if (is_null($this->_statusHistory) || $reload) {
1657
+ $this->_statusHistory = Mage::getResourceModel('sales/order_status_history_collection')
1658
+ ->setOrderFilter($this)
1659
+ ->setOrder('created_at', 'desc')
1660
+ ->setOrder('entity_id', 'desc');
1661
+
1662
+ if ($this->getId()) {
1663
+ foreach ($this->_statusHistory as $status) {
1664
+ $status->setOrder($this);
1665
+ }
1666
+ }
1667
+ }
1668
+ return $this->_statusHistory;
1669
+ }
1670
+
1671
+ /**
1672
+ * Return collection of order status history items.
1673
+ *
1674
+ * @return array
1675
+ */
1676
+ public function getAllStatusHistory()
1677
+ {
1678
+ $history = array();
1679
+ foreach ($this->getStatusHistoryCollection() as $status) {
1680
+ if (!$status->isDeleted()) {
1681
+ $history[] = $status;
1682
+ }
1683
+ }
1684
+ return $history;
1685
+ }
1686
+
1687
+ /**
1688
+ * Return collection of visible on frontend order status history items.
1689
+ *
1690
+ * @return array
1691
+ */
1692
+ public function getVisibleStatusHistory()
1693
+ {
1694
+ $history = array();
1695
+ foreach ($this->getStatusHistoryCollection() as $status) {
1696
+ if (!$status->isDeleted() && $status->getComment() && $status->getIsVisibleOnFront()) {
1697
+ $history[] = $status;
1698
+ }
1699
+ }
1700
+ return $history;
1701
+ }
1702
+
1703
+ public function getStatusHistoryById($statusId)
1704
+ {
1705
+ foreach ($this->getStatusHistoryCollection() as $status) {
1706
+ if ($status->getId()==$statusId) {
1707
+ return $status;
1708
+ }
1709
+ }
1710
+ return false;
1711
+ }
1712
+
1713
+ /**
1714
+ * Set the order status history object and the order object to each other
1715
+ * Adds the object to the status history collection, which is automatically saved when the order is saved.
1716
+ * See the entity_id attribute backend model.
1717
+ * Or the history record can be saved standalone after this.
1718
+ *
1719
+ * @param Mage_Sales_Model_Order_Status_History $status
1720
+ * @return Mage_Sales_Model_Order
1721
+ */
1722
+ public function addStatusHistory(Mage_Sales_Model_Order_Status_History $history)
1723
+ {
1724
+ $history->setOrder($this);
1725
+ $this->setStatus($history->getStatus());
1726
+ if (!$history->getId()) {
1727
+ $this->getStatusHistoryCollection()->addItem($history);
1728
+ }
1729
+ return $this;
1730
+ }
1731
+
1732
+
1733
+ /**
1734
+ * Enter description here...
1735
+ *
1736
+ * @return string
1737
+ */
1738
+ public function getRealOrderId()
1739
+ {
1740
+ $id = $this->getData('real_order_id');
1741
+ if (is_null($id)) {
1742
+ $id = $this->getIncrementId();
1743
+ }
1744
+ return $id;
1745
+ }
1746
+
1747
+ /**
1748
+ * Get currency model instance. Will be used currency with which order placed
1749
+ *
1750
+ * @return Mage_Directory_Model_Currency
1751
+ */
1752
+ public function getOrderCurrency()
1753
+ {
1754
+ if (is_null($this->_orderCurrency)) {
1755
+ $this->_orderCurrency = Mage::getModel('directory/currency')->load($this->getOrderCurrencyCode());
1756
+ }
1757
+ return $this->_orderCurrency;
1758
+ }
1759
+
1760
+ /**
1761
+ * Get formated price value including order currency rate to order website currency
1762
+ *
1763
+ * @param float $price
1764
+ * @param bool $addBrackets
1765
+ * @return string
1766
+ */
1767
+ public function formatPrice($price, $addBrackets = false)
1768
+ {
1769
+ return $this->formatPricePrecision($price, 2, $addBrackets);
1770
+ }
1771
+
1772
+ public function formatPricePrecision($price, $precision, $addBrackets = false)
1773
+ {
1774
+ return $this->getOrderCurrency()->formatPrecision($price, $precision, array(), true, $addBrackets);
1775
+ }
1776
+
1777
+ /**
1778
+ * Retrieve text formated price value includeing order rate
1779
+ *
1780
+ * @param float $price
1781
+ * @return string
1782
+ */
1783
+ public function formatPriceTxt($price)
1784
+ {
1785
+ return $this->getOrderCurrency()->formatTxt($price);
1786
+ }
1787
+
1788
+ /**
1789
+ * Retrieve order website currency for working with base prices
1790
+ *
1791
+ * @return Mage_Directory_Model_Currency
1792
+ */
1793
+ public function getBaseCurrency()
1794
+ {
1795
+ if (is_null($this->_baseCurrency)) {
1796
+ $this->_baseCurrency = Mage::getModel('directory/currency')->load($this->getBaseCurrencyCode());
1797
+ }
1798
+ return $this->_baseCurrency;
1799
+ }
1800
+
1801
+ /**
1802
+ * Retrieve order website currency for working with base prices
1803
+ * @deprecated please use getBaseCurrency instead.
1804
+ *
1805
+ * @return Mage_Directory_Model_Currency
1806
+ */
1807
+ public function getStoreCurrency()
1808
+ {
1809
+ return $this->getData('store_currency');
1810
+ }
1811
+
1812
+ public function formatBasePrice($price)
1813
+ {
1814
+ return $this->formatBasePricePrecision($price, 2);
1815
+ }
1816
+
1817
+ public function formatBasePricePrecision($price, $precision)
1818
+ {
1819
+ return $this->getBaseCurrency()->formatPrecision($price, $precision);
1820
+ }
1821
+
1822
+ public function isCurrencyDifferent()
1823
+ {
1824
+ return $this->getOrderCurrencyCode() != $this->getBaseCurrencyCode();
1825
+ }
1826
+
1827
+ /**
1828
+ * Retrieve order total due value
1829
+ *
1830
+ * @return float
1831
+ */
1832
+ public function getTotalDue()
1833
+ {
1834
+ $total = $this->getGrandTotal()-$this->getTotalPaid();
1835
+ $total = Mage::app()->getStore($this->getStoreId())->roundPrice($total);
1836
+ return max($total, 0);
1837
+ }
1838
+
1839
+ /**
1840
+ * Retrieve order total due value
1841
+ *
1842
+ * @return float
1843
+ */
1844
+ public function getBaseTotalDue()
1845
+ {
1846
+ $total = $this->getBaseGrandTotal()-$this->getBaseTotalPaid();
1847
+ $total = Mage::app()->getStore($this->getStoreId())->roundPrice($total);
1848
+ return max($total, 0);
1849
+ }
1850
+
1851
+ public function getData($key='', $index=null)
1852
+ {
1853
+ if ($key == 'total_due') {
1854
+ return $this->getTotalDue();
1855
+ }
1856
+ if ($key == 'base_total_due') {
1857
+ return $this->getBaseTotalDue();
1858
+ }
1859
+ return parent::getData($key, $index);
1860
+ }
1861
+
1862
+ /**
1863
+ * Retrieve order invoices collection
1864
+ *
1865
+ * @return unknown
1866
+ */
1867
+ public function getInvoiceCollection()
1868
+ {
1869
+ if (is_null($this->_invoices)) {
1870
+ $this->_invoices = Mage::getResourceModel('sales/order_invoice_collection')
1871
+ ->setOrderFilter($this);
1872
+
1873
+ if ($this->getId()) {
1874
+ foreach ($this->_invoices as $invoice) {
1875
+ $invoice->setOrder($this);
1876
+ }
1877
+ }
1878
+ }
1879
+ return $this->_invoices;
1880
+ }
1881
+
1882
+ /**
1883
+ * Retrieve order shipments collection
1884
+ *
1885
+ * @return unknown
1886
+ */
1887
+ public function getShipmentsCollection()
1888
+ {
1889
+ if (empty($this->_shipments)) {
1890
+ if ($this->getId()) {
1891
+ $this->_shipments = Mage::getResourceModel('sales/order_shipment_collection')
1892
+ ->setOrderFilter($this)
1893
+ ->load();
1894
+ } else {
1895
+ return false;
1896
+ }
1897
+ }
1898
+ return $this->_shipments;
1899
+ }
1900
+
1901
+ /**
1902
+ * Retrieve order creditmemos collection
1903
+ *
1904
+ * @return unknown
1905
+ */
1906
+ public function getCreditmemosCollection()
1907
+ {
1908
+ if (empty($this->_creditmemos)) {
1909
+ if ($this->getId()) {
1910
+ $this->_creditmemos = Mage::getResourceModel('sales/order_creditmemo_collection')
1911
+ ->setOrderFilter($this)
1912
+ ->load();
1913
+ } else {
1914
+ return false;
1915
+ }
1916
+ }
1917
+ return $this->_creditmemos;
1918
+ }
1919
+
1920
+ /**
1921
+ * Retrieve order tracking numbers collection
1922
+ *
1923
+ * @return unknown
1924
+ */
1925
+ public function getTracksCollection()
1926
+ {
1927
+ if (empty($this->_tracks)) {
1928
+ $this->_tracks = Mage::getResourceModel('sales/order_shipment_track_collection')
1929
+ ->setOrderFilter($this);
1930
+
1931
+ if ($this->getId()) {
1932
+ $this->_tracks->load();
1933
+ }
1934
+ }
1935
+ return $this->_tracks;
1936
+ }
1937
+
1938
+ /**
1939
+ * Check order invoices availability
1940
+ *
1941
+ * @return bool
1942
+ */
1943
+ public function hasInvoices()
1944
+ {
1945
+ return $this->getInvoiceCollection()->count();
1946
+ }
1947
+
1948
+ /**
1949
+ * Check order shipments availability
1950
+ *
1951
+ * @return bool
1952
+ */
1953
+ public function hasShipments()
1954
+ {
1955
+ return $this->getShipmentsCollection()->count();
1956
+ }
1957
+
1958
+ /**
1959
+ * Check order creditmemos availability
1960
+ *
1961
+ * @return bool
1962
+ */
1963
+ public function hasCreditmemos()
1964
+ {
1965
+ return $this->getCreditmemosCollection()->count();
1966
+ }
1967
+
1968
+
1969
+ /**
1970
+ * Retrieve array of related objects
1971
+ *
1972
+ * Used for order saving
1973
+ *
1974
+ * @return array
1975
+ */
1976
+ public function getRelatedObjects()
1977
+ {
1978
+ return $this->_relatedObjects;
1979
+ }
1980
+
1981
+ public function getCustomerName()
1982
+ {
1983
+ if ($this->getCustomerFirstname()) {
1984
+ $customerName = $this->getCustomerFirstname() . ' ' . $this->getCustomerLastname();
1985
+ }
1986
+ else {
1987
+ $customerName = Mage::helper('sales')->__('Guest');
1988
+ }
1989
+ return $customerName;
1990
+ }
1991
+
1992
+ /**
1993
+ * Add New object to related array
1994
+ *
1995
+ * @param Mage_Core_Model_Abstract $object
1996
+ * @return Mage_Sales_Model_Order
1997
+ */
1998
+ public function addRelatedObject(Mage_Core_Model_Abstract $object)
1999
+ {
2000
+ $this->_relatedObjects[] = $object;
2001
+ return $this;
2002
+ }
2003
+
2004
+ /**
2005
+ * Get formated order created date in store timezone
2006
+ *
2007
+ * @param string $format date format type (short|medium|long|full)
2008
+ * @return string
2009
+ */
2010
+ public function getCreatedAtFormated($format)
2011
+ {
2012
+ return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, true);
2013
+ }
2014
+
2015
+ public function getEmailCustomerNote()
2016
+ {
2017
+ if ($this->getCustomerNoteNotify()) {
2018
+ return $this->getCustomerNote();
2019
+ }
2020
+ return '';
2021
+ }
2022
+
2023
+ /**
2024
+ * Processing object before save data
2025
+ *
2026
+ * @return Mage_Core_Model_Abstract
2027
+ */
2028
+ protected function _beforeSave()
2029
+ {
2030
+ parent::_beforeSave();
2031
+ $this->_checkState();
2032
+ if (!$this->getId()) {
2033
+ $store = $this->getStore();
2034
+ $name = array($store->getWebsite()->getName(),$store->getGroup()->getName(),$store->getName());
2035
+ $this->setStoreName(implode("\n", $name));
2036
+ }
2037
+
2038
+ if (!$this->getIncrementId()) {
2039
+ $incrementId = Mage::getSingleton('eav/config')
2040
+ ->getEntityType('order')
2041
+ ->fetchNewIncrementId($this->getStoreId());
2042
+ $this->setIncrementId($incrementId);
2043
+ }
2044
+
2045
+ if (Mage::getStoreConfig('adventos/customizableId/process') && strlen($this->getIncrementId()) == 9 ){
2046
+ $custom_prefix = Mage::getStoreConfig('adventos/customizableId/order_prefix');
2047
+ if (Mage::getStoreConfig('adventos/customizableId/process_country')){
2048
+ $country = $this->getBillingAddress()->getCountry();
2049
+ $this->setIncrementId(strtoupper($custom_prefix).strtoupper($country).$this->getIncrementId());
2050
+ }else{
2051
+ $this->setIncrementId(strtoupper($custom_prefix).$this->getIncrementId());
2052
+ }
2053
+ }
2054
+
2055
+ /**
2056
+ * Process items dependency for new order
2057
+ */
2058
+ if (!$this->getId()) {
2059
+ $itemsCount = 0;
2060
+ foreach ($this->getAllItems() as $item) {
2061
+ $parent = $item->getQuoteParentItemId();
2062
+ if ($parent && !$item->getParentItem()) {
2063
+ $item->setParentItem($this->getItemByQuoteItemId($parent));
2064
+ } elseif (!$parent) {
2065
+ $itemsCount++;
2066
+ }
2067
+ }
2068
+ // Set items count
2069
+ $this->setTotalItemCount($itemsCount);
2070
+ }
2071
+ if ($this->getCustomer()) {
2072
+ $this->setCustomerId($this->getCustomer()->getId());
2073
+ }
2074
+
2075
+ if ($this->hasBillingAddressId() && $this->getBillingAddressId() === null) {
2076
+ $this->unsBillingAddressId();
2077
+ }
2078
+
2079
+ if ($this->hasShippingAddressId() && $this->getShippingAddressId() === null) {
2080
+ $this->unsShippingAddressId();
2081
+ }
2082
+
2083
+ $this->setData('protect_code', substr(md5(uniqid(mt_rand(), true) . ':' . microtime(true)), 5, 6));
2084
+ return $this;
2085
+ }
2086
+
2087
+ /**
2088
+ * Check order state before saving
2089
+ */
2090
+ protected function _checkState()
2091
+ {
2092
+ if (!$this->getId()) {
2093
+ return $this;
2094
+ }
2095
+
2096
+ $userNotification = $this->hasCustomerNoteNotify() ? $this->getCustomerNoteNotify() : null;
2097
+
2098
+ if (!$this->isCanceled()
2099
+ && !$this->canUnhold()
2100
+ && !$this->canInvoice()
2101
+ && !$this->canShip()) {
2102
+ if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
2103
+ if ($this->getState() !== self::STATE_COMPLETE) {
2104
+ $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
2105
+ }
2106
+ }
2107
+ /**
2108
+ * Order can be closed just in case when we have refunded amount.
2109
+ * In case of "0" grand total order checking ForcedCanCreditmemo flag
2110
+ */
2111
+ elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded()
2112
+ && $this->hasForcedCanCreditmemo())
2113
+ ) {
2114
+ if ($this->getState() !== self::STATE_CLOSED) {
2115
+ $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
2116
+ }
2117
+ }
2118
+ }
2119
+
2120
+ if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) {
2121
+ $this->setState(self::STATE_PROCESSING, true, '', $userNotification);
2122
+ }
2123
+ return $this;
2124
+ }
2125
+
2126
+ /**
2127
+ * Save order related objects
2128
+ *
2129
+ * @return Mage_Sales_Model_Order
2130
+ */
2131
+ protected function _afterSave()
2132
+ {
2133
+ if (null !== $this->_addresses) {
2134
+ $this->_addresses->save();
2135
+ $billingAddress = $this->getBillingAddress();
2136
+ $attributesForSave = array();
2137
+ if ($billingAddress && $this->getBillingAddressId() != $billingAddress->getId()) {
2138
+ $this->setBillingAddressId($billingAddress->getId());
2139
+ $attributesForSave[] = 'billing_address_id';
2140
+ }
2141
+
2142
+ $shippingAddress = $this->getShippingAddress();
2143
+ if ($shippingAddress && $this->getShippigAddressId() != $shippingAddress->getId()) {
2144
+ $this->setShippingAddressId($shippingAddress->getId());
2145
+ $attributesForSave[] = 'shipping_address_id';
2146
+ }
2147
+
2148
+ if (!empty($attributesForSave)) {
2149
+ $this->_getResource()->saveAttribute($this, $attributesForSave);
2150
+ }
2151
+
2152
+ }
2153
+ if (null !== $this->_items) {
2154
+ $this->_items->save();
2155
+ }
2156
+ if (null !== $this->_payments) {
2157
+ $this->_payments->save();
2158
+ }
2159
+ if (null !== $this->_statusHistory) {
2160
+ $this->_statusHistory->save();
2161
+ }
2162
+ foreach ($this->getRelatedObjects() as $object) {
2163
+ $object->save();
2164
+ }
2165
+ return parent::_afterSave();
2166
+ }
2167
+
2168
+ public function getStoreGroupName()
2169
+ {
2170
+ $storeId = $this->getStoreId();
2171
+ if (is_null($storeId)) {
2172
+ return $this->getStoreName(1); // 0 - website name, 1 - store group name, 2 - store name
2173
+ }
2174
+ return $this->getStore()->getGroup()->getName();
2175
+ }
2176
+
2177
+ /**
2178
+ * Resets all data in object
2179
+ * so after another load it will be complete new object
2180
+ *
2181
+ * @return Mage_Sales_Model_Order
2182
+ */
2183
+ public function reset()
2184
+ {
2185
+ $this->unsetData();
2186
+ $this->_actionFlag = array();
2187
+ $this->_addresses = null;
2188
+ $this->_items = null;
2189
+ $this->_payments = null;
2190
+ $this->_statusHistory = null;
2191
+ $this->_invoices = null;
2192
+ $this->_tracks = null;
2193
+ $this->_shipments = null;
2194
+ $this->_creditmemos = null;
2195
+ $this->_relatedObjects = array();
2196
+ $this->_orderCurrency = null;
2197
+ $this->_baseCurrency = null;
2198
+
2199
+ return $this;
2200
+ }
2201
+
2202
+ public function getIsNotVirtual()
2203
+ {
2204
+ return !$this->getIsVirtual();
2205
+ }
2206
+
2207
+ public function getFullTaxInfo()
2208
+ {
2209
+ $rates = Mage::getModel('tax/sales_order_tax')->getCollection()->loadByOrder($this)->toArray();
2210
+ return Mage::getSingleton('tax/calculation')->reproduceProcess($rates['items']);
2211
+ }
2212
+
2213
+ /**
2214
+ * Create new invoice with maximum qty for invoice for each item
2215
+ *
2216
+ * @return Mage_Sales_Model_Order_Invoice
2217
+ */
2218
+ public function prepareInvoice($qtys = array())
2219
+ {
2220
+ $invoice = Mage::getModel('sales/service_order', $this)->prepareInvoice($qtys);
2221
+ return $invoice;
2222
+ }
2223
+
2224
+ /**
2225
+ * Create new shipment with maximum qty for shipping for each item
2226
+ *
2227
+ * @return Mage_Sales_Model_Order_Shipment
2228
+ */
2229
+ public function prepareShipment($qtys = array())
2230
+ {
2231
+ $shipment = Mage::getModel('sales/service_order', $this)->prepareShipment($qtys);
2232
+ return $shipment;
2233
+ }
2234
+
2235
+ /**
2236
+ * Check whether order is canceled
2237
+ *
2238
+ * @return bool
2239
+ */
2240
+ public function isCanceled()
2241
+ {
2242
+ return ($this->getState() === self::STATE_CANCELED);
2243
+ }
2244
+
2245
+ /**
2246
+ * Protect order delete from not admin scope
2247
+ * @return Mage_Sales_Model_Order
2248
+ */
2249
+ protected function _beforeDelete()
2250
+ {
2251
+ $this->_protectFromNonAdmin();
2252
+ return parent::_beforeDelete();
2253
+ }
2254
+ }
app/etc/modules/Adventos_CustomizableId.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Adventos_CustomizableId>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Adventos_CustomizableId>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Adventos_CustomizableId</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Add Prefix to OrderId</summary>
10
+ <description>Add Custom Prefix with optinal Country Shortcut from Billing Address to OrderId.</description>
11
+ <notes>Init Extention</notes>
12
+ <authors><author><name>Karsten Hoffmann</name><user>adventos</user><email>karsten@adventos.de</email></author></authors>
13
+ <date>2013-01-29</date>
14
+ <time>12:26:11</time>
15
+ <contents><target name="magelocal"><dir name="Adventos"><dir name="CustomizableId"><dir name="Helper"><file name="Data.php" hash="83f8320f8eb925bd98acc33c7776bf20"/></dir><dir name="etc"><file name="config.xml" hash="f29f8c002d9704e95c564cfe3826fb23"/><file name="system.xml" hash="a31a65e697f9e9d2bb7c10db054a5b11"/></dir></dir></dir><dir name="Mage"><dir name="Sales"><dir name="Model"><file name="Order.php" hash="2bb28909440da60bcd8f4e1e9444fe55"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Adventos_CustomizableId.xml" hash="7f6a53a16a0bf2ae65a4512312a39954"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>