Iglobal_Main - Version 1.2.0

Version Notes

New Features:
Duty & Fees Integrated into Tax
Order email can be sent from the store

Improvements:
Faster Speeds
Country Region Fixes
iGlobal Stores Updated API

Download this release

Release Info

Developer Matt Flamm
Extension Iglobal_Main
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.1 to 1.2.0

Files changed (36) hide show
  1. app/code/community/Iglobal/Fee/Block/Sales/Order/Total.php +0 -65
  2. app/code/community/Iglobal/Fee/Helper/Data.php +0 -8
  3. app/code/community/Iglobal/Fee/Model/Fee.php +0 -17
  4. app/code/community/Iglobal/Fee/Model/Observer.php +0 -28
  5. app/code/community/Iglobal/Fee/Model/Sales/Order/Total/Creditmemo/Fee.php +0 -17
  6. app/code/community/Iglobal/Fee/Model/Sales/Order/Total/Invoice/Fee.php +0 -17
  7. app/code/community/Iglobal/Fee/Model/Sales/Quote/Address/Total/Fee.php +0 -51
  8. app/code/community/Iglobal/Fee/etc/config.xml +0 -169
  9. app/code/community/Iglobal/Fee/sql/fee_setup/mysql4-install-0.1.0.php +0 -25
  10. app/code/community/Iglobal/Stores/Block/Link.php +26 -26
  11. app/code/community/Iglobal/Stores/Helper/Url.php +24 -24
  12. app/code/community/Iglobal/Stores/Model/International/International.php +48 -186
  13. app/code/community/Iglobal/Stores/Model/Observer.php +2 -2
  14. app/code/community/Iglobal/Stores/Model/Order.php +279 -0
  15. app/code/community/Iglobal/Stores/Model/Rest.php +75 -0
  16. app/code/community/Iglobal/Stores/Model/Rest/Order.php +0 -86
  17. app/code/community/Iglobal/Stores/Model/Rest/Region.php +0 -42
  18. app/code/community/Iglobal/Stores/Model/Sales/Quote/Address/Total/Fee.php +17 -0
  19. app/code/community/Iglobal/Stores/controllers/CheckoutController.php +42 -42
  20. app/code/community/Iglobal/Stores/controllers/InternationalController.php +0 -32
  21. app/code/community/Iglobal/Stores/controllers/SuccessController.php +50 -386
  22. app/code/community/Iglobal/Stores/etc/config.xml +10 -0
  23. app/code/community/Iglobal/Stores/etc/system.xml +79 -59
  24. app/design/adminhtml/default/default/layout/fee.xml +0 -56
  25. app/design/adminhtml/default/default/template/fee/sales/order/refunded.phtml +0 -16
  26. app/design/adminhtml/default/default/template/fee/sales/order/total.phtml +0 -9
  27. app/design/frontend/base/default/layout/fee.xml +0 -50
  28. app/design/frontend/base/default/template/iglobal/checkout/onepage/link.phtml +30 -30
  29. app/design/frontend/base/default/template/iglobal/stores/cart.phtml +21 -24
  30. app/etc/modules/Iglobal_Fee.xml +0 -9
  31. js/iGlobal/ig_welcome_mat_default.css +0 -41
  32. js/iGlobal/ig_welcome_mat_default.js +0 -867
  33. js/iGlobal/igc.cs.magento_default_ice.js +0 -203
  34. js/iGlobal/jquery/jquery.js +0 -9603
  35. js/iGlobal/jquery/jquery.noconflict.js +0 -1
  36. package.xml +14 -12
app/code/community/Iglobal/Fee/Block/Sales/Order/Total.php DELETED
@@ -1,65 +0,0 @@
1
- <?php
2
- class Iglobal_Fee_Block_Sales_Order_Total extends Mage_Core_Block_Template
3
- {
4
- /**
5
- * Get label cell tag properties
6
- *
7
- * @return string
8
- */
9
- public function getLabelProperties()
10
- {
11
- return $this->getParentBlock()->getLabelProperties();
12
- }
13
-
14
- /**
15
- * Get order store object
16
- *
17
- * @return Mage_Sales_Model_Order
18
- */
19
- public function getOrder()
20
- {
21
- return $this->getParentBlock()->getOrder();
22
- }
23
-
24
- /**
25
- * Get totals source object
26
- *
27
- * @return Mage_Sales_Model_Order
28
- */
29
- public function getSource()
30
- {
31
- return $this->getParentBlock()->getSource();
32
- }
33
-
34
- /**
35
- * Get value cell tag properties
36
- *
37
- * @return string
38
- */
39
- public function getValueProperties()
40
- {
41
- return $this->getParentBlock()->getValueProperties();
42
- }
43
-
44
- /**
45
- * Initialize reward points totals
46
- *
47
- * @return Enterprise_Reward_Block_Sales_Order_Total
48
- */
49
- public function initTotals()
50
- {
51
- if ((float) $this->getOrder()->getBaseFeeAmount()) {
52
- $source = $this->getSource();
53
- $value = $source->getFeeAmount();
54
-
55
- $this->getParentBlock()->addTotal(new Varien_Object(array(
56
- 'code' => 'fee',
57
- 'strong' => false,
58
- 'label' => Mage::helper('fee')->formatFee($value),
59
- 'value' => $source instanceof Mage_Sales_Model_Order_Creditmemo ? - $value : $value
60
- )));
61
- }
62
-
63
- return $this;
64
- }
65
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/Helper/Data.php DELETED
@@ -1,8 +0,0 @@
1
- <?php
2
-
3
- class Iglobal_Fee_Helper_Data extends Mage_Core_Helper_Abstract
4
- {
5
- public function formatFee($amount){
6
- return Mage::helper('fee')->__('Customs and Duty Tax');
7
- }
8
- }
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/Model/Fee.php DELETED
@@ -1,17 +0,0 @@
1
- <?php
2
- class Iglobal_Fee_Model_Fee extends Varien_Object{
3
-
4
- public static function getFee(){
5
- return 0;
6
- }
7
- public static function canApply($address){
8
- return true;
9
- //put here your business logic to check if fee should be applied or not
10
- $quote = $address->getQuote();
11
- if($quote->getFeeAmount()){
12
- return true;
13
- } else {
14
- return false;
15
- }
16
- }
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/Model/Observer.php DELETED
@@ -1,28 +0,0 @@
1
- <?php
2
- class Iglobal_Fee_Model_Observer{
3
- public function invoiceSaveAfter(Varien_Event_Observer $observer)
4
- {
5
- $invoice = $observer->getEvent()->getInvoice();
6
- if ($invoice->getBaseFeeAmount()) {
7
- $order = $invoice->getOrder();
8
- $order->setFeeAmountInvoiced($order->getFeeAmountInvoiced() + $invoice->getFeeAmount());
9
- $order->setBaseFeeAmountInvoiced($order->getBaseFeeAmountInvoiced() + $invoice->getBaseFeeAmount());
10
- }
11
- return $this;
12
- }
13
- public function creditmemoSaveAfter(Varien_Event_Observer $observer)
14
- {
15
- /* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
16
- $creditmemo = $observer->getEvent()->getCreditmemo();
17
- if ($creditmemo->getFeeAmount()) {
18
- $order = $creditmemo->getOrder();
19
- $order->setFeeAmountRefunded($order->getFeeAmountRefunded() + $creditmemo->getFeeAmount());
20
- $order->setBaseFeeAmountRefunded($order->getBaseFeeAmountRefunded() + $creditmemo->getBaseFeeAmount());
21
- }
22
- return $this;
23
- }
24
- public function updatePaypalTotal($evt){
25
- $cart = $evt->getPaypalCart();
26
- $cart->updateTotal(Mage_Paypal_Model_Cart::TOTAL_SUBTOTAL,$cart->getSalesEntity()->getFeeAmount());
27
- }
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/Model/Sales/Order/Total/Creditmemo/Fee.php DELETED
@@ -1,17 +0,0 @@
1
- <?php
2
- class Iglobal_Fee_Model_Sales_Order_Total_Creditmemo_Fee extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
3
- {
4
- public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
5
- {
6
- $order = $creditmemo->getOrder();
7
- $feeAmountLeft = $order->getFeeAmountInvoiced() - $order->getFeeAmountRefunded();
8
- $basefeeAmountLeft = $order->getBaseFeeAmountInvoiced() - $order->getBaseFeeAmountRefunded();
9
- if ($basefeeAmountLeft > 0) {
10
- $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $feeAmountLeft);
11
- $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $basefeeAmountLeft);
12
- $creditmemo->setFeeAmount($feeAmountLeft);
13
- $creditmemo->setBaseFeeAmount($basefeeAmountLeft);
14
- }
15
- return $this;
16
- }
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/Model/Sales/Order/Total/Invoice/Fee.php DELETED
@@ -1,17 +0,0 @@
1
- <?php
2
- class Iglobal_Fee_Model_Sales_Order_Total_Invoice_Fee extends Mage_Sales_Model_Order_Invoice_Total_Abstract
3
- {
4
- public function collect(Mage_Sales_Model_Order_Invoice $invoice)
5
- {
6
- $order = $invoice->getOrder();
7
- $feeAmountLeft = $order->getFeeAmount() - $order->getFeeAmountInvoiced();
8
- $baseFeeAmountLeft = $order->getBaseFeeAmount() - $order->getBaseFeeAmountInvoiced();
9
-
10
- $invoice->setGrandTotal($invoice->getGrandTotal() + $feeAmountLeft);
11
- $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseFeeAmountLeft);
12
-
13
- $invoice->setFeeAmount($feeAmountLeft);
14
- $invoice->setBaseFeeAmount($baseFeeAmountLeft);
15
- return $this;
16
- }
17
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/Model/Sales/Quote/Address/Total/Fee.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- class Iglobal_Fee_Model_Sales_Quote_Address_Total_Fee extends Mage_Sales_Model_Quote_Address_Total_Abstract{
3
- protected $_code = 'fee';
4
-
5
- public function collect(Mage_Sales_Model_Quote_Address $address)
6
- {
7
- parent::collect($address);
8
-
9
- $this->_setAmount(0);
10
- $this->_setBaseAmount(0);
11
-
12
- $items = $this->_getAddressItems($address);
13
- if (!count($items)) {
14
- return $this; //this makes only address type shipping to come through
15
- }
16
-
17
-
18
- $quote = $address->getQuote();
19
-
20
- if(Iglobal_Fee_Model_Fee::canApply($address)){
21
- $exist_amount = $quote->getFeeAmount();
22
- $fee = Iglobal_Fee_Model_Fee::getFee();
23
- $balance = $exist_amount; //$fee - $exist_amount;
24
- // $balance = $fee;
25
-
26
- //$this->_setAmount($balance);
27
- //$this->_setBaseAmount($balance);
28
-
29
- $address->setFeeAmount($balance);
30
- $address->setBaseFeeAmount($balance);
31
-
32
- $quote->setFeeAmount($balance);
33
-
34
- $address->setGrandTotal($address->getGrandTotal() + $address->getFeeAmount());
35
- $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseFeeAmount());
36
- }
37
- }
38
-
39
- public function fetch(Mage_Sales_Model_Quote_Address $address)
40
- {
41
- $amt = $address->getFeeAmount();
42
- if($amt != 0){
43
- $address->addTotal(array(
44
- 'code'=>$this->getCode(),
45
- 'title'=>Mage::helper('fee')->__('Customs Duty and Tax'),
46
- 'value'=> $amt
47
- ));
48
- }
49
- return $this;
50
- }
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/etc/config.xml DELETED
@@ -1,169 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Iglobal_Fee>
5
- <version>0.1.0</version>
6
- </Iglobal_Fee>
7
- </modules>
8
- <frontend>
9
- <routers>
10
- <fee>
11
- <use>standard</use>
12
- <args>
13
- <module>Iglobal_Fee</module>
14
- <frontName>fee</frontName>
15
- </args>
16
- </fee>
17
- </routers>
18
- <layout>
19
- <updates>
20
- <fee>
21
- <file>fee.xml</file>
22
- </fee>
23
- </updates>
24
- </layout>
25
- </frontend>
26
- <admin>
27
- <routers>
28
- <fee>
29
- <use>admin</use>
30
- <args>
31
- <module>Iglobal_Fee</module>
32
- <frontName>fee</frontName>
33
- </args>
34
- </fee>
35
- </routers>
36
- </admin>
37
- <adminhtml>
38
- <layout>
39
- <updates>
40
- <fee>
41
- <file>fee.xml</file>
42
- </fee>
43
- </updates>
44
- </layout>
45
- </adminhtml>
46
- <global>
47
- <sales>
48
- <quote>
49
- <totals>
50
- <fee>
51
- <class>fee/sales_quote_address_total_fee</class>
52
- <before>subtotal</before>
53
- </fee>
54
- </totals>
55
- </quote>
56
- <order_invoice>
57
- <totals>
58
- <fee>
59
- <class>fee/sales_order_total_invoice_fee</class>
60
- <before>subtotal</before>
61
- </fee>
62
- </totals>
63
- </order_invoice>
64
- <order_creditmemo>
65
- <totals>
66
- <fee>
67
- <class>fee/sales_order_total_creditmemo_fee</class>
68
- <before>subtotal</before>
69
- </fee>
70
- </totals>
71
- </order_creditmemo>
72
- </sales>
73
- <events>
74
- <paypal_prepare_line_items>
75
- <observers>
76
- <paypal_prepare_line_items>
77
- <class>fee/observer</class>
78
- <method>updatePaypalTotal</method>
79
- </paypal_prepare_line_items>
80
- </observers>
81
- </paypal_prepare_line_items>
82
- <sales_order_invoice_save_after>
83
- <observers>
84
- <sales_order_invoice_save_after>
85
- <class>fee/observer</class>
86
- <method>invoiceSaveAfter</method>
87
- </sales_order_invoice_save_after>
88
- </observers>
89
- </sales_order_invoice_save_after>
90
- <sales_order_creditmemo_save_after>
91
- <observers>
92
- <sales_order_creditmemo_save_after>
93
- <class>fee/observer</class>
94
- <method>creditmemoSaveAfter</method>
95
- </sales_order_creditmemo_save_after>
96
- </observers>
97
- </sales_order_creditmemo_save_after>
98
- </events>
99
- <fieldsets>
100
- <sales_convert_quote_address>
101
- <fee_amount><to_order>*</to_order></fee_amount>
102
- <base_fee_amount><to_order>*</to_order></base_fee_amount>
103
- </sales_convert_quote_address>
104
- </fieldsets>
105
- <pdf>
106
- <totals>
107
- <fee translate="title">
108
- <title>Fee</title>
109
- <source_field>fee_amount</source_field>
110
- <font_size>7</font_size>
111
- <display_zero>0</display_zero>
112
- <sort_order>650</sort_order>
113
- <amount_prefix>-</amount_prefix>
114
- </fee>
115
- </totals>
116
- </pdf>
117
- <models>
118
- <fee>
119
- <class>Iglobal_Fee_Model</class>
120
- <resourceModel>fee_mysql4</resourceModel>
121
- </fee>
122
- <fee_mysql4>
123
- <class>Iglobal_Fee_Model_Mysql4</class>
124
- <entities>
125
- <fee>
126
- <table>fee</table>
127
- </fee>
128
- </entities>
129
- </fee_mysql4>
130
- </models>
131
- <resources>
132
- <fee_setup>
133
- <setup>
134
- <module>Iglobal_Fee</module>
135
- </setup>
136
- <connection>
137
- <use>core_setup</use>
138
- </connection>
139
- </fee_setup>
140
- <fee_write>
141
- <connection>
142
- <use>core_write</use>
143
- </connection>
144
- </fee_write>
145
- <fee_read>
146
- <connection>
147
- <use>core_read</use>
148
- </connection>
149
- </fee_read>
150
- </resources>
151
- <blocks>
152
- <fee>
153
- <class>Iglobal_Fee_Block</class>
154
- </fee>
155
- </blocks>
156
- <helpers>
157
- <fee>
158
- <class>Iglobal_Fee_Helper</class>
159
- </fee>
160
- </helpers>
161
- </global>
162
- <default>
163
- <sales>
164
- <totals_sort>
165
- <fee>15</fee>
166
- </totals_sort>
167
- </sales>
168
- </default>
169
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Fee/sql/fee_setup/mysql4-install-0.1.0.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
-
3
- $installer = $this;
4
-
5
- $installer->startSetup();
6
-
7
- $installer->run("
8
-
9
- ALTER TABLE `".$this->getTable('sales/order')."` ADD `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
10
- ALTER TABLE `".$this->getTable('sales/order')."` ADD `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;
11
- ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
12
- ALTER TABLE `".$this->getTable('sales/quote_address')."` ADD `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;
13
- ALTER TABLE `".$this->getTable('sales/order')."` ADD `fee_amount_invoiced` DECIMAL( 10, 2 ) NOT NULL;
14
- ALTER TABLE `".$this->getTable('sales/order')."` ADD `base_fee_amount_invoiced` DECIMAL( 10, 2 ) NOT NULL;
15
- ALTER TABLE `".$this->getTable('sales/invoice')."` ADD `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
16
- ALTER TABLE `".$this->getTable('sales/invoice')."` ADD `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;
17
- ALTER TABLE `".$this->getTable('sales/order')."` ADD `fee_amount_refunded` DECIMAL( 10, 2 ) NOT NULL;
18
- ALTER TABLE `".$this->getTable('sales/order')."` ADD `base_fee_amount_refunded` DECIMAL( 10, 2 ) NOT NULL;
19
- ALTER TABLE `".$this->getTable('sales/creditmemo')."` ADD `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
20
- ALTER TABLE `".$this->getTable('sales/creditmemo')."` ADD `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;
21
-
22
-
23
- ");
24
-
25
- $installer->endSetup();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Stores/Block/Link.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
-
3
- //this block override returns the url to be used on the primary checkout buttons on the cart page.
4
- //If you are using a custom checkout then this may or may not still work.
5
- //If not, you will need to find how the checkout determines the url, and apply a similar method.
6
- // also refer to ../Helper/Url.php
7
-
8
- class Iglobal_Stores_Block_Link extends Mage_Checkout_Block_Onepage_Link
9
- {
10
- function getCheckoutUrl()
11
- {
12
- //$this->setTemplate('iglobal/checkout/onepage/link.phtml');
13
- //check if the country is international
14
- $countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
15
- $domesticCountries = explode(",", Mage::getStoreConfig('general/country/ig_domestic_countries'));
16
- $isDomestic = in_array ($countryCode, $domesticCountries) ? true : false;
17
-
18
- //return the url
19
-
20
- if (Mage::getStoreConfig('iglobal_integration/igmat/welcome_mat_active') && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle') && Mage::getStoreConfig('iglobal_integration/apireqs/use_iframe') && !$isDomestic){//!$isDomestic && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle')){
21
- //return "if(!ig_isDomesticCountry()){window.location.replace (' " . $this->getUrl('iglobal/checkout', array('_secure'=>true)) . "');} else {window.location.replace ('" . $this->getUrl('checkout/onepage', array('_secure'=>true)) . "');}";
22
- return $this->getUrl('iglobal/checkout', array('_secure'=>true));
23
- } else {
24
- return $this->getUrl('checkout/onepage', array('_secure'=>true));
25
- }
26
- }
27
  }
1
+ <?php
2
+
3
+ //this block override returns the url to be used on the primary checkout buttons on the cart page.
4
+ //If you are using a custom checkout then this may or may not still work.
5
+ //If not, you will need to find how the checkout determines the url, and apply a similar method.
6
+ // also refer to ../Helper/Url.php
7
+
8
+ class Iglobal_Stores_Block_Link extends Mage_Checkout_Block_Onepage_Link
9
+ {
10
+ function getCheckoutUrl()
11
+ {
12
+ //$this->setTemplate('iglobal/checkout/onepage/link.phtml');
13
+ //check if the country is international
14
+ $countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
15
+ $domesticCountries = explode(",", Mage::getStoreConfig('general/country/ig_domestic_countries'));
16
+ $isDomestic = in_array ($countryCode, $domesticCountries) ? true : false;
17
+
18
+ //return the url
19
+
20
+ if (Mage::getStoreConfig('iglobal_integration/igmat/welcome_mat_active') && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle') && Mage::getStoreConfig('iglobal_integration/apireqs/use_iframe') && !$isDomestic){//!$isDomestic && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle')){
21
+ //return "if(!ig_isDomesticCountry()){window.location.replace (' " . $this->getUrl('iglobal/checkout', array('_secure'=>true)) . "');} else {window.location.replace ('" . $this->getUrl('checkout/onepage', array('_secure'=>true)) . "');}";
22
+ return $this->getUrl('iglobal/checkout', array('_secure'=>true));
23
+ } else {
24
+ return $this->getUrl('checkout/onepage', array('_secure'=>true));
25
+ }
26
+ }
27
  }
app/code/community/Iglobal/Stores/Helper/Url.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- class Iglobal_Stores_Helper_Url extends Mage_Checkout_Helper_Url
3
- {
4
-
5
- function getCheckoutUrl()
6
- {
7
- //check if the country is international
8
- $countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
9
- $domesticCountries = explode(",", Mage::getStoreConfig('general/country/ig_domestic_countries'));
10
- $isDomestic = in_array ($countryCode, $domesticCountries) ? 1 : 0;
11
-
12
- //return the url
13
- if (Mage::getStoreConfig('iglobal_integration/igmat/welcome_mat_active') && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle') && Mage::getStoreConfig('iglobal_integration/apireqs/use_iframe')){// check for welcome mat //!$isDomestic && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle')){ // add checks for other admin configs
14
-
15
- // make this a javascript url
16
- return "javascript:if(!ig_isDomesticCountry()){window.location.replace (' " . $this->_getUrl('iglobal/checkout') . "');} else {window.location.replace ('" . $this->_getUrl('checkout/onepage') . "');}";
17
- //return "javascript:if(!ig_isDomesticCountry()){window.location.replace ('{$this->_getUrl('iglobal/checkout')}')return false;} else {window.location.replace ('{$this->_getUrl('checkout/onepage')}";
18
- //return $this->_getUrl('iglobal/checkout');
19
- } else {
20
- return $this->_getUrl('checkout/onepage');
21
- }
22
- }
23
-
24
- }
1
+ <?php
2
+ class Iglobal_Stores_Helper_Url extends Mage_Checkout_Helper_Url
3
+ {
4
+
5
+ function getCheckoutUrl()
6
+ {
7
+ //check if the country is international
8
+ $countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
9
+ $domesticCountries = explode(",", Mage::getStoreConfig('general/country/ig_domestic_countries'));
10
+ $isDomestic = in_array ($countryCode, $domesticCountries) ? 1 : 0;
11
+
12
+ //return the url
13
+ if (Mage::getStoreConfig('iglobal_integration/igmat/welcome_mat_active') && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle') && Mage::getStoreConfig('iglobal_integration/apireqs/use_iframe')){// check for welcome mat //!$isDomestic && Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle')){ // add checks for other admin configs
14
+
15
+ // make this a javascript url
16
+ return "javascript:if(!ig_isDomesticCountry()){window.location.replace (' " . $this->_getUrl('iglobal/checkout') . "');} else {window.location.replace ('" . $this->_getUrl('checkout/onepage') . "');}";
17
+ //return "javascript:if(!ig_isDomesticCountry()){window.location.replace ('{$this->_getUrl('iglobal/checkout')}')return false;} else {window.location.replace ('{$this->_getUrl('checkout/onepage')}";
18
+ //return $this->_getUrl('iglobal/checkout');
19
+ } else {
20
+ return $this->_getUrl('checkout/onepage');
21
+ }
22
+ }
23
+
24
+ }
app/code/community/Iglobal/Stores/Model/International/International.php CHANGED
@@ -1,187 +1,49 @@
1
- <?php
2
-
3
-
4
- class Iglobal_Stores_Model_International_International extends Mage_Core_Model_Abstract
5
- {
6
- protected $_entryPoint = null;
7
-
8
- protected function _construct()
9
- {
10
-
11
-
12
- }
13
-
14
- public function setParameters ($client) {
15
-
16
- //get all the items in the cart
17
- $cart = Mage::getModel('checkout/cart')->getQuote();
18
- //start a loop to set each one
19
- //$i = 0;
20
- foreach ($cart->getAllVisibleItems() as $index=>$item) {
21
- $itemNumber = ++$index;
22
- // This is because Magento fails to load the custom attributes hence we have to go back to the DB.
23
- $weight = "";
24
- $length = "";
25
- $width = "";
26
- $height = "";
27
-
28
- try {
29
- $allItemData = Mage::getModel('catalog/product')->load($item['product_id']);
30
- $weightUnits = "";
31
- $dimUnits = "";
32
-
33
- try {
34
- $weightUnits = "";
35
- if (!empty($allItemData['ig_weight_units'])) {
36
- $weightUnits = $allItemData->getAttributeText('ig_weight_units');
37
- }
38
- } catch (Exception $e) {
39
- $weightUnits = "";
40
- }
41
-
42
- try {
43
- $weight = "";
44
- if (!empty($allItemData['ig_weight'])) {
45
- $weight = $allItemData->getData('ig_weight');
46
- } else if (!empty($allItemData['weight'])) {
47
- $weight = $item->getWeight();
48
- }
49
-
50
- if (!empty($weight)) {
51
- if ($weightUnits=="kg") {
52
- $weight = round(floatval($weight) / 0.453592, 2);
53
- } else if ($weightUnits=="oz") {
54
- $weight = round(floatval($weight) / 16, 2);
55
- } else if ($weightUnits=="g") {
56
- $weight = round(floatval($weight) / 453.592, 2);
57
- } else {//Default is lbs
58
- $weight = round(floatval($weight), 2);
59
- }
60
- } else {
61
- $weight = "";
62
- }
63
- } catch(Exception $e) {
64
- $weight = "";
65
- }
66
-
67
- try {
68
- $dimUnits = "";
69
- if (!empty($allItemData['ig_dimension_units'])) {
70
- $dimUnits = $allItemData->getAttributeText('ig_dimension_units');
71
- }
72
- } catch (Exception $e) {
73
- $dimUnits = "";
74
- }
75
- try {
76
- $length = "";
77
- if (!empty($allItemData['ig_length'])) {
78
- $length = $allItemData->getData('ig_length');
79
- }
80
- $width = "";
81
- if (!empty($allItemData['ig_width'])) {
82
- $width = $allItemData->getData('ig_width');
83
- }
84
- $height = "";
85
- if (!empty($allItemData['ig_height'])) {
86
- $height = $allItemData->getData('ig_height');
87
- }
88
- if (!empty($length) && !empty($width) && !empty($height)) {
89
- if ($dimUnits=="cm") {
90
- $length = ceil(floatval($length) / 2.54);
91
- $width = ceil(floatval($width) / 2.54);
92
- $height = ceil(floatval($height) / 2.54);
93
- } else {//Default is inches
94
- $length = ceil(floatval($length));
95
- $width = ceil(floatval($width));
96
- $height = ceil(floatval($height));
97
- }
98
- } else {
99
- $length = "";
100
- $width = "";
101
- $height = "";
102
- }
103
- } catch(Exception $e) {
104
- $length = "";
105
- $width = "";
106
- $height = "";
107
- }
108
- } catch (Exception $outerE) {
109
-
110
- }
111
-
112
- $itemId = $item->getProductId();
113
- $itemName = $item->getName();
114
- $itemSku = $item->getProduct()->getTypeId() == 'bundle' ? substr($item->getSku(), strpos($item->getSku(), '-')+1) : $item->getSku();
115
- $itemQty = $item->getQty();
116
- $itemPrice = $item->getPrice();
117
- $itemProductUrl = Mage::getModel('catalog/product')->load($item->getProductId())->getProductUrl();
118
- $itemImageUrl = str_replace("http:", "https:",Mage::helper('catalog/image')->init($item->getProduct(), 'thumbnail'));
119
- $itemDescription = Mage::getModel('catalog/product')->load($item->getProductId())->getDescription();
120
- $itemShortDescription = Mage::getModel('catalog/product')->load($item->getProductId())->getDescription();
121
- $itemMageWeight = $item->getWeight();
122
- $itemIgWeight = $weight;
123
- $itemIgLength = $length;
124
- $itemIgWidth = $width;
125
- $itemIgHeight = $height;
126
-
127
- if($itemId) $client->setParameterPost('itemProductId'.$itemNumber, $itemId);
128
- if($itemName) $client->setParameterPost('itemDescription'.$itemNumber, $itemName);
129
- if($itemSku) $client->setParameterPost('itemSku'.$itemNumber, $itemSku);
130
- if($itemQty) $client->setParameterPost('itemQuantity'.$itemNumber, $itemQty);
131
- if($itemPrice) $client->setParameterPost('itemUnitPrice'.$itemNumber, $itemPrice);
132
- if($itemProductUrl) $client->setParameterPost('itemURL'.$itemNumber, $itemProductUrl);
133
- if($itemImageUrl) $client->setParameterPost('itemImageURL'.$itemNumber, $itemImageUrl);
134
- if($itemDescription) $client->setParameterPost('itemDescription'.$itemNumber, $itemDescription);
135
- //if($itemShortDescription) $client->setParameterPost('itemProductIdN'.$itemNumber, $itemShortDescription);
136
- if($itemIgLength) $client->setParameterPost('itemLength'.$itemNumber, $itemIgLength);
137
- if($itemIgWidth) $client->setParameterPost('itemWidth'.$itemNumber, $itemIgWidth);
138
- if($itemIgHeight) $client->setParameterPost('itemHeight'.$itemNumber, $itemIgHeight);
139
- if($itemIgWeight) {
140
- $client->setParameterPost('itemWeight'.$itemNumber, $itemIgWeight);
141
- } elseif ($itemMageWeight) {
142
- $client->setParameterPost('itemWeight'.$itemNumber, $itemMageWeight);
143
- }
144
-
145
- }
146
- }
147
-
148
- public function getTempCartId ()
149
- {
150
- //build a POST and return the response
151
-
152
- $storeNumber = Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid');
153
-
154
- $client = new Varien_Http_Client('https://checkout.iglobalstores.com/iglobalstores/services/TempCartService');
155
- $client->setMethod(Varien_Http_Client::POST);
156
-
157
- $client->setParameterPost('store', $storeNumber);
158
- $this->setParameters($client);
159
-
160
- //$client->setParameterPost('itemDescription1', 'My item for testing temp carts');
161
- //$client->setParameterPost('itemQuantity1', '1');
162
- //$client->setParameterPost('itemUnitPrice1', '123.45');
163
- //set the parameters in a loop
164
-
165
- //$client->setParameterPost('address', '123 fake st');//$address);
166
- //$client->setParameterPost('address', $address);
167
-
168
- //more parameters
169
- //Zend_Debug::dump($client);
170
-
171
- Mage::log("the client data" . print_r($client, true), null, 'international.log', true);
172
-
173
- try{
174
- $response = $client->request();
175
- if ($response->isSuccessful()) {
176
- return $response->getBody();
177
- }
178
- } catch (Exception $e) {
179
- die($e);
180
- }
181
-
182
-
183
- echo "I'm in the function!";
184
- }
185
-
186
- }
187
  ?>
1
+ <?php
2
+
3
+
4
+ class Iglobal_Stores_Model_International_International extends Mage_Core_Model_Abstract
5
+ {
6
+ public function getTempCartId ()
7
+ {
8
+
9
+ //get all the items in the cart
10
+ $cart = Mage::getModel('checkout/cart')->getQuote();
11
+ $items = array();
12
+
13
+ foreach ($cart->getAllVisibleItems() as $index=>$item) {
14
+ $product = $item->getProduct();
15
+ $sku = $item->getSku();
16
+ $dimUnits = $product->getIgDemesionUnits();
17
+ $dim2inch = ['cm' => 2.54, 'in' => 1, '' => 1];
18
+ $weight = $product->getIgWeight();
19
+ if (empty($weight))
20
+ {
21
+ $weight = $item->getWeight();
22
+ }
23
+
24
+ $items[] = [
25
+ "description" => $item->getName(),
26
+ "productId" => $item->getProductId(),
27
+ "sku" => $product->getTypeId() == 'bundle' ? substr($sku, strpos($sku, '-') + 1) : $sku,
28
+ "unitPrice" => $item->getPrice(),
29
+ "quantity" => $item->getQty(),
30
+ "length" => ceil(floatval($product->getIgLength()) / $dim2inch[$dimUnits]),
31
+ "width" => ceil(floatval($product->getIgWidth()) / $dim2inch[$dimUnits]),
32
+ "height" => ceil(floatval($product->getIgHeight()) / $dim2inch[$dimUnits]),
33
+ "weight" => $weight,
34
+ "weightUnits" => strtoupper($product->getIgWeightUnits()),
35
+ "itemURL" => $product->getProductUrl(),
36
+ "imageURL" => str_replace("http:", "https:", Mage::helper('catalog/image')->init($product, 'thumbnail')),
37
+ "itemDescriptionLong" => $product->getDescription(),
38
+
39
+ ];
40
+ }
41
+
42
+ $rest = Mage::getModel('stores/rest');
43
+ $response = $rest->createTempCart([
44
+ "storeId" =>Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid'),
45
+ "items" => $items,]);
46
+ return $response->tempCartUUID;
47
+ }
48
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ?>
app/code/community/Iglobal/Stores/Model/Observer.php CHANGED
@@ -86,11 +86,11 @@ class Iglobal_Stores_Model_Observer
86
  public function orderRec () {
87
 
88
  //get array with all orders in past
89
- $rest = Mage::getModel('stores/rest_order'); // get rest model
90
 
91
  //fetch all orders for the store from iGlobal server
92
  $data = $rest->getAllOrdersSinceDate('20140526');
93
- $orderData = $data['order'];
94
  $restOrders = array();
95
 
96
  //build array of orders with keypairs "ig_order_number" => "the number as a string"
86
  public function orderRec () {
87
 
88
  //get array with all orders in past
89
+ $rest = Mage::getModel('stores/rest'); // get rest model
90
 
91
  //fetch all orders for the store from iGlobal server
92
  $data = $rest->getAllOrdersSinceDate('20140526');
93
+ $orderData = $data['order'];
94
  $restOrders = array();
95
 
96
  //build array of orders with keypairs "ig_order_number" => "the number as a string"
app/code/community/Iglobal/Stores/Model/Order.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iglobal_Stores_Model_Order extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $quote = null;
6
+ protected $iglobal_order_id = null;
7
+ protected $iglobal_order = null;
8
+ protected $rest = null;
9
+ public function setQuote($quote)
10
+ {
11
+ $this->quote = $quote;
12
+ }
13
+
14
+ public function processOrder($orderid)
15
+ {
16
+ $this->iglobal_order_id = $orderid;
17
+ $this->rest = Mage::getModel('stores/rest');
18
+ $this->iglobal_order = $this->rest->getOrder($this->iglobal_order_id)->order;
19
+ Mage::register('duty_tax', $this->iglobal_order->dutyTaxesTotal);
20
+ $shippingAddress = $this->setContactInfo();
21
+ $shippingAddress = $this->setShipping($shippingAddress);
22
+ $this->setPayment($shippingAddress);
23
+ return $this->createOrder();
24
+ }
25
+
26
+ protected function setContactInfo()
27
+ {
28
+ //set customer info
29
+ $this->quote->setCustomerEmail($this->iglobal_order->email);
30
+
31
+ $_name = explode(' ', $this->iglobal_order->name, 2);
32
+ if ($this->iglobal_order->testOrder) {
33
+ $name_first = "TEST ORDER! DO NOT SHIP! - " . array_shift($_name);
34
+ $name_last = array_pop($_name);
35
+ } else {
36
+ $name_first = array_shift($_name);
37
+ $name_last = array_pop($_name);
38
+ }
39
+
40
+ $this->quote->setCustomerFirstname($name_first);
41
+ $this->quote->setCustomerLastname($name_last);
42
+
43
+ $street = $this->iglobal_order->address1;
44
+ if ($this->iglobal_order->address2)
45
+ {
46
+ $street = array($street, $this->iglobal_order->address2);
47
+ }
48
+
49
+ $region = Mage::getModel('directory/region')
50
+ ->loadbyName($this->iglobal_order->state, $this->iglobal_order->countryCode);
51
+ if (!$region->getId())
52
+ {
53
+ // Lookup region from iGlobalstores
54
+ $regionId = $this->rest->getRegionId(
55
+ $this->iglobal_order->countryCode,
56
+ $this->iglobal_order->state,
57
+ $this->iglobal_order_id);
58
+ $region->load($regionId);
59
+ if (!$region->getId())
60
+ {
61
+ // Create a new region
62
+ $region->setData([
63
+ 'country_id' => $this->iglobal_order->countryCode,
64
+ 'defalt_name' => $this->iglobal_order->state
65
+ ])->save();
66
+
67
+ }
68
+ }
69
+
70
+ $addressData = array(
71
+ 'firstname' => $name_first,
72
+ 'lastname' => $name_last,
73
+ 'street' => $street,
74
+ 'city' => $this->iglobal_order->city,
75
+ 'postcode' => $this->iglobal_order->zip,
76
+ 'telephone' => $this->iglobal_order->phone,
77
+ 'region' => $this->iglobal_order->state,
78
+ 'region_id' => $region->getId(),
79
+ 'country_id' => $this->iglobal_order->countryCode,
80
+ 'company' => '',//$this->iglobal_order->company,
81
+ );
82
+
83
+ if (!empty($this->iglobal_order->billingAddress1)) {
84
+ $_nameBilling = explode(' ', $this->iglobal_order->billingName, 2);
85
+ if ($this->iglobal_order->testOrder) {
86
+ $name_first_billing = "TEST ORDER! DO NOT SHIP! - " . array_shift($_nameBilling);
87
+ $name_last_billing = array_pop($_nameBilling);
88
+ } else {
89
+ $name_first_billing = array_shift($_nameBilling);
90
+ $name_last_billing = array_pop($_nameBilling);
91
+ }
92
+
93
+ $streetBilling = $this->iglobal_order->billingAddress1;
94
+ if ($this->iglobal_order->billingAddress2) {
95
+ $streetBilling = array($streetBilling, $this->iglobal_order->billingAddress2);
96
+ }
97
+
98
+ $billingAddressData = array(
99
+ 'firstname' => $name_first_billing,
100
+ 'lastname' => $name_last_billing,
101
+ 'street' => $streetBilling,
102
+ 'city' => $this->iglobal_order->billingCity,
103
+ 'postcode' => $this->iglobal_order->billingZip,
104
+ 'telephone' => $this->iglobal_order->billingPhone,
105
+ 'region' => $this->iglobal_order->state,
106
+ 'region_id' => $region->getId(),
107
+ 'country_id' => $this->iglobal_order->billingCountryCode,
108
+ );
109
+
110
+ } else {
111
+ $billingAddressData = $addressData;
112
+ }
113
+
114
+ if (Mage::getStoreConfig('iglobal_integration/igjq/iglogging'))
115
+ {
116
+ Mage::log('address data for order {$this->iglobal_order_id}: ' . print_r($addressData, true), null, 'iglobal.log', true);
117
+ Mage::log('billing address data for order {$this->iglobal_order_id}: ' . print_r($billingAddressData, true), null, 'iglobal.log', true);
118
+ }
119
+
120
+ $this->quote->getBillingAddress()->addData($billingAddressData);
121
+ $shippingAddress = $this->quote->getShippingAddress()->addData($addressData);
122
+ return $shippingAddress;
123
+ }
124
+
125
+ protected function setItems()
126
+ {
127
+ // @todo pull in the item details in case they have changed.
128
+ }
129
+
130
+ protected function setShipping($shippingAddress)
131
+ {
132
+ //Figure out shipping carrier name etc.
133
+ $shippers = [
134
+ 'DHL_EXPRESS' => ['DHL', 'Express - iGlobal'],
135
+ 'DHL_GLOBAL_MAIL'=> ['DHL', 'Global Mail - iGlobal'],
136
+ 'FEDEX_ECONOMY'=> ['FedExl', 'Economy - iGlobal'],
137
+ 'FEDEX_GROUND'=> ['FedEx', 'Ground - iGlobal'],
138
+ 'FEDEX_PRIORITY'=> ['FedEx', 'Priority - iGlobal'],
139
+ 'UPS_EXPEDITED'=> ['UPS', 'Expedited - iGlobal'],
140
+ 'UPS_EXPRESS'=> ['UPS', 'Express - iGlobal'],
141
+ 'UPS_EXPRESS_SAVER' => ['UPS', 'Express Saver - iGlobal'],
142
+ 'UPS_GROUND' => ['UPS', 'Canada Ground - iGlobal'],
143
+ 'UPS_STANDARD'=> ['UPS', 'Canada Standard - iGlobal'],
144
+ 'USPS_FIRST_CLASS_MAIL_INTERNATIONAL'=> ['USPS', 'First Class Mail, International - iGlobal'],
145
+ 'USPS_PRIORITY_MAIL_EXPRESS_INTERNATIONAL'=> ['USPS', 'Priority Mail Express, International - iGlobal'],
146
+ 'USPS_PRIORITY_MAIL_INTERNATIONAL'=> ['USPS', 'Priority Mail, International - iGlobal'],
147
+ 'APC_EXPEDITED_MAIL'=> ['UPS', 'APC Expedited 3-5 Days - iGlobal'],
148
+ 'APC_PRIORITY_MAIL'=> ['UPS', 'APC Priority Mail 4-9 Days - iGlobal'],
149
+ 'CANADA_POST_EXPEDITED'=> ['UPS', 'Canada Post Expedited - iGlobal'],
150
+ 'FEDEX_IPD'=> ['UPS', 'FedEx IPD - iGlobal'],
151
+ 'UPS_2ND_DAY_AIR'=> ['UPS', 'UPS 2 Day Air - iGlobal'],
152
+ 'UPS_3_DAY_AIR'=> ['UPS', 'UPS 3 Day Air - iGlobal'],
153
+ 'UPS_FREIGHT'=> ['UPS', 'UPS Freight - iGlobal'],
154
+ 'UPS_MAIL_INNOVATIONS'=> ['UPS', 'Bodyguardz - UPS Mail Innovations - iGlobal'],
155
+ 'UPS_NEXT_DAY_AIR_SAVER'=>['UPS', 'UPS Next Day Air Saver - iGlobal'],
156
+ 'UPS_WORLDEASE'=> ['UPS', 'UPS WorldEase - iGlobal'],
157
+ 'USPS_EPACKET'=> ['UPS', 'USPS ePacket - iGlobal'],
158
+ 'USPS_EXPRESS_1'=> ['UPS', 'Express 1 Mail - iGlobal'],
159
+ 'USPS_IPA'=> ['UPS', 'USPS IPA - iGlobal'],
160
+ 'LANDMARK_LGINTREGU' => ['iGlobal', 'Landmark'],
161
+ 'LANDMARK_LGINTSTD' => ['iGlobal', 'Landmark'],
162
+ 'LANDMARK_LGINTSTDU' => ['iGlobal', 'Landmark'],
163
+ 'MSI_PARCEL' => ['iGlobal', 'Landmark'],
164
+ 'MSI_PRIORITY' => ['iGlobal', 'Landmark'],
165
+ 'default' => ['iGlobal', 'International Shipping'],
166
+ ];
167
+ $carrierMethod = $this->iglobal_order->shippingCarrierServiceLevel;
168
+ if (!isset($shippers[$carrierMethod]))
169
+ {
170
+ $carrierMethod = 'default';
171
+ }
172
+ $shipper = $shippers[$carrierMethod];
173
+
174
+ //Add things to the register so they can be used by the shipping method
175
+ Mage::register('shipping_cost', $this->iglobal_order->shippingTotal);
176
+ Mage::register('shipping_carriertitle', $shipper[0]);
177
+ Mage::register('shipping_methodtitle', $shipper[1]);
178
+ $shippingAddress->setCollectShippingRates(true)
179
+ ->collectShippingRates()
180
+ ->setShippingMethod('excellence_excellence');
181
+ return $shippingAddress;
182
+ }
183
+
184
+ protected function setPayment($address)
185
+ {
186
+ $address->setPaymentMethod('iGlobalCreditCard');
187
+
188
+ //updates payment type in Magento Admin area
189
+ $paymentMethod = $this->iglobal_order->paymentProcessing->paymentGateway;
190
+ if($paymentMethod === 'iGlobal_CC'){
191
+ $paymentType = 'iGlobalCreditCard';
192
+ } else if ($paymentMethod === 'iGlobal PayPal') {
193
+ $paymentType = 'iGlobalPaypal';
194
+ } else {
195
+ $paymentType = 'iGlobal';
196
+ }
197
+
198
+ $this->quote->getPayment()->importData(array('method' => $paymentType));
199
+ }
200
+
201
+ protected function createOrder()
202
+ {
203
+
204
+ $this->quote->collectTotals()->save();
205
+ $this->quote->setIsActive(0)->save();
206
+
207
+ $service = Mage::getModel('stores/service_quote', $this->quote);
208
+ $service->submitAll();
209
+ $order = $service->getOrder();
210
+
211
+ // cleaning up
212
+ Mage::getSingleton('checkout/session')->clear();
213
+
214
+ $id = $order->getEntityId();
215
+
216
+ if (!Mage::helper('sales')->canSendNewOrderEmail($storeId) && Mage::getStoreConfig('iglobal_integration/apireqs/send_order_email')) {
217
+ $order->sendNewOrderEmail();
218
+ }
219
+ Mage::getSingleton('checkout/session')->setLastOrderId($order->getId());
220
+ Mage::getSingleton('checkout/session')->setLastRealOrderId($order->getIncrementId());
221
+
222
+
223
+ $transId = Mage::getSingleton('checkout/session')->getLastRealOrderId($order->getIncrementId());
224
+ //Save Order Invoice as paid
225
+ $commentMessage = 'Order automatically imported from iGlobal order ID: '. $this->iglobal_order_id;
226
+
227
+ try {
228
+ $order = Mage::getModel("sales/order")->load($id);
229
+ //add trans ID
230
+ $transaction_id = '34234234234'; //todo: this needs to be set dynamically
231
+ $transaction = Mage::getModel('sales/order_payment_transaction');
232
+ $transaction->setOrderPaymentObject($order->getPayment());
233
+ $transaction->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
234
+ $transaction->setTxnId($transaction_id);
235
+ $transaction->save();
236
+
237
+ $invoices = Mage::getModel('sales/order_invoice')->getCollection()->addAttributeToFilter('order_id', array('eq'=>$order->getId()));
238
+ $invoices->getSelect()->limit(1);
239
+ if ((int)$invoices->count() == 0 && $order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
240
+ if(!$order->canInvoice()) {
241
+ $order->addStatusHistoryComment($commentMessage, false);
242
+ $order->addStatusHistoryComment('iGlobal: Order cannot be invoiced', false);
243
+ $order->save();
244
+ } else {
245
+ $order->addStatusHistoryComment($commentMessage, false);
246
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
247
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
248
+ $invoice->register();
249
+ $invoice->getOrder()->setCustomerNoteNotify(false);
250
+ $invoice->getOrder()->setIsInProcess(true);
251
+ $order->addStatusHistoryComment('Automatically INVOICED by iGlobal', false);
252
+ $transactionSave = Mage::getModel('core/resource_transaction')
253
+ ->addObject($invoice)
254
+ ->addObject($invoice->getOrder());
255
+ $transactionSave->save();
256
+ }
257
+ }
258
+ } catch (Exception $e) {
259
+ $order->addStatusHistoryComment('iGlobal Invoicer: Exception occurred during automatically invoicing. Exception message: '.$e->getMessage(), false);
260
+ $order->save();
261
+ }
262
+ $tableName = Mage::getSingleton("core/resource")->getTableName("sales_flat_order");
263
+ if ($this->iglobal_order->testOrder) {
264
+ //Set the international_order flag and the ig_order_number on the order and mark as a test order
265
+ $query = "UPDATE `" . $tableName . "` SET `international_order` = 1, `ig_order_number` = '{$this->iglobal_order_id}', `iglobal_test_order` = 1 WHERE `entity_id` = '{$id}'";
266
+ Mage::getSingleton('core/resource')->getConnection('core_write')->query($query);
267
+ } else {
268
+ //Set the international_order flag and the ig_order_number on the order
269
+ $query = "UPDATE `" . $tableName . "` SET `international_order` = 1, `ig_order_number` = '{$this->iglobal_order_id}' WHERE `entity_id` = '{$id}'";
270
+ Mage::getSingleton('core/resource')->getConnection('core_write')->query($query);
271
+ }
272
+
273
+ //Send the magento id to iGlobal
274
+ $this->rest->sendMagentoOrderId($this->iglobal_order_id, $id);
275
+ return $order;
276
+ }
277
+
278
+
279
+ }
app/code/community/Iglobal/Stores/Model/Rest.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Iglobal_Stores_Model_Rest extends Mage_Core_Model_Abstract
4
+ {
5
+ protected $_entryPoint = 'https://api.iglobalstores.com/v1/';
6
+ protected $_store = 3; // default store ID
7
+ protected $_key = '';
8
+
9
+ protected function _construct()
10
+ {
11
+ //set store ID
12
+ if (Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid')) {
13
+ $this->_store = Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid');
14
+ }
15
+ //Set API Key
16
+ if (Mage::getStoreConfig('iglobal_integration/apireqs/secret')) {
17
+ $this->_key = Mage::getStoreConfig('iglobal_integration/apireqs/secret');
18
+ }
19
+ }
20
+
21
+ protected function callApi($path, $data, $headers=array())
22
+ {
23
+ $client = new Zend_Http_Client($this->_entryPoint . $path);
24
+ $data = json_encode(array_merge($data, array('store' => $this->_store, 'secret' => $this->_key)));
25
+ $response = $client
26
+ ->setRawData($data, 'application/json')
27
+ ->setHeaders($headers)
28
+ ->request('POST');
29
+
30
+ if ($response->isSuccessful())
31
+ {
32
+ return json_decode($response->getBody());
33
+ }
34
+ return false;
35
+
36
+ }
37
+
38
+ public function getAllOrders()
39
+ {
40
+ $data = array('sinceDate'=>'20100101');
41
+ return $this->callApi('orderNumbers', $data);
42
+ }
43
+
44
+ public function getAllOrdersSinceDate($data)
45
+ {
46
+ $data = array('sinceDate'=>$data);
47
+ return $this->callApi('orderNumbers', $data);
48
+ }
49
+
50
+ public function getOrder($order)
51
+ {
52
+ $data = array('orderId' => $order);
53
+ return $this->callApi('orderDetail', $data);
54
+ }
55
+
56
+ public function sendMagentoOrderId($igc_order_id, $magento_order_id) {
57
+ $data = array('orderId' => $igc_order_id, 'merchantOrderId' => $magento_order_id);
58
+ return $this->callApi('updateMerchantOrderId', $data);
59
+ }
60
+
61
+ public function createTempCart(array $data)
62
+ {
63
+ return $this->callApi('createTempCart', $data);
64
+ }
65
+
66
+ public function getRegionId($countryId, $region, $orderid)
67
+ {
68
+ $data = array('countryCode'=> $countryId,'region'=> $region, 'orderId' => $orderid);
69
+ return $this->callApi(
70
+ 'magento-region',
71
+ $data,
72
+ ["serviceToken" => "31ae7155-5b9e-461f-8353-9a8c3f8ae35974ffec3a-88dc-4acb-8420-270df7967338"]
73
+ );
74
+ }
75
+ }
app/code/community/Iglobal/Stores/Model/Rest/Order.php DELETED
@@ -1,86 +0,0 @@
1
- <?php
2
-
3
- class Iglobal_Stores_Model_Rest_Order extends Mage_Core_Model_Abstract
4
- {
5
- protected $_entryPoint = null;
6
-
7
- protected function _construct()
8
- {
9
- //set store ID
10
- if (Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid')){
11
- //use custom ID
12
- $this->_store = Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid');
13
- } else {
14
- //default store ID
15
- $this->_store = 3;
16
- }
17
-
18
- //Set API Key
19
- if (Mage::getStoreConfig('iglobal_integration/apireqs/secret')){
20
- //use custom key
21
- $this->_key = Mage::getStoreConfig('iglobal_integration/apireqs/secret');
22
- } else {
23
- //default key
24
- $this->_key = '';
25
- }
26
-
27
- //set entryPoint
28
- $this->_entryPoint = 'https://checkout.iglobalstores.com';
29
-
30
- }
31
-
32
- protected function getRestClient()
33
- {
34
- return new Zend_Rest_Client($this->_entryPoint);
35
- }
36
-
37
- protected function addCredentials(array $data)
38
- {
39
- return array_merge($data, array('store'=>$this->_store, 'secret'=>$this->_key));
40
- }
41
-
42
- public function getOrders(array $data)
43
- {
44
- $data = array_merge($data, array('operation'=>'orderNumbers'));
45
- $client = $this->getRestClient();
46
- $result = $client->restPost('/iglobalstores/services/OrderRestService/v1.06', $this->addCredentials($data))->getBody();
47
- return json_decode(json_encode((array) simplexml_load_string($result)),1);
48
- }
49
-
50
- public function getAllOrders()
51
- {
52
- $data = array('operation'=>'orderNumbers', 'sinceDate'=>'20100101');
53
- $client = $this->getRestClient();
54
- $result = $client->restPost('/iglobalstores/services/OrderRestService/v1.06', $this->addCredentials($data))->getBody();
55
- return json_decode(json_encode((array) simplexml_load_string($result)),1);
56
- }
57
-
58
- public function getAllOrdersSinceDate($data)
59
- {
60
- $data = array('operation'=>'orderNumbers', 'sinceDate'=>$data);
61
- $client = $this->getRestClient();
62
- $result = $client->restPost('/iglobalstores/services/OrderRestService/v1.06', $this->addCredentials($data))->getBody();
63
- return json_decode(json_encode((array) simplexml_load_string($result)),1);
64
- }
65
-
66
- public function getOrder($order)
67
- {
68
- $data = array('operation'=>'orderDetail', 'orderId' => $order);
69
- $client = $this->getRestClient();
70
- $result = $client->restPost('iglobalstores/services/OrderRestService/v1.06', $this->addCredentials($data))->getBody();
71
- //echo "Rest result: <br />";
72
- //Zend_Debug::dump($result);
73
- //Mage::log("The rest result for order {$order}:" . Zend_Debug::dump($result), 'mattscustom.log', true);
74
- //Mage::log("The rest result for order {$order}:" . print_r($result, true), null, 'mattscustom.log', true);
75
- //$result = mb_convert_encoding($result, "HTML-ENTITIES", "UTF-8");
76
- return json_decode(json_encode((array) simplexml_load_string($result)),1);
77
- }
78
-
79
- public function sendMagentoOrderId($igc_order_id, $magento_order_id) {
80
- $data = array('operation'=>'updateMerchantOrderId', 'orderId' => $igc_order_id, 'merchantOrderId' => $magento_order_id);
81
- $client = $this->getRestClient();
82
- $client->restPost('iglobalstores/services/OrderRestService', $this->addCredentials($data))->getBody();
83
- }
84
-
85
- }
86
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Stores/Model/Rest/Region.php DELETED
@@ -1,42 +0,0 @@
1
- <?php
2
-
3
- class Iglobal_Stores_Model_Rest_Region extends Mage_Core_Model_Abstract
4
- {
5
- protected $_entryPoint = null;
6
-
7
- protected function _construct()
8
- {
9
-
10
-
11
- //Set Service Key
12
- $this -> _key = '{31ae7155-5b9e-461f-8353-9a8c3f8ae35974ffec3a-88dc-4acb-8420-270df7967338}';
13
-
14
- //set entryPoint
15
- $this->_entryPoint = 'https://api.iglobalstores.com/v1/magento-region';
16
-
17
- }
18
-
19
- protected function getRestClient()
20
- {
21
- return new Zend_Http_Client($this->_entryPoint);
22
- }
23
-
24
- protected function addCredentials(array $data)
25
- {
26
- return array_merge($data, array('serviceToken'=>$this->_key));
27
- }
28
-
29
- public function getRegionId($countryId, $region, $order)
30
- {
31
- $data = array('countryCode'=> $countryId,'region'=> $region, 'orderId' => $order);
32
- $client = $this->getRestClient();
33
- $client->setRawData(json_encode($data), 'application/json')->setHeaders("serviceToken:31ae7155-5b9e-461f-8353-9a8c3f8ae35974ffec3a-88dc-4acb-8420-270df7967338")->request('POST');
34
- $result = $client->request()->getBody();
35
- $resArray = json_decode($result, true);
36
- //Mage::log("The region rest result for order {$order}:" . Zend_Debug::dump($result), 'mattscustom.log', true);
37
- //Mage::log("The region rest result for order {$order}:" . print_r($result, true), null, 'mattscustom.log', true);
38
- return $resArray;
39
- }
40
-
41
- }
42
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Stores/Model/Sales/Quote/Address/Total/Fee.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Iglobal_Stores_Model_Sales_Quote_Address_Total_Fee extends Mage_Sales_Model_Quote_Address_Total_Tax
3
+ {
4
+ public function collect(Mage_Sales_Model_Quote_Address $address)
5
+ {
6
+
7
+ $fee = Mage::registry('duty_tax');
8
+ if ($fee) {
9
+ // Do not override taxes if there is no duty_tax set.
10
+ $this->_setAddress($address);
11
+ $this->_setAmount($fee);
12
+ $this->_setBaseAmount($fee);
13
+ } else {
14
+ parent::collect($address);
15
+ }
16
+ }
17
+ }
app/code/community/Iglobal/Stores/controllers/CheckoutController.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
- //
3
- // Load the iGlobal hosted checkout in an iframe, cause it's awesome
4
- //
5
- class Iglobal_Stores_CheckoutController extends Mage_Core_Controller_Front_Action
6
- {
7
- public function indexAction()
8
- {
9
- //todo: add a check to see if they are domestic and then redirect to domestic checkout
10
-
11
-
12
- $cartQty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
13
- if (!$cartQty) {
14
- $this->_redirect('checkout/cart');
15
- die();
16
- //echo "The Cart is Empty";
17
- }
18
-
19
- $tempcart = Mage::getModel('stores/international_international');
20
-
21
- if (!$tempcart) {
22
- echo "No tempcart!";
23
- die();
24
- }
25
-
26
- $cartId = $tempcart->getTempCartId();
27
-
28
- // echo out the html that will build the iframe
29
- $domCode = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>International Checkout</title> <style type="text/css"> body, html {margin: 0; padding: 0; height: 100%; overflow: hidden;} #content{position:absolute; left: 0; right: 0; bottom: 0; top: 0px;} </style></head><body><div id="content"><iframe width="100%" height="100%" frameborder="0" src="';
30
- //this is where we build the url for the checkout
31
- $subdomain = (Mage::getStoreConfig('iglobal_integration/apireqs/igsubdomain') ? Mage::getStoreConfig('iglobal_integration/apireqs/igsubdomain') : "checkout");
32
- $storeNumber = (Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid') ? Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid') : "3");
33
- $countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
34
-
35
- $iframeUrl = 'https://' . $subdomain . '.iglobalstores.com/?store=' . $storeNumber . '&tempCartUUID=' . $cartId . '&country=' . $countryCode;
36
-
37
- $domCode = $domCode . $iframeUrl . '"/></div></body></html>';
38
-
39
- echo $domCode;
40
-
41
- }
42
-
43
  }
1
+ <?php
2
+ //
3
+ // Load the iGlobal hosted checkout in an iframe, cause it's awesome
4
+ //
5
+ class Iglobal_Stores_CheckoutController extends Mage_Core_Controller_Front_Action
6
+ {
7
+ public function indexAction()
8
+ {
9
+ //todo: add a check to see if they are domestic and then redirect to domestic checkout
10
+
11
+
12
+ $cartQty = (int) Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
13
+ if (!$cartQty) {
14
+ $this->_redirect('checkout/cart');
15
+ die();
16
+ //echo "The Cart is Empty";
17
+ }
18
+
19
+ $tempcart = Mage::getModel('stores/international_international');
20
+
21
+ if (!$tempcart) {
22
+ echo "No tempcart!";
23
+ die();
24
+ }
25
+
26
+ $cartId = $tempcart->getTempCartId();
27
+
28
+ // echo out the html that will build the iframe
29
+ $domCode = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>International Checkout</title> <style type="text/css"> body, html {margin: 0; padding: 0; height: 100%; overflow: hidden;} #content{position:absolute; left: 0; right: 0; bottom: 0; top: 0px;} </style></head><body><div id="content"><iframe width="100%" height="100%" frameborder="0" src="';
30
+ //this is where we build the url for the checkout
31
+ $subdomain = (Mage::getStoreConfig('iglobal_integration/apireqs/igsubdomain') ? Mage::getStoreConfig('iglobal_integration/apireqs/igsubdomain') : "checkout");
32
+ $storeNumber = (Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid') ? Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid') : "3");
33
+ $countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
34
+
35
+ $iframeUrl = 'https://' . $subdomain . '.iglobalstores.com/?store=' . $storeNumber . '&tempCartUUID=' . $cartId . '&country=' . $countryCode;
36
+
37
+ $domCode = $domCode . $iframeUrl . '"/></div></body></html>';
38
+
39
+ echo $domCode;
40
+
41
+ }
42
+
43
  }
app/code/community/Iglobal/Stores/controllers/InternationalController.php DELETED
@@ -1,32 +0,0 @@
1
-
2
- <?php
3
-
4
- class Iglobal_Stores_InternationalController extends Mage_Core_Controller_Front_Action
5
- {
6
- public function indexAction()
7
- {
8
- echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
9
- <html xmlns="http://www.w3.org/1999/xhtml">
10
- <head>
11
- <title>Test Layout</title>
12
- <style type="text/css">
13
- body, html
14
- {
15
- margin: 0; padding: 0; height: 100%; overflow: hidden;
16
- }
17
-
18
- #content
19
- {
20
- position:absolute; left: 0; right: 0; bottom: 0; top: 0px;
21
- }
22
- </style>
23
- </head>
24
- <body>
25
- <div id="content">
26
- <iframe width="100%" height="100%" frameborder="0" src="https://jessiesteele.iglobalstores.com/?store=324&tempCartUUID=e5fa40f6-758c-4b63-af09-0a99783c1609&country=AL" />
27
- </div>
28
- </body>
29
- </html> ';
30
- }
31
-
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Iglobal/Stores/controllers/SuccessController.php CHANGED
@@ -1,386 +1,50 @@
1
- <?php
2
-
3
- class Iglobal_Stores_SuccessController extends Mage_Core_Controller_Front_Action
4
- {
5
- public function indexAction()
6
- {
7
-
8
- $_order = $this->getRequest()->getParam('orderId', null);
9
- try
10
- {
11
- $quote = Mage::getSingleton('checkout/session')->getQuote()->setStoreId(Mage::app()->getStore()->getId());
12
- $table = "sales_flat_order";
13
- $tableName = Mage::getSingleton("core/resource")->getTableName($table);
14
- $existsQuery = "SELECT `entity_id` FROM `" . $tableName. "` WHERE `ig_order_number` = '{$_order}'";
15
- $orderExists = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchRow($existsQuery);
16
-
17
- if(!$_order || $orderExists) {
18
- header('Location: /');
19
- die();
20
- }
21
-
22
-
23
- $rest = Mage::getModel('stores/rest_order');
24
- $data = $rest->getOrder($_order);
25
- //Mage::log("the data in the controller for order {$_order}:" . print_r($data, true), null, 'mattscustom.log', true);
26
- //set ddp
27
- $quote->setFeeAmount($data['dutyTaxesTotal']);
28
-
29
- //set customer info
30
- $quote->setCustomerEmail($data['email']);
31
-
32
- $_name = explode(' ', $data['name'], 2);
33
- if ($data['testOrder'] == "true") {
34
- $name_first = "TEST ORDER! DO NOT SHIP! - " . array_shift($_name);
35
- $name_last = array_pop($_name);
36
- } else {
37
- $name_first = array_shift($_name);
38
- $name_last = array_pop($_name);
39
- }
40
-
41
- $quote->setCustomerFirstname($name_first);
42
- $quote->setCustomerLastname($name_last);
43
-
44
- $street = $data['address2'] ? array($data['address1'], $data['address2']) : $data['address1'];
45
-
46
- // to fix error with countries w/o zip codes
47
- if (is_array($data['zip'])){
48
- $igcZipCode = ' ';
49
- }else {
50
- $igcZipCode = $data['zip'];
51
- }
52
-
53
- $regionData = Mage::getModel('stores/rest_region');
54
- $regionReq = $rest->getRegionId($data['countryCode'], $data['state'], $_order);
55
- //Zend_Debug::dump($regionReq);
56
- echo $regionReq['magentoRegionId'];
57
- $mageRegion = $regionReq['magentoRegionId'];
58
-
59
- $addressData = array(
60
- 'firstname' => $name_first,
61
- 'lastname' => $name_last,
62
- 'street' => $street,
63
- 'city' => $data['city'],
64
- 'postcode' => $igcZipCode,
65
- 'telephone' => $data['phone'],
66
- //'region' => Mage::getModel('directory/region')->load($mageRegion)->getName(),
67
- 'region' => $data['state'],
68
- 'region_id' => $mageRegion,
69
- 'country_id' => $data['countryCode'],
70
- 'company' => '',//$data['company'],
71
- );
72
-
73
- $billingCheckVar = $data['billingAddress1'];
74
- if (!empty($billingCheckVar)){
75
- $_nameBilling = explode(' ', $data['billingName'], 2);
76
- if ($data['testOrder'] == "true") {
77
- $name_first_billing = "TEST ORDER! DO NOT SHIP! - " . array_shift($_nameBilling);
78
- $name_last_billing = array_pop($_nameBilling);
79
- } else {
80
- $name_first_billing = array_shift($_nameBilling);
81
- $name_last_billing = array_pop($_nameBilling);
82
- }
83
-
84
-
85
- $streetBilling = $data['billingAddress2'] ? array($data['billingAddress1'], $data['billingAddress2']) : $data['billingAddress1'];
86
-
87
- // to fix error with countries w/o zip codes
88
- if (is_array($data['billingZip'])){
89
- $igcZipCodeBilling = ' ';
90
- }else {
91
- $igcZipCodeBilling = $data['billingZip'];
92
- }
93
-
94
- $billingAddressData = array(
95
- 'firstname' => $name_first_billing,
96
- 'lastname' => $name_last_billing,
97
- 'street' => $streetBilling,
98
- 'city' => $data['billingCity'],
99
- 'postcode' => $igcZipCodeBilling,
100
- 'telephone' => $data['billingPhone'],
101
- //'region' => Mage::getModel('directory/region')->load($mageRegion)->getName(),
102
- 'region' => $data['state'],
103
- //'region_id' => $mageRegion,
104
- 'country_id' => $data['billingCountryCode'],
105
- );
106
-
107
- } else {
108
- $billingAddressData = $addressData;
109
- }
110
-
111
-
112
- Mage::log('address data for order {$_order}: ' . print_r($addressData, true), null, 'mattscustom.log', true);
113
-
114
- Mage::log('billing address data for order {$_order}: ' . print_r($billingAddressData, true), null, 'mattscustom.log', true);
115
-
116
- //Figure out shipping carrier name etc.
117
- $shippingRate = $data['shippingTotal'];
118
- $shippingCarrierMethod = $data['shippingCarrierServiceLevel'];
119
- switch ($shippingCarrierMethod) {
120
- case 'DHL_EXPRESS' :
121
- $shipper = 'excellence_excellence';
122
- $shippingCarrierTitle = 'DHL';
123
- $shippingMethodTitle = 'Express - iGlobal';
124
- break;
125
- case 'DHL_GLOBAL_MAIL' :
126
- $shipper = 'excellence_excellence';
127
- $shippingCarrierTitle = 'DHL';
128
- $shippingMethodTitle = 'Global Mail - iGlobal';
129
- break;
130
- case 'FEDEX_ECONOMY' :
131
- $shipper = 'excellence_excellence';
132
- $shippingCarrierTitle = 'FedExl';
133
- $shippingMethodTitle = 'Economy - iGlobal';
134
- break;
135
- case 'FEDEX_GROUND' :
136
- $shipper = 'excellence_excellence';
137
- $shippingCarrierTitle = 'FedEx';
138
- $shippingMethodTitle = 'Ground - iGlobal';
139
- break;
140
- case 'FEDEX_PRIORITY' :
141
- $shipper = 'excellence_excellence';
142
- $shippingCarrierTitle = 'FedEx';
143
- $shippingMethodTitle = 'Priority - iGlobal';
144
- break;
145
- case 'UPS_EXPEDITED' :
146
- $shipper = 'excellence_excellence';
147
- $shippingCarrierTitle = 'UPS';
148
- $shippingMethodTitle = 'Expedited - iGlobal';
149
- break;
150
- case 'UPS_EXPRESS' :
151
- $shipper = 'excellence_excellence';
152
- $shippingCarrierTitle = 'UPS';
153
- $shippingMethodTitle = 'Express - iGlobal';
154
- break;
155
- case 'UPS_EXPRESS_SAVER':
156
- $shipper = 'excellence_excellence';
157
- $shippingCarrierTitle = 'UPS';
158
- $shippingMethodTitle = 'Express Saver - iGlobal';
159
- break;
160
- case 'UPS_GROUND':
161
- $shipper = 'excellence_excellence';
162
- $shippingCarrierTitle = 'UPS';
163
- $shippingMethodTitle = 'Canada Ground - iGlobal';
164
- break;
165
- case 'UPS_STANDARD' :
166
- $shipper = 'excellence_excellence';
167
- $shippingCarrierTitle = 'UPS';
168
- $shippingMethodTitle = 'Canada Standard - iGlobal';
169
- break;
170
- case 'USPS_FIRST_CLASS_MAIL_INTERNATIONAL' :
171
- $shipper = 'excellence_excellence';
172
- $shippingCarrierTitle = 'USPS';
173
- $shippingMethodTitle = 'First Class Mail, International - iGlobal';
174
- break;
175
- case 'USPS_PRIORITY_MAIL_EXPRESS_INTERNATIONAL' :
176
- $shipper = 'excellence_excellence';
177
- $shippingCarrierTitle = 'USPS';
178
- $shippingMethodTitle = 'Priority Mail Express, International - iGlobal';
179
- break;
180
- case 'USPS_PRIORITY_MAIL_INTERNATIONAL' :
181
- $shipper = 'excellence_excellence';
182
- $shippingCarrierTitle = 'USPS';
183
- $shippingMethodTitle = 'Priority Mail, International - iGlobal';
184
- break;
185
- case 'APC_EXPEDITED_MAIL' :
186
- $shipper = 'excellence_excellence';
187
- $shippingCarrierTitle = 'UPS';
188
- $shippingMethodTitle = 'APC Expedited 3-5 Days - iGlobal';