magnetofraktjaktv23 - Version 0.2.3

Version Notes

Integrates Fraktjakt for a complete shipping solution for Posten, Schenker, Bussgods, DHL, DSV, UPS, Fedex...

Download this release

Release Info

Developer Fraktjakt Ecommerce Team
Extension magnetofraktjaktv23
Version 0.2.3
Comparing to
See all releases


Version 0.2.3

Files changed (22) hide show
  1. app/code/community/Fraktjakt/Fraktjaktmodule/Block/Adminhtml/Sales/Order/Shipment/View.php +19 -0
  2. app/code/community/Fraktjakt/Fraktjaktmodule/Block/Adminhtml/Sales/Order/View.php +19 -0
  3. app/code/community/Fraktjakt/Fraktjaktmodule/Block/Button.php +36 -0
  4. app/code/community/Fraktjakt/Fraktjaktmodule/Helper/Data.php +6 -0
  5. app/code/community/Fraktjakt/Fraktjaktmodule/Model/Carrier/Shippingmethod.php +1137 -0
  6. app/code/community/Fraktjakt/Fraktjaktmodule/Model/Observer.php +535 -0
  7. app/code/community/Fraktjakt/Fraktjaktmodule/Model/Source/Dimentionunits.php +35 -0
  8. app/code/community/Fraktjakt/Fraktjaktmodule/Model/Source/Method.php +13 -0
  9. app/code/community/Fraktjakt/Fraktjaktmodule/Model/Source/Weightunits.php +30 -0
  10. app/code/community/Fraktjakt/Fraktjaktmodule/controllers/Checkout/CartController.php +76 -0
  11. app/code/community/Fraktjakt/Fraktjaktmodule/etc/config.xml +92 -0
  12. app/code/community/Fraktjakt/Fraktjaktmodule/etc/system.xml +174 -0
  13. app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-install-0.2.0.php +260 -0
  14. app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-upgrade-0.2.0-0.2.1.php +139 -0
  15. app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-upgrade-0.2.1-0.2.2.php +34 -0
  16. app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-upgrade-0.2.2-0.2.3.php +32 -0
  17. app/design/frontend/base/default/template/fraktjakt/checkout/cart/shipping.phtml +147 -0
  18. app/design/frontend/base/default/template/fraktjakt/checkout/onepage/shipping_method/fraktjakttemplate.phtml +138 -0
  19. app/design/frontend/base/default/template/fraktjakt/fraktjaktmodule/checkout/cart/shipping.phtml +147 -0
  20. app/design/frontend/base/default/template/fraktjakt/fraktjaktmodule/checkout/onepage/shipping_method/fraktjakttemplate.phtml +138 -0
  21. app/etc/modules/Fraktjakt_Fraktjaktmodule.xml +8 -0
  22. package.xml +27 -0
app/code/community/Fraktjakt/Fraktjaktmodule/Block/Adminhtml/Sales/Order/Shipment/View.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Fraktjakt_Fraktjaktmodule_Block_Adminhtml_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Sales_Order_Shipment_View {
3
+
4
+
5
+
6
+ public function __construct() {
7
+ $url = 'http://www.fraktjakt.se/orders/list?webshop=1';
8
+
9
+ $this->_addButton('testbutton', array(
10
+ 'label' => Mage::helper('Sales')->__('Administrera frakten'),
11
+ 'onclick' => "setLocation('$url')",
12
+ 'class' => 'go'
13
+ ), 0, 100, 'header', 'header');
14
+
15
+ parent::__construct();
16
+
17
+ }
18
+ }
19
+ ?>
app/code/community/Fraktjakt/Fraktjaktmodule/Block/Adminhtml/Sales/Order/View.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Fraktjakt_Fraktjaktmodule_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
3
+
4
+
5
+
6
+ public function __construct() {
7
+ $url = 'http://www.fraktjakt.se/orders/list?webshop=1';
8
+
9
+ $this->_addButton('testbutton', array(
10
+ 'label' => Mage::helper('Sales')->__('Administrera frakten'),
11
+ 'onclick' => "setLocation('$url')",
12
+ 'class' => 'go'
13
+ ), 0, 100, 'header', 'header');
14
+
15
+ parent::__construct();
16
+
17
+ }
18
+ }
19
+ ?>
app/code/community/Fraktjakt/Fraktjaktmodule/Block/Button.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Fraktjakt_Fraktjaktmodule_Block_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected $_code = 'fraktjakt_fraktjaktmodule';
6
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
7
+ {
8
+ $fraktjaktLogin = Mage::getStoreConfig('carriers/'.$this->_code.'/fraktjaktLogin');
9
+ $fraktjaktPassword = Mage::getStoreConfig('carriers/'.$this->_code.'/fraktjaktPassword');
10
+
11
+ $this->setElement($element);
12
+ //$url = $this->getUrl('/'); //
13
+
14
+ if($this->getConfig('test_mode') == 1)
15
+ {
16
+ $url = 'http://api2.fraktjakt.se/account/login?login='.$fraktjaktLogin.'&password='.$fraktjaktPassword;
17
+
18
+ }
19
+ else
20
+ {
21
+ $url = 'http://www.fraktjakt.se/account/login?login='.$fraktjaktLogin.'&password='.$fraktjaktPassword;
22
+
23
+ }
24
+ $html = $this->getLayout()->createBlock('adminhtml/widget_button')
25
+ ->setType('button')
26
+ ->setClass('scalable')
27
+ ->setLabel('Run Now !')
28
+ ->setTarget('_blank')
29
+ ->setOnClick("setLocation('$url')")
30
+ ->toHtml();
31
+
32
+ return $html;
33
+ }
34
+
35
+
36
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Fraktjakt_Fraktjaktmodule_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/Model/Carrier/Shippingmethod.php ADDED
@@ -0,0 +1,1137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Fraktjakt_Fraktjaktmodule_Model_Carrier_Shippingmethod extends Mage_Shipping_Model_Carrier_Abstract
4
+ {
5
+
6
+ protected $_code = 'fraktjakt_fraktjaktmodule';
7
+ protected $_totalfinalp = 0;
8
+
9
+
10
+
11
+ public function _help()
12
+ {
13
+ return Mage::helper('fraktjakt_fraktjaktmodule');
14
+ }
15
+
16
+ public function getConfig($key)
17
+ {
18
+ return Mage::getStoreConfig('carriers/'.$this->_code.'/'.$key);
19
+ }
20
+
21
+ // public function setStore($st)
22
+ // {
23
+ // $this->store = $st;
24
+ // }
25
+
26
+ public function getStoreLocale()
27
+ {
28
+ return Mage::app()->getLocale()->getLocaleCode();
29
+ }
30
+
31
+ public function returnSwedish()
32
+ {
33
+ return ($this->getconfig('returnlang') == 1 ||
34
+ ($this->getconfig('returnlangstore') == 1 && stristr($this->getStoreLocale(),'sv_')));
35
+ }
36
+
37
+ public function log($data, $force =false)
38
+ {
39
+ if($force || $this->getConfig('test_mode') || $this->getConfig('debug'))
40
+ {
41
+ mage::log($data);
42
+ }
43
+ }
44
+
45
+ private function getReadResource()
46
+ {
47
+ return Mage::getSingleton('core/resource')
48
+ ->getConnection('core_read');
49
+ }
50
+
51
+ private function getWriteResource()
52
+ {
53
+ return Mage::getSingleton('core/resource')
54
+ ->getConnection('core_write');
55
+ }
56
+
57
+ private function getSession()
58
+ {
59
+ return Mage::getSingleton('core/session');
60
+ }
61
+
62
+ private function getSessionId()
63
+ {
64
+ return $this->getSession()->getSessionId();
65
+ }
66
+
67
+ private function getCacheTable()
68
+ {
69
+ return 'fraktjakt_cache';
70
+ }
71
+
72
+ private function clearCache()
73
+ {
74
+ // really we only need to do this a few times a day for maintenance. It should be done in a cron script I suppose
75
+ if(((int)rand()) %3)
76
+ {
77
+ $sql = " delete from ".$this->getCacheTable()." where to_days(created) != to_days(now()) ";
78
+ $this->log($sql);
79
+ $this->getWriteResource()->query($sql);
80
+ }
81
+ }
82
+
83
+ private function addCache($itemshash, $response, $response_id)
84
+ {
85
+ if($this->getConfig('usecache'))
86
+ {
87
+ $session_id = $this->getSessionId();
88
+ //$response = str_replace("'",'\\\'',serialize($response));
89
+ $response = serialize($response);
90
+ $sql = " insert into ".$this->getCacheTable()." set
91
+ `session_id` = '{$session_id}',
92
+ `request_hash` = '{$itemshash}',
93
+ `response` = ?,
94
+ `response_id` = '{$response_id}'
95
+ ";
96
+ $this->log($sql.$response);
97
+ $this->getWriteResource()->query($sql,$response);
98
+ }
99
+ }
100
+
101
+ private function checkCache($itemshash)
102
+ {
103
+ if($this->getConfig('usecache'))
104
+ {
105
+ $session = $this->getSessionId();
106
+ $this->clearCache();
107
+ $sql = " select * from ".$this->getCacheTable()." where session_id = '{$session}' and request_hash = '{$itemshash}' order by created desc limit 1";
108
+ // $this->log($sql);
109
+ $ret = $this->getReadResource()->fetchRow($sql);
110
+ $this->log("we have cacheS!|".substr(print_r($ret['response'],1),0,85)."|");
111
+ if(isset($ret['response']) && strlen($ret['response']))
112
+ {
113
+ return unserialize($ret['response']);
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+
119
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
120
+ {
121
+
122
+
123
+ $error = false;
124
+ // skip if not enabled
125
+ if (!$this->getConfig('active'))
126
+ {
127
+ return false;
128
+ }
129
+
130
+ // weight
131
+ // $request->getPackageWeight()
132
+
133
+ if($this->getConfig('min_shipping_weight') > 0
134
+ && ( $request->getPackageWeight() < $this->getConfig('min_shipping_weight')*2.204)
135
+ )
136
+ {
137
+ $error = $this->_help()->__("Shipment is Under Weight for this method.");
138
+ $this->log("under weight");
139
+ if(!$this->getConfig('showmethod'))
140
+ {
141
+ return false;
142
+ }
143
+ }
144
+
145
+ if($this->getConfig('max_shipping_weight') > 0
146
+ && ( $request->getPackageWeight() > $this->getConfig('max_shipping_weight')*2.204)
147
+ )
148
+ {
149
+ $error = $this->_help()->__("Shipment is Over Weight for this method.");
150
+ $this->log("under weight");
151
+ if(!$this->getConfig('showmethod'))
152
+ {
153
+ return false;
154
+ }
155
+ }
156
+
157
+ if($this->getConfig('min_shipping_value') > 0
158
+ && ( $request->getPackageValue() < $this->getConfig('min_shipping_value'))
159
+ )
160
+ {
161
+ $error = $this->_help()->__("Shipment is Under Value for this method.");
162
+ $this->log("under value");
163
+ if(!$this->getConfig('showmethod'))
164
+ {
165
+ return false;
166
+ }
167
+ }
168
+
169
+ if($this->getConfig('max_shipping_value') > 0
170
+ && ( $request->getPackageValue() > $this->getConfig('max_shipping_value'))
171
+ )
172
+ {
173
+ $error = $this->_help()->__("Shipment is Over Value for this method.");
174
+ $this->log("over value");
175
+ if(!$this->getConfig('showmethod'))
176
+ {
177
+ return false;
178
+ }
179
+ }
180
+
181
+ $result = Mage::getModel('shipping/rate_result');
182
+
183
+ $this->log("what is error ". print_r($error,1));
184
+ if($error !== false)
185
+ {
186
+ $this->log("we has error");
187
+ $emsg = $error;
188
+ $error = Mage::getModel('shipping/rate_result_error');
189
+ $error->setCarrier($this->_code);
190
+ $error->setCarrierTitle($this->getConfigData('title'));
191
+ //$error->setErrorMessage($errorTitle);
192
+ $error->setErrorMessage($emsg);
193
+ $result->append($error);
194
+ return $result;
195
+ }
196
+
197
+ $items_xml = $this->_getItems($request);
198
+ $xml_bits = $this->_makeXML($request, $items_xml);
199
+
200
+
201
+ if (!$xml_bits)
202
+ {
203
+ $this->log("failed items");
204
+ $error = $this->_help()->__("Failed to get Item Query");
205
+ if(!$this->getConfig('showmethod'))
206
+ {
207
+ return false;
208
+ }
209
+ }
210
+
211
+ $items_hash = md5($items_xml);
212
+ $isCache = false;
213
+ $this->log("Can Post XML Request".$xml_bits);
214
+ $testcache = $this->checkCache($items_hash);
215
+
216
+ if(!$error && $this->getConfig('usecache') && $testcache !== false)
217
+ {
218
+
219
+
220
+ $this->log("Using Cache");
221
+ $xml_result = $testcache;
222
+ $isCache = true;
223
+ unset($testcache);
224
+ }
225
+ else
226
+ {
227
+ $xml_result = $this->_postBits($xml_bits);
228
+ $this->log("LIVE QUERY");
229
+ }
230
+ //print_r($xml_result);
231
+ //$xml_result = $this->_postBits($xml_bits);
232
+ try{
233
+ $this->_store_response($xml_result);
234
+ $this->log("Can Post XML Request".print_r($xml_result,1));
235
+
236
+ $xml_results = @simplexml_load_string($xml_result);
237
+ echo $xml_results;
238
+ if($xml_results){
239
+
240
+ $expath = $xml_results->xpath('code');
241
+ //print_r($expath);
242
+ //echo $expath[0];
243
+ //exit;
244
+ if(is_array($expath) && isset($expath[0]) && $expath[0] == '2')
245
+ {
246
+ $xpath = $xml_results->xpath('error_message');
247
+ $error1 = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '0';
248
+ if($error1 == '' || $error1 == 0)
249
+ {
250
+
251
+ $error1 = $this->_help()->__("There was an unknown problem with Fraktjakt_Fraktjaktmodule");
252
+ $errtmp = $this->getConfig('specificerrmsg');
253
+ if(isset($errtmp))
254
+ {
255
+ $error1 = $errtmp;
256
+
257
+ }
258
+
259
+ }
260
+
261
+ // email error bits here
262
+
263
+
264
+ if ($this->getConfig('erroremail') == 1) {
265
+ $message = $this->_help()->__(" Fraktjakt_Fraktjaktmodule failed quoting\n\n %s" , print_r($xml_results,1) . "\n\n " . print_r($items_xml,1));
266
+ $to = Mage::getStoreConfig('trans_email/ident_support/email');
267
+ $subject = $this->_help()->__('Fraktjakt_Fraktjaktmodule Quote Failure');
268
+ $headers = 'From: ' .$to. "\r\n" .
269
+ 'Reply-To: ' . $to . "\r\n" .
270
+ 'X-Mailer: PHP/' . phpversion();
271
+
272
+ mail($to, $subject, $message, $headers);
273
+ }
274
+
275
+ $this->log('Unknown Error with Fraktjakt_Fraktjaktmodule: '.$error1, true);
276
+ if(strlen($this->getConfig('failover_ratetitle')) && $this->getConfig('failover_rate') > 0)
277
+ {
278
+ $this->log('Using FAILOVER');
279
+ $method = Mage::getModel('shipping/rate_result_method');
280
+ $method->setCarrier($this->_code);
281
+ $method->setCarrierTitle($this->getConfig('title'));
282
+ $method->setMethod('Regular');
283
+ $method->setMethodTitle($this->getConfig('failover_ratetitle'));
284
+ $method->setCost($this->getConfig('failover_rate'));
285
+ $method->setPrice($this->getConfig('failover_rate'));
286
+ $result->append($method);
287
+ return $result;
288
+ return $error;
289
+ }
290
+ $this->log('Returning Error');
291
+
292
+
293
+ $error = Mage::getModel('shipping/rate_result_error');
294
+
295
+
296
+ $error->setCarrier($this->_code);
297
+ $error->setCarrierTitle($this->getConfigData('title'));
298
+ //$error->setErrorMessage($errorTitle);
299
+ $error->setErrorMessage($error1);
300
+ $result->append($error);
301
+ return $result;
302
+ return $error;
303
+
304
+ }
305
+
306
+ if($error !== false)
307
+ {
308
+ $this->log(__LINE__ . ' we have Returning Error');
309
+ return $error;
310
+ }
311
+
312
+ unset($items_xml);
313
+ unset($xml_bits);
314
+
315
+ $xpath = $xml_results->xpath('id');
316
+ $requestID = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '0';
317
+
318
+ if(!$isCache)
319
+ {
320
+ $this->addCache($items_hash, $xml_result, $requestID);
321
+ }
322
+ unset($xml_result);
323
+ $xpath = $xml_results->xpath('tax_class');
324
+ //echo "<pre>";
325
+ //print_r($xpath);
326
+ //exit;
327
+ $handling = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '0';
328
+ $allowedMethods = explode(",", strtolower($this->getConfigData('allowed_methods')));
329
+ mage::log(__CLASS__ . __FUNCTION__ . " all rates returned by Fraktjakt_Fraktjaktmodule " . print_r($xml_results,1));
330
+ //print_r($xml_results->shipping_products);
331
+ //exit;
332
+ foreach($xml_results->shipping_products->shipping_product as $prod)
333
+ {
334
+
335
+
336
+ //echo "<pre>";
337
+ //print_r($prod);
338
+
339
+ $xpath = $prod->xpath('description');
340
+ $name = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
341
+ $xpath = $prod->xpath('agent_link');
342
+ $agent_link = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
343
+ //exit;
344
+ /* if(!in_array(strtolower($name) ,$allowedMethods))
345
+ {
346
+ continue;
347
+ }*/
348
+ //continue;
349
+ $xpath = $prod->xpath('arrival_time');
350
+ $delivery = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
351
+ $xpath = $prod->xpath('agent_info');
352
+ $agent_info = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
353
+ $xpath = $prod->xpath('price');
354
+ $rate = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
355
+ $xpath = $prod->xpath('id');
356
+ $shippingid = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
357
+
358
+ $method = Mage::getModel('shipping/rate_result_method');
359
+
360
+ //print_r( $method);
361
+ $method->setCarrier($this->_code);
362
+ $method->setCarrierTitle(Mage::getStoreConfig('carriers/'.$this->_code.'/title'));
363
+ $method->setMethod($name);
364
+ $est_text = 'Est. Delivery';
365
+
366
+ if($this->returnSwedish())
367
+ {
368
+ $est_text = 'Est. Leverans';
369
+ }
370
+ if(empty($delivery))
371
+ {
372
+ $delivery = "?";
373
+ }
374
+ if(empty($agent_info))
375
+ {
376
+ $agent_info = "Home delivery";
377
+ }
378
+ $method->setMethodTitle( $name);
379
+ $method->setMethodDescription( $name."@".$delivery."@".$agent_info."@".$requestID."@".$shippingid."@".$agent_link);
380
+ $method->setCost($rate);
381
+ $method->setPrice($rate);
382
+ $result->append($method);
383
+
384
+ }
385
+ return $result;
386
+ }
387
+ else
388
+ {
389
+ if(strlen($this->getConfig('failover_ratetitle')) && $this->getConfig('failover_rate') > 0)
390
+ {
391
+ $this->log('Using FAILOVER');
392
+ $method = Mage::getModel('shipping/rate_result_method');
393
+ $method->setCarrier($this->_code);
394
+ $method->setCarrierTitle($this->getConfig('title'));
395
+ $method->setMethod('Regular');
396
+ $method->setMethodTitle($this->getConfig('failover_ratetitle'));
397
+ $method->setMethodDescription($this->getConfig('failover_ratetitle'));
398
+ $method->setCost($this->getConfig('failover_rate'));
399
+ $method->setPrice($this->getConfig('failover_rate'));
400
+ $result->append($method);
401
+ return $result;
402
+
403
+ }
404
+ }
405
+ }
406
+ catch (Exception $e) {
407
+ //print_r($result);
408
+ //exit;
409
+
410
+ if(strlen($this->getConfig('failover_ratetitle')) && $this->getConfig('failover_rate') > 0)
411
+ {
412
+ $this->log('Using FAILOVER');
413
+ $method = Mage::getModel('shipping/rate_result_method');
414
+ $method->setCarrier($this->_code);
415
+ $method->setCarrierTitle($this->getConfig('title'));
416
+ $method->setMethod('Regular');
417
+ $method->setMethodTitle($this->getConfig('failover_ratetitle'));
418
+ $method->setCost($this->getConfig('failover_rate'));
419
+ $method->setPrice($this->getConfig('failover_rate'));
420
+ $result->append($method);
421
+ return $result;
422
+
423
+ }
424
+ }
425
+
426
+ }
427
+
428
+
429
+ public function _store_response($xml_result)
430
+ {
431
+ $quote_id = Mage::getSingleton('checkout/session')->getQuoteId();
432
+ $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
433
+ $field = false;
434
+ $value = false;
435
+ $cw = Mage::getSingleton('core/resource')
436
+ ->getConnection('core_write');
437
+ $cr = Mage::getSingleton('core/resource')
438
+ ->getConnection('core_read');
439
+
440
+ $table = Mage::getSingleton('core/resource')->getTablename('fraktjakt_packing');
441
+
442
+ $this->log("current quote id ".Mage::getSingleton('checkout/session')->getQuoteId());
443
+ $this->log("current order id ".Mage::getSingleton('checkout/session')->getLastRealOrderId());
444
+ // figure out if this will work to get the order id
445
+ // what happens on mini checkout?
446
+ // then how do we get it into the shipment creation
447
+ if($order_id)
448
+ {
449
+ // updateing / inserting with order id
450
+ $field = "order_id";
451
+ $value = Mage::getSingleton('checkout/session')->getLastRealOrderId();
452
+ //$clear_query = "delete from {$table} where $field <
453
+ }
454
+ elseif($quote_id)
455
+ {
456
+ $field = "quote_id";
457
+ $value = Mage::getSingleton('checkout/session')->getQuoteId();
458
+ }
459
+
460
+ if($value == false)
461
+ {
462
+ $test = Mage::getSingleton('adminhtml/session_quote')->getQuoteId();
463
+ if($test)
464
+ {
465
+ $field = "quote_id";
466
+ $quote_id = $value = $test;
467
+ //mage::log("Setting from admin Quoote " . $value);
468
+ }
469
+ }
470
+ if($value == false || $value == '')
471
+ {
472
+ //mage::log(__CLASS__ . __LINE__ . " " . $field . "exiting as we dont have value " . $value);
473
+ return;
474
+ }
475
+
476
+ $test = "select * from {$table} where {$field} = $value order by id desc limit 1";
477
+ $row = $cr->fetchRow($test);
478
+ $additional = '';
479
+ if($order_id && $quote_id)
480
+ {
481
+ $additional = ", quote_id = {$quote_id}";
482
+ }
483
+ if(isset($row['id']))
484
+ {
485
+ $sql = "update {$table} set response_data = ? {$additional} where {$field} = $value";
486
+ }
487
+ else
488
+ {
489
+ $sql = "insert into {$table} set response_data = ?, quote_id = '{$quote_id}', order_id = '{$order_id}'";
490
+ }
491
+ //mage::log(__CLASS__ . " saving ". $sql);
492
+ //echo $xml_result;
493
+ //echo $sql ;
494
+ //exit;
495
+
496
+ $cw->query($sql,$xml_result);
497
+ }
498
+
499
+ public function _postBits($xml)
500
+ {
501
+
502
+ if($this->getConfig('test_mode') == 1)
503
+ {
504
+ $url = "http://api2.fraktjakt.se/fraktjakt/query_xml";
505
+ }
506
+ else
507
+ {
508
+ $url = "http://api1.fraktjakt.se/fraktjakt/query_xml";
509
+ }
510
+ $httpHeaders = array(
511
+ // BOF: PHP bug #47906 circumvention (http://bugs.php.net/bug.php?id=47906)
512
+ "Expect: ", // Disable the 100-continue header
513
+ // EOF: PHP bug #47906 circumvention
514
+ "Accept-Charset: ISO 8859-1",
515
+ "Content-type: application/x-www-form-urlencoded"
516
+ );
517
+ $httpPostParams = array(
518
+ 'md5_checksum' => md5($xml),
519
+ 'xml' => utf8_encode($xml)
520
+ );
521
+
522
+ if (is_array($httpPostParams)) {
523
+ foreach ($httpPostParams as $key => $value) {
524
+ $httpPostParams[$key] = $key .'='. urlencode($value);
525
+ }
526
+ $httpPostParams = implode('&', $httpPostParams);
527
+ }
528
+
529
+
530
+
531
+ /*echo "<pre>";
532
+ print_r($xml);*/
533
+ $ch = curl_init();
534
+ /*
535
+ curl_setopt($ch, CURLOPT_POST,1);
536
+ curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode($xml));
537
+ curl_setopt($ch, CURLOPT_URL,$url);
538
+ curl_setopt($ch, CURLOPT_PORT,30000);
539
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
540
+ $qresult = curl_exec($ch);*/
541
+ curl_setopt($ch, CURLOPT_FAILONERROR, 0); // fail on errors
542
+ curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); // forces a non-cached connection
543
+ if ($httpHeaders) curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); // set http headers
544
+ curl_setopt($ch, CURLOPT_POST, 1); // initialize post method
545
+ curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode($xml));
546
+ curl_setopt($ch, CURLOPT_URL,$url);
547
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $httpPostParams); // variables to post
548
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
549
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30); // timeout after 30s
550
+ $qresult = curl_exec($ch);
551
+
552
+
553
+ /*curl_error($ch);
554
+ print_r($qresult);
555
+ exit;*/
556
+ if (curl_errno($ch))
557
+ {
558
+ $tmp = $qresult;
559
+ $qresult = "<code>2</code>\n";
560
+ $qresult = "<error_message>Error communicating with Fraktjakt_Fraktjaktmodule " .
561
+ curl_error($ch)."</error_message>\n".$tmp;
562
+ }
563
+ else
564
+ {
565
+ curl_close($ch);
566
+ }
567
+
568
+
569
+ unset($ch);
570
+ unset($tmp);
571
+ unset($xml);
572
+ return $qresult;
573
+ }
574
+
575
+ public function _makeXML(Mage_Shipping_Model_Rate_Request $request, $items)
576
+ {
577
+ //mage::log("--- items --- " . print_r($items));
578
+ $consignorID = Mage::getStoreConfig('carriers/'.$this->_code.'/consignorID');
579
+ $consignorkey = Mage::getStoreConfig('carriers/'.$this->_code.'/consignorkey');
580
+ $store_currency = Mage::app()->getStore()-> getCurrentCurrencyCode();
581
+
582
+ //added var checks + instantiations for cases like !request
583
+ $issues = 0;
584
+ $hasaddress = false;
585
+ $customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping();
586
+ if ($customerAddressId){
587
+ $mainAddress = Mage::getModel('customer/address')->load($customerAddressId);
588
+ $hasaddres = true;
589
+ }
590
+
591
+ //city
592
+ if ($request->getDestCity()) {
593
+ $city = $request->getDestCity();
594
+ } elseif ($hasaddress) {
595
+ $city = $mainAddress->getCity();
596
+ } else {
597
+ $city = "";
598
+ //$issues++;
599
+ }
600
+
601
+ //region code
602
+ if ($request->getDestRegionCode()) {
603
+ $prov = $request->getDestRegionCode();
604
+ } elseif ($hasaddress) {
605
+ $prov = $mainAddress->getRegionId();
606
+ } else {
607
+ $prov = "";
608
+ //$issues++;
609
+ }
610
+
611
+ //street line
612
+ if ($request->getDestStreet()) {
613
+ $streetline = $request->getDestStreet();
614
+ } elseif ($hasaddress) {
615
+ $streetline = $mainAddress->getStreet1();
616
+ $streetline1 = $mainAddress->getStreet2();
617
+ } else {
618
+ $streetline = "";
619
+ $streetline1 = "";
620
+ //$issues++;
621
+ }
622
+
623
+
624
+
625
+ //country code
626
+ if ($request->getDestCountryId()) {
627
+ $destCountry = $request->getDestCountryId();
628
+ } elseif ($hasaddress) {
629
+ $destCountry = $mainAddress->getCountryId();
630
+ } else {
631
+ $destCountry = "";
632
+ $issues++;
633
+ }
634
+
635
+
636
+ $country = Mage::getModel('directory/country')->load($destCountry)->getIso2Code();
637
+
638
+ $postal = '';
639
+
640
+ //postal code
641
+ if (($request->getDestPostcode()) && ($request->getDestPostcode() != "-")) {
642
+ $postal = $request->getDestPostcode();
643
+ } elseif ($hasaddress) {
644
+ $postal = $mainAddress->getPostcode();
645
+ } else {
646
+ $postal = "";
647
+ $issues++;
648
+ }
649
+
650
+
651
+
652
+ if ($request->getOrigPostcode())
653
+ {
654
+ $spostalcode = $request->getOrigPostcode();
655
+ }
656
+ else
657
+ {
658
+ $spostalcode = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
659
+ }
660
+
661
+ // later this can be switched based on customers selected language on site (EN || SV)
662
+ $return_lang = 'EN';
663
+ if($this->returnSwedish())
664
+ {
665
+ $return_lang = 'sv';
666
+ }
667
+ //mage::log($issues);
668
+ if ($issues == 0) {
669
+
670
+
671
+ $xml_bits = '<?xml version="1.0" encoding="iso-8859-1"?>';
672
+ $xml_bits.='
673
+ <shipment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
674
+ <value>'.sprintf("%01.2f", $this->_totalfinalp).'</value>
675
+ ';
676
+ $xml_bits.= "
677
+ <consignor>
678
+ <id>".$consignorID."</id>
679
+ <key>".$consignorkey."</key>
680
+ <currency>".$store_currency."</currency>
681
+ <language>".$return_lang."</language>
682
+ <encoding>ISO 8859-1</encoding>
683
+ </consignor>
684
+ <no_agents>0</no_agents>
685
+ <agents_in>1</agents_in>
686
+ <parcels>
687
+ ".$items."
688
+ </parcels>
689
+ <address>
690
+ <street_address_1>".$streetline."</street_address_1>
691
+ <street_address_2>".$streetline1."</street_address_2>
692
+ <postal_code>".$postal."</postal_code>
693
+ <city_name>".$city."</city_name>
694
+ <residential>1</residential>
695
+ <country_code>".$country."</country_code>
696
+ <country_subdivision_code>F</country_subdivision_code>
697
+ </address>
698
+ <referrer_code></referrer_code>
699
+ </shipment>
700
+ ";
701
+
702
+
703
+
704
+ /*echo $xml_bits;
705
+ exit;*/
706
+ unset($return_lang);
707
+ unset($consignorID);
708
+ unset($consignorkey);
709
+ unset($spostalcode);
710
+ unset($items);
711
+ unset($city);
712
+ unset($prov);
713
+ unset($streetline);
714
+ unset($streetline1);
715
+ unset($country);
716
+ unset($postal);
717
+
718
+ return $xml_bits;
719
+ } else {
720
+ unset($return_lang);
721
+ unset($consignorID);
722
+ unset($consignorkey);
723
+ unset($spostalcode);
724
+ unset($items);
725
+ unset($city);
726
+ unset($prov);
727
+ unset($streetline);
728
+ unset($streetline1);
729
+ unset($country);
730
+ unset($postal);
731
+
732
+ return false;
733
+ }
734
+
735
+ }
736
+
737
+ private function setDefaults()
738
+ {
739
+
740
+ $this->_weight_low = 1;
741
+ if(is_numeric($this->getConfig('weight_low')))
742
+ {
743
+ $this->_weight_low = $this->getConfig('weight_low');
744
+ }
745
+
746
+ $this->_default_widthlow = 1;
747
+ if(is_numeric($this->getConfig('default_widthlow')))
748
+ {
749
+ $this->_default_widthlow = $this->getConfig('default_widthlow');
750
+ }
751
+
752
+ $this->_default_widthhigh = 1;
753
+ if(is_numeric($this->getConfig('default_widthhigh')))
754
+ {
755
+ $this->_default_widthhigh = $this->getConfig('default_widthhigh');
756
+ }
757
+
758
+ $this->_default_heightlow = 1;
759
+ if(is_numeric($this->getConfig('default_heightlow')))
760
+ {
761
+ $this->_default_heightlow = $this->getConfig('default_heightlow');
762
+ }
763
+
764
+ $this->_default_heighthigh = 1;
765
+ if(is_numeric($this->getConfig('default_heighthigh')))
766
+ {
767
+ $this->_default_heighthigh = $this->getConfig('default_heighthigh');
768
+ }
769
+ $this->_default_lengthlow = 1;
770
+
771
+ if(is_numeric($this->getConfig('default_lengthlow')))
772
+ {
773
+ $this->_default_lengthlow = $this->getConfig('default_lengthlow');
774
+ }
775
+
776
+ $this->_default_lengthhigh = 1;
777
+ if(is_numeric($this->getConfig('default_lengthhigh')))
778
+ {
779
+ $this->_default_lengthhigh = $this->getConfig('default_lengthhigh');
780
+ }
781
+ }
782
+
783
+ public function _getItems(Mage_Shipping_Model_Rate_Request $request)
784
+ {
785
+ $this->_totalPrice = 0.0;
786
+ $this->_package_width = 0;
787
+ $this->_package_height = 0;
788
+ $this->_package_length = 0;
789
+ $this->shipping_weight = 0;
790
+ $this->_items_xml = "";
791
+ $this->setDefaults();
792
+ $freeBoxes = 0;
793
+
794
+ $this->setFreeBoxes($freeBoxes);
795
+
796
+
797
+ foreach( $request->getAllItems() as $item )
798
+ {
799
+ $free_shipping = false;
800
+ $free_shipping_children = false;
801
+
802
+ if ($item->getProduct()->isVirtual() || $item->getParentItem())
803
+ {
804
+ continue;
805
+ }
806
+
807
+ if ($item->getHasChildren() && $item->isShipSeparately())
808
+ {
809
+ foreach ($item->getChildren() as $child)
810
+ {
811
+ if ($child->getFreeShipping() && !$child->getProduct()->isVirtual())
812
+ {
813
+ continue;
814
+ }
815
+ // we add item to list
816
+
817
+ }
818
+ }
819
+ elseif ($item->getFreeShipping())
820
+ {
821
+ continue;
822
+ }
823
+ $this->_items_xml .= $this->getItemXml($item);
824
+ $this->_totalfinalp .= $this->getItemTotalPrice($item);
825
+
826
+ }
827
+ /*$data = "
828
+ <itemsPrice>".sprintf("%01.2f", $this->_totalPrice)."</itemsPrice>
829
+ <lineItems>".$this->_items_xml." </lineItems>
830
+ ";*/
831
+ $data = $this->_items_xml;
832
+ $this->_items_xml = '';
833
+ $this->_totalPrice = 0;
834
+ return $data;
835
+ }
836
+
837
+ private function getConvertedWeight($w,$u)
838
+ {
839
+ $weight = $w;
840
+ switch($u)
841
+ {
842
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::LB:
843
+ $weight = round($w*0.4535,2);
844
+ break;
845
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::GR:
846
+ $weight = round($w*0.001,2);
847
+ break;
848
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::OZ:
849
+ $weight = round($w*0.028349,2);
850
+ break;
851
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::KG:
852
+ default:
853
+ $weight = $w;
854
+ break;
855
+ }
856
+ return $weight;
857
+ }
858
+
859
+ private function getConvertedMeasure($w,$u)
860
+ {
861
+ $unit = $w;
862
+ switch($u)
863
+ {
864
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits::MM:
865
+ $unit = round($w*0.1,0);
866
+ break;
867
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits::FT:
868
+ $unit = round($w*30.48,0);
869
+ break;
870
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits::IN:
871
+ $unit = round($w*2.54,0);
872
+ break;
873
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits::M:
874
+ $unit = round($w*100,0);
875
+ break;
876
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits::KM:
877
+ $unit = round($w*100000,0);
878
+ break;
879
+ case Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits::CM:
880
+ default:
881
+ $unit = $w;
882
+ break;
883
+ }
884
+ return $unit;
885
+ }
886
+
887
+
888
+ private function getItemTotalPrice($item)
889
+ {
890
+ $qty = (int)$item->getQty() ? (int)$item->getQty() : 1;
891
+ $product = Mage::getModel('catalog/product')->load( $item->getProductId() );
892
+
893
+
894
+
895
+ //$this->_totalPrice += $product->getFinalPrice() * $qty;
896
+ if($this->getConfig('product_cost') && $product->getCost() > 0)
897
+ {
898
+ $this->_totalPrice = $product->getCost() * $qty;
899
+ }
900
+ else
901
+ {
902
+ $this->log("p p " . $product->getFinalPrice() . " and i P ". $product->getPrice());
903
+ $this->_totalPrice = $product->getFinalPrice() * $qty;
904
+ }
905
+
906
+ return $this->_totalPrice;
907
+ }
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
916
+
917
+
918
+
919
+
920
+
921
+
922
+ private function getItemXml($item)
923
+ {
924
+ // Get quanity for each Item and multiply by volume
925
+ $qty = (int)$item->getQty() ? (int)$item->getQty() : 1;
926
+ $product = Mage::getModel('catalog/product')->load( $item->getProductId() );
927
+
928
+
929
+
930
+ //$this->_totalPrice += $product->getFinalPrice() * $qty;
931
+ if($this->getConfig('product_cost') && $product->getCost() > 0)
932
+ {
933
+ $this->_totalPrice += $product->getCost() * $qty;
934
+ }
935
+ else
936
+ {
937
+ $this->log("p p " . $product->getFinalPrice() . " and i P ". $product->getPrice());
938
+ $this->_totalPrice += $product->getFinalPrice() * $qty;
939
+ }
940
+
941
+ $height = $this->getConvertedMeasure($product->getHeight(), $product->getDimensionUnits());
942
+ //$weight = $this->getConvertedWeight($product->getWeight(),$product->getWeightUnits())*$qty;
943
+ $weight = $this->getConvertedWeight($product->getWeight(),$product->getWeightMeasure());
944
+ $width = $this->getConvertedMeasure($product->getWidth(), $product->getDimensionUnits());
945
+ $length = $this->getConvertedMeasure($product->getLength(), $product->getDimensionUnits());
946
+ $title = substr($product->getSku().';'.preg_replace('/[^a-z0-9\s\'\.\_]/i','',substr($product->getName(),0,32)." ..."),0,32);
947
+ $Readytoship = $product->getReadytoship();
948
+
949
+ if(intval($length) < 1 || intval($width) < 1 || intval($height) < 1 )
950
+ {
951
+ $length = $width = $height = 1;
952
+ }
953
+
954
+ $Readytoship = "";
955
+ if($product->getReadytoship() != 1)
956
+ {
957
+ $Readytoship = '';
958
+
959
+ }
960
+
961
+ if(ceil($weight) <= 0.0000)
962
+ {
963
+ $weight = .7; //default to 7.7 kg
964
+ }
965
+
966
+ if($height < 1 || !is_numeric($height))
967
+ {
968
+ $height = $this->_default_heightlow; // just a low default
969
+ if($weight >= $this->_weight_low) // less than 1k no height (default 2)
970
+ {
971
+ $height = $this->_default_heighthigh;
972
+ }
973
+
974
+ }
975
+
976
+ if($width < 1 || !is_numeric($width))
977
+ {
978
+ $width = $this->_default_widthlow; // just a low default
979
+ if($weight >= $this->_weight_low)
980
+ { // less than 1k no height (default 2)
981
+ $width = $this->_default_widthhigh;
982
+ }
983
+ }
984
+
985
+ // Create default value for length should value be missing
986
+ if($length < 1 || !is_numeric($length))
987
+ {
988
+ $length = $this->_default_lengthlow; // just a low default
989
+ if($weight >= $this->_weight_low) // less than 1k no height (default 2)
990
+ {
991
+ $length = $this->_default_lengthhigh;
992
+ }
993
+ }
994
+ $aweight = $weight;
995
+ /*$aheight = $height*$qty;*/
996
+
997
+ if($product->getReadytoship() != 1)
998
+ {
999
+
1000
+ $this->_package_height += $height;
1001
+ if($width > $this->_package_width) $this->_package_width = $width;
1002
+ if($length > $this->_package_length) $this->_package_length = $length;
1003
+ $this->shipping_weight += $aweight;
1004
+
1005
+
1006
+
1007
+
1008
+ $items_xml = "\n
1009
+ <parcel>
1010
+ <weight>{$this->shipping_weight}</weight>
1011
+ <length>{$this->_package_length}</length>
1012
+ <width>{$this->_package_width}</width>
1013
+ <height>{$this->_package_height}</height>
1014
+ </parcel>
1015
+ ";
1016
+
1017
+ }
1018
+ else
1019
+ {
1020
+ $items_xml = "\n
1021
+ <parcel>
1022
+ <weight>{$aweight}</weight>
1023
+ <length>{$length}</length>
1024
+ <width>{$width}</width>
1025
+ <height>{$height}</height>
1026
+ </parcel>
1027
+ ";
1028
+ }
1029
+
1030
+
1031
+
1032
+ return $items_xml;
1033
+ }
1034
+
1035
+ public function isTrackingAvailable()
1036
+ {
1037
+ return true;
1038
+ }
1039
+
1040
+ public function getTrackingInfo($tracking)
1041
+ {
1042
+ $info = array();
1043
+
1044
+ $result = $this->getTracking($tracking);
1045
+
1046
+ if($result instanceof Mage_Shipping_Model_Tracking_Result)
1047
+ {
1048
+ if ($trackings = $result->getAllTrackings())
1049
+ {
1050
+ return $trackings[0];
1051
+ }
1052
+ }
1053
+ elseif (is_string($result) && !empty($result))
1054
+ {
1055
+ return $result;
1056
+ }
1057
+
1058
+ return false;
1059
+ }
1060
+
1061
+ public function getTracking($trackings)
1062
+ {
1063
+ if (!is_array($trackings))
1064
+ {
1065
+ $trackings = array($trackings);
1066
+ }
1067
+ return $this->_getCgiTracking($trackings);
1068
+
1069
+
1070
+
1071
+ /*$this->setXMLAccessRequest();
1072
+ $this->_getXmlTracking($trackings);*/
1073
+
1074
+ }
1075
+
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+ protected function _getCgiTracking($trackings)
1082
+ {
1083
+ $result = Mage::getModel('shipping/tracking_result');
1084
+ $defaults = $this->getDefaults();
1085
+ foreach($trackings as $tracking)
1086
+ {
1087
+ $status = Mage::getModel('shipping/tracking_result_status');
1088
+ $status->setCarrier('fraktjakt_fraktjaktmodule');
1089
+ $status->setCarrierTitle($this->getConfigData('title'));
1090
+ $status->setTracking($tracking);
1091
+ $status->setPopup(1);
1092
+ $status->setUrl("http://www.fraktjakt.se/trace/list_shipment/$tracking");
1093
+ $result->append($status);
1094
+ }
1095
+
1096
+
1097
+ $this->_result = $result;
1098
+ return $result;
1099
+ }
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+ public function getMethod()
1108
+ {
1109
+ $arr = array("Schenker Privpak AB - Privatpaket",
1110
+ "Bussgods - Bussbox 5 kg (emballage ingår)",
1111
+ "Bussgods - Privat",
1112
+ "Schenker AB - DB SCHENKERprivpak, Ombud - Standard",
1113
+ "Schenker AB - DB SCHENKERprivpak, Till jobbet (Leverans till privatpersonsarbetsplats) (inkl utkörning)",
1114
+ "Schenker AB - DB SCHENKERprivpak, Hem - Dag utan avisering och kvittens (inklutkörning)",
1115
+ "Bussgods - Bussgods Prio",
1116
+ "Schenker AB - DB SCHENKERprivpak, Hem- Dag med avisering (inkl utkörning)",
1117
+ "Schenker AB - DB SCHENKERprivpak, Hem- kväll med avisering (inkl utkörning)"
1118
+ );
1119
+ return $arr;
1120
+ }
1121
+
1122
+ public function getServiceMap()
1123
+ {
1124
+ $arr = array(
1125
+ 30 => "Schenker Privpak AB - Privatpaket",
1126
+ 92 => "Bussgods - Bussbox 5 kg (emballage ingår)",
1127
+ 25 => "Bussgods - Privat",
1128
+ 84 => "Schenker AB - DB SCHENKERprivpak, Ombud - Standard",
1129
+ 88 => "Schenker AB - DB SCHENKERprivpak, Till jobbet (Leverans till privatpersonsarbetsplats) (inkl utkörning)",
1130
+ 85 => "Schenker AB - DB SCHENKERprivpak, Hem - Dag utan avisering och kvittens (inklutkörning)",
1131
+ 100 => "Bussgods - Bussgods Prio",
1132
+ 86 => "Schenker AB - DB SCHENKERprivpak, Hem- Dag med avisering (inkl utkörning)",
1133
+ 87 => "Schenker AB - DB SCHENKERprivpak, Hem- kväll med avisering (inkl utkörning)"
1134
+ );
1135
+ return $arr;
1136
+ }
1137
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/Model/Observer.php ADDED
@@ -0,0 +1,535 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Fraktjakt_Fraktjaktmodule_Model_Observer
4
+ {
5
+
6
+ protected $_code = 'fraktjakt_fraktjaktmodule';
7
+
8
+
9
+ public function getConfig($key)
10
+ {
11
+ return Mage::getStoreConfig('carriers/'.$this->_code.'/'.$key);
12
+ }
13
+ public function getStoreLocale()
14
+ {
15
+ return Mage::app()->getLocale()->getLocaleCode();
16
+ }
17
+ public function returnSwedish()
18
+ {
19
+ return ($this->getconfig('returnlang') == 1 ||
20
+ ($this->getconfig('returnlangstore') == 1 && stristr($this->getStoreLocale(),'sv_')));
21
+ }
22
+
23
+ public function salestest($observer)
24
+ {
25
+
26
+
27
+ $incrementid = $observer->getEvent()->getOrder()->getIncrementId();
28
+ $order = Mage::getModel('sales/order')->loadByIncrementId($incrementid);
29
+ //Mage::log("madhurima2222");
30
+
31
+
32
+
33
+ /* $shipment_collection = Mage::getResourceModel('sales/order_shipment_collection');
34
+ $shipment_collection->addAttributeToFilter('order_id', $incrementid);
35
+ $shipment_collection->load();*/
36
+
37
+
38
+
39
+
40
+
41
+
42
+ /**
43
+ * Check order existing
44
+ */
45
+ if (!$order->getId()) {
46
+ Mage::throwException('The order no longer exists.');
47
+ return false;
48
+ }
49
+ /**
50
+ * Check shipment is available to create separate from invoice
51
+ */
52
+ if ($order->getForcedDoShipmentWithInvoice()) {
53
+ // $this->_getSession()->addError($this->__('Cannot do shipment for the order separately from invoice.'));
54
+ Mage::throwException('Cannot do shipment for the order separately from invoice.');
55
+ return false;
56
+ }
57
+ /**
58
+ * Check shipment create availability
59
+ */
60
+ /* if (!$order->canShip()) {
61
+ Mage::throwException('Cannot do shipment for the order.');
62
+
63
+ return false;
64
+ }*/
65
+
66
+
67
+
68
+ $shipment_collection = Mage::getResourceModel('sales/order_shipment_collection');
69
+ $shipment_collection->addAttributeToFilter('order_id', $orderId);
70
+ $shipment_collection->load();
71
+
72
+ $firstItem = $shipment_collection->getFirstItem();
73
+ if(count($shipment_collection) > 1)
74
+ {
75
+
76
+ Mage::throwException('already shiped.');
77
+ }
78
+ else
79
+ {
80
+
81
+
82
+
83
+ // Is the order shipable?
84
+ if($order->canShip())
85
+ {
86
+
87
+
88
+
89
+
90
+ $store_currency = Mage::app()->getStore()-> getCurrentCurrencyCode();
91
+
92
+
93
+ $shippingAddress = $order->getShippingAddress();
94
+
95
+
96
+
97
+ $rates = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()
98
+ ->getShippingRatesCollection();
99
+
100
+
101
+ foreach ($rates as $rate) {
102
+
103
+ $_rate = $rate->getData();
104
+
105
+
106
+
107
+
108
+ if ( strcmp ( trim($_rate['code']), trim(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod())) == 0 )
109
+ {
110
+ list($mtitle,$md,$mag,$sid,$spid) = preg_split('/[@]/',$_rate['method_description']);
111
+ }
112
+
113
+
114
+ }
115
+
116
+
117
+ $items = $order->getAllVisibleItems();
118
+
119
+ $itemsInOrder = array();
120
+
121
+ foreach($items as $item) {
122
+
123
+ $product = $item->getProduct();
124
+ //Mage::log($product);
125
+ //echo "<pre>";
126
+ //print_r($product);
127
+ // $itemsInOrder[] = $product->name;
128
+
129
+ /* $items_xml = "\n
130
+ <commodity>
131
+ <name>{$product->name}</name>
132
+ <quantity>{$item->getQtyOrdered()}</quantity>
133
+ <quantity_units>{$product->dimension_units}</quantity_units>
134
+ <description>{$product->short_description}</description>
135
+ <country_of_manufacture>{$product->country_of_manufacture}</country_of_manufacture>
136
+ <weight>{$product->weight}</weight>
137
+ <unit_price>{$product->price}</unit_price>
138
+ </commodity>
139
+ ";*/
140
+ $quantity = round($item->getQtyOrdered());
141
+
142
+ $items_xml = "\n
143
+ <commodity>
144
+ <name>{$product->name}</name>
145
+ <quantity>{$quantity}</quantity>
146
+ </commodity>
147
+ ";
148
+
149
+
150
+
151
+
152
+
153
+ $return_lang = 'EN';
154
+ if($this->returnSwedish())
155
+ {
156
+ $return_lang = 'sv';
157
+ }
158
+
159
+
160
+ $consignorID = Mage::getStoreConfig('carriers/'.$this->_code.'/consignorID');
161
+ $consignorkey = Mage::getStoreConfig('carriers/'.$this->_code.'/consignorkey');
162
+
163
+ $xml_bits = '<?xml version="1.0" encoding="iso-8859-1"?>';
164
+ $xml_bits.='<OrderSpecification> ';
165
+ $xml_bits.= "
166
+ <consignor>
167
+ <id>".$consignorID."</id>
168
+ <key>".$consignorkey."</key>
169
+ <currency>".$store_currency."</currency>
170
+ <language>".$return_lang."</language>
171
+ <encoding>iso-8859-1</encoding>
172
+ </consignor>
173
+ <shipment_id>".$sid."</shipment_id>
174
+ <shipping_product_id>".$spid."</shipping_product_id>
175
+ <reference> order #".$order->getId()."</reference>
176
+ <commodities>
177
+ ".$items_xml."
178
+ </commodities>
179
+ <recipient>
180
+ <company_to>".$shippingAddress->getCompany()."</company_to>
181
+ <name_to>". trim($shippingAddress->getFirstname() . " " . $shippingAddress->getLastname()) ."</name_to>
182
+ <telephone_to>".$shippingAddress->getTelephone()."</telephone_to>
183
+ <email_to>".$shippingAddress->getEmail()."</email_to>
184
+ </recipient>
185
+ <booking>
186
+ <pickup_date>".date('Y-m-d')."</pickup_date>
187
+ <driving_instruction>testing testing</driving_instruction>
188
+ <user_notes>testing</user_notes>
189
+ </booking>
190
+ </OrderSpecification>
191
+ ";
192
+
193
+ Mage::log($xml_bits);
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+ if($this->getConfig('test_mode') == 1)
214
+ {
215
+ $url = "http://api2.fraktjakt.se/orders/order_xml";
216
+ }
217
+ else
218
+ {
219
+ $url = "http://api1.fraktjakt.se/orders/order_xml";
220
+ }
221
+
222
+ $httpHeaders = array(
223
+ "Expect: ", // Disable the 100-continue header
224
+ "Accept-Charset: ISO 8859-1",
225
+ "Content-type: application/x-www-form-urlencoded"
226
+ );
227
+ $httpPostParams = array(
228
+ 'md5_checksum' => md5($xml_bits),
229
+ 'xml' => utf8_encode($xml_bits)
230
+ );
231
+
232
+ if (is_array($httpPostParams)) {
233
+ foreach ($httpPostParams as $key => $value) {
234
+ $httpPostParams[$key] = $key .'='. urlencode($value);
235
+ }
236
+ $httpPostParams = implode('&', $httpPostParams);
237
+ }
238
+
239
+
240
+
241
+ $ch = curl_init();
242
+
243
+ curl_setopt($ch, CURLOPT_FAILONERROR, 0); // fail on errors
244
+ curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); // forces a non-cached connection
245
+ if ($httpHeaders) curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); // set http headers
246
+ curl_setopt($ch, CURLOPT_POST, 1); // initialize post method
247
+ curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode($xml_bits));
248
+ curl_setopt($ch, CURLOPT_URL,$url);
249
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $httpPostParams); // variables to post
250
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
251
+ curl_setopt($ch, CURLOPT_TIMEOUT, 30); // timeout after 30s
252
+ $qresult = curl_exec($ch);
253
+ Mage::log(curl_error($ch));
254
+ Mage::log($qresult);
255
+
256
+
257
+
258
+
259
+
260
+ if (curl_errno($ch))
261
+ {
262
+ $tmp = $qresult;
263
+ $qresult = "<error>999</error>\n";
264
+ $qresult = "<statusmessage>Error communicating with Fraktjakt_Fraktjaktmodule " .
265
+ curl_error($ch)."</statusmessage>\n".$tmp;
266
+ }
267
+ else
268
+ {
269
+
270
+
271
+ $xml_results = simplexml_load_string($qresult);
272
+ $xpath = $xml_results->xpath('code');
273
+ $requestID = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '2';
274
+
275
+ if($requestID == '2')
276
+ {
277
+
278
+
279
+ $xpath = $xml_results->xpath('error_message');
280
+ $emessage = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
281
+ if(!empty($emessage))
282
+ {
283
+ // Mage::getSingleton('chekout/session')->addError($emessage);
284
+ Mage::throwException($emessage);
285
+ }
286
+ else
287
+ {
288
+ // Mage::getSingleton('chekout/session')->addError('Error communicating with Fraktjakt_Fraktjaktmodule');
289
+ Mage::throwException('Error communicating with Fraktjakt_Fraktjaktmodule');
290
+ }
291
+
292
+
293
+ // curl_close($ch);
294
+ //exit;
295
+
296
+ }
297
+ else if($requestID == '1')
298
+ {
299
+ $xpath = $xml_results->xpath('warning_message');
300
+ $wmessage = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
301
+
302
+ if(!empty($wmessage))
303
+ {
304
+ // Mage::getSingleton('chekout/session')->addError($wmessage);
305
+ Mage::throwException($wmessage);
306
+ }
307
+ else
308
+ {
309
+ Mage::throwException('Error communicating with Fraktjakt_Fraktjaktmodule');
310
+ //Mage::getSingleton('chekout/session')->addError('Error communicating with Fraktjakt_Fraktjaktmodule');
311
+ }
312
+ curl_close($ch);
313
+ //exit;
314
+ }
315
+ else if($requestID == '0')
316
+ {
317
+ $xpath = $xml_results->xpath('shipment_id');
318
+ $shipmentTrackingNumber = ($xpath !== FALSE && isset($xpath[0])) ? (string)$xpath[0] : '';
319
+ // Mage::log(print_r($product));
320
+ //$shipmentid = Mage::getModel('sales/order_shipment_api')->create($order->getIncrementId(), array());
321
+
322
+
323
+ //$shipmentid = Mage::getModel('sales/order_shipment_api')->create( $incrementid, array());
324
+
325
+
326
+
327
+ /*$shipment = $observer->getEvent()->getShipment();
328
+ $track = Mage::getModel('sales/order_shipment_track')
329
+ ->setNumber($wshipment_id) //tracking number / awb number
330
+ ->setCarrierCode($order->getShippingCarrier()->getCarrierCode()) //carrier code
331
+ ->setTitle('Fraktjakt_Fraktjaktmodule'); //carrier title
332
+ $shipment->addTrack($track);*/
333
+
334
+
335
+ try {
336
+
337
+
338
+ $shipment = Mage::getModel('sales/service_order', $order)
339
+ ->prepareShipment($this->_getItemQtys($order));
340
+
341
+
342
+
343
+ /**
344
+ * Carrier Codes can be like "ups" / "fedex" / "custom",
345
+ * but they need to be active from the System Configuration area.
346
+ * These variables can be provided custom-value, but it is always
347
+ * suggested to use Order values
348
+ */
349
+ /*$shipmentCarrierCode = 'SPECIFIC_CARRIER_CODE';
350
+ $shipmentCarrierTitle = 'Fraktjakt_Fraktjaktmodule';
351
+
352
+ $arrTracking = array(
353
+ 'carrier_code' => isset($shipmentCarrierCode) ? $shipmentCarrierCode : $order->getShippingCarrier()->getCarrierCode(),
354
+ 'title' => isset($shipmentCarrierTitle) ? $shipmentCarrierTitle : $order->getShippingCarrier()->getConfigData('title'),
355
+ 'number' => $shipmentTrackingNumber,
356
+ 'url' => $shipmentTrackingNumber,
357
+ );
358
+
359
+ $track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);*/
360
+ Mage::log('Previous All data by Madhurima');
361
+ //$data = $this->getRequest()->getPost('shipment');
362
+ $ship_data = $shipment->getOrder()->getData();
363
+ Mage::log($ship_data);
364
+
365
+ // Mage::log($data);
366
+ //exit;
367
+
368
+ if (empty($shipmentTrackingNumber)) {
369
+ //Mage::throwException($this->__('Tracking number cannot be empty.'));
370
+ Mage::throwException('Tracking number cannot be empty.');
371
+ }
372
+
373
+ $track = Mage::getModel('sales/order_shipment_track')
374
+ ->setNumber($shipmentTrackingNumber)
375
+ ->setCarrierCode( $order->getShippingCarrier()->getCarrierCode())
376
+ ->setUrl("http://www.fraktjakt.se/trace/list_shipment/$shipmentTrackingNumber")
377
+ ->setTitle($order->getShippingCarrier()->getConfigData('title'));
378
+
379
+ $shipment->addTrack($track);
380
+
381
+
382
+ // Register Shipment
383
+ $shipment->register();
384
+ /* $comment = '';
385
+ if (!empty($data['comment_text'])) {
386
+ $shipment->addComment(
387
+ $data['comment_text'],
388
+ isset($data['comment_customer_notify']),
389
+ isset($data['is_visible_on_front'])
390
+ );
391
+ if (isset($data['comment_customer_notify'])) {
392
+ $comment = $data['comment_text'];
393
+ }
394
+ }
395
+
396
+ if (!empty($data['send_email'])) {
397
+ $shipment->setEmailSent(true);
398
+ }
399
+
400
+ $shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
401
+ $responseAjax = new Varien_Object();
402
+ $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label'];
403
+
404
+ if ($isNeedCreateLabel && $this->_createShippingLabel($shipment)) {
405
+ $responseAjax->setOk(true);
406
+ }*/
407
+ //$this->_createShippingLabel($shipment);
408
+ $customerEmailComments='';
409
+ // Save the Shipment
410
+ $this->_saveShipment($shipment, $order, $customerEmailComments);
411
+ }
412
+ catch (Exception $e) { echo 'Shipment creation failed on order '. $incrementid . ': ', $e->getMessage(); }
413
+
414
+ // Finally, Save the Order
415
+ // $this->_saveOrder($order);
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+ }
429
+
430
+
431
+
432
+
433
+
434
+ curl_close($ch);
435
+ }
436
+
437
+
438
+
439
+ unset($spostalcode);
440
+ unset($items);
441
+ unset($city);
442
+ unset($prov);
443
+ unset($streetline);
444
+ unset($country);
445
+ unset($postal);
446
+
447
+
448
+
449
+ unset($ch);
450
+ unset($tmp);
451
+ unset($xml);
452
+
453
+
454
+ }
455
+
456
+
457
+ }
458
+ //END Handle Shipment
459
+ }
460
+
461
+
462
+ return $this;
463
+
464
+ }
465
+
466
+ /**
467
+ * Get the Quantities shipped for the Order, based on an item-level
468
+ * This method can also be modified, to have the Partial Shipment functionality in place
469
+ *
470
+ * @param $order Mage_Sales_Model_Order
471
+ * @return array
472
+ */
473
+ protected function _getItemQtys(Mage_Sales_Model_Order $order)
474
+ {
475
+ $qty = array();
476
+
477
+ foreach ($order->getAllItems() as $_eachItem) {
478
+ if ($_eachItem->getParentItemId()) {
479
+ $qty[$_eachItem->getParentItemId()] = $_eachItem->getQtyOrdered();
480
+ } else {
481
+ $qty[$_eachItem->getId()] = $_eachItem->getQtyOrdered();
482
+ }
483
+ }
484
+
485
+ return $qty;
486
+ }
487
+
488
+ /**
489
+ * Saves the Shipment changes in the Order
490
+ *
491
+ * @param $shipment Mage_Sales_Model_Order_Shipment
492
+ * @param $order Mage_Sales_Model_Order
493
+ * @param $customerEmailComments string
494
+ */
495
+ protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = '')
496
+ {
497
+ $customerEmailComments='';
498
+ $shipment->getOrder()->setIsInProcess(true);
499
+ $transactionSave = Mage::getModel('core/resource_transaction')
500
+ ->addObject($shipment)
501
+ ->addObject($order)
502
+ ->save();
503
+
504
+ $ship_data = $shipment->getOrder()->getData();
505
+ $customerEmail=$ship_data['customer_email'];
506
+ $emailSentStatus = $shipment->getData('email_sent');
507
+ if (!is_null($customerEmail)) {
508
+ $shipment->sendEmail(true, $customerEmailComments);
509
+ $shipment->setEmailSent(true);
510
+ }
511
+
512
+ return $this;
513
+ }
514
+
515
+
516
+
517
+
518
+
519
+ /**
520
+ * Saves the Order, to complete the full life-cycle of the Order
521
+ * Order status will now show as Complete
522
+ *
523
+ * @param $order Mage_Sales_Model_Order
524
+ */
525
+ protected function _saveOrder(Mage_Sales_Model_Order $order)
526
+ {
527
+ $order->setData('state', Mage_Sales_Model_Order::STATE_COMPLETE);
528
+ $order->setData('status', Mage_Sales_Model_Order::STATE_COMPLETE);
529
+
530
+ $order->save();
531
+
532
+ return $this;
533
+ }
534
+
535
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/Model/Source/Dimentionunits.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
3
+ {
4
+ const MM = 'mm';
5
+ const CM = 'cm';
6
+ const IN = 'in';
7
+ const FT = 'ft';
8
+ const M = 'm';
9
+ const KM = 'km';
10
+
11
+ public function toOptionArray()
12
+ {
13
+ $arr = array();
14
+ $arr[] = array('value'=> self::CM, 'label'=>'cm');
15
+ $arr[] = array('value'=> self::MM, 'label'=>'mm');
16
+ $arr[] = array('value'=> self::IN, 'label'=>'tum');
17
+ $arr[] = array('value'=> self::FT, 'label'=>'fot');
18
+ $arr[] = array('value'=> self::M, 'label'=>'meter');
19
+ $arr[] = array('value'=> self::KM, 'label'=>'kilometer');
20
+ return $arr;
21
+ }
22
+
23
+ public function getAllOptions()
24
+ {
25
+ return $this->toOptionArray();
26
+ }
27
+
28
+
29
+ public function toOptionHash()
30
+ {
31
+ $source = $this->_getSource();
32
+ return $source ? $source->toOptionHash() : array();
33
+ }
34
+
35
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/Model/Source/Method.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Fraktjakt_Fraktjaktmodule_Model_Source_Method
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ $shipmeth = Mage::getSingleton('Fraktjakt_Fraktjaktmodule_Model_Carrier_Shippingmethod');
7
+ $arr = array();
8
+ foreach ($shipmeth->getMethod() as $v) {
9
+ $arr[] = array('value'=>$v, 'label'=>$v);
10
+ }
11
+ return $arr;
12
+ }
13
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/Model/Source/Weightunits.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
3
+ {
4
+ const KG = 'kg';
5
+ const LB = 'lb';
6
+ const OZ = 'oz';
7
+ const GR = 'gr';
8
+ public function toOptionArray()
9
+ {
10
+ $arr = array();
11
+ $arr[] = array('value'=> self::KG, 'label'=>'kg');
12
+ $arr[] = array('value'=> self::GR, 'label'=>'grams');
13
+ $arr[] = array('value'=> self::LB, 'label'=>'LB');
14
+ $arr[] = array('value'=> self::OZ, 'label'=>'Oz');
15
+ return $arr;
16
+ }
17
+
18
+ public function getAllOptions()
19
+ {
20
+ return $this->toOptionArray();
21
+ }
22
+
23
+
24
+ public function toOptionHash()
25
+ {
26
+ $source = $this->_getSource();
27
+ return $source ? $source->toOptionHash() : array();
28
+ }
29
+
30
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/controllers/Checkout/CartController.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Checkout
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Shopping cart controller
29
+ */
30
+
31
+ require_once 'Mage/Checkout/controllers/CartController.php';
32
+ class Fraktjakt_Fraktjaktmodule_Checkout_CartController extends Mage_Checkout_CartController
33
+ {
34
+
35
+ /**
36
+ * Initialize shipping information
37
+ */
38
+ public function estimatePostAction()
39
+ {
40
+ $country = (string) $this->getRequest()->getParam('country_id');
41
+ $postcode = (string) $this->getRequest()->getParam('estimate_postcode');
42
+ $city = (string) $this->getRequest()->getParam('estimate_city');
43
+ $regionId = (string) $this->getRequest()->getParam('region_id');
44
+ $region = (string) $this->getRequest()->getParam('region');
45
+ $street = (string) $this->getRequest()->getParam('estimate_street');
46
+
47
+ $this->_getQuote()->getShippingAddress()
48
+ ->setCountryId($country)
49
+ ->setCity($city)
50
+ ->setPostcode($postcode)
51
+ ->setRegionId($regionId)
52
+ ->setRegion($region)
53
+ ->setStreet($street)
54
+ ->setCollectShippingRates(true);
55
+ $this->_getQuote()->save();
56
+ $this->_goBack();
57
+
58
+ Mage::log("yes I am here");
59
+
60
+ parent::estimatePostAction();
61
+ }
62
+
63
+ /* public function addAction()
64
+ {
65
+ echo 'I successfully Override Cart Controller';
66
+ parent::addAction();
67
+ }
68
+ public function indexAction()
69
+ {
70
+ Mage::log("I successfully Override Cart Controller");
71
+ echo 'I successfully Override Cart Controller';
72
+ parent::estimatePostAction();
73
+ }*/
74
+
75
+
76
+ }
app/code/community/Fraktjakt/Fraktjaktmodule/etc/config.xml ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <default>
4
+ <carriers>
5
+ <fraktjakt_fraktjaktmodule>
6
+ <active>1</active>
7
+ <sallowspecific>0</sallowspecific>
8
+ <model>Fraktjakt_Fraktjaktmodule_Model_Carrier_Shippingmethod</model>
9
+ <name>Fraktjakt_Fraktjaktmodule</name>
10
+ <title>Fraktjakt_Fraktjaktmodule</title>
11
+ <specificerrmsg>Din valda frakttjänst är inte tillgänglig för din mottagaradress.</specificerrmsg>
12
+ <erroremail>0</erroremail>
13
+ <handling_type>F</handling_type>
14
+ <min_shipping_value>0</min_shipping_value>
15
+ <max_shipping_value>0</max_shipping_value>
16
+ <min_shipping_weight>0</min_shipping_weight>
17
+ <max_shipping_weight>0</max_shipping_weight>
18
+ <showmethod>0</showmethod>
19
+ </fraktjakt_fraktjaktmodule>
20
+ </carriers>
21
+ </default>
22
+ <modules>
23
+ <Fraktjakt_Fraktjaktmodule>
24
+ <version>0.2.3</version>
25
+ </Fraktjakt_Fraktjaktmodule>
26
+ </modules>
27
+ <global>
28
+
29
+ <models>
30
+ <fraktjakt_fraktjaktmodule>
31
+ <class>Fraktjakt_Fraktjaktmodule_Model</class>
32
+ </fraktjakt_fraktjaktmodule>
33
+ </models>
34
+ <helpers>
35
+ <fraktjakt_fraktjaktmodule>
36
+ <class>Fraktjakt_Fraktjaktmodule_Helper</class>
37
+ </fraktjakt_fraktjaktmodule>
38
+ </helpers>
39
+ <blocks>
40
+ <fraktjakt_fraktjaktmodule>
41
+ <class>Fraktjakt_Fraktjaktmodule_Block</class>
42
+ </fraktjakt_fraktjaktmodule>
43
+ </blocks>
44
+ <resources>
45
+ <fraktjakt_fraktjaktmodule_setup>
46
+ <setup>
47
+ <module>Fraktjakt_Fraktjaktmodule</module>
48
+ </setup>
49
+ <connection>
50
+ <use>core_setup</use>
51
+ </connection>
52
+ </fraktjakt_fraktjaktmodule_setup>
53
+ </resources>
54
+ <events>
55
+ <sales_order_save_after>
56
+ <observers>
57
+ <Fraktjakt_Fraktjaktmodule_Model_Observer>
58
+ <type>singleton</type>
59
+ <class>Fraktjakt_Fraktjaktmodule_Model_Observer</class>
60
+ <method>salestest</method>
61
+ </Fraktjakt_Fraktjaktmodule_Model_Observer>
62
+ </observers>
63
+ </sales_order_save_after>
64
+ </events>
65
+ <blocks>
66
+ <adminhtml>
67
+ <rewrite>
68
+ <sales_order_view>Fraktjakt_Fraktjaktmodule_Block_Adminhtml_Sales_Order_View</sales_order_view>
69
+ <sales_order_shipment_view>Fraktjakt_Fraktjaktmodule_Block_Adminhtml_Sales_Order_Shipment_View</sales_order_shipment_view>
70
+ </rewrite>
71
+ </adminhtml>
72
+ </blocks>
73
+ </global>
74
+ <frontend>
75
+ <routers>
76
+ <checkout>
77
+ <args>
78
+ <modules>
79
+ <Fraktjakt_Fraktjaktmodule before="Mage_Checkout">Fraktjakt_Fraktjaktmodule_Checkout</Fraktjakt_Fraktjaktmodule>
80
+ </modules>
81
+ </args>
82
+ </checkout>
83
+ </routers>
84
+ <layout>
85
+ <updates>
86
+ <fraktjakt_fraktjaktmodule>
87
+ <file>fraktjakt_fraktjaktmodule.xml</file>
88
+ </fraktjakt_fraktjaktmodule>
89
+ </updates>
90
+ </layout>
91
+ </frontend>
92
+ </config>
app/code/community/Fraktjakt/Fraktjaktmodule/etc/system.xml ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <carriers>
5
+ <groups>
6
+ <fraktjakt_fraktjaktmodule translate="label" module="shipping">
7
+ <label>Fraktjakt</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>13</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <consignorID translate="label">
15
+ <label>consignor ID</label>
16
+ <frontend_type>text</frontend_type>
17
+ <sort_order>3</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ </consignorID>
22
+ <consignorkey translate="label">
23
+ <label>consignor key</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>3</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>0</show_in_store>
29
+ </consignorkey>
30
+ <fraktjaktLogin translate="label">
31
+ <label>Fraktjakt Login</label>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>96</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ </fraktjaktLogin>
38
+ <fraktjaktPassword translate="label">
39
+ <label>Fraktjakt Lösenord</label>
40
+ <frontend_type>password</frontend_type>
41
+ <sort_order>97</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>1</show_in_website>
44
+ <show_in_store>0</show_in_store>
45
+ </fraktjaktPassword>
46
+ <run translate="label">
47
+ <label>Run now</label>
48
+ <frontend_type>button</frontend_type>
49
+ <frontend_model>fraktjakt_fraktjaktmodule/button</frontend_model>
50
+ <sort_order>98</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>1</show_in_website>
53
+ <show_in_store>0</show_in_store>
54
+ </run>
55
+ <active translate="label">
56
+ <label>Enabled</label>
57
+ <frontend_type>select</frontend_type>
58
+ <source_model>adminhtml/system_config_source_yesno</source_model>
59
+ <sort_order>1</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>0</show_in_store>
63
+ </active>
64
+ <test_mode translate="label">
65
+ <label>Test Mode</label>
66
+ <frontend_type>select</frontend_type>
67
+ <source_model>adminhtml/system_config_source_yesno</source_model>
68
+ <sort_order>4</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>0</show_in_store>
72
+ </test_mode>
73
+ <debug translate="label">
74
+ <label>Debug Mode</label>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>adminhtml/system_config_source_yesno</source_model>
77
+ <sort_order>4</sort_order>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>1</show_in_website>
80
+ <show_in_store>0</show_in_store>
81
+ </debug>
82
+ <usecache translate="label">
83
+ <label>Use Cache for faster Checkout Page loads?</label>
84
+ <frontend_type>select</frontend_type>
85
+ <source_model>adminhtml/system_config_source_yesno</source_model>
86
+ <sort_order>4</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>0</show_in_store>
90
+ </usecache>
91
+ <returnlang translate="label">
92
+ <label>Set SV Return Language (Default is EN)</label>
93
+ <frontend_type>select</frontend_type>
94
+ <source_model>adminhtml/system_config_source_yesno</source_model>
95
+ <sort_order>4</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>1</show_in_website>
98
+ <show_in_store>0</show_in_store>
99
+ </returnlang>
100
+ <returnlangstore translate="label">
101
+ <label>Return Swedish based on Store Language? (Defaults to english unless the store is SV)</label>
102
+ <frontend_type>select</frontend_type>
103
+ <source_model>adminhtml/system_config_source_yesno</source_model>
104
+ <sort_order>4</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>0</show_in_store>
108
+ </returnlangstore>
109
+ <sort_order translate="label">
110
+ <label>Sort order</label>
111
+ <frontend_type>text</frontend_type>
112
+ <sort_order>100</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>0</show_in_store>
116
+ </sort_order>
117
+ <title translate="label">
118
+ <label>Title</label>
119
+ <frontend_type>text</frontend_type>
120
+ <sort_order>2</sort_order>
121
+ <show_in_default>1</show_in_default>
122
+ <show_in_website>1</show_in_website>
123
+ <show_in_store>1</show_in_store>
124
+ </title>
125
+ <failover_ratetitle translate="label">
126
+ <label>Fallback-frakttjänst</label>
127
+ <frontend_type>text</frontend_type>
128
+ <sort_order>7</sort_order>
129
+ <show_in_default>1</show_in_default>
130
+ <show_in_website>1</show_in_website>
131
+ <show_in_store>0</show_in_store>
132
+ </failover_ratetitle>
133
+ <failover_rate translate="label">
134
+ <label>Fallback-kostnad för frakt</label>
135
+ <frontend_type>text</frontend_type>
136
+ <sort_order>7</sort_order>
137
+ <show_in_default>1</show_in_default>
138
+ <show_in_website>1</show_in_website>
139
+ <show_in_store>0</show_in_store>
140
+ </failover_rate>
141
+ <sallowspecific translate="label">
142
+ <label>Frakt till tillgängliga länder</label>
143
+ <frontend_type>select</frontend_type>
144
+ <sort_order>90</sort_order>
145
+ <frontend_class>shipping-applicable-country</frontend_class>
146
+ <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
147
+ <show_in_default>1</show_in_default>
148
+ <show_in_website>1</show_in_website>
149
+ <show_in_store>0</show_in_store>
150
+ </sallowspecific>
151
+ <specificcountry translate="label">
152
+ <label>Frakt till enstaka länder</label>
153
+ <frontend_type>multiselect</frontend_type>
154
+ <sort_order>91</sort_order>
155
+ <source_model>adminhtml/system_config_source_country</source_model>
156
+ <show_in_default>1</show_in_default>
157
+ <show_in_website>1</show_in_website>
158
+ <show_in_store>0</show_in_store>
159
+ </specificcountry>
160
+ <erroremail translate="label">
161
+ <label>Skicka emailrapport om misslyckade fraktsökningar</label>
162
+ <frontend_type>select</frontend_type>
163
+ <source_model>adminhtml/system_config_source_yesno</source_model>
164
+ <sort_order>92</sort_order>
165
+ <show_in_default>1</show_in_default>
166
+ <show_in_website>1</show_in_website>
167
+ <show_in_store>0</show_in_store>
168
+ </erroremail>
169
+ </fields>
170
+ </fraktjakt_fraktjaktmodule>
171
+ </groups>
172
+ </carriers>
173
+ </sections>
174
+ </config>
app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-install-0.2.0.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+ $installer->startSetup();
6
+ $eav = new Mage_Eav_Model_Entity_Setup('sales_setup');
7
+ $cw = Mage::getSingleton('core/resource')
8
+ ->getConnection('core_write');
9
+ $cr = Mage::getSingleton('core/resource')
10
+ ->getConnection('core_read');
11
+
12
+ $sql = ' CREATE TABLE IF NOT EXISTS `fraktjakt_cache` (
13
+ `id` int(10) NOT NULL AUTO_INCREMENT,
14
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
15
+ `session_id` varchar(255) NOT NULL,
16
+ `request_hash` varchar(255) NOT NULL,
17
+ `response` text NOT NULL,
18
+ `response_id` int(10) NOT NULL,
19
+ PRIMARY KEY (`id`),
20
+ KEY `session_id` (`session_id`),
21
+ KEY `response_id` (`response_id`)
22
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
23
+
24
+
25
+
26
+ $row = $cw->query($sql);
27
+
28
+ $sql = ' CREATE TABLE IF NOT EXISTS `fraktjakt_packing` (
29
+ `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
30
+ `order_id` INT( 10 ) NOT NULL ,
31
+ `response_data` text NOT NULL ,
32
+ `shipping_products` text NOT NULL ,
33
+ UNIQUE (
34
+ `order_id`
35
+ )
36
+ ) ENGINE = MYISAM ;';
37
+
38
+
39
+ $row = $cw->query($sql);
40
+
41
+
42
+ // Get entity model id 'sales/order'
43
+ $sql = 'SELECT entity_type_id FROM '.$this->getTable('eav_entity_type').' WHERE entity_type_code="catalog_product"';
44
+ $row = $cr->fetchRow($sql);
45
+
46
+ $attribute_model = Mage::getModel('eav/entity_attribute');
47
+ $pattributes = array();
48
+ $attribute_code = 'length';
49
+ $attribute_id = $attribute_model->getIdByCode('catalog_product', $attribute_code);
50
+
51
+ if(!isset($attribute_id) || !is_numeric($attribute_id) || $attribute_id == 0)
52
+ {
53
+ // Create EAV-attribute for the order comment.
54
+ $c = array (
55
+ 'entity_type_id' => $row['entity_type_id'],
56
+ 'attribute_code' => $attribute_code,
57
+ 'backend_type' => 'decimal', // MySQL-Datatype
58
+ 'frontend_input' => 'text', // Type of the HTML form element
59
+ 'is_global' => '1',
60
+ 'is_visible' => '1',
61
+ 'is_filterable' => '0',
62
+ 'apply_to' => 'simple,configurable',
63
+ 'is_visible_on_front' => 0,
64
+ 'is_comparable' => '0',
65
+ 'is_searchable' => '0',
66
+ 'is_required' => '0',
67
+ 'is_user_defined' => '0',
68
+ 'frontend_label' => 'Length',
69
+ 'note' => 'Length of shippable product',
70
+ );
71
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
72
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
73
+ ->setStoreId(0)
74
+ ->addData($c);
75
+ $attribute->save();
76
+ $pattributes[] = $c['attribute_code'];
77
+ }
78
+
79
+ $attribute_code = 'width';
80
+ $attribute_id = $attribute_model->getIdByCode('catalog_product', $attribute_code);
81
+
82
+ if(!isset($attribute_id) || !is_numeric($attribute_id) || $attribute_id == 0)
83
+ {
84
+ // Create EAV-attribute for the order comment.
85
+ $c = array (
86
+ 'entity_type_id' => $row['entity_type_id'],
87
+ 'attribute_code' => $attribute_code,
88
+ 'backend_type' => 'decimal', // MySQL-Datatype
89
+ 'frontend_input' => 'text', // Type of the HTML form element
90
+ 'is_global' => '1',
91
+ 'is_visible' => '1',
92
+ 'is_filterable' => '0',
93
+ 'apply_to' => 'simple,configurable',
94
+ 'is_visible_on_front' => 0,
95
+ 'is_comparable' => '0',
96
+ 'is_searchable' => '0',
97
+ 'is_required' => '0',
98
+ 'is_user_defined' => '0',
99
+
100
+ 'frontend_label' => 'Width',
101
+ 'note' => 'Width of shippable product',
102
+ );
103
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
104
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
105
+ ->setStoreId(0)
106
+ ->addData($c);
107
+ $attribute->save();
108
+ $pattributes[] = $c['attribute_code'];
109
+ }
110
+
111
+
112
+ $attribute_code = 'height';
113
+ $attribute_id = $attribute_model->getIdByCode('catalog_product', $attribute_code);
114
+
115
+ if(!isset($attribute_id) || !is_numeric($attribute_id) || $attribute_id == 0)
116
+ {
117
+ // Create EAV-attribute for the order comment.
118
+ $c = array (
119
+ 'entity_type_id' => $row['entity_type_id'],
120
+ 'attribute_code' => $attribute_code,
121
+ 'backend_type' => 'decimal', // MySQL-Datatype
122
+ 'frontend_input' => 'text', // Type of the HTML form element
123
+ 'is_global' => '1',
124
+ 'is_visible' => '1',
125
+ 'is_filterable' => '0',
126
+ 'apply_to' => 'simple,configurable',
127
+ 'is_visible_on_front' => 0,
128
+ 'is_comparable' => '0',
129
+ 'is_searchable' => '0',
130
+ 'is_required' => '0',
131
+ 'is_user_defined' => '0',
132
+
133
+ 'frontend_label' => 'Height',
134
+ 'note' => 'Height of shippable product',
135
+ );
136
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
137
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
138
+ ->setStoreId(0)
139
+ ->addData($c);
140
+ $attribute->save();
141
+ $pattributes[] = $c['attribute_code'];
142
+ }
143
+
144
+ $attribute_code = 'weight_measure';
145
+ $attribute_id = $attribute_model->getIdByCode('catalog_product', $attribute_code);
146
+
147
+ if(!isset($attribute_id) || !is_numeric($attribute_id) || $attribute_id == 0)
148
+ {
149
+ // mage::log(__CLASS__ ." osdfdi " . Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::KG);
150
+ // Create EAV-attribute for the order comment.
151
+ $c = array (
152
+ 'entity_type_id' => $row['entity_type_id'],
153
+ 'attribute_code' => $attribute_code,
154
+ 'backend_type' => 'varchar', // MySQL-Datatype
155
+ 'source_model' => 'Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits',
156
+ 'frontend_input' => 'select', // Type of the HTML form element
157
+ 'backend_table' => '',
158
+ 'frontend_model' => '',
159
+ 'is_global' => '1',
160
+ 'is_visible' => '1',
161
+ 'is_filterable' => '0',
162
+ 'apply_to' => 'simple,configurable',
163
+ 'is_visible_on_front' => '0',
164
+ 'is_comparable' => '0',
165
+ 'is_searchable' => '0',
166
+ 'is_required' => '0',
167
+ 'is_user_defined' => '0',
168
+
169
+ 'frontend_label' => 'Weight Units',
170
+ 'default_value' => 'kg',
171
+ 'note' => 'Select the appropriate unit of measure',
172
+ );
173
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
174
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
175
+ ->setStoreId(0)
176
+ ->addData($c);
177
+ $attribute->save();
178
+ $eav->updateAttribute('catalog_product', $attribute_code, 'source_model', 'Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits');
179
+ $pattributes[] = $c['attribute_code'];
180
+ }
181
+ $attribute_code = 'readytoship';
182
+ $attribute_id = $attribute_model->getIdByCode('catalog_product', $attribute_code);
183
+
184
+ if(!isset($attribute_id) || !is_numeric($attribute_id) || $attribute_id == 0)
185
+ {
186
+ // Create EAV-attribute for the order comment.
187
+ $c = array (
188
+ 'entity_type_id' => $row['entity_type_id'],
189
+ 'attribute_code' => $attribute_code,
190
+ 'backend_type' => 'int', // MySQL-Datatype
191
+ 'source_model' => 'eav/entity_attribute_source_boolean',
192
+ 'backend_table' => '',
193
+ 'frontend_model' => '',
194
+ 'frontend_input' => 'select', // Type of the HTML form element
195
+ 'is_global' => '1',
196
+ 'is_visible' => '1',
197
+ 'is_filterable' => '0',
198
+ 'apply_to' => 'simple,configurable',
199
+ 'is_visible_on_front' => '0',
200
+ 'is_comparable' => '0',
201
+ 'is_searchable' => '0',
202
+ 'is_required' => '0',
203
+ 'is_user_defined' => '0',
204
+
205
+ 'frontend_label' => 'Item is Ready to Ship as is',
206
+ // 'default_value' => Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::KG,
207
+ 'note' => 'Does this item need further packaging? (*Or is it ready to ship in its current box?)',
208
+ );
209
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
210
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
211
+ ->setStoreId(0)
212
+ ->addData($c);
213
+ $attribute->save();
214
+
215
+ $eav->updateAttribute('catalog_product', $attribute_code, 'source_model', 'eav/entity_attribute_source_boolean');
216
+ $pattributes[] = $c['attribute_code'];
217
+ }
218
+
219
+
220
+ Mage::app('default');
221
+
222
+ // $attrib_model_setup = Mage::getModel('eav/entity_setup');
223
+ $attrib_model_setup = Mage::getModel('eav/entity_setup', 'eav_setup');
224
+ $entityTypeId = $row['entity_type_id'];
225
+ $attr_group = 'General';
226
+
227
+
228
+ $sets = $cr->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $row['entity_type_id']);
229
+ foreach($sets as $set)
230
+ {
231
+ foreach($pattributes as $attributeCode)
232
+ {
233
+ $attrib_model_setup->addAttributeToSet($entityTypeId, $set['attribute_set_id'], $attr_group, $attributeCode, $sortOrder);
234
+ }
235
+ }
236
+
237
+
238
+
239
+ // if they had the free extension installed
240
+ // lets copy the settings.
241
+ if(Mage::getStoreConfig('carriers/fraktjakt_fraktjaktmodule/active') || strlen(Mage::getStoreConfig('carriers/fraktjakt_fraktjaktmodule/title')))
242
+ {
243
+ $table = $this->getTable('core/config_data');
244
+ $config = $cr->fetchAll('select * from '.$table.' where path like \'%carriers/fraktjakt_fraktjaktmodule%\' ');
245
+ foreach($config as $piece)
246
+ {
247
+ $value = $piece['value'];
248
+ $config_id = 'NULL';
249
+ $scope = $piece['scope'];
250
+ $scope_id = $piece['scope_id'];
251
+ $path = $piece['path'];
252
+ if($path == 'carriers/fraktjakt_fraktjaktmodule/active')
253
+ {
254
+ $value = 0;
255
+ }
256
+ $sql = "insert into {$table} values (NULL, '{$scope}', '{$scope_id}', '{$path}', ?)";
257
+ $cw->query($sql,$value);
258
+ }
259
+ }
260
+ $installer->endSetup();
app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-upgrade-0.2.0-0.2.1.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+ $installer->startSetup();
6
+ $eav = new Mage_Eav_Model_Entity_Setup('sales_setup');
7
+ $cw = Mage::getSingleton('core/resource')
8
+ ->getConnection('core_write');
9
+ $cr = Mage::getSingleton('core/resource')
10
+ ->getConnection('core_read');
11
+
12
+
13
+ // Get entity model id 'sales/order'
14
+ $sql = 'SELECT entity_type_id FROM '.$this->getTable('eav_entity_type').' WHERE entity_type_code="catalog_product"';
15
+ $row = $cr->fetchRow($sql);
16
+
17
+ $attribute_model = Mage::getModel('eav/entity_attribute');
18
+ $pattributes = array();
19
+
20
+
21
+
22
+
23
+ mage::log(__FILE__ . __LINE__ );
24
+ $attribute_code = 'dimension_units';
25
+ $attribute_id = $attribute_model->getIdByCode('catalog_product', $attribute_code);
26
+
27
+ if(!isset($attribute_id) || !is_numeric($attribute_id) || $attribute_id == 0)
28
+ {
29
+ //mage::log(__CLASS__ ." osdfdi " . Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::KG);
30
+ // Create EAV-attribute for the order comment.
31
+ $c = array (
32
+ 'entity_type_id' => $row['entity_type_id'],
33
+ 'attribute_code' => $attribute_code,
34
+ 'backend_type' => 'varchar', // MySQL-Datatype
35
+ 'source_model' => 'Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits',
36
+ 'frontend_input' => 'select', // Type of the HTML form element
37
+ 'backend_table' => '',
38
+ 'frontend_model' => '',
39
+ 'is_global' => '1',
40
+ 'is_visible' => '1',
41
+ 'is_filterable' => '0',
42
+ 'apply_to' => 'simple,configurable',
43
+ 'is_visible_on_front' => '0',
44
+ 'is_comparable' => '0',
45
+ 'is_searchable' => '0',
46
+ 'is_required' => '0',
47
+ 'is_user_defined' => '0',
48
+
49
+ 'frontend_label' => 'Dimension Units',
50
+ 'default_value' => 'cm',
51
+ 'note' => 'Select the appropriate unit of measure',
52
+ );
53
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
54
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
55
+ ->setStoreId(0)
56
+ ->addData($c);
57
+ $attribute->save();
58
+ $eav->updateAttribute('catalog_product', $attribute_code, 'source_model', 'Fraktjakt_Fraktjaktmodule_Model_Source_Dimentionunits');
59
+ $pattributes[] = $c['attribute_code'];
60
+ }
61
+ $attribute_code = 'readytoship';
62
+ $attribute_id = $attribute_model->getIdByCode('catalog_product', $attribute_code);
63
+
64
+ if(!isset($attribute_id) || !is_numeric($attribute_id) || $attribute_id == 0)
65
+ {
66
+ // Create EAV-attribute for the order comment.
67
+ $c = array (
68
+ 'entity_type_id' => $row['entity_type_id'],
69
+ 'attribute_code' => $attribute_code,
70
+ 'backend_type' => 'int', // MySQL-Datatype
71
+ 'source_model' => 'eav/entity_attribute_source_boolean',
72
+ 'backend_table' => '',
73
+ 'frontend_model' => '',
74
+ 'frontend_input' => 'select', // Type of the HTML form element
75
+ 'is_global' => '1',
76
+ 'is_visible' => '1',
77
+ 'is_filterable' => '0',
78
+ 'apply_to' => 'simple,configurable',
79
+ 'is_visible_on_front' => '0',
80
+ 'is_comparable' => '0',
81
+ 'is_searchable' => '0',
82
+ 'is_required' => '0',
83
+ 'is_user_defined' => '0',
84
+
85
+ 'frontend_label' => 'Item is Ready to Ship as is',
86
+ // 'default_value' => Fraktjakt_Fraktjaktmodule_Model_Source_Weightunits::KG,
87
+ 'note' => 'Does this item need further packaging? (*Or is it ready to ship in its current box?)',
88
+ );
89
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
90
+ $attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
91
+ ->setStoreId(0)
92
+ ->addData($c);
93
+ $attribute->save();
94
+
95
+ $eav->updateAttribute('catalog_product', $attribute_code, 'source_model', 'eav/entity_attribute_source_boolean');
96
+ $pattributes[] = $c['attribute_code'];
97
+ }
98
+
99
+ mage::log(__FILE__ . __LINE__ );
100
+ Mage::app('default');
101
+ mage::log(__FILE__ . __LINE__ );
102
+ $attrib_model_setup = Mage::getModel('eav/entity_setup', 'eav_setup');
103
+ $entityTypeId = $row['entity_type_id'];
104
+ $attr_group = 'General';
105
+ mage::log(__FILE__ . __LINE__ );
106
+
107
+ $sets = $cr->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $row['entity_type_id']);
108
+ foreach($sets as $set)
109
+ {
110
+ foreach($pattributes as $attributeCode)
111
+ {
112
+ $attrib_model_setup->addAttributeToSet($entityTypeId, $set['attribute_set_id'], $attr_group, $attributeCode, $sortOrder);
113
+ }
114
+ }
115
+
116
+ mage::log(__FILE__ . __LINE__ );
117
+
118
+ // if they had the free extension installed
119
+ // lets copy the settings.
120
+ if(Mage::getStoreConfig('carriers/fraktjakt_fraktjaktmodule/active') || strlen(Mage::getStoreConfig('carriers/fraktjakt_fraktjaktmodule/title')))
121
+ {
122
+ $table = $this->getTable('core/config_data');
123
+ $config = $cr->fetchAll('select * from '.$table.' where path like \'%carriers/fraktjakt_fraktjaktmodule%\' ');
124
+ foreach($config as $piece)
125
+ {
126
+ $value = $piece['value'];
127
+ $config_id = 'NULL';
128
+ $scope = $piece['scope'];
129
+ $scope_id = $piece['scope_id'];
130
+ $path = $piece['path'];
131
+ if($path == 'carriers/fraktjakt_fraktjaktmodule/active')
132
+ {
133
+ $value = 0;
134
+ }
135
+ $sql = "insert into {$table} values (NULL, '{$scope}', '{$scope_id}', '{$path}', ?)";
136
+ $cw->query($sql,$value);
137
+ }
138
+ }
139
+ $installer->endSetup();
app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-upgrade-0.2.1-0.2.2.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+ $installer->startSetup();
6
+ $eav = new Mage_Eav_Model_Entity_Setup('sales_setup');
7
+ $cw = Mage::getSingleton('core/resource')
8
+ ->getConnection('core_write');
9
+ $cr = Mage::getSingleton('core/resource')
10
+ ->getConnection('core_read');
11
+
12
+
13
+
14
+ $sql = ' drop table if exists fraktjakt_packing';
15
+ $table = Mage::getSingleton('core/resource')->getTablename('fraktjakt_packing');
16
+ $row = $cw->query($sql);
17
+
18
+ $sql = "CREATE TABLE IF NOT EXISTS `{$table}` (
19
+ `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
20
+ `order_id` INT( 10 ) NOT NULL ,
21
+ `quote_id` INT( 10 ) NOT NULL ,
22
+ `response_data` text NOT NULL
23
+ ) ENGINE = MYISAM ;";
24
+
25
+ $row = $cw->query($sql);
26
+
27
+ $sql = "alter table `{$table}` add index(order_id)";
28
+
29
+ $row = $cw->query($sql);
30
+ $sql = "alter table `{$table}` add index(quote_id)";
31
+
32
+ $row = $cw->query($sql);
33
+
34
+ $installer->endSetup();
app/code/community/Fraktjakt/Fraktjaktmodule/sql/fraktjaktmodule_setup/mysql4-upgrade-0.2.2-0.2.3.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+ $installer->startSetup();
6
+ $eav = new Mage_Eav_Model_Entity_Setup('sales_setup');
7
+ $cw = Mage::getSingleton('core/resource')
8
+ ->getConnection('core_write');
9
+ $cr = Mage::getSingleton('core/resource')
10
+ ->getConnection('core_read');
11
+
12
+
13
+
14
+ $table = Mage::getSingleton('core/resource')->getTablename('fraktjakt_shipment_dimensions');
15
+
16
+ $sql = "CREATE TABLE IF NOT EXISTS `{$table}` (
17
+ `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
18
+ `shipment_id` INT( 10 ) NOT NULL ,
19
+ `weight` decimal( 10,5 ) NOT NULL ,
20
+ `length` decimal( 10,5 ) NOT NULL ,
21
+ `width` decimal( 10,5 ) NOT NULL ,
22
+ `height` decimal( 10,5 ) NOT NULL
23
+ ) ENGINE = MYISAM ;";
24
+
25
+ $row = $cw->query($sql);
26
+
27
+ $sql = "alter table `{$table}` add index(shipment_id)";
28
+
29
+ $row = $cw->query($sql);
30
+
31
+
32
+ $installer->endSetup();
app/design/frontend/base/default/template/fraktjakt/checkout/cart/shipping.phtml ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php /** @var $this Mage_Checkout_Block_Cart_Shipping */ ?>
28
+ <div class="shipping">
29
+ <h2><?php echo $this->__('Estimate Shipping and Tax') ?></h2>
30
+ <div class="shipping-form">
31
+ <form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">
32
+ <p><?php echo $this->__('Enter your destination to get a shipping estimate.') ?></p>
33
+ <ul class="form-list">
34
+ <li>
35
+ <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
36
+ <div class="input-box">
37
+ <?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
38
+ </div>
39
+ </li>
40
+ <li>
41
+ <label for="address" class="required"><em>*</em><?php echo $this->__('Address') ?></label>
42
+ <div class="input-box">
43
+
44
+ <input class="input-text validate-address required-entry" type="text" id="street" name="estimate_street" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet1()) ?>" />
45
+
46
+ </div>
47
+ </li>
48
+ <?php //if($this->getStateActive()): ?>
49
+ <li>
50
+ <label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
51
+ <div class="input-box">
52
+ <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
53
+ <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
54
+ </select>
55
+ <script type="text/javascript">
56
+ //<![CDATA[
57
+ $('region_id').setAttribute('defaultValue', "<?php echo $this->getEstimateRegionId() ?>");
58
+ //]]>
59
+ </script>
60
+ <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
61
+ </div>
62
+ </li>
63
+ <?php //endif; ?>
64
+ <?php if($this->getCityActive()): ?>
65
+ <li>
66
+ <label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
67
+ <div class="input-box">
68
+ <input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
69
+ </div>
70
+ </li>
71
+ <?php endif; ?>
72
+ <li>
73
+ <label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?>><?php if ($this->isZipCodeRequired()) echo '<em>*</em>' ?><?php echo $this->__('Zip/Postal Code') ?></label>
74
+ <div class="input-box">
75
+ <input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />
76
+ </div>
77
+ </li>
78
+ </ul>
79
+ <div class="buttons-set">
80
+ <button type="button" title="<?php echo $this->__('Get a Quote') ?>" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Get a Quote') ?></span></span></button>
81
+ </div>
82
+ </form>
83
+ <script type="text/javascript">
84
+ //<![CDATA[
85
+ new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
86
+ //]]>
87
+ </script>
88
+
89
+ <?php if (($_shippingRateGroups = $this->getEstimateRates())): ?>
90
+ <form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
91
+ <dl class="sp-methods">
92
+ <?php foreach ($_shippingRateGroups as $code => $_rates): ?>
93
+ <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
94
+ <dd>
95
+ <ul>
96
+ <?php foreach ($_rates as $_rate): ?>
97
+ <li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
98
+ <?php if ($_rate->getErrorMessage()): ?>
99
+ <?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
100
+ <?php else: ?>
101
+ <input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
102
+ <label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
103
+ <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
104
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
105
+ <?php echo $_excl; ?>
106
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
107
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
108
+ <?php endif; ?>
109
+ </label>
110
+ <?php endif ?>
111
+ </li>
112
+ <?php endforeach; ?>
113
+ </ul>
114
+ </dd>
115
+ <?php endforeach; ?>
116
+ </dl>
117
+ <div class="buttons-set">
118
+ <button type="submit" title="<?php echo $this->__('Update Total') ?>" class="button" name="do" value="<?php echo $this->__('Update Total') ?>"><span><span><?php echo $this->__('Update Total') ?></span></span></button>
119
+ </div>
120
+ </form>
121
+ <?php endif; ?>
122
+ <script type="text/javascript">
123
+ //<![CDATA[
124
+ var coShippingMethodForm = new VarienForm('shipping-zip-form');
125
+ var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
126
+
127
+ coShippingMethodForm.submit = function () {
128
+ var country = $F('country');
129
+ var optionalZip = false;
130
+
131
+ for (i=0; i < countriesWithOptionalZip.length; i++) {
132
+ if (countriesWithOptionalZip[i] == country) {
133
+ optionalZip = true;
134
+ }
135
+ }
136
+ if (optionalZip) {
137
+ $('postcode').removeClassName('required-entry');
138
+ }
139
+ else {
140
+ $('postcode').addClassName('required-entry');
141
+ }
142
+ return VarienForm.prototype.submit.bind(coShippingMethodForm)();
143
+ }
144
+ //]]>
145
+ </script>
146
+ </div>
147
+ </div>
app/design/frontend/base/default/template/fraktjakt/checkout/onepage/shipping_method/fraktjakttemplate.phtml ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php /** @var $this Mage_Checkout_Block_Onepage_Shipping_Method_Available */ ?>
28
+ <style>
29
+
30
+ .sp-methods .price {
31
+ font-weight:normal;
32
+ }
33
+ </style>
34
+ <?php $_shippingRateGroups = $this->getShippingRates(); ?>
35
+ <?php if (!$_shippingRateGroups): ?>
36
+ <p><?php echo $this->__('Vi ber om ursäkt. För tillfället kunde ingen fraktkostnad kunde beräknas.') ?></p>
37
+ <?php else: ?>
38
+ <dl class="sp-methods">
39
+ <?php $shippingCodePrice = array(); ?>
40
+ <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
41
+ <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
42
+ <dd>
43
+ <ul>
44
+ <li> <table width="100%" border="0"> <tr> <td width="5%"></td><td align="left" width="40%"><strong>Frakttjänst</strong></td>
45
+ <td width="15%"><strong>Leveranstid</strong></td><td width="20%"><strong>Ombud</strong></td> <td><strong>Kostnad</strong></td>
46
+ </tr></table></li>
47
+ <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
48
+ <?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
49
+ <li> <table width="100%" border="0">
50
+ <tr>
51
+ <?php if ($_rate->getErrorMessage()): ?>
52
+ <ul class="messages"><li class="error-msg"><ul><li><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li></ul></li></ul>
53
+ <?php else: ?>
54
+ <td width="5%">
55
+ <?php if ($_sole) : ?>
56
+ <span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" /></span>
57
+ <?php else: ?>
58
+ <input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
59
+ </td>
60
+ <?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
61
+ <script type="text/javascript">
62
+ //<![CDATA[
63
+ lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
64
+ //]]>
65
+ </script>
66
+ <?php endif; ?>
67
+
68
+ <?php endif; ?>
69
+
70
+
71
+ <?php $mt=$this->escapeHtml($_rate->getMethodTitle());
72
+ $nmt=$this->escapeHtml($_rate->getMethodDescription());
73
+ list($mtitle,$md,$mag,$md1,$mag1,$surl)=preg_split('/[@]/',$nmt);
74
+ ?>
75
+ <td align="left" width="40%"> <label for="s_method_<?php echo $_rate->getCode() ?>"><strong> <?php echo $mtitle; ?>
76
+
77
+
78
+
79
+
80
+ </strong></label></td>
81
+ <td width="15%"> <?php echo $md; ?></td>
82
+ <td width="20%">
83
+ <?php if(!empty($surl)){?>
84
+ <a href="<?php echo $surl; ?>" target="_blank">
85
+ <?php } ?>
86
+ <?php echo $mag; ?>
87
+
88
+ <?php if(!empty($surl)){?>
89
+ </a>
90
+ <?php } ?>
91
+ </td>
92
+ <td> <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
93
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
94
+ <?php echo $_excl; ?>
95
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
96
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
97
+ <?php endif; ?> </td>
98
+
99
+
100
+
101
+
102
+ <?php endif ?></tr>
103
+ </table>
104
+ </li>
105
+ <?php endforeach; ?>
106
+ </ul>
107
+ </dd>
108
+ <?php endforeach; ?>
109
+ </dl>
110
+ <script type="text/javascript">
111
+ //<![CDATA[
112
+ <?php if (!empty($shippingCodePrice)): ?>
113
+ var shippingCodePrice = {<?php echo implode(',',$shippingCodePrice); ?>};
114
+ <?php endif; ?>
115
+
116
+ $$('input[type="radio"][name="shipping_method"]').each(function(el){
117
+ Event.observe(el, 'click', function(){
118
+ if (el.checked == true) {
119
+ var getShippingCode = el.getValue();
120
+ <?php if (!empty($shippingCodePrice)): ?>
121
+ var newPrice = shippingCodePrice[getShippingCode];
122
+ if (!lastPrice) {
123
+ lastPrice = newPrice;
124
+ quoteBaseGrandTotal += newPrice;
125
+ }
126
+ if (newPrice != lastPrice) {
127
+ quoteBaseGrandTotal += (newPrice-lastPrice);
128
+ lastPrice = newPrice;
129
+ }
130
+ <?php endif; ?>
131
+ checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
132
+ return false;
133
+ }
134
+ });
135
+ });
136
+ //]]>
137
+ </script>
138
+ <?php endif; ?>
app/design/frontend/base/default/template/fraktjakt/fraktjaktmodule/checkout/cart/shipping.phtml ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php /** @var $this Mage_Checkout_Block_Cart_Shipping */ ?>
28
+ <div class="shipping">
29
+ <h2><?php echo $this->__('Estimate Shipping and Tax') ?></h2>
30
+ <div class="shipping-form">
31
+ <form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">
32
+ <p><?php echo $this->__('Enter your destination to get a shipping estimate.') ?></p>
33
+ <ul class="form-list">
34
+ <li>
35
+ <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
36
+ <div class="input-box">
37
+ <?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
38
+ </div>
39
+ </li>
40
+ <li>
41
+ <label for="address" class="required"><em>*</em><?php echo $this->__('Address') ?></label>
42
+ <div class="input-box">
43
+
44
+ <input class="input-text validate-address required-entry" type="text" id="street" name="estimate_street" value="<?php echo $this->escapeHtml($this->getAddress()->getStreet1()) ?>" />
45
+
46
+ </div>
47
+ </li>
48
+ <?php //if($this->getStateActive()): ?>
49
+ <li>
50
+ <label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
51
+ <div class="input-box">
52
+ <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
53
+ <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
54
+ </select>
55
+ <script type="text/javascript">
56
+ //<![CDATA[
57
+ $('region_id').setAttribute('defaultValue', "<?php echo $this->getEstimateRegionId() ?>");
58
+ //]]>
59
+ </script>
60
+ <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
61
+ </div>
62
+ </li>
63
+ <?php //endif; ?>
64
+ <?php if($this->getCityActive()): ?>
65
+ <li>
66
+ <label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
67
+ <div class="input-box">
68
+ <input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
69
+ </div>
70
+ </li>
71
+ <?php endif; ?>
72
+ <li>
73
+ <label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?>><?php if ($this->isZipCodeRequired()) echo '<em>*</em>' ?><?php echo $this->__('Zip/Postal Code') ?></label>
74
+ <div class="input-box">
75
+ <input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />
76
+ </div>
77
+ </li>
78
+ </ul>
79
+ <div class="buttons-set">
80
+ <button type="button" title="<?php echo $this->__('Get a Quote') ?>" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Get a Quote') ?></span></span></button>
81
+ </div>
82
+ </form>
83
+ <script type="text/javascript">
84
+ //<![CDATA[
85
+ new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
86
+ //]]>
87
+ </script>
88
+
89
+ <?php if (($_shippingRateGroups = $this->getEstimateRates())): ?>
90
+ <form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
91
+ <dl class="sp-methods">
92
+ <?php foreach ($_shippingRateGroups as $code => $_rates): ?>
93
+ <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
94
+ <dd>
95
+ <ul>
96
+ <?php foreach ($_rates as $_rate): ?>
97
+ <li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
98
+ <?php if ($_rate->getErrorMessage()): ?>
99
+ <?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
100
+ <?php else: ?>
101
+ <input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
102
+ <label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
103
+ <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
104
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
105
+ <?php echo $_excl; ?>
106
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
107
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
108
+ <?php endif; ?>
109
+ </label>
110
+ <?php endif ?>
111
+ </li>
112
+ <?php endforeach; ?>
113
+ </ul>
114
+ </dd>
115
+ <?php endforeach; ?>
116
+ </dl>
117
+ <div class="buttons-set">
118
+ <button type="submit" title="<?php echo $this->__('Update Total') ?>" class="button" name="do" value="<?php echo $this->__('Update Total') ?>"><span><span><?php echo $this->__('Update Total') ?></span></span></button>
119
+ </div>
120
+ </form>
121
+ <?php endif; ?>
122
+ <script type="text/javascript">
123
+ //<![CDATA[
124
+ var coShippingMethodForm = new VarienForm('shipping-zip-form');
125
+ var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
126
+
127
+ coShippingMethodForm.submit = function () {
128
+ var country = $F('country');
129
+ var optionalZip = false;
130
+
131
+ for (i=0; i < countriesWithOptionalZip.length; i++) {
132
+ if (countriesWithOptionalZip[i] == country) {
133
+ optionalZip = true;
134
+ }
135
+ }
136
+ if (optionalZip) {
137
+ $('postcode').removeClassName('required-entry');
138
+ }
139
+ else {
140
+ $('postcode').addClassName('required-entry');
141
+ }
142
+ return VarienForm.prototype.submit.bind(coShippingMethodForm)();
143
+ }
144
+ //]]>
145
+ </script>
146
+ </div>
147
+ </div>
app/design/frontend/base/default/template/fraktjakt/fraktjaktmodule/checkout/onepage/shipping_method/fraktjakttemplate.phtml ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php /** @var $this Mage_Checkout_Block_Onepage_Shipping_Method_Available */ ?>
28
+ <style>
29
+
30
+ .sp-methods .price {
31
+ font-weight:normal;
32
+ }
33
+ </style>
34
+ <?php $_shippingRateGroups = $this->getShippingRates(); ?>
35
+ <?php if (!$_shippingRateGroups): ?>
36
+ <p><?php echo $this->__('Vi ber om ursäkt. För tillfället kunde ingen fraktkostnad kunde beräknas.') ?></p>
37
+ <?php else: ?>
38
+ <dl class="sp-methods">
39
+ <?php $shippingCodePrice = array(); ?>
40
+ <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
41
+ <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
42
+ <dd>
43
+ <ul>
44
+ <li> <table width="100%" border="0"> <tr> <td width="5%"></td><td align="left" width="40%"><strong>Frakttjänst</strong></td>
45
+ <td width="15%"><strong>Leveranstid</strong></td><td width="20%"><strong>Ombud</strong></td> <td><strong>Kostnad</strong></td>
46
+ </tr></table></li>
47
+ <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
48
+ <?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
49
+ <li> <table width="100%" border="0">
50
+ <tr>
51
+ <?php if ($_rate->getErrorMessage()): ?>
52
+ <ul class="messages"><li class="error-msg"><ul><li><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li></ul></li></ul>
53
+ <?php else: ?>
54
+ <td width="5%">
55
+ <?php if ($_sole) : ?>
56
+ <span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" /></span>
57
+ <?php else: ?>
58
+ <input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
59
+ </td>
60
+ <?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
61
+ <script type="text/javascript">
62
+ //<![CDATA[
63
+ lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
64
+ //]]>
65
+ </script>
66
+ <?php endif; ?>
67
+
68
+ <?php endif; ?>
69
+
70
+
71
+ <?php $mt=$this->escapeHtml($_rate->getMethodTitle());
72
+ $nmt=$this->escapeHtml($_rate->getMethodDescription());
73
+ list($mtitle,$md,$mag,$md1,$mag1,$surl)=preg_split('/[@]/',$nmt);
74
+ ?>
75
+ <td align="left" width="40%"> <label for="s_method_<?php echo $_rate->getCode() ?>"><strong> <?php echo $mtitle; ?>
76
+
77
+
78
+
79
+
80
+ </strong></label></td>
81
+ <td width="15%"> <?php echo $md; ?></td>
82
+ <td width="20%">
83
+ <?php if(!empty($surl)){?>
84
+ <a href="<?php echo $surl; ?>" target="_blank">
85
+ <?php } ?>
86
+ <?php echo $mag; ?>
87
+
88
+ <?php if(!empty($surl)){?>
89
+ </a>
90
+ <?php } ?>
91
+ </td>
92
+ <td> <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
93
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
94
+ <?php echo $_excl; ?>
95
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
96
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
97
+ <?php endif; ?> </td>
98
+
99
+
100
+
101
+
102
+ <?php endif ?></tr>
103
+ </table>
104
+ </li>
105
+ <?php endforeach; ?>
106
+ </ul>
107
+ </dd>
108
+ <?php endforeach; ?>
109
+ </dl>
110
+ <script type="text/javascript">
111
+ //<![CDATA[
112
+ <?php if (!empty($shippingCodePrice)): ?>
113
+ var shippingCodePrice = {<?php echo implode(',',$shippingCodePrice); ?>};
114
+ <?php endif; ?>
115
+
116
+ $$('input[type="radio"][name="shipping_method"]').each(function(el){
117
+ Event.observe(el, 'click', function(){
118
+ if (el.checked == true) {
119
+ var getShippingCode = el.getValue();
120
+ <?php if (!empty($shippingCodePrice)): ?>
121
+ var newPrice = shippingCodePrice[getShippingCode];
122
+ if (!lastPrice) {
123
+ lastPrice = newPrice;
124
+ quoteBaseGrandTotal += newPrice;
125
+ }
126
+ if (newPrice != lastPrice) {
127
+ quoteBaseGrandTotal += (newPrice-lastPrice);
128
+ lastPrice = newPrice;
129
+ }
130
+ <?php endif; ?>
131
+ checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
132
+ return false;
133
+ }
134
+ });
135
+ });
136
+ //]]>
137
+ </script>
138
+ <?php endif; ?>
app/etc/modules/Fraktjakt_Fraktjaktmodule.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Fraktjakt_Fraktjaktmodule>
4
+ <active>true</active>
5
+ <codePool>community</codePool>
6
+ </Fraktjakt_Fraktjaktmodule>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>magnetofraktjaktv23</name>
4
+ <version>0.2.3</version>
5
+ <stability>stable</stability>
6
+ <license uri="www.opensource.org/licenses/gpl-license.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Integrates Fraktjakt for a complete shipping solution for Posten, Schenker, Bussgods, DHL, DSV, UPS, Fedex...</summary>
10
+ <description>Integrates Fraktjakt with your Magento webshop for a complete shipping solution for Posten, Schenker, Bussgods, DHL, DSV, UPS, Fedex and more!&#xD;
11
+ &lt;p&gt;Fraktjakt gives your customers access to all shipping services in one complete and easy to manage solution!&#xD;
12
+ No matter if they simply wants the cheapest shipment, the fastest shipment, the most convinient home delivery or closest shipping agent. Fraktjakt intergrates them all and lets your customer decide. &lt;/p&gt;&#xD;
13
+ &lt;p&gt;Quick and easy with cheaper shipments for everyone, through Fraktjakt's discounted shipments as well as personal shipping contracts. No wonder it increases your sales!&lt;/p&gt;&#xD;
14
+ &lt;p&gt;Read more and create your free Fraktjakt account today on&#xD;
15
+ http://www.fraktjakt.se &lt;/p&gt;&#xD;
16
+ &lt;p&gt;PLEASE NOTE that Fraktjakt currently only supports swedish webshops!&lt;/p&gt;&#xD;
17
+ &#xD;
18
+ User manual for this extension in swedish:&#xD;
19
+ &lt;a href="http://www.fraktjakt.se/downloads/Fraktjakt_Magento_Manual.pdf"&gt;http://www.fraktjakt.se/downloads/Fraktjakt_Magento_Manual.pdf&lt;/a&gt;</description>
20
+ <notes>Integrates Fraktjakt for a complete shipping solution for Posten, Schenker, Bussgods, DHL, DSV, UPS, Fedex...</notes>
21
+ <authors><author><name>Fraktjakt Ecommerce Team</name><user>Fraktjakt</user><email>info@fraktjakt.se</email></author></authors>
22
+ <date>2014-04-30</date>
23
+ <time>06:02:47</time>
24
+ <contents><target name="magecommunity"><dir name="Fraktjakt"><dir name="Fraktjaktmodule"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><dir name="Shipment"><file name="View.php" hash="9889746bb5f43449514dbebb595237a4"/></dir><file name="View.php" hash="d034207157a53e6c014e79f380b00152"/></dir></dir></dir><file name="Button.php" hash="c824ef0424300a1da6dcbc58e2755074"/></dir><dir name="Helper"><file name="Data.php" hash="312b2968f8d82ae8257a9018664e6e52"/></dir><dir name="Model"><dir name="Carrier"><file name="Shippingmethod.php" hash="fa779f79c3fc0413bf4ecfd917eb5bf8"/></dir><file name="Observer.php" hash="a3c7929ddff94c93d6af8644bb51bdaa"/><dir name="Source"><file name="Dimentionunits.php" hash="c4bc1eba6379368c519d6d7300edac32"/><file name="Method.php" hash="b46ca3dd9149eed71e8d5bb5212a579b"/><file name="Weightunits.php" hash="779c6d30923739673eaa7fd9bf6b4cf1"/></dir></dir><dir name="controllers"><dir name="Checkout"><file name="CartController.php" hash="3ed401189982efec2155a9e3ff2a759a"/></dir></dir><dir name="etc"><file name="config.xml" hash="129239912e2852d24fb2a57aaa242364"/><file name="system.xml" hash="e98455d95799ffc2f8f99c8740493def"/></dir><dir name="sql"><dir name="fraktjaktmodule_setup"><file name="mysql4-install-0.2.0.php" hash="eecc35926e3e0041c4ab965d125243f5"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="b49db5998a45e77676a4202496f92373"/><file name="mysql4-upgrade-0.2.1-0.2.2.php" hash="0c4b02e51a8e97fd977a98b813b56708"/><file name="mysql4-upgrade-0.2.2-0.2.3.php" hash="4b7a0f0b0bd2d69ae688bc233584738a"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Fraktjakt_Fraktjaktmodule.xml" hash="c8d95d33412e623b7ffd9730d6beb467"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="fraktjakt_fraktjaktmodule.xml" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><dir name="template"><dir name="fraktjakt"><dir name="checkout"><dir name="cart"><file name="shipping.phtml" hash="13cd347cc10ac07ecfac22f3f8916b39"/></dir><dir name="onepage"><dir name="shipping_method"><file name="fraktjakttemplate.phtml" hash="ba7c66a594d8bdcaeef4587a5112ad69"/></dir></dir></dir><dir name="fraktjaktmodule"><dir name="checkout"><dir name="cart"><file name="shipping.phtml" hash="13cd347cc10ac07ecfac22f3f8916b39"/></dir><dir name="onepage"><dir name="shipping_method"><file name="fraktjakttemplate.phtml" hash="ba7c66a594d8bdcaeef4587a5112ad69"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
25
+ <compatible/>
26
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><extension><name>gd</name><min>1.0.1</min><max>1.0.2</max></extension></required></dependencies>
27
+ </package>