Owebia_Shipping_2 - Version 2.4.0

Version Notes

[2.4.0 - 27 juin 2011]
Correction d'un bug lorsque plusieurs produits identiques avec des options différentes sont présents dans le panier (la valeur de l'option était toujours égale à celle du premier produit)
Ajout de la possibilité d'utiliser les expressions régulières dans les champs "destination" et "origin"
Ajout de la variable {car.weight.for-charge}
Mise à jour de la documentation en français
Mise à jour de l'éditeur
Correction d'un bug de l'éditeur lorsqu'on éditait une destination puis qu'on cliquait sur Annuler

Download this release

Release Info

Developer Magento Core Team
Extension Owebia_Shipping_2
Version 2.4.0
Comparing to
See all releases


Version 2.4.0

app/code/community/Owebia/Shipping2/Block/Adminhtml/System/Config/Form/Field/Config.php ADDED
@@ -0,0 +1,46 @@
1
+ <?php
2
+
3
+ class Owebia_Shipping2_Block_Adminhtml_System_Config_Form_Field_Config extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private static $JS_INCLUDED = false;
6
+
7
+ private function label($input) {
8
+ return str_replace(array("\r\n","\r","\n","'"),array("\\n","\\n","\\n","\\'"),$this->__($input));
9
+ }
10
+
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
12
+ $output = '';
13
+ if (!self::$JS_INCLUDED) {
14
+ $include_path = Mage::getBaseUrl('js').'owebia/shipping2';
15
+ $output = "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js\"></script>\n"
16
+ ."<script type=\"text/javascript\" src=\"".$include_path."/os2editor.js?t=".time()."\"></script>\n"
17
+ ."<script type=\"text/javascript\">\n"
18
+ ."//<![CDATA[\n"
19
+ ."jQuery.noConflict();\n"
20
+ ."var os2editor = new OS2Editor({\n"
21
+ ."ajax_url: '".$this->getUrl('owebia-shipping2/ajax')."?isAjax=true',\n"
22
+ ."form_key: FORM_KEY,\n"
23
+ ."menu_item_dissociate_label: '".$this->label('Dissociate')."',\n"
24
+ ."menu_item_remove_label: '".$this->label('Remove')."',\n"
25
+ ."menu_item_edit_label: '".$this->label('Edit')."',\n"
26
+ ."prompt_new_value_label: '".$this->label('Enter the new value:')."',\n"
27
+ ."default_row_label: '".$this->label('[No label]')."',\n"
28
+ ."loading_label: '".$this->label('Loading...')."'\n"
29
+ ."});\n"
30
+ ."//]]>\n"
31
+ ."</script>\n"
32
+ ."<link type=\"text/css\" href=\"".$include_path."/os2editor.css?t=".time()."\" rel=\"stylesheet\" media=\"all\"/>\n"
33
+ ;
34
+ self::$JS_INCLUDED = true;
35
+ }
36
+
37
+ $shipping_code = preg_replace('/^groups\[([^\]]*)\].*#x2F;','\1',$element->getName());
38
+ return $output
39
+ .'<div style="margin-bottom:1px;">'
40
+ .'<button type="button" class="scalable" onclick="os2editor.open(this,\''.$shipping_code.'\');"><span>'.$this->__("Open editor").'</span></button>'
41
+ .'&nbsp;<button type="button" class="scalable" onclick="os2editor.help(\'summary\',this,\''.$shipping_code.'\');"><span>'.$this->__("Help").'</span></button>'
42
+ .'</div>'
43
+ .$element->getElementHtml().'<br/>'
44
+ ;
45
+ }
46
+ }
app/code/community/Owebia/Shipping2/Controller/Abstract.php ADDED
@@ -0,0 +1,130 @@
1
+ <?php
2
+
3
+ /**
4
+ * Magento Owebia Shipping2 Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Owebia
17
+ * @package Owebia_Shipping2
18
+ * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Owebia_Shipping2_Controller_Abstract extends Mage_Adminhtml_Controller_Action
24
+ {
25
+ public function __() {
26
+ $args = func_get_args();
27
+ $message = array_shift($args);
28
+ if ($message instanceof OS_Message) {
29
+ $args = $message->args;
30
+ $message = $message->message;
31
+ }
32
+
33
+ $output = Mage::helper('shipping')->__($message);
34
+ if (count($args)==0) return $output;
35
+
36
+ if (!isset($this->_translate_inline)) $this->_translate_inline = Mage::getSingleton('core/translate')->getTranslateInline();
37
+ if ($this->_translate_inline) {
38
+ $parts = explode('}}{{',$output);
39
+ $parts[0] = vsprintf($parts[0],$args);
40
+ return implode('}}{{',$parts);
41
+ }
42
+ else return vsprintf($output,$args);
43
+ }
44
+
45
+ protected function getModulePath($path) {
46
+ if (file_exists(dirname(__FILE__).'/Owebia_Shipping2_'.str_replace('/','_',$path))) {
47
+ return 'Owebia_Shipping2_'.str_replace('/','_',$path);
48
+ } else {
49
+ return Mage::getBaseDir('code').'/community/Owebia/Shipping2/'.$path;
50
+ }
51
+ }
52
+
53
+ protected function getMimeType($extension) {
54
+ $mime_type_array = array(
55
+ '.gz' => 'application/x-gzip',
56
+ '.tgz' => 'application/x-gzip',
57
+ '.zip' => 'application/zip',
58
+ '.pdf' => 'application/pdf',
59
+ '.png' => 'image/png',
60
+ '.gif' => 'image/gif',
61
+ '.jpg' => 'image/jpeg',
62
+ '.jpeg' => 'image/jpeg',
63
+ '.txt' => 'text/plain',
64
+ '.htm' => 'text/html',
65
+ '.html' => 'text/html',
66
+ '.mpg' => 'video/mpeg',
67
+ '.avi' => 'video/x-msvideo',
68
+ );
69
+ return isset($mime_type_array[$extension]) ? $mime_type_array[$extension] : 'application/octet-stream';
70
+ }
71
+
72
+ protected function forceDownload($filename, $content) {
73
+ if (headers_sent()) {
74
+ trigger_error('forceDownload($filename) - Headers have already been sent',E_USER_ERROR);
75
+ return false;
76
+ }
77
+
78
+ $extension = strrchr($filename,'.');
79
+ $mime_type = $this->getMimeType($extension);
80
+
81
+ header('Content-disposition: attachment; filename="'.$filename.'"');
82
+ header('Content-Type: application/force-download');
83
+ header('Content-Transfer-Encoding: '.$mime_type."\n"); // Surtout ne pas enlever le \n
84
+ //header('Content-Length: '.filesize($filename));
85
+ header('Pragma: no-cache');
86
+ header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
87
+ header('Expires: 0');
88
+ echo $content;
89
+ return true;
90
+ }
91
+
92
+ protected function jsEscape($input) {
93
+ return str_replace(array("\r\n","\r","\n","'"),array("\\n","\\n","\\n","\\'"),$input);
94
+ }
95
+
96
+ protected function cleanKey($key) {
97
+ return preg_replace('/[^a-z0-9-_]/i','_-_',$key);
98
+ }
99
+
100
+ protected function page($id, $title, $content) {
101
+ return "<div id=\"os2editor-".$id."-page\" class=\"os2editor-page\">"
102
+ .$this->pageHeader($title,$this->button('Close',"os2editor.closePage(this);",'cancel'))
103
+ ."<div class=\"page-content\">".$content."</div>"
104
+ ."</div>"
105
+ ;
106
+ }
107
+
108
+ protected function pageHeader($title, $buttons) {
109
+ return "<div class=\"content-header\">"
110
+ ."<table cellspacing=\"0\"><tr>"
111
+ ."<td><h3>".$this->__($title)."</h3></td>"
112
+ ."<td class=\"form-buttons\">"
113
+ .$buttons
114
+ ."</td>"
115
+ ."</tr></table>"
116
+ ."</div>"
117
+ ;
118
+ }
119
+
120
+ protected function untranslated_button($label, $onclick, $class_name='') {
121
+ $class_name = 'scalable'.($class_name!='' ? ' '.$class_name : '');
122
+ return "<button type=\"button\" class=\"".$class_name."\" onclick=\"".$onclick."\"><span>".$label."</span></button>";
123
+ }
124
+
125
+ protected function button($label, $onclick, $class_name='') {
126
+ return $this->untranslated_button($this->__($label),$onclick,$class_name);
127
+ }
128
+ }
129
+
130
+ ?>
app/code/community/Owebia/Shipping2/Model/Carrier/AbstractOwebiaShipping.php ADDED
@@ -0,0 +1,512 @@
1
+ <?php
2
+
3
+ /**
4
+ * Magento Owebia Shipping 2 Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Owebia
17
+ * @package Owebia_Shipping2
18
+ * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ // Pour g�rer les cas o� il y a eu compilation
24
+ if (file_exists(dirname(__FILE__).'/Owebia_Shipping2_includes_OwebiaShippingHelper.php')) include_once 'Owebia_Shipping2_includes_OwebiaShippingHelper.php';
25
+ else include_once Mage::getBaseDir('code').'/community/Owebia/Shipping2/includes/OwebiaShippingHelper.php';
26
+
27
+
28
+
29
+ class Magento_Product implements OS_Product {
30
+ private $parent_cart_item;
31
+ private $cart_item;
32
+ private $cart_product;
33
+ private $loaded_product;
34
+ private $quantity;
35
+ private $options;
36
+
37
+ public function Magento_Product($cart_item, $parent_cart_item) {
38
+ $this->cart_item = $cart_item;
39
+ $this->cart_product = $cart_item->getProduct();
40
+ $this->parent_cart_item = $parent_cart_item;
41
+ $this->quantity = isset($parent_cart_item) ? $parent_cart_item->getQty() : $cart_item->getQty();
42
+ }
43
+
44
+ private function getProductOptions() {
45
+ if (isset($this->options)) return $this->options;
46
+ $item = $this->cart_item;
47
+ $options = array();
48
+ if ($optionIds = $item->getOptionByCode('option_ids')) {
49
+ foreach (explode(',', $optionIds->getValue()) as $optionId) {
50
+ if ($option = $item->getProduct()->getOptionById($optionId)) {
51
+ $quoteItemOption = $item->getOptionByCode('option_' . $option->getId());
52
+
53
+ $group = $option->groupFactory($option->getType())
54
+ ->setOption($option)
55
+ ->setQuoteItemOption($quoteItemOption);
56
+
57
+ $label = $option->getTitle();
58
+ $options[$label] = array(
59
+ 'label' => $label,
60
+ 'value' => $group->getFormattedOptionValue($quoteItemOption->getValue()),
61
+ 'print_value' => $group->getPrintableOptionValue($quoteItemOption->getValue()),
62
+ 'value_id' => $quoteItemOption->getValue(),
63
+ 'option_id' => $option->getId(),
64
+ 'option_type' => $option->getType(),
65
+ 'custom_view' => $group->isCustomizedView()
66
+ );
67
+ }
68
+ }
69
+ }
70
+ if ($addOptions = $item->getOptionByCode('additional_options')) {
71
+ $options = array_merge($options, unserialize($addOptions->getValue()));
72
+ }
73
+ $this->options = $options;
74
+ return $this->options;
75
+ }
76
+
77
+ public function getOption($option_name, $get_by_id=false) {
78
+ $value = null;
79
+ $product = $this->cart_product;
80
+ $options = $this->getProductOptions();
81
+ if (isset($options[$option_name])) return $get_by_id ? $options[$option_name]['value_id'] : $options[$option_name]['value'];
82
+ else return $value;
83
+ /*
84
+ foreach ($product->getOptions() as $option) {
85
+ if ($option->getTitle()==$option_name) {
86
+ $custom_option = $product->getCustomOption('option_'.$option->getId());
87
+ if ($custom_option) {
88
+ $value = $custom_option->getValue();
89
+ if ($option->getType()=='drop_down' && !$get_by_id) {
90
+ $option_value = $option->getValueById($value);
91
+ if ($option_value) $value = $option_value->getTitle();
92
+ }
93
+ }
94
+ break;
95
+ }
96
+ }
97
+ */
98
+ }
99
+
100
+ public function getAttribute($attribute_name, $get_by_id=false) {
101
+ $value = null;
102
+ $product = $this->_getLoadedProduct();
103
+
104
+ if ($attribute_name=='price-tax+discount') {
105
+ return $this->cart_item['base_original_price']-$this->cart_item['discount_amount']/$this->quantity;
106
+ } else if ($attribute_name=='price-tax-discount') {
107
+ return $this->cart_item['base_original_price'];
108
+ } else if ($attribute_name=='price+tax+discount') {
109
+ return $this->cart_item['base_original_price']+($this->cart_item['tax_amount']-$this->cart_item['discount_amount'])/$this->quantity;
110
+ } else if ($attribute_name=='price+tax-discount') {
111
+ return $this->cart_item['price_incl_tax'];
112
+ //return Mage::helper('checkout')->getPriceInclTax($this->cart_item);
113
+ }
114
+ $attribute = $product->getResource()->getAttribute($attribute_name);
115
+ if ($attribute) {
116
+ $input_type = $attribute->getFrontend()->getInputType();
117
+ switch ($input_type) {
118
+ case 'select' :
119
+ $value = $get_by_id ? $product->getData($attribute_name) : $product->getAttributeText($attribute_name);
120
+ break;
121
+ default :
122
+ $value = $product->getData($attribute_name);
123
+ break;
124
+ }
125
+ }
126
+ return $value;
127
+ }
128
+
129
+ private function _getLoadedProduct() {
130
+ if (!isset($this->loaded_product)) $this->loaded_product = Mage::getModel('catalog/product')->load($this->cart_product->getId());
131
+ return $this->loaded_product;
132
+ }
133
+
134
+ public function getQuantity() {
135
+ return $this->quantity;
136
+ }
137
+
138
+ public function getName() {
139
+ return $this->cart_product->getName();
140
+ }
141
+
142
+ public function getWeight() {
143
+ return $this->cart_product->getWeight();
144
+ }
145
+
146
+ public function getSku() {
147
+ return $this->cart_product->getSku();
148
+ }
149
+
150
+ public function getStockData($key) {
151
+ $stock = $this->cart_product->getStockItem();
152
+ switch ($key) {
153
+ case 'is_in_stock':
154
+ return (bool)$stock->getIsInStock();
155
+ case 'quantity':
156
+ $quantity = $stock->getQty();
157
+ return $stock->getIsQtyDecimal() ? (float)$quantity : (int)$quantity;
158
+ }
159
+ return null;
160
+ }
161
+ }
162
+
163
+ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
164
+ extends Mage_Shipping_Model_Carrier_Abstract
165
+ {
166
+ protected $_translate_inline;
167
+ protected $_result;
168
+ protected $_config;
169
+ protected $_countries;
170
+ protected $_helper;
171
+ protected $_messages;
172
+
173
+ /**
174
+ * Collect rates for this shipping method based on information in $request
175
+ *
176
+ * @param Mage_Shipping_Model_Rate_Request $data
177
+ * @return Mage_Shipping_Model_Rate_Result
178
+ */
179
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
180
+ // skip if not enabled
181
+ if (!$this->__getConfigData('active')) return false;
182
+
183
+ //$this->display($request->_data);
184
+
185
+ $process = $this->__getDefaultProcess();
186
+ $process['data'] = array_merge($this->__getDefaultProcessData($request->_data['store_id']),array(
187
+ 'cart.price-tax+discount' => $request->_data['package_value_with_discount'],
188
+ 'cart.price-tax-discount' => $request->_data['package_value'],
189
+ 'cart.weight' => $request->_data['package_weight'],
190
+ 'cart.quantity' => $request->_data['package_qty'],
191
+ 'destination.country.code' => $request->_data['dest_country_id'],
192
+ 'destination.region.code' => $request->_data['dest_region_code'],
193
+ 'destination.postcode' => $request->_data['dest_postcode'],
194
+ 'origin.country.code' => $request->_data['country_id'],
195
+ 'origin.region.code' => $request->_data['region_id'],
196
+ 'origin.postcode' => $request->_data['postcode'],
197
+ 'free_shipping' => $request->getFreeShipping(),
198
+ ));
199
+
200
+ $tax_amount = 0;
201
+ $full_price = 0;
202
+ $cart_items = array();
203
+ $items = $request->getAllItems();
204
+ $quote_total_collected = false;
205
+ for ($i=0, $n=count($items); $i<$n; $i++) {
206
+ $item = $items[$i];
207
+ if ($item->getProduct() instanceof Mage_Catalog_Model_Product) {
208
+ switch (get_class($item)) {
209
+ case 'Mage_Sales_Model_Quote_Address_Item': // Multishipping
210
+ $key = $item->getQuoteItemId();
211
+ break;
212
+ case 'Mage_Sales_Model_Quote_Item': // Onepage checkout
213
+ default:
214
+ $key = $item->getId();
215
+ break;
216
+ }
217
+
218
+ $cart_items[$key] = $item;
219
+ $tax_amount += $item->getData('tax_amount');
220
+ $full_price += Mage::helper('checkout')->getSubtotalInclTax($item); // ok
221
+ }
222
+ }
223
+
224
+ $process['data']['cart.price+tax+discount'] = $tax_amount+$process['data']['cart.price-tax+discount'];
225
+ $process['data']['cart.price+tax-discount'] = $full_price;
226
+ $process['data']['cart.price_excluding_tax'] = $process['data']['cart.price-tax+discount'];
227
+ $process['data']['cart.price_including_tax'] = $process['data']['cart.price+tax+discount'];
228
+ $process['data']['cart.weight.for-charge'] = $process['data']['cart.weight'];
229
+
230
+ foreach ($cart_items as $item) {
231
+ if ($item->getProduct()->getTypeId()!='configurable') {
232
+ $parent_item_id = $item->getParentItemId();
233
+ $magento_product = new Magento_Product($item, isset($cart_items[$parent_item_id]) ? $cart_items[$parent_item_id] : null);
234
+ $process['cart.products'][] = $magento_product;
235
+ if ($item->getFreeShipping()) $process['data']['cart.weight.for-charge'] -= $magento_product->getWeight() * $magento_product->getQuantity();
236
+ }
237
+ }
238
+
239
+ if (!$process['data']['free_shipping']) {
240
+ foreach ($cart_items as $item) {
241
+ if ($item->getProduct() instanceof Mage_Catalog_Model_Product) {
242
+ if ($item->getFreeShipping()) $process['data']['free_shipping'] = true;
243
+ else {
244
+ $process['data']['free_shipping'] = false;
245
+ break;
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ return $this->getRates($process);
252
+ }
253
+
254
+ public function display($var) {
255
+ $i = 0;
256
+ foreach ($var as $name => $value) {
257
+ //if ($i>20)
258
+ echo "{$name} => {$value}<br/>";
259
+ //$this->_helper->debug($name.' => '.$value.'<br/>');
260
+ $i++;
261
+ }
262
+ }
263
+
264
+ public function getRates($process) {
265
+ $this->_process($process);
266
+ return $process['result'];
267
+ }
268
+
269
+ public function getAllowedMethods() {
270
+ $process = array();
271
+ $config = $this->_getConfig();
272
+ $allowed_methods = array();
273
+ if (count($config)>0) {
274
+ foreach ($config as $row) $allowed_methods[$row['*code']] = isset($row['label']) ? $row['label']['value'] : 'No label';
275
+ }
276
+ return $allowed_methods;
277
+ }
278
+
279
+ public function isTrackingAvailable() {
280
+ return true;
281
+ }
282
+
283
+ public function getTrackingInfo($tracking_number) {
284
+ $tracking_url = $this->__getConfigData('tracking_view_url');
285
+ $parts = explode(':',$tracking_number);
286
+ if (count($parts)>=2) {
287
+ $tracking_number = $parts[1];
288
+
289
+ $process = array();
290
+ $config = $this->_getConfig();
291
+
292
+ if (isset($config[$parts[0]]['tracking_url'])) {
293
+ $row = $config[$parts[0]];
294
+ $tmp_tracking_url = $this->_helper->getRowProperty($row,'tracking_url');
295
+ if (isset($tmp_tracking_url)) $tracking_url = $tmp_tracking_url;
296
+ }
297
+ }
298
+
299
+ $tracking_status = Mage::getModel('shipping/tracking_result_status')
300
+ ->setCarrier($this->_code)
301
+ ->setCarrierTitle($this->__getConfigData('title'))
302
+ ->setTracking($tracking_number)
303
+ ->addData(
304
+ array(
305
+ 'status'=>'<a target="_blank" href="'.str_replace('{tracking_number}',$tracking_number,$tracking_url).'">'.__('track the package').'</a>'
306
+ )
307
+ )
308
+ ;
309
+ $tracking_result = Mage::getModel('shipping/tracking_result')
310
+ ->append($tracking_status)
311
+ ;
312
+
313
+ if ($trackings = $tracking_result->getAllTrackings()) return $trackings[0];
314
+ return false;
315
+ }
316
+
317
+ /***************************************************************************************************************************/
318
+
319
+ protected function _process(&$process) {
320
+ $process['data'] = array_merge($process['data'],array(
321
+ 'destination.country.name' => $this->__getCountryName($process['data']['destination.country.code']),
322
+ 'origin.country.name' => $this->__getCountryName($process['data']['origin.country.code']),
323
+ ));
324
+
325
+ $debug = (bool)(isset($_GET['debug']) ? $_GET['debug'] : $this->__getConfigData('debug'));
326
+ if ($debug) $this->_helper->initDebug($this->_code,$process['data']);
327
+
328
+ $value_found = false;
329
+ foreach ($process['config'] as $row) {
330
+ $result = $this->_helper->processRow($process,$row);
331
+ $this->_addMessages($this->_helper->getMessages());
332
+ if ($result->success) {
333
+ $value_found = true;
334
+ $this->__appendMethod($process,$row,$result->result);
335
+ if ($process['stop_to_first_match']) break;
336
+ }
337
+ }
338
+
339
+ $http_request = Mage::app()->getFrontController()->getRequest();
340
+ if ($debug && $this->_checkRequest($http_request,'checkout/cart/index')) {
341
+ Mage::getSingleton('core/session')->addNotice('DEBUG'.$this->_helper->getDebug());
342
+ }
343
+
344
+ //$this->_appendErrors($process,$this->_messages);
345
+ //if (!$value_found) $this->__appendError($process,$this->__('No match found'));
346
+ }
347
+
348
+ protected function _checkRequest($http_request, $path) {
349
+ list($router,$controller,$action) = explode('/',$path);
350
+ return $http_request->getRouteName()==$router && $http_request->getControllerName()==$controller && $http_request->getActionName()==$action;
351
+ }
352
+
353
+ protected function _getConfig() {
354
+ if (!isset($this->_config)) {
355
+ $this->_helper = new OwebiaShippingHelper($this->__getConfigData('config'));
356
+ $this->_config = $this->_helper->getConfig();
357
+ $this->_addMessages($this->_helper->getMessages());
358
+ }
359
+ return $this->_config;
360
+ }
361
+
362
+ protected function _getMethodText($process, $row, $property) {
363
+ if (!isset($row[$property])) return '';
364
+
365
+ $output = '';
366
+ return $output . ' '.$this->_helper->evalInput($process,$row,$property,str_replace(
367
+ array(
368
+ '{cart.weight}',
369
+ '{cart.price_including_tax}',
370
+ '{cart.price_excluding_tax}',
371
+ '{cart.price-tax+discount}',
372
+ '{cart.price-tax-discount}',
373
+ '{cart.price+tax+discount}',
374
+ '{cart.price+tax-discount}',
375
+ ),
376
+ array(
377
+ $process['data']['cart.weight'].$process['data']['cart.weight.unit'],
378
+ $this->__formatPrice($process['data']['cart.price_including_tax']),
379
+ $this->__formatPrice($process['data']['cart.price_excluding_tax']),
380
+ $this->__formatPrice($process['data']['cart.price-tax+discount']),
381
+ $this->__formatPrice($process['data']['cart.price-tax-discount']),
382
+ $this->__formatPrice($process['data']['cart.price+tax+discount']),
383
+ $this->__formatPrice($process['data']['cart.price+tax-discount']),
384
+ ),
385
+ $this->_helper->getRowProperty($row, $property)
386
+ ));
387
+ }
388
+
389
+ protected function _addMessages($messages) {
390
+ if (!is_array($messages)) $messages = array($messages);
391
+ if (!is_array($this->_messages)) $this->_messages = $messages;
392
+ else $this->_messages = array_merge($this->_messages,$messages);
393
+ }
394
+
395
+ protected function _appendErrors(&$process, $messages) {
396
+ if (is_array($messages)) {
397
+ foreach ($messages as $message) {
398
+ $this->__appendError($process,$this->__($message));
399
+ }
400
+ }
401
+ }
402
+
403
+ /***************************************************************************************************************************/
404
+
405
+ protected function __getDefaultProcess() {
406
+ $process = array(
407
+ 'cart.products' => array(),
408
+ 'config' => $this->_getConfig(),
409
+ 'data' => null,
410
+ 'result' => Mage::getModel('shipping/rate_result'),
411
+ 'stop_to_first_match' => $this->__getConfigData('stop_to_first_match'),
412
+ );
413
+ return $process;
414
+ }
415
+
416
+ protected function __getDefaultProcessData($store_id=null) {
417
+ if (!isset($store_id)) $store = Mage::app()->getStore();
418
+ else $store = Mage::app()->getStore($store_id);
419
+
420
+ $mage_config = Mage::getConfig();
421
+ $customer_group_id = Mage::getSingleton('customer/session')->getCustomerGroupId();
422
+ if ($customer_group_id==0) { // Pour les commandes depuis Adminhtml
423
+ $customer_group_id2 = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getCustomerGroupId();
424
+ if (isset($customer_group_id2)) $customer_group_id = $customer_group_id2;
425
+ }
426
+ $customer_group_code = Mage::getSingleton('customer/group')->load($customer_group_id)->getCode();
427
+ $timestamp = Mage::getModel('core/date')->timestamp();
428
+
429
+ $properties = array_merge(OwebiaShippingHelper::getDefaultProcessData(),array(
430
+ 'info.magento.version' => Mage::getVersion(),
431
+ 'info.module.version' => (string)$mage_config->getNode('modules/Owebia_Shipping2/version'),
432
+ 'info.carrier.code' => $this->_code,
433
+ 'cart.weight.unit' => Mage::getStoreConfig('owebia/shipping/weight_unit'),
434
+ 'cart.coupon' => Mage::getSingleton('checkout/session')->getQuote()->getCouponCode(),
435
+ 'customer.group.id' => $customer_group_id,
436
+ 'customer.group.code' => $customer_group_code,
437
+ 'store.id' => $store->getId(),
438
+ 'store.code' => $store->getCode(),
439
+ 'store.name' => $store->getConfig('general/store_information/name'),
440
+ 'store.address' => $store->getConfig('general/store_information/address'),
441
+ 'store.phone' => $store->getConfig('general/store_information/phone'),
442
+ 'date.timestamp' => $timestamp,
443
+ 'date.year' => (int)date('Y',$timestamp),
444
+ 'date.month' => (int)date('m',$timestamp),
445
+ 'date.day' => (int)date('d',$timestamp),
446
+ 'date.hour' => (int)date('H',$timestamp),
447
+ 'date.minute' => (int)date('i',$timestamp),
448
+ 'date.second' => (int)date('s',$timestamp),
449
+ ));
450
+ return $properties;
451
+ }
452
+
453
+ protected function __getConfigData($key) {
454
+ return $this->getConfigData($key);
455
+ }
456
+
457
+ protected function __appendMethod(&$process, $row, $fees) {
458
+ $method = Mage::getModel('shipping/rate_result_method')
459
+ ->setCarrier($this->_code)
460
+ ->setCarrierTitle($this->__getConfigData('title'))
461
+ ->setMethod($row['*code'])
462
+ ->setMethodTitle($this->_getMethodText($process,$row,'label'))
463
+ ->setMethodDescription($this->_getMethodText($process,$row,'description'))
464
+ ->setPrice($fees)
465
+ ->setCost($fees)
466
+ ;
467
+
468
+ $process['result']->append($method);
469
+ }
470
+
471
+ protected function __appendError(&$process, $message) {
472
+ if (isset($process['result'])) {
473
+ $error = Mage::getModel('shipping/rate_result_error')
474
+ ->setCarrier($this->_code)
475
+ ->setCarrierTitle($this->__getConfigData('title'))
476
+ ->setErrorMessage($message)
477
+ ;
478
+ $process['result']->append($error);
479
+ }
480
+ }
481
+
482
+ protected function __formatPrice($price) {
483
+ if (!isset($this->_core_helper)) $this->_core_helper = Mage::helper('core');
484
+ return $this->_core_helper->currency($price);
485
+ }
486
+
487
+ protected function __($message) {
488
+ $args = func_get_args();
489
+ $message = array_shift($args);
490
+ if ($message instanceof OS_Message) {
491
+ $args = $message->args;
492
+ $message = $message->message;
493
+ }
494
+
495
+ $output = Mage::helper('shipping')->__($message);
496
+ if (count($args)==0) return $output;
497
+
498
+ if (!isset($this->_translate_inline)) $this->_translate_inline = Mage::getSingleton('core/translate')->getTranslateInline();
499
+ if ($this->_translate_inline) {
500
+ $parts = explode('}}{{',$output);
501
+ $parts[0] = vsprintf($parts[0],$args);
502
+ return implode('}}{{',$parts);
503
+ }
504
+ else return vsprintf($output,$args);
505
+ }
506
+
507
+ protected function __getCountryName($country_code) {
508
+ return Mage::getModel('directory/country')->load($country_code)->getName();
509
+ }
510
+ }
511
+
512
+ ?>
app/code/community/Owebia/Shipping2/Model/Carrier/OwebiaShipping1.php ADDED
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ /**
4
+ * Magento Owebia Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Owebia
17
+ * @package Owebia_Shipping_2
18
+ * @copyright Copyright (c) 2008-09 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Owebia_Shipping2_Model_Carrier_OwebiaShipping1
24
+ extends Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
25
+ {
26
+ protected $_code = 'owebiashipping1';
27
+ }
28
+
29
+ ?>
app/code/community/Owebia/Shipping2/Model/Carrier/OwebiaShipping2.php ADDED
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ /**
4
+ * Magento Owebia Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Owebia
17
+ * @package Owebia_Shipping_2
18
+ * @copyright Copyright (c) 2008-09 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Owebia_Shipping2_Model_Carrier_OwebiaShipping2
24
+ extends Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
25
+ {
26
+ protected $_code = 'owebiashipping2';
27
+ }
28
+
29
+ ?>
app/code/community/Owebia/Shipping2/Model/Carrier/OwebiaShipping3.php ADDED
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ /**
4
+ * Magento Owebia Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Owebia
17
+ * @package Owebia_Shipping_2
18
+ * @copyright Copyright (c) 2008-09 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Owebia_Shipping2_Model_Carrier_OwebiaShipping3
24
+ extends Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
25
+ {
26
+ protected $_code = 'owebiashipping3';
27
+ }
28
+
29
+ ?>
app/code/community/Owebia/Shipping2/changelog ADDED
@@ -0,0 +1,223 @@
1
+ [2.4.0 - 27 juin 2011]
2
+ Correction d'un bug lorsque plusieurs produits identiques avec des options diff�rentes sont pr�sents dans le panier (la valeur de l'option �tait toujours �gale � celle du premier produit)
3
+ Ajout de la possibilit� d'utiliser les expressions r�guli�res dans les champs "destination" et "origin"
4
+ Ajout de la variable {car.weight.for-charge}
5
+ Mise � jour de la documentation en fran�ais
6
+ Mise � jour de l'�diteur
7
+ Correction d'un bug de l'�diteur lorsqu'on �ditait une destination puis qu'on cliquait sur Annuler
8
+
9
+ [2.3.11 - 28 avril 2011]
10
+ Correction d'un probl�me d'encodage/d�codage entre le javascript et le php via ajax (les signes "+" disparaissaient)
11
+ Surcharge du fichier Mage/Checkout/controllers/CartController.php pour corriger un probl�me avec Magento : les champs Mage_Sales_Quote_Item->_data['tax_amount'] n'�taient pas mis � jour correctement, ce qui cr�ait un d�calage et faussait la variable {cart.price+tax+discount}
12
+
13
+ [2.3.10 - 12 avril 2011]
14
+ Correction d'un probl�me dans AjaxController.php : passage direct d'un tableau par r�f�rence, il faut d'abord cr�er le tableau dans une variable puis passer la variable par r�f�rence
15
+ Ajout de la variable {cart.coupon}
16
+ Ajout des variables {cart.price-tax+discount}, {cart.price-tax-discount}, {cart.price+tax+discount}, {cart.price+tax-discount} qui permettent d'avoir le montant que l'on d�sire, avec ou sans prise en compte des taxes et des remises
17
+ Gestion semblable pour les attributs des produits : product.attribute.price-tax+discount utilisable dans une structure {sum} par exemple
18
+ Ajout de la possibilit� de r�cup�rer la valeur minimum ou maximum d'un attribut ou d'une option (utilisation identique � sum)
19
+
20
+ [2.3.9 - 20 janvier 2011]
21
+ Correction d'un probl�me avec le fichier adminhtml.xml (il y avait un commentaire avant l'en-t�te XML)
22
+
23
+ [2.3.8 - 14 janvier 2011]
24
+ Correction d'un bug avec la propri�t� "customer_groups" lorsqu'on utilisait les id's (is_int remplac� par ctype_digit)
25
+ Modifications des champs de configuration :
26
+ - Le champ "debug" devient de type Oui/Non
27
+ - Le champ "auto-compression" devient "compression" de type Oui/Non
28
+ Impl�mentation d'une compression efficace :
29
+ - La configuration est compress�e � l'aide de la fonction gzcompress() puis encod�e en base 64 afin d'�tre facilement plac�e dans un champ textarea
30
+ - La longueur de configuration peut �tre divis�e par 4 gr�ce � la compression
31
+ - La compression peut �tre utile sur certaines configurations o� la longueur des champs est limit�e
32
+ Am�lioration de l'�diteur :
33
+ - R�cup�ration des groupes utilisateurs de Magento et cr�ation d'un bouton pour chacun d'eux
34
+ - Ajout d'un bouton "Aide" (qui ouvre l'aide de l'�diteur) � droite du bouton "Ouvrir l'�diteur"
35
+ - Centralisation du changelog dans un fichier app/code/community/Owebia/Shipping2/changelog plut�t que dans les fichiers de langue
36
+ - L'�diteur compresse/d�compresse la configuration (si la compression est activ�e)
37
+ Am�lioration du debug
38
+ - Ajout des versions de PHP et de Magento
39
+ - Correction du chemin du fichier OwebiaShippingHelper.php
40
+ - Affichage du debug par la commande Mage::getSingleton('core/session')->addNotice() afin d'avoir un affichage plus propre (� l'int�rieur des balises html)
41
+ - Affichage du debug seulement sur la page checkout/cart/index
42
+ Cr�ation d'un fichier app/code/community/Owebia/Shipping2/etc/adminhtml.xml (pour r�soudre les probl�mes d'acc�s � la section de configuration Owebia)
43
+ Mise � jour des tarifs par d�faut avec les tarifs Colissimo Particuliers 2010 et Chronopost web 2010
44
+
45
+ [2.3.7 - 11 janvier 2011]
46
+ Modification de la r�cup�ration du timestamp courant en tenant compte du fuseau horaire s�lectionn�
47
+ Modification du CSS de l'�diteur pour palier � une modification du CSS du backoffice (sur les balises legend)
48
+ Ajout de contr�les isset dans le fichier app/code/community/Owebia/Shipping2/controllersAjaxController.php (merci � Damien C.)
49
+ �chappement des guillemets doubles dans la m�thode _getConfig() dans le fichier js/owebia/shipping2/os2editor.js (merci � Damien C.)
50
+ Ajout de la m�thode getRates() dans la classe Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping qui permet de r�cup�rer les frais de port en injectant les donn�es que l'on souhaite en param�tre
51
+ R��criture de la m�thode collectRates()
52
+
53
+ [2.3.6 - 23 novembre 2010]
54
+ Ajout d'un fichier app/etc/modules/Owebia_Shipping_2.xml vide pour �craser celui des versions pr�c�dentes � la 2.3.0 afin d'�viter une cohabitation de deux versions
55
+ Am�lioration du traitement des commentaires avec l'�diteur (gestion des caract�res #)
56
+
57
+ [2.3.5 - 08 novembre 2010]
58
+ Correction d'un probl�me chez les utilisateurs ayant une version de PHP ant�rieure � 5.3.0
59
+
60
+ [2.3.4 - 06 novembre 2010]
61
+ Correction d'un bug introduit dans la version 2.3.2 lors de l'utilisation des attributs et options avec les fonctions sum, count et count distinct
62
+
63
+ [2.3.3 - 05 novembre 2010]
64
+ Possibilit� de faire des copie de propri�t�s de fa�on r�cursive avec contr�le de boucle infinie
65
+
66
+ [2.3.2 - 05 novembre 2010]
67
+ Am�lioration de l'�diteur :
68
+ - Ajout de l'aide en langue anglais
69
+ - Ajout d'informations dans l'aide
70
+ - Ajout des messages d'erreur de la configuration, avec possibilit� de correction rapide
71
+ - Ajout de champs pour les lignes ignor�es : on peut ainsi les modifier et appliquer les modifications
72
+ Ajout de la possibilit� d'acc�der aux informations sur le stock d'un produit gr�ce aux variables {product.stock.is_in_stock} et {product.stock.quantity}
73
+ Suppression de l'affichage du message d'erreur ""Correspondance non trouv�e""
74
+ Correction d'un bug avec les groupes utilisateur ($id==null retournait true lorsque $id �tait �gal � 0)
75
+ Correction d'une erreur de r�cup�ration de l'unit� de poids
76
+ Am�liorations diverses
77
+
78
+ [2.3.1 - 29 octobre 2010]
79
+ Correction d'un bug dans le fichier AjaxController : une variable n'�tait pas d�finie, ce qui g�n�rait une erreur avec certaines configurations PHP
80
+
81
+ [2.3.0 - 28 octobre 2010]
82
+ Correction d'un bug avec le caract�re * dans les champs ""destination"" et ""origin"" comme jocker
83
+ Ajout d'un �diteur pour faciliter la modification des configurations Owebia Shipping
84
+ L'�diteur contient �galement une aide
85
+ D�placement de certains fichiers pour mieux correspondre � la structure de Magento
86
+
87
+ [2.2.8 - 20 octobre 2010]
88
+ Correction d'une erreur dans l'include d'OwebiaShippingHelper lorsqu'on utilise le Compiler
89
+ Correction d'un bug de calcul du prix TTC dans certains cas ('row_total_with_discount' est �gal � 0)
90
+ Ajout de la possibilit� d'utiliser le caract�re * dans les champs ""destination"" et ""origin"" comme jocker (par exemple ""FR(25*)"" retournera vrai pour tous les codes postaux du d�partement du Doubs)
91
+ Ajout d'un bouton pour fermer la console de debug
92
+ Ajout d'informations dans le debug (tests sur la destination et l'origine, liste des variables pass�es en param�tre)
93
+ Affichage du debug uniquement sur la page panier (pas sur les pages en ajax)
94
+ R�cup�ration du bon customer group lors d'une commande cr��e depuis le backoffice de Magento
95
+
96
+ [2.2.7 - 27 ao�t 2010]
97
+ Possibilit� d'utiliser les variables personnalis�es (custom variables) de Magento gr�ce � la syntaxe {customvar.my_var} ou � la syntaxe standard {{customVar code=my_var}}
98
+
99
+ [2.2.6 - 25 ao�t 2010]
100
+ Correction d'un bug avec la fonction getRowProperty() : utilisation de preg_match_all() � la place de while(preg_match()) et utilisation de continue � la place de break
101
+
102
+ [2.2.5 - 22 ao�t 2010]
103
+ Correction d'un bug avec les propri�t�s de type bool�enne sp�cifi�es sans les guillemets (comme la propri�t� enabled)
104
+ Correction d'un bug avec la propri�t� customer_groups
105
+
106
+ [2.2.4 - 10 ao�t 2010]
107
+ Utilisation de Mage::getModel('directory/country')->load($country_code)->getName() � la place de Mage::getModel('core/locale')->getLocale()->getTranslationList('territory',null,2) pour r�cup�rer le nom d'un pays dans la langue courante (la premi�re solution semble retourner le nom du pays dans la langue principale de la boutique), merci � coolshop pour la solution propos�e
108
+ Remplacement de la valeur de configuration ""Afficher quand indisponible"" par la valeur ""Debug"" car la solution pr�c�dente posait des probl�mes avec Magento 1.4.0
109
+ Am�lioration de la clart� du debug (utilisation de couleurs et d'indentations)
110
+ Correction de bugs l�gers
111
+ Mise � jour de la syntaxe de la configuration propos�e par d�faut
112
+
113
+ [2.2.3 - 29 juillet 2010]
114
+ Correction d'un bug avec le traitement de formules dont le r�sultat est false
115
+
116
+ [2.2.2 - 29 juillet 2010]
117
+ Am�lioration du syst�me de cache des formules
118
+
119
+ [2.2.1 - 27 juillet 2010]
120
+ Correction de petits bugs
121
+
122
+ [2.2.0 - 22 juillet 2010]
123
+ Possibilit� de compression/d�compression de la configuration
124
+ Modification de certaines propri�t�s ({weight} => {cart.weight}, {price_excluding_tax} => {cart.price_excluding_tax}, {price_including_tax} => {cart.price_including_tax}, {products_quantity} => {cart.quantity},{contry} => {destination.country.name})
125
+ Syntaxe l�g�rement modifi� pour {product.attribute.xxx} et {product.option.xxx} (pas de s)
126
+ Ajout de nouvelles propri�t�s utilisables dans le foreach : {selection.weight}, {selection.quantity}, {product.weight}, {product.quantity}
127
+ Possibilit� d'utiliser {product.attribute.xxx} et {product.option.xxx} dans le foreach
128
+
129
+ [2.1.9 - 20 juillet 2010]
130
+ �valuation des formules contenues dans les propri�t�s ""label"" et ""description""
131
+
132
+ [2.1.8 - 20 juillet 2010]
133
+ Correction d'une erreur dans le foreach (l'attribut �tait toujours ""name"")
134
+
135
+ [2.1.7 - 19 juillet 2010]
136
+ Ajout de la syntaxe foreach product.attribute.xxx
137
+
138
+ [2.1.6 - 28 d�cembre 2009]
139
+ Correction d'une erreur dans le nom d'une variable qui entrainait un plantage dans certaines situations
140
+
141
+ [2.1.5 - 28 d�cembre 2009]
142
+ Modification de la syntaxe des tables (pour offrir plus de souplesse)
143
+
144
+ [2.1.4 - 24 d�cembre 2009]
145
+ Modification de la syntaxe d'utilisation des propri�t�s des produits (pour offrir beaucoup plus de souplesse)
146
+ Possibilit� de filtrer les produits dont on veut utiliser les propri�t�s.
147
+ Ajout de 'COUNT DISTINCT'
148
+
149
+ [2.1.3 - 17 d�cembre 2009]
150
+ Correction du calcul du nombre de produits dont les propri�t�s correspondent ""{count ..."" : prise en compte de la quantit�
151
+ Simplification de la syntaxe de copie de propri�t�
152
+
153
+ [2.1.2 - 27 novembre 2009]
154
+ Correction d'un probl�me de priorit� entre l'op�rateur ""="" et l'op�rateur ""and"" dans l'�valuation des formules : ajout de parenth�ses autour de la formule
155
+
156
+ [2.1.1 - 26 novembre 2009]
157
+ Suppression de la propri�t� 'product_properties' qui doit �tre utilis�e dans la propri�t� 'conditions'
158
+ Am�liorations diverses
159
+
160
+ [2.1.0 - 24 novembre 2009]
161
+ Regroupement des propri�t�s 'fees_table', 'fees_formula' et 'fixed_fees' dans une unique propri�t� 'fees'
162
+ Regroupement des propri�t�s 'prices_range' et 'weights_range' dans une unique propri�t� 'conditions'
163
+ Suppression de la propri�t� 'reference_value'
164
+ Suppression des propri�t�s 'free_shipping__fees_table', 'free_shipping__fees_formula' et 'free_shipping__fixed_fees' (utiliser '{free_shipping}' dans la propri�t� 'conditions' � la place)
165
+ Ajout d'un analyseur de syntaxe de la configuration pour indiquer l'utilisation de propri�t�s non reconnues ou de propri�t�s obsol�tes, les valeurs non reconnues, les virgules manquantes en fin de ligne, les doublons des propri�t�s 'code'
166
+ Utilisation des valeurs des propri�t�s obsol�tes dans leur nouvel �quivalent
167
+ Possibilit� de copier une propri�t� avec la syntaxe ""{copy 'colissimo'.'fees'}""
168
+ Nouvelle syntaxe pour les tables (ancienne propri�t� 'fees_table') : ""{table 'weight' 1.0:2.50, 2.0:3.00}"" qui peuvent d�sormais �tre int�gr�es dans des formules
169
+ S�paration des m�thodes publique, priv�es g�n�riques (pr�fixe '_'), priv�es sp�cifiques � Magento (pr�fixe '__') pour faciliter le portage du module vers un autre syst�me de boutique en ligne que Magento
170
+
171
+ [2.0.12 - 19 novembre 2009]
172
+ Am�lioration de la transmission des variables entre les m�thodes de la classe
173
+
174
+ [2.0.11 - 19 novembre 2009]
175
+ Correction du filtrage en fonction des options et des attributs des produits en pr�sence de produits configurables
176
+
177
+ [2.0.10 - 13 novembre 2009]
178
+ Am�lioration du filtrage en fonction des options et des attributs des produits
179
+ Correction du filtrage en fonction des options des produits
180
+
181
+ [2.0.9 - 12 novembre 2009]
182
+ Correction du filtrage en fonction des options des produits
183
+
184
+ [2.0.8 - 12 novembre 2009]
185
+ Possibilit� de filtrer en fonction des options des produits
186
+
187
+ [2.0.7 - 04 novembre 2009]
188
+ Possibilit� de filtrer en fonction de l'origine de livraison
189
+ Possibilit� de filtrer en fonction des attributs de produits
190
+ Possibilit� de sp�cifier un code postal dans le filtrage de la destination
191
+ Compatibilit� avec Magento 1.4.* : utilisation de la fonction getTranslationList au lieu de getCountryTranslationList qui est d�pr�ci�e
192
+
193
+ [2.0.6 - 02 octobre 2009]
194
+ Possibilit� de sp�cifier des groupes de clients
195
+
196
+ [2.0.5 - 18 ao�t 2009]
197
+ Ajout de la possibilit� de sp�cifier dans la destination le monde entier sauf certains pays
198
+ Correction d'un probl�me de parsing de la destination lorsqu'il n'y avait qu'un seul code r�gion entre parenth�ses
199
+ Possibilit� d'avoir des codes r�gion comprenant des espaces
200
+
201
+ [2.0.4 - 28 juillet 2009]
202
+ Suppression des options ""Unit� de poids"" et ""Utiliser le montant TTC"" de chaque mode de livraison
203
+ Possibilit� d'inclure ou d'exclure les valeurs limites dans les champs 'prices_range', 'weights_range' et 'fees_table' gr�ce aux caract�res '[' et ']'
204
+ Possibilit� de sp�cifier dans les champs 'prices_range' et 'fees_table' si on utilise le montant HT ou TTC
205
+ Ajout du champ 'enabled' et suppression de la possibilit� de d�sactiver un bloc de configuration avec le caract�re '#'
206
+ Modification du message d'erreur par d�faut
207
+ Ajout d'un message d'erreur en cas d'erreur d'interpr�tation d'une formule de calcul de frais
208
+
209
+ [2.0.3 - 27 juillet 2009]
210
+ Correction d'une erreur dans l'interpr�tation des formules avec des fonctions � arguments multiples (min, max, rand)
211
+
212
+ [2.0.2 - 27 juin 2009]
213
+ Correction d'une erreur d'expression r�guli�re
214
+
215
+ [2.0.1 - 25 juin 2009]
216
+ Uniformisation du nom des variables dans les valeurs de r�f�rence : 'price_excluding_tax' et 'price_including_tax' � la place de la valeur 'price'
217
+ Correction d'un probl�me de Magento qui ne semble pas retourner la bonne valeur lors de l'appel � la m�thode $request->getFreeShipping()
218
+ Ajout du champ 'description' qui permet d'ajouter une description � une m�thode de livraison qui peut �tre r�cup�r�e gr�ce � la m�thode $_rate->getMethodDescription()
219
+ Corrections de bugs
220
+
221
+ [2.0 - 3 avril 2009]
222
+ Cr�ation de la version 2.0 du module Owebia Shipping qui n'est plus compatible avec les anciennes versions
223
+
app/code/community/Owebia/Shipping2/controllers/AjaxController.php ADDED
@@ -0,0 +1,469 @@
1
+ <?php
2
+
3
+ /**
4
+ * Magento Owebia Shipping2 Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Owebia
17
+ * @package Owebia_Shipping2
18
+ * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ class Owebia_Shipping2_AjaxController extends Owebia_Shipping2_Controller_Abstract
24
+ {
25
+ private function getPropertyHelper($row_id, $property_key, $property) {
26
+ $cleaned_property = $this->cleanKey($property_key);
27
+ $prefix = "r-".$row_id."-p-".$cleaned_property;
28
+ $value = isset($property['original_value']) ? $property['original_value'] : (isset($property['value']) ? $property['value'] : '');
29
+
30
+ switch ($property_key) {
31
+ case 'enabled':
32
+ $enabled = $value!==false;
33
+ return "<p><select id=\"".$prefix."\" class=\"field\">"
34
+ ."<option value=\"0\"".($enabled ? '' : ' selected="selected"').">".$this->__('Disabled')."</option>"
35
+ ."<option value=\"1\"".($enabled ? ' selected="selected"' : '').">".$this->__('Enabled')."</option>"
36
+ ."</select><p>";
37
+ break;
38
+ case 'label':
39
+ case 'description':
40
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
41
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
42
+ ."<p>"
43
+ .$this->button('Destination country',"os2editor.insertAtCaret(this,'{destination.country.name}');")
44
+ .$this->button('Cart weight',"os2editor.insertAtCaret(this,'{cart.weight}');")
45
+ .$this->button('Cart quantity',"os2editor.insertAtCaret(this,'{cart.quantity}');")
46
+ .$this->button('Price including tax',"os2editor.insertAtCaret(this,'{cart.price_including_tax}');")
47
+ .$this->button('Price excluding tax',"os2editor.insertAtCaret(this,'{cart.price_excluding_tax}');")
48
+ ."</p>"
49
+ ."</fieldset>";
50
+ break;
51
+ case 'fees':
52
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
53
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
54
+ ."<p><span class=\"buttons-set-label\">".$this->__('Cart')."</span>"
55
+ .$this->button('Weight',"os2editor.insertAtCaret(this,'{cart.weight}');")
56
+ .$this->button('Products quantity',"os2editor.insertAtCaret(this,'{cart.quantity}');")
57
+ .$this->button('Price including tax',"os2editor.insertAtCaret(this,'{cart.price_including_tax}');")
58
+ .$this->button('Price excluding tax',"os2editor.insertAtCaret(this,'{cart.price_excluding_tax}');")
59
+ ."</p>"
60
+ ."<p><span class=\"buttons-set-label\">".$this->__('Selection')."</span>"
61
+ .$this->button('Weight',"os2editor.insertAtCaret(this,'{selection.weight}');")
62
+ .$this->button('Products quantity',"os2editor.insertAtCaret(this,'{selection.quantity}');")
63
+ ."</p>"
64
+ ."<p><span class=\"buttons-set-label\">".$this->__('Product')."</span>"
65
+ .$this->button('Weight',"os2editor.insertAtCaret(this,'{product.weight}');")
66
+ .$this->button('Quantity',"os2editor.insertAtCaret(this,'{product.quantity}');")
67
+ ."</p>"
68
+ ."</fieldset>";
69
+ break;
70
+ case 'conditions':
71
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
72
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
73
+ ."<p><span class=\"buttons-set-label\">".$this->__('Cart')."</span>"
74
+ .$this->button('Weight',"os2editor.insertAtCaret(this,'{cart.weight}');")
75
+ .$this->button('Products quantity',"os2editor.insertAtCaret(this,'{cart.quantity}');")
76
+ .$this->button('Price including tax',"os2editor.insertAtCaret(this,'{cart.price_including_tax}');")
77
+ .$this->button('Price excluding tax',"os2editor.insertAtCaret(this,'{cart.price_excluding_tax}');")
78
+ ."</p>"
79
+ ."</fieldset>";
80
+ break;
81
+ case 'customer_groups':
82
+ $groups = CustomerGroup::getCustomerGroups();
83
+ $output = '';
84
+ foreach ($groups as $group) {
85
+ $output .= $this->untranslated_button(htmlentities($group->getCode()),"os2editor.insertAtCaret(this,'".$this->jsEscape($group->getId())."');");
86
+ }
87
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
88
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Display')."</legend>"
89
+ ."<p>"
90
+ .$this->button('Display original input',"os2editor.updatePropertyValue('original-value',this,false);")
91
+ .$this->button('Display names',"os2editor.updatePropertyValue('full-value',this,false);")
92
+ .$this->button('Display identifiers',"os2editor.updatePropertyValue('compact-value',this,true);")
93
+ ."</p>"
94
+ ."</fieldset>"
95
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
96
+ ."<p>"
97
+ //.$this->button('Not logged in',"os2editor.insertAtCaret(this,'NOT LOGGED IN');")
98
+ .$output
99
+ ."</p>"
100
+ ."</fieldset>"
101
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Preview')."</legend>"
102
+ ."<div class=\"preview-items-list customer-group-list\">".$this->getCustomerGroupsPreview($value)."</div>"
103
+ ."</fieldset>"
104
+ ;
105
+ break;
106
+ case 'tracking_url':
107
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
108
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
109
+ ."<p>"
110
+ .$this->button('Tracking number',"os2editor.insertAtCaret(this,'{tracking_number}');")
111
+ ."</p>"
112
+ ."</fieldset>";
113
+ break;
114
+ case 'destination':
115
+ case 'origin':
116
+ $parsed_value = $this->parseAddressFilter($value);
117
+ $excluding = $parsed_value['excluding'];
118
+ return "<div class=\"address-filters-property\"><p>"
119
+ ."<input type=\"radio\" class=\"excluding\" id=\"".$prefix."-exluding-0\" name=\"".$prefix."-exluding\""
120
+ ." value=\"0\"".(!$excluding ? " checked=\"checked\"" : '')." onclick=\"os2editor.updateAddressFilterPreview(this);\"/>"
121
+ ."<label for=\"".$prefix."-exluding-0\"> ".$this->__('Limit to')."</label> &nbsp; "
122
+ ."<input type=\"radio\" class=\"excluding\" id=\"".$prefix."-exluding-1\" name=\"".$prefix."-exluding\""
123
+ ." value=\"1\"".($excluding ? " checked=\"checked\"" : '')." onclick=\"os2editor.updateAddressFilterPreview(this);\"/>"
124
+ ."<label for=\"".$prefix."-exluding-1\"> ".$this->__('Exclude')."</label></p>"
125
+ ."<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
126
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Display')."</legend>"
127
+ ."<p>"
128
+ .$this->button('Display original input',"os2editor.updatePropertyValue('original-value',this,false);")
129
+ .$this->button('Display corrected names',"os2editor.updatePropertyValue('full-value',this,false);")
130
+ .$this->button('Display codes',"os2editor.updatePropertyValue('compact-value',this,true);")
131
+ ."</p>"
132
+ ."</fieldset>"
133
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Preview')."</legend>"
134
+ ."<div class=\"preview-items-list address-filter-list\">".$this->getAddressFiltersPreview($parsed_value)."</div>"
135
+ ."</fieldset>"
136
+ ."</div>"
137
+ ;
138
+ break;
139
+ case '*comment' :
140
+ $lines = explode("\n",trim($value));
141
+ for ($i=0; $i<count($lines); $i++) {
142
+ $lines[$i] = preg_replace('/^# ?/','',$lines[$i]);
143
+ }
144
+ $value = implode("\n",$lines);
145
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>";
146
+ default :
147
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>";
148
+ }
149
+ }
150
+
151
+ private function getCustomerGroupsPreview($input) {
152
+ if (trim($input)=='') return '';
153
+ $elems = explode(',',$input);
154
+ $customer_groups = array();
155
+ foreach ($elems as $elem) {
156
+ $customer_groups[] = new CustomerGroup($elem);
157
+ }
158
+ return implode('',$customer_groups);
159
+ }
160
+
161
+ private function getAddressFiltersPreview($data) {
162
+ $address_filters = array();
163
+ foreach ($data['countries'] as $country) {
164
+ $address_filters[] = new AddressFilter($country);
165
+ }
166
+ return implode('',$address_filters);
167
+ }
168
+
169
+ private function parseAddressFilter($address_filter) {
170
+ $output = array(
171
+ 'excluding' => false,
172
+ 'countries' => array(),
173
+ 'original' => $address_filter,
174
+ );
175
+
176
+ $address_filter = str_replace(
177
+ array('\(', '\)', '\,'),
178
+ array('__opening_parenthesis__', '__closing_parenthesis__', '__comma__'),
179
+ $address_filter
180
+ );
181
+ $address_filter = str_replace(array("\r\n","\r","\n"),array(',',',',','),$address_filter);
182
+
183
+ if (preg_match('# *\* *- *\((.*)\) *#s',$address_filter,$result)) {
184
+ $address_filter = $result[1];
185
+ $output['excluding'] = true;
186
+ }
187
+
188
+ $tmp_address_filter_array = explode(',',trim($address_filter));
189
+
190
+ $concat = false;
191
+ $concatened = '';
192
+ $address_filter_array = array();
193
+ $i = 0;
194
+
195
+ foreach ($tmp_address_filter_array as $address_filter) {
196
+ if ($concat) $concatened .= ','.$address_filter;
197
+ else {
198
+ if ($i<count($tmp_address_filter_array)-1 && preg_match('#\(#',$address_filter)) {
199
+ $concat = true;
200
+ $concatened .= $address_filter;
201
+ } else $address_filter_array[] = $address_filter;
202
+ }
203
+ if (preg_match('#\)#',$address_filter)) {
204
+ $address_filter_array[] = $concatened;
205
+ $concatened = '';
206
+ $concat = false;
207
+ }
208
+ $i++;
209
+ }
210
+
211
+ foreach ($address_filter_array as $address_filter) {
212
+ $address_filter = trim($address_filter);
213
+ $original_address_filter = str_replace(
214
+ array('__opening_parenthesis__', '__closing_parenthesis__', '__comma__'),
215
+ array('\(', '\)', '\,'),
216
+ $address_filter
217
+ );
218
+ if (trim($address_filter)!='') {
219
+ if (preg_match('# *([^,(]+) *(-)? *(?:\( *(-)? *(.*)\))? *#s', $address_filter,$result)) {
220
+ $country_code = $result[1];
221
+
222
+ $region_codes = isset($result[4]) ? explode(',',$result[4]) : array();
223
+ $in_array = false;
224
+ for ($i=count($region_codes); --$i>=0;) {
225
+ $code = trim(str_replace(
226
+ array('__opening_parenthesis__', '__closing_parenthesis__', '__comma__'),
227
+ array('\(', '\)', '\,'),
228
+ $region_codes[$i]
229
+ ));
230
+ $region_codes[$i] = $code;
231
+ }
232
+ /*$in_array = in_array($address['region_code'],$region_codes,true) || in_array($address['postcode'],$region_codes,true);*/
233
+ $excluding_region = isset($result[2]) && $result[2]=='-' || isset($result[3]) && $result[3]=='-';
234
+ $output['countries'][] = array(
235
+ 'excluding' => $excluding_region,
236
+ 'country_code' => $country_code,
237
+ 'region_codes' => implode(',',$region_codes),
238
+ 'original' => $original_address_filter,
239
+ );
240
+ } else {
241
+ $output['countries'][] = array(
242
+ 'excluding' => null,
243
+ 'country_code' => $original_address_filter,
244
+ 'region_codes' => null,
245
+ 'original' => $original_address_filter,
246
+ );
247
+ }
248
+ }
249
+ }
250
+ return $output;
251
+ }
252
+
253
+ private function getRowUI(&$row, $selected) {
254
+ $row['_ID_']['value'] = isset($row['_ID_']['value']) ? $row['_ID_']['value'] : uniqid('c');
255
+ $row_id = $row['_ID_']['value'];
256
+
257
+ if (isset($row['lines'])) {
258
+ $output = "<div id=\"r-".$row_id."-container\" class=\"row-container has-error ignored-lines".($selected ? ' selected' : '')."\">"
259
+ ."<div class=\"row-header\" onclick=\"os2editor.selectRow('".$row_id."');\">"
260
+ ."<div class=\"row-actions\">"
261
+ .$this->button('Apply changes',"os2editor.applyChanges();")
262
+ .$this->button('Delete',"os2editor.removeRow(this);",'delete')
263
+ ."</div>"
264
+ ."<div class=\"row-title\">".$this->__('Ignored lines')."</div></div>"
265
+ ."<div class=\"properties-container\"><textarea class=\"field\">".$row['lines']."</textarea></div></div>";
266
+ return $output;
267
+ }
268
+
269
+ if (!isset($row['label'])) {
270
+ $row['label']['value'] = $this->__('New shipping method');
271
+ }
272
+
273
+ $properties = array(
274
+ 'enabled' => 'Enabled',
275
+ 'code' => 'Code',
276
+ 'label' => 'Label',
277
+ 'description' => 'Description',
278
+ 'destination' => 'Destination',
279
+ 'origin' => 'Origin',
280
+ 'conditions' => 'Conditions',
281
+ 'fees' => 'Fees',
282
+ 'customer_groups' => 'Customer groups',
283
+ 'tracking_url' => 'Tracking url',
284
+ '*comment' => 'Comment',
285
+ );
286
+
287
+ $label = $row['label']['value'];
288
+ $output = "<div id=\"r-".$row_id."-container\" class=\"row-container".($selected ? ' selected' : '')."\">"
289
+ ."<div class=\"row-header\" onclick=\"os2editor.selectRow('".$row_id."');\">"
290
+ ."<div class=\"row-actions\">".$this->button('Delete',"os2editor.removeRow(this);",'delete')."</div><div class=\"row-title\">".$label."</div></div>"
291
+ ."<div class=\"properties-container\">";
292
+ $list = "<ul class=\"properties-list\">";
293
+ $j = 0;
294
+ foreach ($properties as $property_key => $label) {
295
+ $cleaned_property = $this->cleanKey($property_key);
296
+ $value = isset($row[$property_key]) ? trim($row[$property_key]['value']) : '';
297
+ $list .= "<li id=\"r-".$row_id."-p-".$cleaned_property."-item\" class=\"property-item".($j==0 ? ' selected' : '')
298
+ .($value==='' ? ' empty' : '')
299
+ ."\" onclick=\"os2editor.selectProperty('".$row_id."','".$cleaned_property."');\">".$this->__($label)."</li>";
300
+ $output .= "<div id=\"r-".$row_id."-p-".$cleaned_property."-container\" class=\"property-container"
301
+ .($j==0 ? ' selected' : '')."\" property-name=\"".$property_key."\">"
302
+ ."<div class=\"buttons-set\" style=\"text-align:right;\">".$this->button('Help',"os2editor.help('property.".$property_key."');",'help')."</div>"
303
+ .$this->getPropertyHelper($row_id,$property_key,isset($row[$property_key]) ? $row[$property_key] : array())."</div>";
304
+ $j++;
305
+ }
306
+ foreach ($row as $property_key => $property) {
307
+ if (!isset($properties[$property_key]) && substr($property_key,0,1)!='*') {
308
+ $label = $property_key;
309
+ $cleaned_property = $this->cleanKey($property_key);
310
+ $value = isset($row[$property_key]) ? trim($row[$property_key]['value']) : '';
311
+ $list .= "<li id=\"r-".$row_id."-p-".$cleaned_property."-item\" class=\"property-item".($j==0 ? ' selected' : '')
312
+ .(empty($value) ? ' empty' : '').($cleaned_property=='_ID_' ? ' hide' : '')
313
+ ."\" onclick=\"os2editor.selectProperty('".$row_id."','".$cleaned_property."');\">".$this->__($label)."</li>";
314
+ $output .= "<div id=\"r-".$row_id."-p-".$cleaned_property."-container\" class=\"property-container"
315
+ .($j==0 ? ' selected' : '')."\" property-name=\"".$property_key."\">"
316
+ ."<div class=\"buttons-set\" style=\"text-align:right;\">".$this->button('Help',"os2editor.help('property.".$property_key."');",'help')."</div>"
317
+ .$this->getPropertyHelper($row_id,$property_key,$property)."</div>";
318
+ $j++;
319
+ }
320
+ }
321
+ $output .= $list."</div></div>";
322
+ return $output;
323
+ }
324
+
325
+ private function getConfigErrors($config) {
326
+ $script = "os2editor.resetErrors();";
327
+ foreach ($config as $row_code => $row) {
328
+ if (isset($row['*messages'])) {
329
+ $error = '';
330
+ foreach ($row['*messages'] as $message) {
331
+ $error .= "<p>".$this->__($message)."</p>";
332
+ }
333
+ if ($error!='') $script .= "os2editor.setError('".$row['_ID_']['value']."','','".$this->jsEscape($error)."');";
334
+ }
335
+ foreach ($row as $property_key => $property) {
336
+ if (isset($property['messages']) && is_array($property['messages'])) {
337
+ $error = '';
338
+ foreach ($property['messages'] as $message) {
339
+ $error .= "<p>".$this->__($message)."</p>";
340
+ }
341
+ if ($error!='') {
342
+ $script .= "os2editor.setError('".$row['_ID_']['value']."','".$property_key."','"
343
+ .$this->jsEscape($error
344
+ .($property['value']!=$property['original_value'] ?
345
+ "<p>"
346
+ .$this->button('Correct',"os2editor.correct('".$row['_ID_']['value']."','".$property_key."','".$this->jsEscape($property['value'])."');")
347
+ ."</p>" : '')
348
+ )."');";
349
+ }
350
+ }
351
+ }
352
+ }
353
+ //$script .= "alert('".str_replace(array("\r\n","\n","\'","'"),array(" "," ","\\\'","\'"),$script)."');";
354
+ return $script;
355
+ }
356
+
357
+ private function loadConfig($input) {
358
+ include_once $this->getModulePath('includes/OwebiaShippingHelper.php');
359
+
360
+ $helper = new OwebiaShippingHelper($input);
361
+ $helper->checkConfig();
362
+ $config = $helper->getConfig();
363
+ //print_r($config);
364
+
365
+ $output = "<div class=\"buttons-set\">"
366
+ .$this->button('Add a shipping method',"os2editor.addRow();",'add')
367
+ ."</div><div class=\"config-container\">";
368
+ $i = 0;
369
+ foreach ($config as &$row) {
370
+ $output .= $this->getRowUI($row,$i==0);
371
+ $i++;
372
+ }
373
+ $output .= "</div><script type=\"text/javascript\">".$this->getConfigErrors($config)."</script>";
374
+ return $output;
375
+ }
376
+
377
+ public function indexAction() {
378
+ header('Content-Type: text/html; charset=UTF-8');
379
+
380
+ include_once $this->getModulePath('includes/OS2_AddressFilter.php');
381
+ include_once $this->getModulePath('includes/OS2_CustomerGroup.php');
382
+
383
+ switch ($_POST['what']) {
384
+ case 'open':
385
+ $output = ""
386
+ // Donate page
387
+ .$this->page('donate',"Support the development of Owebia Shipping 2 extension",$this->__('{os2editor.donate-page.content}'))
388
+ // Help page
389
+ .$this->page('help',"Owebia Shipping 2 extension help",'')
390
+ // Main page
391
+ .$this->pageHeader("Owebia Shipping 2 configuration editor",
392
+ $this->button('Save',"os2editor.save();",'save')
393
+ .$this->button('Export',"os2editor.saveToFile();",'')
394
+ .$this->button('Load',"os2editor.showConfigLoader();",'')
395
+ .$this->button('Close',"os2editor.close();",'cancel')
396
+ )
397
+ ."<div id=\"os2-editor-config-loader\">"
398
+ ."<textarea></textarea>"
399
+ ."<div class=\"buttons-set\">"
400
+ .$this->button('Load',"os2editor.loadConfig();",'')
401
+ .$this->button('Cancel',"os2editor.hideConfigLoader();",'cancel')
402
+ ."</div>"
403
+ ."</div>"
404
+ ."<div id=\"os2-editor-config-container\">".$this->loadConfig($_POST['input'])."</div>"
405
+ ."<div class=\"donate-container\">"
406
+ ."<table cellspacing=\"0\"><tr>"
407
+ ."<td>".$this->__('You appreciate this extension and would like to help?')."</td>"
408
+ ."<td class=\"form-buttons\">"
409
+ .$this->button('Donate',"os2editor.openPage('donate');",'donate')
410
+ ."</td>"
411
+ ."</tr></table>"
412
+ ."</div>"
413
+ ;
414
+ echo $output;
415
+ exit;
416
+ case 'help':
417
+ $output = $this->__('{os2editor.help.'.$_POST['input'].'}');
418
+ if ($_POST['input']=='changelog') {
419
+ $changelog = @file_get_contents($this->getModulePath('changelog'));
420
+ $output = str_replace('{changelog}',mb_convert_encoding($changelog,'UTF-8','ISO-8859-1'),$output);
421
+ }
422
+ echo $output;
423
+ exit;
424
+ case 'add-row':
425
+ $row = array(); // Passage par r�f�rence
426
+ echo $this->getRowUI($row,true);
427
+ exit;
428
+ case 'load-config':
429
+ echo $this->loadConfig($_POST['config']);
430
+ exit;
431
+ case 'check-config':
432
+ include_once $this->getModulePath('includes/OwebiaShippingHelper.php');
433
+
434
+ $helper = new OwebiaShippingHelper($_POST['config']);
435
+ $helper->checkConfig();
436
+ //print_r($helper->getConfig(),$out);
437
+ //$script = "alert('".$this->jsEscape($_POST['config'])."');";
438
+ $script = $this->getConfigErrors($helper->getConfig());
439
+ //$script = "alert('".$this->jsEscape($this->getConfigErrors($helper->getConfig()))."');";
440
+ break;
441
+ case 'save-config':
442
+ include_once $this->getModulePath('includes/OwebiaShippingHelper.php');
443
+
444
+ $helper = new OwebiaShippingHelper($_POST['config']);
445
+ $compress = (bool)Mage::getStoreConfig('carriers/'.$_POST['shipping_code'].'/compression');
446
+ $output = $helper->formatConfig($compress,$keys_to_remove=array('_ID_'));
447
+ //Mage::getConfig()->saveConfig('carriers/'.$_POST['shipping_code'].'/config',$output);
448
+ echo $output;
449
+ exit;
450
+ case 'save-to-file':
451
+ include_once $this->getModulePath('includes/OwebiaShippingHelper.php');
452
+
453
+ $helper = new OwebiaShippingHelper(urldecode($_POST['config']));
454
+ $formatted_config = $helper->formatConfig(false,$keys_to_remove=array('_ID_'));
455
+ $this->forceDownload('owebia-shipping-config.txt',$formatted_config);
456
+ exit;
457
+ case 'get-address-filters':
458
+ $result = $this->parseAddressFilter($_POST['input']);
459
+ echo $this->getAddressFiltersPreview($result);
460
+ exit;
461
+ case 'get-customer-groups':
462
+ echo $this->getCustomerGroupsPreview($_POST['input']);
463
+ exit;
464
+ }
465
+
466
+ echo "<script type=\"text/javascript\">".$script."</script>";
467
+ exit;
468
+ }
469
+ }
app/code/community/Owebia/Shipping2/controllers/Checkout/CartController.php ADDED
@@ -0,0 +1,33 @@
1
+ <?php
2
+
3
+ if (file_exists(dirname(__FILE__).'/Mage_Checkout_CartController.php')) include_once 'Mage_Checkout_CartController.php';
4
+ else include_once Mage::getBaseDir('code').'/core/Mage/Checkout/controllers/CartController.php';
5
+
6
+ class Owebia_Shipping2_Checkout_CartController extends Mage_Checkout_CartController
7
+ {
8
+ /**
9
+ * Initialize shipping information
10
+ */
11
+ public function estimatePostAction()
12
+ {
13
+ $country = (string) $this->getRequest()->getParam('country_id');
14
+ $postcode = (string) $this->getRequest()->getParam('estimate_postcode');
15
+ $city = (string) $this->getRequest()->getParam('estimate_city');
16
+ $regionId = (string) $this->getRequest()->getParam('region_id');
17
+ $region = (string) $this->getRequest()->getParam('region');
18
+
19
+ $this->_getQuote()->getShippingAddress()
20
+ ->setCountryId($country)
21
+ ->setCity($city)
22
+ ->setPostcode($postcode)
23
+ ->setRegionId($regionId)
24
+ ->setRegion($region)
25
+ ->setCollectShippingRates(true);
26
+
27
+ // Recalcul des totaux
28
+ $this->_getQuote()->collectTotals();
29
+
30
+ $this->_getQuote()->save();
31
+ $this->_goBack();
32
+ }
33
+ }
app/code/community/Owebia/Shipping2/etc/adminhtml.xml ADDED
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0" ?>
2
+ <!-- Magento 1.4.0 and upper -->
3
+ <config>
4
+ <acl>
5
+ <resources>
6
+ <admin>
7
+ <children>
8
+ <system>
9
+ <children>
10
+ <config>
11
+ <children>
12
+ <owebia>
13
+ <title>Owebia Section</title>
14
+ <sort_order>100</sort_order>
15
+ </owebia>
16
+ </children>
17
+ </config>
18
+ </children>
19
+ </system>
20
+ </children>
21
+ </admin>
22
+ </resources>
23
+ </acl>
24
+ <translate>
25
+ <modules>
26
+ <Mage_Shipping>
27
+ <files>
28
+ <owebia-shipping2>Owebia_Shipping2.csv</owebia-shipping2>
29
+ </files>
30
+ </Mage_Shipping>
31
+ </modules>
32
+ </translate>
33
+ </config>
app/code/community/Owebia/Shipping2/etc/config.xml ADDED
@@ -0,0 +1,519 @@
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento Owebia Shipping Module
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * @category Owebia
17
+ * @package Owebia_Shipping
18
+ * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+ -->
23
+ <config>
24
+ <modules>
25
+ <Owebia_Shipping2>
26
+ <version>2.3.8</version>
27
+ <depends>
28
+ <Mage_Shipping />
29
+ </depends>
30
+ </Owebia_Shipping2>
31
+ </modules>
32
+
33
+ <global>
34
+ <models>
35
+ <owebia-shipping2>
36
+ <class>Owebia_Shipping2_Model</class>
37
+ </owebia-shipping2>
38
+ </models>
39
+ <blocks>
40
+ <owebia-shipping2>
41
+ <class>Owebia_Shipping2_Block</class>
42
+ </owebia-shipping2>
43
+ </blocks>
44
+
45
+ <!--
46
+ <helpers>
47
+ <owebia-shipping2>
48
+ <class>Owebia_Shipping2_Helper</class>
49
+ </owebia-shipping2>
50
+ </helpers>
51
+ -->
52
+
53
+ <resources>
54
+ <sales>
55
+ <shipping>
56
+ <carriers>
57
+ <owebiashipping1>
58
+ <class>Owebia_Shipping2_Model_Carrier_OwebiaShipping1</class>
59
+ </owebiashipping1>
60
+ <owebiashipping2>
61
+ <class>Owebia_Shipping2_Model_Carrier_OwebiaShipping2</class>
62
+ </owebiashipping2>
63
+ <owebiashipping3>
64
+ <class>Owebia_Shipping2_Model_Carrier_OwebiaShipping3</class>
65
+ </owebiashipping3>
66
+ </carriers>
67
+ </shipping>
68
+ </sales>
69
+ </resources>
70
+ </global>
71
+
72
+ <admin>
73
+ <routers>
74
+ <owebia-shipping2>
75
+ <use>admin</use>
76
+ <args>
77
+ <module>Owebia_Shipping2</module>
78
+ <frontName>owebia-shipping2</frontName>
79
+ </args>
80
+ </owebia-shipping2>
81
+ </routers>
82
+ </admin>
83
+ <adminhtml>
84
+ <!--
85
+ <menu>
86
+ <owebia translate="title" module="adminhtml">
87
+ <title>Owebia</title>
88
+ <sort_order>100</sort_order>
89
+ <children>
90
+ <owebiashipping2>
91
+ <title>Owebia Shipping 2</title>
92
+ <action>owebia-shipping2/index</action>
93
+ </owebiashipping2>
94
+ <ajax>
95
+ <title>Owebia Shipping 2 ajax</title>
96
+ <action>owebia-shipping2/ajax</action>
97
+ </ajax>
98
+ </children>
99
+ </owebia>
100
+ </menu>
101
+ -->
102
+ <!-- Magento lower than 1.4.0 -->
103
+ <acl>
104
+ <resources>
105
+ <admin>
106
+ <children>
107
+ <system>
108
+ <children>
109
+ <config>
110
+ <children>
111
+ <owebia>
112
+ <title>Owebia Section</title>
113
+ <sort_order>100</sort_order>
114
+ </owebia>
115
+ </children>
116
+ </config>
117
+ </children>
118
+ </system>
119
+ </children>
120
+ </admin>
121
+ </resources>
122
+ </acl>
123
+ <translate>
124
+ <modules>
125
+ <Mage_Shipping>
126
+ <files>
127
+ <owebia-shipping2>Owebia_Shipping2.csv</owebia-shipping2>
128
+ </files>
129
+ </Mage_Shipping>
130
+ </modules>
131
+ </translate>
132
+ </adminhtml>
133
+
134
+ <frontend>
135
+ <translate>
136
+ <modules>
137
+ <Mage_Shipping>
138
+ <files>
139
+ <owebia-shipping2>Owebia_Shipping2.csv</owebia-shipping2>
140
+ </files>
141
+ </Mage_Shipping>
142
+ </modules>
143
+ </translate>
144
+ <routers>
145
+ <checkout>
146
+ <args>
147
+ <modules>
148
+ <owebia-shipping2 before="Mage_Checkout">Owebia_Shipping2_Checkout</owebia-shipping2>
149
+ </modules>
150
+ </args>
151
+ </checkout>
152
+ </routers>
153
+ </frontend>
154
+
155
+ <default>
156
+ <owebia>
157
+ <shipping>
158
+ <weight_unit>kg</weight_unit>
159
+ </shipping>
160
+ </owebia>
161
+ <carriers>
162
+ <owebiashipping1>
163
+ <active>0</active>
164
+ <title>Colissimo / Chronopost / Export 3J</title>
165
+ <model>Owebia_Shipping2_Model_Carrier_OwebiaShipping1</model>
166
+ <tracking_view_url></tracking_view_url>
167
+ <config><![CDATA[
168
+ #####
169
+ # Colissimo
170
+ #
171
+ # Validité
172
+ # Tarifs du 1er mars 2010
173
+ # Crédits
174
+ # Configuration réalisée par owebia
175
+
176
+ # Colissimo National (France, Monaco, Andorre)
177
+ {
178
+ label: "Colissimo National",
179
+ code: "colissimo",
180
+ tracking_url: "http://www.coliposte.net/particulier/suivi_particulier.jsp?colispart={tracking_number}",
181
+ destination: "FR,MC,AD",
182
+ fees: "{table {cart.weight} in 0.5:5.55, 1.0:6.80, 2.0:7.75, 3.0:8.70, 5.0:10.60, 7.0:12.50, 10.0:15.35, 15.0:17.45, 30.0:23.75}",
183
+ }
184
+ # Colissimo National + Recommandé R1
185
+ {
186
+ label: "Colissimo National Recommandé R1",
187
+ code: "colissimo_r1",
188
+ tracking_url: "{colissimo.tracking_url}",
189
+ destination: "{colissimo.destination}",
190
+ conditions: "{cart.price_excluding_tax}<=50.00",
191
+ fees: "{table {cart.weight} in 0.5:7.85, 1.0:9.10, 2.0:10.05, 3.0:11.00, 5.0:12.90, 7.0:14.80, 10.0:17.65, 15.0:19.75, 30.0:26.05}",
192
+ }
193
+ # Colissimo National + Recommandé R2
194
+ {
195
+ label: "Colissimo National Recommandé R2",
196
+ code: "colissimo_r2",
197
+ tracking_url: "{colissimo.tracking_url}",
198
+ destination: "{colissimo.destination}",
199
+ conditions: "({cart.price_excluding_tax}>50.00) and ({cart.price_excluding_tax}<=200.00)",
200
+ fees: "{table {cart.weight} in 0.5:8.75, 1.0:10.00, 2.0:10.95, 3.0:11.90, 5.0:13.80, 7.0:15.70, 10.0:18.55, 15.0:20.65, 30.0:26.95}",
201
+ }
202
+ # Colissimo National + Recommandé R3
203
+ {
204
+ label: "Colissimo National Recommandé R3",
205
+ code: "colissimo_r3",
206
+ tracking_url: "{colissimo.tracking_url}",
207
+ destination: "{colissimo.destination}",
208
+ conditions: "({cart.price_excluding_tax}>200.00) and ({cart.price_excluding_tax}<=400.00)",
209
+ fees: "{table {cart.weight} in 0.5:9.95, 1.0:11.20, 2.0:12.15, 3.0:13.10, 5.0:15.00, 7.0:16.90, 10.0:19.75, 15.0:21.85, 30.0:28.15}",
210
+ }
211
+ # Colissimo National + Recommandé R4
212
+ {
213
+ label: "Colissimo National Recommandé R4",
214
+ code: "colissimo_r4",
215
+ tracking_url: "{colissimo.tracking_url}",
216
+ destination: "{colissimo.destination}",
217
+ conditions: "({cart.price_excluding_tax}>400.00) and ({cart.price_excluding_tax}<=600.00)",
218
+ fees: "{table {cart.weight} in 0.5:11.15, 1.0:12.40, 2.0:13.35, 3.0:14.30, 5.0:16.20, 7.0:18.10, 10.0:20.95, 15.0:23.05, 30.0:29.35}",
219
+ }
220
+ # Colissimo National + Recommandé R5
221
+ {
222
+ label: "Colissimo National Recommandé R5",
223
+ code: "colissimo_r5",
224
+ tracking_url: "{colissimo.tracking_url}",
225
+ destination: "{colissimo.destination}",
226
+ conditions: "{cart.price_excluding_tax}>600.00",
227
+ fees: "1.30+{table {cart.weight} in 0.5:12.35, 1.0:13.60, 2.0:14.55, 3.0:15.50, 5.0:17.40, 7.0:19.30, 10.0:22.15, 15.0:24.25, 30.0:30.55}",
228
+ }
229
+
230
+ # Colissimo National + Accusé réception
231
+ {
232
+ enabled: false,
233
+ label: "Colissimo National",
234
+ code: "colissimo_ar",
235
+ tracking_url: "{colissimo.tracking_url}",
236
+ destination: "{colissimo.destination}",
237
+ fees: "1.30+{colissimo.fees}",
238
+ }
239
+ # Colissimo National + Recommandé R1 + Accusé réception
240
+ {
241
+ enabled: false,
242
+ label: "Colissimo National Recommandé R1",
243
+ code: "colissimo_ar_r1",
244
+ tracking_url: "{colissimo.tracking_url}",
245
+ destination: "{colissimo.destination}",
246
+ conditions: "{colissimo_r1.conditions}",
247
+ fees: "1.30+{colissimo_r1.fees}",
248
+ }
249
+ # Colissimo National + Recommandé R2 + Accusé réception
250
+ {
251
+ enabled: false,
252
+ label: "Colissimo National Recommandé R2",
253
+ code: "colissimo_ar_r2",
254
+ tracking_url: "{colissimo.tracking_url}",
255
+ destination: "{colissimo.destination}",
256
+ conditions: "{colissimo_r2.conditions}",
257
+ fees: "1.30+{colissimo_r2.fees}",
258
+ }
259
+ # Colissimo National + Recommandé R3 + Accusé réception
260
+ {
261
+ enabled: false,
262
+ label: "Colissimo National Recommandé R3",
263
+ code: "colissimo_ar_r3",
264
+ tracking_url: "{colissimo.tracking_url}",
265
+ destination: "{colissimo.destination}",
266
+ conditions: "{colissimo_r3.conditions}",
267
+ fees: "1.30+{colissimo_r3.fees}",
268
+ }
269
+ # Colissimo National + Recommandé R4 + Accusé réception
270
+ {
271
+ enabled: false,
272
+ label: "Colissimo National Recommandé R4",
273
+ code: "colissimo_ar_r4",
274
+ tracking_url: "{colissimo.tracking_url}",
275
+ destination: "{colissimo.destination}",
276
+ conditions: "{colissimo_r4.conditions}",
277
+ fees: "1.30+{colissimo_r4.fees}",
278
+ }
279
+ # Colissimo National + Recommandé R5 + Accusé réception
280
+ {
281
+ enabled: false,
282
+ label: "Colissimo National Recommandé R5",
283
+ code: "colissimo_ar_r5",
284
+ tracking_url: "{colissimo.tracking_url}",
285
+ destination: "{colissimo.destination}",
286
+ conditions: "{colissimo_r5.conditions}",
287
+ fees: "1.30+{colissimo_r5.fees}",
288
+ }
289
+
290
+ # Colissimo International OM1 (Départements et collectivités d'outre-mer)
291
+ # Guadeloupe, Martinique, Guyane, Réunion, Mayotte,
292
+ # Saint-Pierre et Miquelon, Saint-Martin, Saint-Barthélémy
293
+ {
294
+ label: "Colissimo OM1 Assuré",
295