Version Notes
New Features:
Save off payment transaction details to the order transaction.
Download this release
Release Info
Developer | Brian Olsen |
Extension | Iglobal_Main |
Version | 1.5.6 |
Comparing to | |
See all releases |
Code changes from version 1.5.5 to 1.5.6
- app/code/community/Iglobal/Stores.full/Block/Ajax.php +8 -0
- app/code/community/Iglobal/Stores.full/Block/Cart.php +45 -0
- app/code/community/Iglobal/Stores.full/Block/Includes.php +8 -0
- app/code/community/Iglobal/Stores.full/Block/Link.php +20 -0
- app/code/community/Iglobal/Stores.full/Helper/Configoptions.php +6 -0
- app/code/community/Iglobal/Stores.full/Helper/Data.php +232 -0
- app/code/community/Iglobal/Stores.full/Helper/Url.php +17 -0
- app/code/community/Iglobal/Stores.full/Model/Carrier.php +78 -0
- app/code/community/Iglobal/Stores.full/Model/Configoptions.php +17 -0
- app/code/community/Iglobal/Stores.full/Model/International/International.php +35 -0
- app/code/community/Iglobal/Stores.full/Model/Observer.php +105 -0
- app/code/community/Iglobal/Stores.full/Model/Order.php +391 -0
- app/code/community/Iglobal/Stores.full/Model/Payment/Iglobal.php +45 -0
- app/code/community/Iglobal/Stores.full/Model/Payment/Iglobalcreditcard.php +7 -0
- app/code/community/Iglobal/Stores.full/Model/Payment/Iglobalpaypal.php +7 -0
- app/code/community/Iglobal/Stores.full/Model/Resource/Setup.php +160 -0
- app/code/community/Iglobal/Stores.full/Model/Rest.php +75 -0
- app/code/community/Iglobal/Stores.full/Model/Service/Quote.php +9 -0
- app/code/community/Iglobal/Stores.full/Model/Tax.php +25 -0
- app/code/community/Iglobal/Stores.full/controllers/AjaxController.php +38 -0
- app/code/community/Iglobal/Stores.full/controllers/CheckoutController.php +52 -0
- app/code/community/Iglobal/Stores.full/controllers/SuccessController.php +47 -0
- app/code/community/Iglobal/Stores.full/etc/adminhtml.xml +35 -0
- app/code/community/Iglobal/Stores.full/etc/config.xml +371 -0
- app/code/community/Iglobal/Stores.full/etc/system.xml +653 -0
- app/code/community/Iglobal/Stores.full/sql/iglobal_stores_setup/mysql4-install-0.1.0.php +36 -0
- app/code/community/Iglobal/Stores.full/sql/iglobal_stores_setup/mysql4-upgrade-0.1.0-0.1.1.php +4 -0
- app/code/community/Iglobal/Stores.full/sql/iglobal_stores_setup/mysql4-upgrade-0.1.1-0.1.2.php +15 -0
- app/code/community/Iglobal/Stores.full/sql/iglobal_stores_setup/mysql4-upgrade-0.1.2-0.1.3.php +4 -0
- app/code/community/Iglobal/Stores.full/sql/iglobal_stores_setup/mysql4-upgrade-0.1.3-1.0.0.php +4 -0
- app/code/community/Iglobal/Stores/.DS_Store +0 -0
- app/code/community/Iglobal/Stores/Helper/Data.php +2 -1
- app/code/community/Iglobal/Stores/Model/International/International.php +3 -1
- app/code/community/Iglobal/Stores/Model/Observer.php +105 -102
- app/code/community/Iglobal/Stores/Model/Order.php +59 -21
- app/code/community/Iglobal/Stores/Model/Payment/Iglobal.php +45 -20
- app/code/community/Iglobal/Stores/Model/Payment/Iglobalcreditcard.php +7 -21
- app/code/community/Iglobal/Stores/Model/Payment/Iglobalpaypal.php +7 -21
- app/code/community/Iglobal/Stores/Model/Rest.php +2 -0
- app/code/community/Iglobal/Stores/controllers/SuccessController.php +5 -4
- js/iGlobal/ig_welcome_mat_default.css +4 -19
- js/iGlobal/ig_welcome_mat_default.js +1 -1
- package.xml +5 -6
app/code/community/Iglobal/Stores.full/Block/Ajax.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Iglobal_Stores_Block_Ajax extends Mage_Core_Block_Template
|
3 |
+
{
|
4 |
+
public function includeFiles()
|
5 |
+
{
|
6 |
+
|
7 |
+
}
|
8 |
+
}
|
app/code/community/Iglobal/Stores.full/Block/Cart.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Iglobal_Stores_Block_Cart extends Mage_Core_Block_Template
|
3 |
+
{
|
4 |
+
|
5 |
+
protected function _construct()
|
6 |
+
{
|
7 |
+
parent::_construct();
|
8 |
+
$this->setTemplate('iglobal/stores/cart.phtml');
|
9 |
+
}
|
10 |
+
|
11 |
+
public function igAttrBlock()
|
12 |
+
{
|
13 |
+
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
|
14 |
+
Zend_Debug::dump($items);
|
15 |
+
echo '<div class="igItemAttr" style="display: none;">';
|
16 |
+
foreach($items as $item) {
|
17 |
+
|
18 |
+
$image = Mage::helper('catalog/image')->init($item->getProduct(), 'thumbnail');
|
19 |
+
$my_product = Mage::getModel('catalog/product')->load($item->getProductId());
|
20 |
+
$my_product_url = $my_product->getProductUrl();
|
21 |
+
|
22 |
+
echo '<div class="igItemDetails">';
|
23 |
+
echo '<p class="igID">'.$item->getProductId().'</p><br />';
|
24 |
+
echo '<p class="igName">'.$item->getName().'</p><br />';
|
25 |
+
echo '<p class="igSku">'.$item->getSku().'</p><br />';
|
26 |
+
echo '<p class="igQty">'.$item->getQty().'</p><br />';
|
27 |
+
echo '<p class="igPrice">'.$item->getPrice().'</p><br />';
|
28 |
+
|
29 |
+
echo '<p class="igUrl">'.$my_product_url.'</p><br />';
|
30 |
+
echo '<p class="igImage">I'. $image.'</p><br />';
|
31 |
+
echo '<p class="igDescription">'. $item->getdescription.'</p><br />';
|
32 |
+
echo '<p class="igWeight">'.$item->getWeight().'</p><br />';
|
33 |
+
echo '<p class="igLength">'. $item->getLength.'</p><br />';
|
34 |
+
echo '<p class="igHeight">'. $item->getHeight.'</p><br />';
|
35 |
+
echo '</div><!-- end igItemDetails-->';
|
36 |
+
|
37 |
+
echo "<br />";
|
38 |
+
}
|
39 |
+
echo '</div><!--end igItemAttr-->';
|
40 |
+
|
41 |
+
//return $items;
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
}
|
app/code/community/Iglobal/Stores.full/Block/Includes.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Iglobal_Stores_Block_Includes extends Mage_Core_Block_Template
|
3 |
+
{
|
4 |
+
public function includeFiles()
|
5 |
+
{
|
6 |
+
|
7 |
+
}
|
8 |
+
}
|
app/code/community/Iglobal/Stores.full/Block/Link.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
//return the url
|
13 |
+
if (Mage::getStoreConfig('iglobal_integration/igmat/welcome_mat_active')
|
14 |
+
&& Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle')){
|
15 |
+
return $this->getUrl('iglobal/checkout', array('_secure'=>true));
|
16 |
+
} else {
|
17 |
+
return $this->getUrl('checkout/onepage', array('_secure'=>true));
|
18 |
+
}
|
19 |
+
}
|
20 |
+
}
|
app/code/community/Iglobal/Stores.full/Helper/Configoptions.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Helper_Configoptions extends Mage_Core_Helper_Abstract{
|
4 |
+
|
5 |
+
|
6 |
+
}
|
app/code/community/Iglobal/Stores.full/Helper/Data.php
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Path for config.
|
7 |
+
*/
|
8 |
+
const XML_CONFIG_PATH = 'iglobal_integration/igjq/';
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Name library directory.
|
12 |
+
*/
|
13 |
+
const NAME_DIR_JS = 'iGlobal/jquery/';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* List files for include.
|
17 |
+
*
|
18 |
+
* @var array
|
19 |
+
*/
|
20 |
+
protected $_files = array(
|
21 |
+
'jquery.js',
|
22 |
+
'jquery.noconflict.js',
|
23 |
+
);
|
24 |
+
|
25 |
+
public function units2lbs($value, $unit='lbs')
|
26 |
+
{
|
27 |
+
$unit = ($unit ? $unit : "lbs");
|
28 |
+
$convert = array('kg' => 0.453592, 'oz' => 16, 'g' => 453.592, 'lbs' => 1);
|
29 |
+
$value = round(floatval($value) / $convert[$unit], 2);
|
30 |
+
if($value){
|
31 |
+
return $value;
|
32 |
+
}
|
33 |
+
return null;
|
34 |
+
}
|
35 |
+
|
36 |
+
public function dim2inch($value, $dim='in')
|
37 |
+
{
|
38 |
+
$dim = ($dim ? $dim : "in");
|
39 |
+
$convert = array('cm' => 2.54, 'in' => 1);
|
40 |
+
$value = ceil(floatval($value) / $convert[$dim]);
|
41 |
+
if($value){
|
42 |
+
return $value;
|
43 |
+
}
|
44 |
+
return null;
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getDimensions($product, $item)
|
48 |
+
{
|
49 |
+
$dim = $product->getAttributeText('ig_dimension_units');
|
50 |
+
$weight = $product->getIgWeight();
|
51 |
+
if (empty($weight))
|
52 |
+
{
|
53 |
+
$weight = $item->getWeight();
|
54 |
+
}
|
55 |
+
$dimensions = array(
|
56 |
+
'weight' => $this->units2lbs($this->getProductAttribute($product, 'weight'), $product->getAttributeText('ig_weight_units')),
|
57 |
+
'length' => $this->dim2inch($this->getProductAttribute($product, 'length'), $dim),
|
58 |
+
'width' => $this->dim2inch($this->getProductAttribute($product, 'width'), $dim),
|
59 |
+
'height' => $this->dim2inch($this->getProductAttribute($product, 'height'), $dim),
|
60 |
+
);
|
61 |
+
return $dimensions;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function getItemDetails($item)
|
65 |
+
{
|
66 |
+
$product = $item->getProduct();
|
67 |
+
// reload the product to get all attributes
|
68 |
+
$product = $product->load($product->getId());
|
69 |
+
//get options on the items
|
70 |
+
$options = $product->getTypeInstance(true)->getOrderOptions($product);
|
71 |
+
$optionList = "";
|
72 |
+
if ($options && isset($options["options"])) {
|
73 |
+
$optionList = "|";
|
74 |
+
foreach ($options["options"] as $option) { //todo: add loops for $options[additional_options] and $options[attributes_info] to get all possible options
|
75 |
+
$optionList = $optionList . $option["label"] . ':"' . $option["value"] . '"|';
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
$details = array(
|
80 |
+
'productId' => $product->getId(),
|
81 |
+
'sku' => $product->getSku(),
|
82 |
+
'description' => $product->getName(),
|
83 |
+
'unitPrice' => $item->getPrice(),
|
84 |
+
'quantity' => $item->getQty(),
|
85 |
+
'itemURL' => $product->getProductUrl(),
|
86 |
+
'imageURL' => str_replace("http:", "https:", Mage::helper('catalog/image')->init($product, 'thumbnail')),
|
87 |
+
'itemDescriptionLong' => $optionList,
|
88 |
+
'countryOfOrigin' => $this->getProductAttribute($product, 'country_of_origin'),
|
89 |
+
'itemBrand' => $this->getProductAttribute($product, 'brand'),
|
90 |
+
'itemCategory' => $this->getProductAttribute($product, 'category'),
|
91 |
+
'itemHSCode' => $this->getProductAttribute($product, 'hs_code'),
|
92 |
+
'itemCustomization' => $this->getProductAttribute($product, 'customization'),
|
93 |
+
'itemColor' => $this->getProductAttribute($product, 'color'),
|
94 |
+
'itemMaterial' => $this->getProductAttribute($product, 'material'),
|
95 |
+
'status' => $this->getProductAttribute($product, 'status'),
|
96 |
+
'nonShippable' => (bool)$this->getProductAttribute($product, 'non_shippable'),
|
97 |
+
) + $this->getDimensions($product, $item);
|
98 |
+
return $details;
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Check enabled.
|
103 |
+
*
|
104 |
+
* @return bool
|
105 |
+
*/
|
106 |
+
public function isEnabled()
|
107 |
+
{
|
108 |
+
return (bool) $this->_getConfigValue('enabled', $store = '');
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Check if the country is domestic
|
113 |
+
* @return bool
|
114 |
+
*/
|
115 |
+
public function isDomestic(){
|
116 |
+
$countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
|
117 |
+
$domesticCountries = explode(",", Mage::getStoreConfig('general/country/ig_domestic_countries'));
|
118 |
+
return in_array($countryCode, $domesticCountries);
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Create the iGlobal checkout url
|
123 |
+
* @param $tempCart
|
124 |
+
* @return string
|
125 |
+
*/
|
126 |
+
public function getCheckoutUrl($tempCart){
|
127 |
+
$subdomain = (Mage::getStoreConfig('iglobal_integration/apireqs/igsubdomain') ? Mage::getStoreConfig('iglobal_integration/apireqs/igsubdomain') : "checkout");
|
128 |
+
$storeNumber = (Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid') ? Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid') : "3");
|
129 |
+
$countryCode = (isset($_COOKIE['igCountry']) ? $_COOKIE['igCountry'] : "");
|
130 |
+
$url = 'https://' . $subdomain . '.iglobalstores.com/?store=' . $storeNumber . '&tempCartUUID=' . $tempCart . '&country=' . $countryCode;
|
131 |
+
|
132 |
+
|
133 |
+
//grab customer info if logged in and carry over to iglobal checkout
|
134 |
+
if(Mage::getSingleton('customer/session')->isLoggedIn()){
|
135 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
136 |
+
$shipping_id = $customer->getDefaultShipping();
|
137 |
+
|
138 |
+
if($shipping_id){
|
139 |
+
$shipping_address = Mage::getModel('customer/address')->load($shipping_id);
|
140 |
+
}
|
141 |
+
|
142 |
+
$customer_params = '';
|
143 |
+
|
144 |
+
if(!$shipping_address){
|
145 |
+
$customer_params .= '&customerName=' . $customer['firstname'] . ' ' . $customer['lastname'];
|
146 |
+
$customer_params .= '&customerCompany=' . $customer['company'];
|
147 |
+
$customer_params .= '&customerEmail=' . $customer['email'];
|
148 |
+
$customer_params .= '&customerPhone=' . $customer['telephone'];
|
149 |
+
}else{
|
150 |
+
$customer_params .= '&customerName=' . $shipping_address['firstname'] . ' ' . $shipping_address['lastname'];
|
151 |
+
$customer_params .= '&customerCompany=' . $shipping_address['company'];
|
152 |
+
$customer_params .= '&customerEmail=' . $customer['email'];
|
153 |
+
$customer_params .= '&customerPhone=' . $shipping_address['telephone'];
|
154 |
+
$customer_params .= '&customerAddress1=' . $shipping_address->getStreet(1);
|
155 |
+
$customer_params .= '&customerAddress2=' . $shipping_address->getStreet(2);
|
156 |
+
$customer_params .= '&customerCity=' . $shipping_address['city'];
|
157 |
+
$customer_params .= '&customerState=' . $shipping_address['region'];
|
158 |
+
$customer_params .= '&customerCountry=' . $shipping_address['country_id'];
|
159 |
+
$customer_params .= '&customerZip=' . $shipping_address['postcode'];
|
160 |
+
}
|
161 |
+
$url .= $customer_params;
|
162 |
+
}
|
163 |
+
return $url;
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Return path file.
|
168 |
+
*
|
169 |
+
* @param $file
|
170 |
+
*
|
171 |
+
* @return string
|
172 |
+
*/
|
173 |
+
public function getJQueryPath($file)
|
174 |
+
{
|
175 |
+
return self::NAME_DIR_JS . $file;
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Create a json string of the confg settings for the welcome mat.
|
180 |
+
* @return string
|
181 |
+
*/
|
182 |
+
public function getJavascriptVars()
|
183 |
+
{
|
184 |
+
$data = array (
|
185 |
+
'storeId' =>Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid'),
|
186 |
+
'subdomain' => Mage::getStoreConfig('iglobal_integration/apireqs/igsubdomain'),
|
187 |
+
'flag_parent' => Mage::getStoreConfig('iglobal_integration/igmat/flag_parent'),
|
188 |
+
'flag_method' => Mage::getStoreConfig('iglobal_integration/igmat/flag_method'),
|
189 |
+
'flag_code' => Mage::getStoreConfig('iglobal_integration/igmat/flag_code'),
|
190 |
+
'domesticCountries' => Mage::getStoreConfig('general/country/ig_domestic_countries'),
|
191 |
+
'storeLogo' => Mage::getStoreConfig('iglobal_integration/igmat/store_logo'),
|
192 |
+
'cartUrl' => Mage::getUrl('checkout/cart'),
|
193 |
+
);
|
194 |
+
//figure out what countries are serviced
|
195 |
+
if (Mage::getStoreConfig('general/country/allow')) {
|
196 |
+
//define iGlobal serviced countries
|
197 |
+
$allCountries = array("AP"=>"APO/FPO","AF"=>"Afghanistan","AL"=>"Albania","DZ"=>"Algeria","AS"=>"American Samoa","AD"=>"Andorra","AO"=>"Angola","AI"=>"Anguilla","AG"=>"Antigua","AR"=>"Argentina","AM"=>"Armenia","AW"=>"Aruba","AU"=>"Australia","AT"=>"Austria","AZ"=>"Azerbaijan","BS"=>"Bahamas","BH"=>"Bahrain","BD"=>"Bangladesh","BB"=>"Barbados","BY"=>"Belarus","BE"=>"Belgium","BZ"=>"Belize","BJ"=>"Benin","BM"=>"Bermuda","BT"=>"Bhutan","BO"=>"Bolivia","BQ"=>"Bonaire","BA"=>"Bosnia & Herzegovina","BW"=>"Botswana","BR"=>"Brazil","VG"=>"Virgin Islands (British)","BN"=>"Brunei","BG"=>"Bulgaria","BF"=>"Burkina Faso","BI"=>"Burundi","KH"=>"Cambodia","CM"=>"Cameroon","CA"=>"Canada","IC"=>"Canary Islands","CV"=>"Cape Verde","KY"=>"Cayman Islands","CF"=>"Central African Republic","TD"=>"Chad","CL"=>"Chile","CN"=>"China - People's Republic of","CO"=>"Colombia","KM"=>"Comoros","CG"=>"Congo","CK"=>"Cook Islands","CR"=>"Costa Rica","HR"=>"Croatia","CW"=>"Curaçao","CY"=>"Cyprus","CZ"=>"Czech Republic","DK"=>"Denmark","DJ"=>"Djibouti","DM"=>"Dominica","DO"=>"Dominican Republic","TL"=>"Timor-Leste","EC"=>"Ecuador","EG"=>"Egypt","SV"=>"El Salvador","GQ"=>"Equatorial Guinea","ER"=>"Eritrea","EE"=>"Estonia","ET"=>"Ethiopia","FK"=>"Falkland Islands","FO"=>"Faroe Islands (Denmark)","FJ"=>"Fiji","FI"=>"Finland","FR"=>"France","GF"=>"French Guiana","GA"=>"Gabon","GM"=>"Gambia","GE"=>"Georgia","DE"=>"Germany","GI"=>"Gibraltar","GR"=>"Greece","GL"=>"Greenland (Denmark)","GD"=>"Grenada","GP"=>"Guadeloupe","GU"=>"Guam","GH"=>"Ghana","GT"=>"Guatemala","GG"=>"Guernsey","GN"=>"Guinea","GW"=>"Guinea-Bissau","GY"=>"Guyana","HT"=>"Haiti","HN"=>"Honduras","HK"=>"Hong Kong","HU"=>"Hungary","IS"=>"Iceland","IN"=>"India","ID"=>"Indonesia","IQ"=>"Iraq","IE"=>"Ireland - Republic Of","IL"=>"Israel","IT"=>"Italy","CI"=>"Ivory Coast","JM"=>"Jamaica","JP"=>"Japan","JE"=>"Jersey","JO"=>"Jordan","KZ"=>"Kazakhstan","KE"=>"Kenya","KI"=>"Kiribati","KR"=>"Korea","KW"=>"Kuwait","KG"=>"Kyrgyzstan","LA"=>"Laos","LV"=>"Latvia","LB"=>"Lebanon","LS"=>"Lesotho","LR"=>"Liberia","LT"=>"Lithuania","LI"=>"Liechtenstein","LU"=>"Luxembourg","MO"=>"Macau","MK"=>"Macedonia","MG"=>"Madagascar","MW"=>"Malawi","MY"=>"Malaysia","MV"=>"Maldives","ML"=>"Mali","MT"=>"Malta","MH"=>"Marshall Islands","MQ"=>"Martinique","MR"=>"Mauritania","MU"=>"Mauritius","YT"=>"Mayotte","MX"=>"Mexico","MD"=>"Moldova","FM"=>"Micronesia - Federated States of","MC"=>"Monaco","MN"=>"Mongolia","ME"=>"Montenegro","MS"=>"Montserrat","MA"=>"Morocco","MZ"=>"Mozambique","MM"=>"Myanmar","NA"=>"Namibia","NR"=>"Nauru","NP"=>"Nepal","NL"=>"Netherlands (Holland)","NV"=>"Nevis","NC"=>"New Caledonia","NZ"=>"New Zealand","NI"=>"Nicaragua","NE"=>"Niger","NG"=>"Nigeria","NU"=>"Niue Island","NF"=>"Norfolk Island","MP"=>"Northern Mariana Islands","NO"=>"Norway","OM"=>"Oman","PK"=>"Pakistan","PA"=>"Panama","PG"=>"Papua New Guinea","PY"=>"Paraguay","PW"=>"Palau","PE"=>"Peru","PH"=>"Philippines","PL"=>"Poland","PT"=>"Portugal","PR"=>"Puerto Rico","QA"=>"Qatar","RE"=>"Reunion","RO"=>"Romania","RU"=>"Russia","RW"=>"Rwanda","SM"=>"San Marino","ST"=>"Sao Tome & Principe","SA"=>"Saudi Arabia","SN"=>"Senegal","RS"=>"Serbia & Montenegro","SC"=>"Seychelles","SL"=>"Sierra Leone","SG"=>"Singapore","SK"=>"Slovakia","SI"=>"Slovenia","SB"=>"Solomon Islands","ZA"=>"South Africa","SS"=>"South Sudan","ES"=>"Spain","LK"=>"Sri Lanka","BL"=>"St. Barthelemy","EU"=>"St. Eustatius","KN"=>"St. Kitts and Nevis","LC"=>"St. Lucia","MF"=>"St. Maarten","VC"=>"St. Vincent","SD"=>"Sudan","SR"=>"Suriname","SZ"=>"Swaziland","SE"=>"Sweden","CH"=>"Switzerland","PF"=>"Tahiti","TW"=>"Taiwan","TJ"=>"Tajikistan","TZ"=>"Tanzania","TH"=>"Thailand","TG"=>"Togo","TO"=>"Tonga","TT"=>"Trinidad and Tobago","TN"=>"Tunisia","TR"=>"Turkey","TM"=>"Turkmenistan","TC"=>"Turks and Caicos Islands","TV"=>"Tuvalu","VI"=>"Virgin Islands (U.S.)","UG"=>"Uganda","UA"=>"Ukraine","AE"=>"United Arab Emirates","GB"=>"United Kingdom","US"=>"United States","UY"=>"Uruguay","UZ"=>"Uzbekistan","VU"=>"Vanuatu","VE"=>"Venezuela","VN"=>"Vietnam","VA"=>"Vatican City","WS"=>"Western Samoa","YE"=>"Yemen","ZM"=>"Zambia","ZW"=>"Zimbabwe");
|
198 |
+
|
199 |
+
//allowed country list
|
200 |
+
$allowedCountries = Mage::getStoreConfig('general/country/allow');
|
201 |
+
$allowedCountries = array_flip(explode("," , $allowedCountries));
|
202 |
+
|
203 |
+
//countries that are both allowed and iGlobal available
|
204 |
+
$servicedCountries = array_intersect_key ($allCountries, $allowedCountries);
|
205 |
+
$data['servicedCountries'] = $servicedCountries;
|
206 |
+
}
|
207 |
+
return Mage::helper('core')->jsonEncode($data);
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Return list files.
|
212 |
+
*
|
213 |
+
* @return array
|
214 |
+
*/
|
215 |
+
public function getFiles()
|
216 |
+
{
|
217 |
+
return $this->_files;
|
218 |
+
}
|
219 |
+
|
220 |
+
protected function getProductAttribute($product, $attributeName) {
|
221 |
+
$value = Mage::getStoreconfig('iglobal_integration/ig_item_attribute/' . $attributeName);
|
222 |
+
if($value) {
|
223 |
+
return $product->getData($value);
|
224 |
+
}
|
225 |
+
return null;
|
226 |
+
}
|
227 |
+
protected function _getConfigValue($key, $store)
|
228 |
+
{
|
229 |
+
return Mage::getStoreConfig(self::XML_CONFIG_PATH . $key, $store = '');
|
230 |
+
}
|
231 |
+
|
232 |
+
}
|
app/code/community/Iglobal/Stores.full/Helper/Url.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Iglobal_Stores_Helper_Url extends Mage_Checkout_Helper_Url
|
3 |
+
{
|
4 |
+
|
5 |
+
function getCheckoutUrl()
|
6 |
+
{
|
7 |
+
// return the url
|
8 |
+
if (Mage::getStoreConfig('iglobal_integration/igmat/welcome_mat_active')
|
9 |
+
&& Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle')) {
|
10 |
+
// send them to the iglobal checkout
|
11 |
+
return $this->_getUrl('iglobal/checkout');
|
12 |
+
} else {
|
13 |
+
return $this->_getUrl('checkout/onepage');
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Carrier.php
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Iglobal_Stores_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract
|
3 |
+
implements Mage_Shipping_Model_Carrier_Interface {
|
4 |
+
protected $_code = 'ig';
|
5 |
+
|
6 |
+
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
|
7 |
+
{
|
8 |
+
if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
|
9 |
+
return false;
|
10 |
+
}
|
11 |
+
|
12 |
+
$price = $this->getConfigData('price'); // set a default shipping price maybe 0
|
13 |
+
|
14 |
+
$result = Mage::getModel('shipping/rate_result');
|
15 |
+
$show = Mage::registry('shipping_cost');
|
16 |
+
if($show){
|
17 |
+
|
18 |
+
$method = Mage::getModel('shipping/rate_result_method');
|
19 |
+
$method->setCarrier($this->_code);
|
20 |
+
$method->setMethod(Mage::registry('shipping_carriertitle'));
|
21 |
+
$method->setCarrierTitle($this->_code);
|
22 |
+
$method->setMethodTitle(Mage::registry('shipping_methodtitle'));
|
23 |
+
if(Mage::registry('shipping_cost')){
|
24 |
+
$method->setPrice(Mage::registry('shipping_cost'));
|
25 |
+
$method->setCost(Mage::registry('shipping_cost'));
|
26 |
+
} else {
|
27 |
+
$method->setPrice($price);
|
28 |
+
$method->setCost($price);
|
29 |
+
}
|
30 |
+
$result->append($method);
|
31 |
+
|
32 |
+
}else{
|
33 |
+
$error = Mage::getModel('shipping/rate_result_error');
|
34 |
+
$error->setCarrier($this->_code);
|
35 |
+
$error->setCarrierTitle($this->getConfigData('name'));
|
36 |
+
$error->setErrorMessage($this->getConfigData('specificerrmsg'));
|
37 |
+
$result->append($error);
|
38 |
+
}
|
39 |
+
return $result;
|
40 |
+
}
|
41 |
+
public function getAllowedMethods()
|
42 |
+
{
|
43 |
+
return array($this->_code =>$this->getConfigData('name'),
|
44 |
+
'DHL_EXPRESS' => 'Express',
|
45 |
+
'DHL_GLOBAL_MAIL' => 'Global Mail',
|
46 |
+
'FEDEX_ECONOMY' => 'Economy',
|
47 |
+
'FEDEX_GROUND' => 'Ground',
|
48 |
+
'FEDEX_IPD' => 'FedEx IPD',
|
49 |
+
'FEDEX_PRIORITY' => 'Priority',
|
50 |
+
'UPS_2ND_DAY_AIR' => 'UPS 2 Day Air',
|
51 |
+
'UPS_3_DAY_AIR' => 'UPS 3 Day Air',
|
52 |
+
'UPS_3_DAY_SELECT' => 'UPS_3_DAY_SELECT',
|
53 |
+
'UPS_EXPEDITED' => 'Expedited',
|
54 |
+
'UPS_EXPRESS' => 'Express',
|
55 |
+
'UPS_EXPRESS_SAVER' => 'Express Saver',
|
56 |
+
'UPS_FREIGHT' => 'UPS Freight',
|
57 |
+
'UPS_GROUND' => 'Canada Ground',
|
58 |
+
'UPS_NEXT_DAY_AIR_SAVER' =>'UPS Next Day Air Saver',
|
59 |
+
'UPS_SAVER' => 'UPS_SAVER',
|
60 |
+
'UPS_STANDARD' => 'Canada Standard',
|
61 |
+
'UPS_WORLDEASE' => 'UPS WorldEase',
|
62 |
+
'UPS_WORLDWIDE_EXPEDITED' => 'Expedited',
|
63 |
+
'UPS_WORLDWIDE_EXPRESS' => 'Express',
|
64 |
+
'USPS_EXPRESS_1' => 'Express 1 Mail',
|
65 |
+
'USPS_FIRST_CLASS' => 'First Class Mail',
|
66 |
+
'USPS_FIRST_CLASS_MAIL_INTERNATIONAL' => 'First Class Mail, International',
|
67 |
+
'USPS_FIRST_CLASS_PACKAGE_INTL_SERVICE' => 'First Class Mail, International',
|
68 |
+
'USPS_PRIORITY' => 'USPS Priority',
|
69 |
+
'USPS_PRIORITY_DOMESTIC' =>'USPS Priority Domestic',
|
70 |
+
'USPS_PRIORITY_EXPRESS' => 'USPS Priority Express',
|
71 |
+
'USPS_PRIORITY_EXPRESS_INTL' => 'USPS Priority Express',
|
72 |
+
'USPS_PRIORITY_INTL' => 'USPS Priority',
|
73 |
+
'USPS_PRIORITY_MAIL_EXPRESS_INTERNATIONAL' => 'Priority Mail Express, International',
|
74 |
+
'USPS_PRIORITY_MAIL_INTERNATIONAL' => 'Priority Mail, International',
|
75 |
+
);
|
76 |
+
|
77 |
+
}
|
78 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Configoptions.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Model_ConfigOptions extends Mage_Eav_Model_Entity_Attribute_Source_Store
|
4 |
+
{
|
5 |
+
public function toOptionArray()
|
6 |
+
{
|
7 |
+
$collection = Mage::getResourceModel('catalog/product_attribute_collection')->load();
|
8 |
+
$options = array(array('value'=> null, 'label'=> '- Not mapped -' ));
|
9 |
+
foreach($collection as $attr) {
|
10 |
+
if($attr->getIsVisible()) {
|
11 |
+
$options[] = array('value' => $attr->getAttributeCode(), 'label' => $attr->getFrontendLabel());
|
12 |
+
}
|
13 |
+
}
|
14 |
+
return $options;
|
15 |
+
}
|
16 |
+
|
17 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/International/International.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
$helper = Mage::helper('stores');
|
13 |
+
foreach ($cart->getAllVisibleItems() as $item) {
|
14 |
+
$items[] = $helper->getItemDetails($item);
|
15 |
+
}
|
16 |
+
// Check for discounts to add as a negative line item
|
17 |
+
$totals = $cart->getTotals();
|
18 |
+
if (isset($totals['discount']))
|
19 |
+
{
|
20 |
+
$items[] = array(
|
21 |
+
'description' => $totals['discount']->getTitle(),
|
22 |
+
'quantity' => 1,
|
23 |
+
'unitPrice' => $totals['discount']->getValue()
|
24 |
+
);
|
25 |
+
}
|
26 |
+
$rest = Mage::getModel('stores/rest');
|
27 |
+
$response = $rest->createTempCart(array(
|
28 |
+
"storeId" => Mage::getStoreConfig('iglobal_integration/apireqs/iglobalid'),
|
29 |
+
"referenceId" => $cart->getId(),
|
30 |
+
"externalConfirmationPageURL" => MAge::getUrl('iglobal/success', array('_secure'=> true)),
|
31 |
+
"misc6" => "iGlobal v".Mage::getConfig()->getModuleConfig("Iglobal_Stores")->version. ", Magento v".Mage::getVersion(),
|
32 |
+
"items" => $items,));
|
33 |
+
return $response->tempCartUUID;
|
34 |
+
}
|
35 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Observer.php
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Created by JetBrains PhpStorm.
|
4 |
+
* User: david
|
5 |
+
* Date: 5/9/13
|
6 |
+
* Time: 3:24 PM
|
7 |
+
* To change this template use File | Settings | File Templates.
|
8 |
+
*/
|
9 |
+
|
10 |
+
class Iglobal_Stores_Model_Observer
|
11 |
+
{
|
12 |
+
public function __construct()
|
13 |
+
{
|
14 |
+
//Just constructor for fun
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
public function orderCreated($observer)
|
19 |
+
{
|
20 |
+
//$observer contains the object returns in the event.
|
21 |
+
$event = $observer->getEvent();
|
22 |
+
$order = $event->getOrder();
|
23 |
+
if($order->getRelationParentId()){
|
24 |
+
$parentOrder = Mage::getModel('sales/order')->load($order->getRelationParentId());
|
25 |
+
if($parentOrder->getIgOrderNumber()){
|
26 |
+
$order->setIglobalTestOrder($parentOrder->getIglobalTestOrder());
|
27 |
+
$order->setIgOrderNumber($parentOrder->getIgOrderNumber());
|
28 |
+
$order->setInternationalOrder(1);
|
29 |
+
$order->save();
|
30 |
+
}
|
31 |
+
}
|
32 |
+
return $this;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Added jQuery library.
|
37 |
+
*
|
38 |
+
* @param Varien_Event_Observer $observer
|
39 |
+
*
|
40 |
+
* @return string
|
41 |
+
*/
|
42 |
+
public function prepareLayoutBefore(Varien_Event_Observer $observer)
|
43 |
+
{
|
44 |
+
if (!Mage::helper('stores')->isEnabled()) {
|
45 |
+
return $this;
|
46 |
+
}
|
47 |
+
|
48 |
+
/* @var $block Mage_Page_Block_Html_Head */
|
49 |
+
$block = $observer->getEvent()->getBlock();
|
50 |
+
|
51 |
+
if ("head" == $block->getNameInLayout()) {
|
52 |
+
foreach (Mage::helper('stores')->getFiles() as $file) {
|
53 |
+
$block->addJs(Mage::helper('stores')->getJQueryPath($file));
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
|
60 |
+
public function orderRec () {
|
61 |
+
|
62 |
+
//build array of orders currently in magento
|
63 |
+
$magentoOrders = array();
|
64 |
+
$orders = Mage::getModel('sales/order')->getCollection()
|
65 |
+
->addFilter('international_order', 1)
|
66 |
+
->addFieldToFilter('ig_order_number', array('notnull'=> true))
|
67 |
+
->getItems();
|
68 |
+
|
69 |
+
foreach ($orders as $order) {
|
70 |
+
$magentoOrders[$order->getIgOrderNumber()] = $order;
|
71 |
+
}
|
72 |
+
$date = date("Ymd", strtotime("-1 week"));
|
73 |
+
//get array with all orders in past
|
74 |
+
$data = Mage::getModel('stores/rest')->getAllOrdersSinceDate($date);
|
75 |
+
if(!isset($data) || !isset($data->orders)) {
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
foreach ($data->orders as $igOrder)
|
79 |
+
{
|
80 |
+
|
81 |
+
if ($igOrder->testOrder)
|
82 |
+
{
|
83 |
+
continue;
|
84 |
+
}
|
85 |
+
if(array_key_exists($igOrder->id, $magentoOrders)) {
|
86 |
+
// check status
|
87 |
+
Mage::getModel('stores/order')->checkStatus($magentoOrders[$igOrder->id]);
|
88 |
+
|
89 |
+
} else {
|
90 |
+
try {
|
91 |
+
// re-import the order
|
92 |
+
// Mage::getModel('stores/order')->processOrder($igOrder->id);
|
93 |
+
}
|
94 |
+
catch(Exception $e)
|
95 |
+
{
|
96 |
+
mail('monitoring@iglobalstores.com, magentomissedorders@iglobalstores.com',
|
97 |
+
'Magento Integration Error - International order failed to import',
|
98 |
+
'International order# '. $igOrder->id .'.'. ' Exception Message: '.$e->getMessage());
|
99 |
+
Mage::log("International order #{$igOrder->id} failed to import!" .$e, Zend_Log::ERR, 'iglobal.log', true);
|
100 |
+
}
|
101 |
+
|
102 |
+
}
|
103 |
+
}
|
104 |
+
}
|
105 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Order.php
ADDED
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Model_Order extends Mage_Core_Model_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
const STATUS_FRAUD = 'IGLOBAL_FRAUD_REVIEW';
|
7 |
+
const STATUS_IN_PROCESS = 'IGLOBAL_ORDER_IN_PROCESS';
|
8 |
+
const STATUS_HOLD = 'IGLOBAL_ORDER_ON_HOLD';
|
9 |
+
const STATUS_CANCELED = 'IGLOBAL_ORDER_CANCELED';
|
10 |
+
|
11 |
+
protected $quote = null;
|
12 |
+
protected $iglobal_order_id = null;
|
13 |
+
protected $iglobal_order = null;
|
14 |
+
protected $rest = null;
|
15 |
+
|
16 |
+
public function setQuote($quote)
|
17 |
+
{
|
18 |
+
$this->quote = $quote;
|
19 |
+
}
|
20 |
+
|
21 |
+
public function checkStatus($order)
|
22 |
+
{
|
23 |
+
if (!$this->iglobal_order)
|
24 |
+
{
|
25 |
+
$this->setIglobalOrder($order->getIgOrderNumber());
|
26 |
+
}
|
27 |
+
$status = $this->iglobal_order->orderStatus;
|
28 |
+
if (($status == self::STATUS_FRAUD || $status == self::STATUS_HOLD || $status == self::STATUS_CANCELED) && $order->canHold()) {
|
29 |
+
$order->hold();
|
30 |
+
$order->addStatusHistoryComment("Order Set to {$status} by iGlobal", false);
|
31 |
+
$order->save();
|
32 |
+
} elseif ($status == self::STATUS_IN_PROCESS && $order->canUnhold()) {
|
33 |
+
$order->unhold();
|
34 |
+
$order->addStatusHistoryComment("Order Set to {$status} by iGlobal", false);
|
35 |
+
$order->save();
|
36 |
+
}
|
37 |
+
}
|
38 |
+
public function setIglobalOrder($orderid)
|
39 |
+
{
|
40 |
+
$this->iglobal_order_id = $orderid;
|
41 |
+
if (!$this->iglobal_order)
|
42 |
+
{
|
43 |
+
$this->rest = Mage::getModel('stores/rest');
|
44 |
+
$this->iglobal_order = $this->rest->getOrder($this->iglobal_order_id)->order;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
public function processOrder($orderid, $quote=NULL)
|
49 |
+
{
|
50 |
+
$this->setIglobalOrder($orderid);
|
51 |
+
if ($this->iglobal_order->merchantOrderId)
|
52 |
+
{
|
53 |
+
//return false;
|
54 |
+
}
|
55 |
+
// check the if this is the same quote that was sent.
|
56 |
+
if ($quote)
|
57 |
+
{
|
58 |
+
$this->quote = $quote;
|
59 |
+
} elseif (!$this->quote) {
|
60 |
+
$this->quote = Mage::getSingleton('checkout/session')->getQuote();
|
61 |
+
}
|
62 |
+
|
63 |
+
if ($this->iglobal_order->referenceId && $this->iglobal_order->referenceId != $this->quote->getId())
|
64 |
+
{
|
65 |
+
$this->quote->load($this->iglobal_order->referenceId);
|
66 |
+
}
|
67 |
+
|
68 |
+
// Set the duty_tax for the address total collection to use
|
69 |
+
Mage::register('duty_tax', $this->iglobal_order->dutyTaxesTotal);
|
70 |
+
$shippingAddress = $this->setContactInfo();
|
71 |
+
$this->setItems();
|
72 |
+
$shippingAddress = $this->setShipping($shippingAddress);
|
73 |
+
$this->setPayment($shippingAddress);
|
74 |
+
$order = $this->createOrder();
|
75 |
+
Mage::unregister('duty_tax');
|
76 |
+
Mage::unregister('shipping_cost');
|
77 |
+
Mage::unregister('shipping_carriertitle');
|
78 |
+
Mage::unregister('shipping_methodtitle');
|
79 |
+
return $order;
|
80 |
+
}
|
81 |
+
protected function regionId($state, $countryCode){
|
82 |
+
$region = Mage::getModel('directory/region')->loadbyName($state, $countryCode);
|
83 |
+
if (!$region->getId())
|
84 |
+
{
|
85 |
+
// Lookup region from iGlobalstores
|
86 |
+
$regionId = $this->rest->getRegionId($countryCode, $state, $this->iglobal_order_id);
|
87 |
+
$region->load($regionId->magentoRegionId);
|
88 |
+
if (!$region->getId())
|
89 |
+
{
|
90 |
+
try {
|
91 |
+
// Create a new region
|
92 |
+
$region->setData(array('country_id' => $countryCode, 'code'=> $regionId->isoCode,'default_name' => $state))->save();
|
93 |
+
} catch (Exception $e) {
|
94 |
+
return null;
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
return $region->getId();
|
99 |
+
}
|
100 |
+
protected function setContactInfo()
|
101 |
+
{
|
102 |
+
//set customer info
|
103 |
+
$this->quote->setCustomerEmail($this->iglobal_order->email);
|
104 |
+
|
105 |
+
$_name = explode(' ', $this->iglobal_order->name, 2);
|
106 |
+
if ($this->iglobal_order->testOrder) {
|
107 |
+
$name_first = "TEST ORDER! DO NOT SHIP! - " . array_shift($_name);
|
108 |
+
$name_last = array_pop($_name);
|
109 |
+
} else {
|
110 |
+
$name_first = array_shift($_name);
|
111 |
+
$name_last = array_pop($_name);
|
112 |
+
}
|
113 |
+
|
114 |
+
$this->quote->setCustomerFirstname($name_first);
|
115 |
+
$this->quote->setCustomerLastname($name_last);
|
116 |
+
|
117 |
+
$street = $this->iglobal_order->address1;
|
118 |
+
if ($this->iglobal_order->address2)
|
119 |
+
{
|
120 |
+
$street = array($street, $this->iglobal_order->address2);
|
121 |
+
}
|
122 |
+
|
123 |
+
$addressData = array(
|
124 |
+
'firstname' => $name_first,
|
125 |
+
'lastname' => $name_last,
|
126 |
+
'street' => $street,
|
127 |
+
'city' => $this->iglobal_order->city,
|
128 |
+
'postcode' => $this->iglobal_order->zip,
|
129 |
+
'telephone' => $this->iglobal_order->phone,
|
130 |
+
'region' => $this->iglobal_order->state,
|
131 |
+
'region_id' => $this->regionId($this->iglobal_order->state, $this->iglobal_order->countryCode),
|
132 |
+
'country_id' => $this->iglobal_order->countryCode,
|
133 |
+
'company' => $this->iglobal_order->company,
|
134 |
+
);
|
135 |
+
|
136 |
+
if (!empty($this->iglobal_order->billingAddress1)) {
|
137 |
+
$_nameBilling = explode(' ', $this->iglobal_order->billingName, 2);
|
138 |
+
if ($this->iglobal_order->testOrder) {
|
139 |
+
$name_first_billing = "TEST ORDER! DO NOT SHIP! - " . array_shift($_nameBilling);
|
140 |
+
$name_last_billing = array_pop($_nameBilling);
|
141 |
+
} else {
|
142 |
+
$name_first_billing = array_shift($_nameBilling);
|
143 |
+
$name_last_billing = array_pop($_nameBilling);
|
144 |
+
}
|
145 |
+
|
146 |
+
$streetBilling = $this->iglobal_order->billingAddress1;
|
147 |
+
if ($this->iglobal_order->billingAddress2) {
|
148 |
+
$streetBilling = array($streetBilling, $this->iglobal_order->billingAddress2);
|
149 |
+
}
|
150 |
+
|
151 |
+
$billingAddressData = array(
|
152 |
+
'firstname' => $name_first_billing,
|
153 |
+
'lastname' => $name_last_billing,
|
154 |
+
'street' => $streetBilling,
|
155 |
+
'city' => $this->iglobal_order->billingCity,
|
156 |
+
'postcode' => $this->iglobal_order->billingZip,
|
157 |
+
'telephone' => $this->iglobal_order->billingPhone,
|
158 |
+
'region' => $this->iglobal_order->billingState,
|
159 |
+
'region_id' => $this->regionId($this->iglobal_order->billingState, $this->iglobal_order->billingCountryCode),
|
160 |
+
'country_id' => $this->iglobal_order->billingCountryCode,
|
161 |
+
'company' => $this->iglobal_order->company,
|
162 |
+
);
|
163 |
+
|
164 |
+
} else {
|
165 |
+
$billingAddressData = $addressData;
|
166 |
+
}
|
167 |
+
|
168 |
+
if (Mage::getStoreConfig('iglobal_integration/igjq/iglogging'))
|
169 |
+
{
|
170 |
+
Mage::log('address data for order {$this->iglobal_order_id}: ' . print_r($addressData, true), null, 'iglobal.log', true);
|
171 |
+
Mage::log('billing address data for order {$this->iglobal_order_id}: ' . print_r($billingAddressData, true), null, 'iglobal.log', true);
|
172 |
+
}
|
173 |
+
|
174 |
+
$this->quote->getBillingAddress()->addData($billingAddressData);
|
175 |
+
$shippingAddress = $this->quote->getShippingAddress()->addData($addressData);
|
176 |
+
return $shippingAddress;
|
177 |
+
}
|
178 |
+
|
179 |
+
protected function setItems()
|
180 |
+
{
|
181 |
+
$quote_items = array();
|
182 |
+
$ig_items = array();
|
183 |
+
foreach($this->quote->getAllVisibleItems() as $item) {
|
184 |
+
$quote_items[$item->getProductId()] = $item;
|
185 |
+
}
|
186 |
+
foreach ($this->iglobal_order->items as $item) {
|
187 |
+
if ($item->productId) { // discounts do not have a productId set
|
188 |
+
$ig_items[$item->productId] = $item;
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
$missing = array_diff_key($ig_items, $quote_items);
|
193 |
+
$extra = array_diff_key($quote_items, $ig_items);
|
194 |
+
foreach ($missing as $pid => $item)
|
195 |
+
{
|
196 |
+
// Add the product to the quote
|
197 |
+
$product = Mage::getModel("catalog/product")->load($pid);
|
198 |
+
if ($product->getId())
|
199 |
+
{
|
200 |
+
$this->quote->addProduct($product, new Varien_Object(array('qty'=> $item->quantity)));
|
201 |
+
} else {
|
202 |
+
Mage::log("Missing sku `{$item->sku}' for {$this->iglobal_order_id}", null, 'iglobal.log', true);
|
203 |
+
}
|
204 |
+
}
|
205 |
+
foreach($extra as $item)
|
206 |
+
{
|
207 |
+
// $this->quote->removeItem($item->getId());
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
protected function setShipping($shippingAddress)
|
212 |
+
{
|
213 |
+
$shippers = Mage::getModel("stores/carrier")->getAllowedMethods();
|
214 |
+
$carrierMethod = $this->iglobal_order->shippingCarrierServiceLevel;
|
215 |
+
if (!$carrierMethod || !array_key_exists($carrierMethod, $shippers)) {
|
216 |
+
$carrierMethod = 'ig';
|
217 |
+
}
|
218 |
+
$shippingMethod = $this->iglobal_order->customerSelectedShippingName;
|
219 |
+
if(!$shippingMethod) {
|
220 |
+
$shippingMethod = "International shipping";
|
221 |
+
}
|
222 |
+
|
223 |
+
//Add things to the register so they can be used by the shipping method
|
224 |
+
Mage::register('shipping_cost', $this->iglobal_order->shippingTotal);
|
225 |
+
Mage::register('shipping_carriertitle', $carrierMethod);
|
226 |
+
Mage::register('shipping_methodtitle', $shippingMethod);
|
227 |
+
$shippingAddress->setCollectShippingRates(true)
|
228 |
+
->collectShippingRates()
|
229 |
+
->setShippingMethod('ig_'.$carrierMethod);
|
230 |
+
return $shippingAddress;
|
231 |
+
}
|
232 |
+
|
233 |
+
protected function setPayment($address)
|
234 |
+
{
|
235 |
+
$address->setPaymentMethod('iGlobalCreditCard');
|
236 |
+
|
237 |
+
//updates payment type in Magento Admin area
|
238 |
+
if (isset($this->iglobal_order->paymentProcessing)) {
|
239 |
+
$data = (array) $this->iglobal_order->paymentProcessing;
|
240 |
+
} else {
|
241 |
+
$data = array();
|
242 |
+
}
|
243 |
+
$data['ccType'] = 'AMEX';
|
244 |
+
if(isset( $this->iglobal_order->paymentProcessing->paymentGateway)) {
|
245 |
+
$paymentMethod = $this->iglobal_order->paymentProcessing->paymentGateway;
|
246 |
+
} else if (isset($this->iglobal_order->paymentProcessing->cardType)) {
|
247 |
+
$paymentMethod = $this->iglobal_order->paymentProcessing->cardType;
|
248 |
+
} else {
|
249 |
+
$paymentMethod = 'iGlobal';
|
250 |
+
}
|
251 |
+
switch($paymentMethod) {
|
252 |
+
case 'iGlobal_CC':
|
253 |
+
case 'AUTHORIZE_NET':
|
254 |
+
case 'BRAINTREE':
|
255 |
+
case 'CYBERSOURCE':
|
256 |
+
case 'INTERPAY':
|
257 |
+
case 'STRIPE':
|
258 |
+
case 'USA_EPAY':
|
259 |
+
$data['method'] = 'iGlobalCreditCard';
|
260 |
+
break;
|
261 |
+
case 'iGlobal PayPal':
|
262 |
+
case 'INTERPAY_PAYPAL':
|
263 |
+
case 'PAYPAL_EXPRESS':
|
264 |
+
$data['method'] = 'iGlobalPaypal';
|
265 |
+
break;
|
266 |
+
default:
|
267 |
+
$data['method'] = 'iGlobal';
|
268 |
+
}
|
269 |
+
$this->quote->getPayment()->importData($data);
|
270 |
+
}
|
271 |
+
|
272 |
+
protected function setTransactionInfo($order){
|
273 |
+
//add trans ID
|
274 |
+
try {
|
275 |
+
$transaction_id = $this->iglobal_order->paymentProcessing->transactionId;
|
276 |
+
} catch (Exception $e){
|
277 |
+
$transaction_id = '34234234234';
|
278 |
+
}
|
279 |
+
if(!$transaction_id) {
|
280 |
+
$transaction_id = '34234234234';
|
281 |
+
}
|
282 |
+
$transaction = Mage::getModel('sales/order_payment_transaction');
|
283 |
+
$transaction->setOrderPaymentObject($order->getPayment());
|
284 |
+
$transaction->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
|
285 |
+
$transaction->setTxnId($transaction_id);
|
286 |
+
if(isset($this->iglobal_order->paymentProcessing)) {
|
287 |
+
$transaction->setAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, (array)$this->iglobal_order->paymentProcessing);
|
288 |
+
if ($this->iglobal_order->paymentProcessing->transactionType == "AUTH_CAPTURE") {
|
289 |
+
$transaction->setTxnType(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
|
290 |
+
}
|
291 |
+
}
|
292 |
+
$transaction->save();
|
293 |
+
}
|
294 |
+
|
295 |
+
protected function createOrder()
|
296 |
+
{
|
297 |
+
|
298 |
+
$this->quote->collectTotals()->save();
|
299 |
+
$this->quote->setIsActive(0)->save();
|
300 |
+
|
301 |
+
$service = Mage::getModel('stores/service_quote', $this->quote);
|
302 |
+
$service->submitAll();
|
303 |
+
$order = $service->getOrder();
|
304 |
+
if($order) {
|
305 |
+
// cleaning up
|
306 |
+
Mage::getSingleton('checkout/session')->clear();
|
307 |
+
} else {
|
308 |
+
$this->quote->setIsActive(1)->save();
|
309 |
+
return;
|
310 |
+
}
|
311 |
+
|
312 |
+
|
313 |
+
$id = $order->getEntityId();
|
314 |
+
|
315 |
+
if (Mage::getStoreConfig('iglobal_integration/apireqs/send_order_email')) {
|
316 |
+
$order->sendNewOrderEmail();
|
317 |
+
}
|
318 |
+
Mage::getSingleton('checkout/session')->setLastOrderId($order->getId());
|
319 |
+
Mage::getSingleton('checkout/session')->setLastRealOrderId($order->getIncrementId());
|
320 |
+
|
321 |
+
|
322 |
+
$transId = Mage::getSingleton('checkout/session')->getLastRealOrderId($order->getIncrementId());
|
323 |
+
//Save Order Invoice as paid
|
324 |
+
$commentMessage = 'Order automatically imported from iGlobal order ID: '. $this->iglobal_order_id;
|
325 |
+
try {
|
326 |
+
$order = Mage::getModel("sales/order")->load($id);
|
327 |
+
$this->setTransactionInfo($order);
|
328 |
+
|
329 |
+
$invoices = Mage::getModel('sales/order_invoice')->getCollection()->addAttributeToFilter('order_id', array('eq'=>$order->getId()));
|
330 |
+
$invoices->getSelect()->limit(1);
|
331 |
+
if ((int)$invoices->count() == 0 && $order->getState() == Mage_Sales_Model_Order::STATE_NEW) {
|
332 |
+
if(!$order->canInvoice()) {
|
333 |
+
$order->addStatusHistoryComment($commentMessage, false);
|
334 |
+
$order->addStatusHistoryComment('iGlobal: Order cannot be invoiced', false);
|
335 |
+
$order->save();
|
336 |
+
} else {
|
337 |
+
$order->addStatusHistoryComment($commentMessage, false);
|
338 |
+
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
339 |
+
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
|
340 |
+
$invoice->register();
|
341 |
+
$invoice->getOrder()->setCustomerNoteNotify(false);
|
342 |
+
$invoice->getOrder()->setIsInProcess(true);
|
343 |
+
$order->addStatusHistoryComment('Automatically INVOICED by iGlobal', false);
|
344 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
345 |
+
->addObject($invoice)
|
346 |
+
->addObject($invoice->getOrder());
|
347 |
+
$transactionSave->save();
|
348 |
+
}
|
349 |
+
}
|
350 |
+
$this->checkStatus($order);
|
351 |
+
|
352 |
+
// add customer notes
|
353 |
+
if($this->iglobal_order->notes){
|
354 |
+
foreach ($this->iglobal_order->notes as $note) {
|
355 |
+
if($note->customerNote) {
|
356 |
+
$order->addStatusHistoryComment($note->note, false);
|
357 |
+
}
|
358 |
+
}
|
359 |
+
}
|
360 |
+
$extraNote = "";
|
361 |
+
if($this->iglobal_order->birthDate) {
|
362 |
+
$extraNote .= "Birthdate: " . $this->iglobal_order->birthDate . "\n";
|
363 |
+
}
|
364 |
+
if($this->iglobal_order->nationalIdentifier) {
|
365 |
+
$extraNote .= "National Identifier: " . $this->iglobal_order->nationalIdentifier . "\n";
|
366 |
+
}
|
367 |
+
if($this->iglobal_order->boxCount) {
|
368 |
+
$extraNote .= "Boxes: " . $this->iglobal_order->boxCount . "\n";
|
369 |
+
}
|
370 |
+
|
371 |
+
if($extraNote) {
|
372 |
+
$order->addStatusHistoryComment($extraNote, false);
|
373 |
+
}
|
374 |
+
} catch (Exception $e) {
|
375 |
+
$order->addStatusHistoryComment('iGlobal Invoicer: Exception occurred during automatically invoicing. Exception message: '.$e->getMessage(), false);
|
376 |
+
$order->save();
|
377 |
+
}
|
378 |
+
if ($this->iglobal_order->testOrder) {
|
379 |
+
$order->setIglobalTestOrder(1);
|
380 |
+
}
|
381 |
+
$order->setIgOrderNumber($this->iglobal_order_id);
|
382 |
+
$order->setInternationalOrder(1);
|
383 |
+
$order->save();
|
384 |
+
|
385 |
+
//Send the magento id to iGlobal
|
386 |
+
$this->rest->sendMagentoOrderId($this->iglobal_order_id, $order->getIncrementId());
|
387 |
+
return $order;
|
388 |
+
}
|
389 |
+
|
390 |
+
|
391 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Payment/Iglobal.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Model_Payment_Iglobal extends Mage_Payment_Model_Method_Abstract
|
4 |
+
{
|
5 |
+
|
6 |
+
protected $_code = 'iGlobal';
|
7 |
+
protected $_canUseInternal = true;
|
8 |
+
protected $_canUseCheckout = false;
|
9 |
+
protected $_canUseForMultishipping = false;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Assign data to info model instance
|
13 |
+
*
|
14 |
+
* @param mixed $data
|
15 |
+
* @return Mage_Payment_Model_Info
|
16 |
+
*/
|
17 |
+
public function assignData($data)
|
18 |
+
{
|
19 |
+
$info = $this->getInfoInstance();
|
20 |
+
if ($data instanceof Varien_Object) {
|
21 |
+
$data = $data->getData();
|
22 |
+
}
|
23 |
+
if (is_array($data)) {
|
24 |
+
$info->addData($data);
|
25 |
+
if(array_key_exists('cardType', $data)) {
|
26 |
+
$info->setCcType($data['cardType']);
|
27 |
+
}
|
28 |
+
$monthMap = array(
|
29 |
+
'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,
|
30 |
+
'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12,
|
31 |
+
);
|
32 |
+
if(array_key_exists('cardExpMonth', $data) and array_key_exists($data['cardExpMonth'],$monthMap)) {
|
33 |
+
$info->setCcExpMonth($monthMap[$data['cardExpMonth']]);
|
34 |
+
}
|
35 |
+
if(array_key_exists('cardExpYear', $data)) {
|
36 |
+
$info->setCcExpYear($data['cardExpYear']);
|
37 |
+
}
|
38 |
+
if(array_key_exists('lastFour', $data)) {
|
39 |
+
$info->setCcLast4($data['lastFour']);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
return $this;
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Payment/Iglobalcreditcard.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Model_Payment_IglobalCreditCard extends Iglobal_Stores_Model_Payment_Iglobal
|
4 |
+
{
|
5 |
+
protected $_code = 'iGlobalCreditCard';
|
6 |
+
}
|
7 |
+
|
app/code/community/Iglobal/Stores.full/Model/Payment/Iglobalpaypal.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Model_Payment_IglobalPaypal extends Iglobal_Stores_Model_Payment_Iglobal
|
4 |
+
{
|
5 |
+
protected $_code = 'iGlobalPaypal';
|
6 |
+
}
|
7 |
+
|
app/code/community/Iglobal/Stores.full/Model/Resource/Setup.php
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
|
4 |
+
{
|
5 |
+
/**
|
6 |
+
* Create an attribute.
|
7 |
+
*
|
8 |
+
* For reference, see Mage_Adminhtml_Catalog_Product_AttributeController::saveAction().
|
9 |
+
*
|
10 |
+
* @return int|false
|
11 |
+
*/
|
12 |
+
function createAttribute($labelText, $attributeCode, $inputType, $option = -1, $values = -1, $productTypes = -1)
|
13 |
+
{
|
14 |
+
$setInfo = array('SetID'=>'4', 'GroupID'=>'7');
|
15 |
+
$labelText = trim($labelText);
|
16 |
+
$attributeCode = trim($attributeCode);
|
17 |
+
|
18 |
+
if($labelText == '' || $attributeCode == '')
|
19 |
+
{
|
20 |
+
//$this->logError("Can't import the attribute with an empty label or code. LABEL= [$labelText] CODE= [$attributeCode]");
|
21 |
+
return false;
|
22 |
+
}
|
23 |
+
|
24 |
+
if($values === -1)
|
25 |
+
$values = array();
|
26 |
+
|
27 |
+
if($productTypes === -1)
|
28 |
+
$productTypes = array();
|
29 |
+
|
30 |
+
if($setInfo !== -1 && (isset($setInfo['SetID']) == false || isset($setInfo['GroupID']) == false))
|
31 |
+
{
|
32 |
+
//$this->logError("Please provide both the set-ID and the group-ID of the attribute-set if you'd like to subscribe to one.");
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
|
36 |
+
//$this->logInfo("Creating attribute [$labelText] with code [$attributeCode].");
|
37 |
+
|
38 |
+
//>>>> Build the data structure that will define the attribute. See
|
39 |
+
// Mage_Adminhtml_Catalog_Product_AttributeController::saveAction().
|
40 |
+
|
41 |
+
if($inputType === 'text'){
|
42 |
+
$data = array(
|
43 |
+
'is_global' => '1',
|
44 |
+
'frontend_input' => 'text',
|
45 |
+
'default_value_text' => '',
|
46 |
+
'default_value_yesno' => '0',
|
47 |
+
'default_value_date' => '',
|
48 |
+
'default_value_textarea' => '',
|
49 |
+
'is_unique' => '0',
|
50 |
+
'is_required' => '0',
|
51 |
+
'frontend_class' => 'validate-number',
|
52 |
+
'is_searchable' => '0',
|
53 |
+
'is_visible_in_advanced_search' => '0',
|
54 |
+
'is_comparable' => '0',
|
55 |
+
'is_used_for_promo_rules' => '0',
|
56 |
+
'is_html_allowed_on_front' => '1',
|
57 |
+
'is_visible_on_front' => '0',
|
58 |
+
'used_in_product_listing' => '0',
|
59 |
+
'used_for_sort_by' => '0',
|
60 |
+
'is_configurable' => '0',
|
61 |
+
'is_filterable' => '0',
|
62 |
+
'is_filterable_in_search' => '0',
|
63 |
+
'backend_type' => 'varchar',
|
64 |
+
'default_value' => '',
|
65 |
+
);
|
66 |
+
}
|
67 |
+
elseif($inputType === 'select'){
|
68 |
+
$data = array(
|
69 |
+
'is_global' => '1',
|
70 |
+
'frontend_input' => 'select',
|
71 |
+
'default_value_text' => '',
|
72 |
+
'default_value_yesno' => '0',
|
73 |
+
'default_value_date' => '',
|
74 |
+
'default_value_textarea' => '',
|
75 |
+
'is_unique' => '0',
|
76 |
+
'is_required' => '1',
|
77 |
+
'frontend_class' => '',
|
78 |
+
'is_searchable' => '0',
|
79 |
+
'is_visible_in_advanced_search' => '0',
|
80 |
+
'is_comparable' => '0',
|
81 |
+
'is_used_for_promo_rules' => '0',
|
82 |
+
'is_html_allowed_on_front' => '1',
|
83 |
+
'is_visible_on_front' => '0',
|
84 |
+
'used_in_product_listing' => '0',
|
85 |
+
'used_for_sort_by' => '0',
|
86 |
+
'is_configurable' => '0',
|
87 |
+
'is_filterable' => '0',
|
88 |
+
'is_filterable_in_search' => '0',
|
89 |
+
'backend_type' => 'int',
|
90 |
+
'default_value' => '',
|
91 |
+
);
|
92 |
+
}
|
93 |
+
// Now, overlay the incoming values on to the defaults.
|
94 |
+
foreach($values as $key => $newValue)
|
95 |
+
if(isset($data[$key]) == false)
|
96 |
+
{
|
97 |
+
//$this->logError("Attribute feature [$key] is not valid.");
|
98 |
+
return false;
|
99 |
+
}
|
100 |
+
|
101 |
+
else
|
102 |
+
$data[$key] = $newValue;
|
103 |
+
|
104 |
+
// Valid product types: simple, grouped, configurable, virtual, bundle, downloadable, giftcard
|
105 |
+
$data['apply_to'] = $productTypes;
|
106 |
+
$data['attribute_code'] = $attributeCode;
|
107 |
+
$data['frontend_label'] = array(
|
108 |
+
0 => $labelText,
|
109 |
+
1 => '',
|
110 |
+
3 => '',
|
111 |
+
2 => '',
|
112 |
+
4 => '',
|
113 |
+
);
|
114 |
+
|
115 |
+
//<<<<
|
116 |
+
|
117 |
+
//>>>> Build the model.
|
118 |
+
|
119 |
+
$model = Mage::getModel('catalog/resource_eav_attribute');
|
120 |
+
|
121 |
+
$model->addData($data);
|
122 |
+
|
123 |
+
if($setInfo !== -1)
|
124 |
+
{
|
125 |
+
$model->setAttributeSetId($setInfo['SetID']);
|
126 |
+
$model->setAttributeGroupId($setInfo['GroupID']);
|
127 |
+
}
|
128 |
+
|
129 |
+
$entityTypeID = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
|
130 |
+
$model->setEntityTypeId($entityTypeID);
|
131 |
+
|
132 |
+
$model->setIsUserDefined(1);
|
133 |
+
|
134 |
+
//<<<<
|
135 |
+
|
136 |
+
// Save.
|
137 |
+
|
138 |
+
try
|
139 |
+
{
|
140 |
+
$model->save();
|
141 |
+
}
|
142 |
+
catch(Exception $ex)
|
143 |
+
{
|
144 |
+
// $this->logError("Attribute [$labelText] could not be saved: " . $ex->getMessage());
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
$id = $model->getId();
|
148 |
+
|
149 |
+
if($inputType=='select' && $option !== -1){
|
150 |
+
$option['attribute_id'] = $id;
|
151 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
152 |
+
$setup->addAttributeOption($option);
|
153 |
+
}
|
154 |
+
|
155 |
+
|
156 |
+
//$this->logInfo("Attribute [$labelText] has been saved as ID ($id).");
|
157 |
+
|
158 |
+
return $id;
|
159 |
+
}
|
160 |
+
}
|
app/code/community/Iglobal/Stores.full/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/';
|
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('v1/orderNumbers', $data);
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getAllOrdersSinceDate($data)
|
45 |
+
{
|
46 |
+
$data = array('sinceDate'=>$data);
|
47 |
+
return $this->callApi('v1/orderNumbers', $data);
|
48 |
+
}
|
49 |
+
|
50 |
+
public function getOrder($order)
|
51 |
+
{
|
52 |
+
$data = array('orderId' => $order);
|
53 |
+
return $this->callApi('v2/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('v1/updateMerchantOrderId', $data);
|
59 |
+
}
|
60 |
+
|
61 |
+
public function createTempCart(array $data)
|
62 |
+
{
|
63 |
+
return $this->callApi('v1/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 |
+
'v1/magento-region',
|
71 |
+
$data,
|
72 |
+
array("serviceToken" => "31ae7155-5b9e-461f-8353-9a8c3f8ae35974ffec3a-88dc-4acb-8420-270df7967338")
|
73 |
+
);
|
74 |
+
}
|
75 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Service/Quote.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Iglobal_Stores_Model_Service_Quote extends Mage_Sales_Model_Service_Quote
|
4 |
+
{
|
5 |
+
protected function _validate()
|
6 |
+
{
|
7 |
+
return $this;
|
8 |
+
}
|
9 |
+
}
|
app/code/community/Iglobal/Stores.full/Model/Tax.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Iglobal_Stores_Model_Tax extends Mage_Sales_Model_Quote_Address_Total_Abstract
|
3 |
+
{
|
4 |
+
protected $_code = 'tax';
|
5 |
+
public function setCode($code)
|
6 |
+
{
|
7 |
+
// store the international fee in the tax field.
|
8 |
+
return $this;
|
9 |
+
}
|
10 |
+
public function collect(Mage_Sales_Model_Quote_Address $address)
|
11 |
+
{
|
12 |
+
if(Mage::getStoreConfig('iglobal_integration/apireqs/ice_toggle'))
|
13 |
+
{
|
14 |
+
$fee = Mage::registry('duty_tax');
|
15 |
+
if ($fee)
|
16 |
+
{
|
17 |
+
$this->_setAddress($address);
|
18 |
+
$this->_setAmount($fee);
|
19 |
+
$this->_setBaseAmount($fee);
|
20 |
+
}
|
21 |
+
}
|
22 |
+
return $this;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
app/code/community/Iglobal/Stores.full/controllers/AjaxController.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|