Owebia_Shipping_2 - Version 2.4.2

Version Notes

[2.4.2 - 07 octobre 2011]
Support des nombres décimaux représentés sous la forme 5.3290705182E-15
Modification de la licence du code source (MIT au lieu de OSL 3.0)
Mise à jour des mentions de copyright et de licence
Nettoyage du code source (suppression de lignes de code en commentaire)
Initialisation des formules sum et count à 0 au lieu de null (pour éviter les erreurs de formule si aucun produit ne correpond)
Ajout des alias "a" et "attr" pour "attribute", "o" et "opt" pour "option", "p" pour "product", "c" pour "cart", "s" pour "selection"
Correction de la récupération des variables personnalisées : getValue('text') au lieu de getValue('plain')
Support des catégories
product.categories dans les conditions de boucle foreach
{product.category} et {product.category.id} comme variables dans les boucles foreach
product.category, product.category.id, product.categories, product.categories.id dans les conditions des opérations sum, count, min et max
Amélioration du debug

Download this release

Release Info

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


Code changes from version 2.4.1 to 2.4.2

app/code/community/Owebia/Shipping2/Block/Adminhtml/System/Config/Form/Field/Config.php CHANGED
@@ -1,5 +1,24 @@
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;
1
  <?php
2
 
3
+ /**
4
+ * Copyright (c) 2008-11 Owebia
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
15
+ *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
18
+ * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
+
22
  class Owebia_Shipping2_Block_Adminhtml_System_Config_Form_Field_Config extends Mage_Adminhtml_Block_System_Config_Form_Field
23
  {
24
  private static $JS_INCLUDED = false;
app/code/community/Owebia/Shipping2/Controller/Abstract.php CHANGED
@@ -1,24 +1,23 @@
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
  {
1
  <?php
2
 
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
  class Owebia_Shipping2_Controller_Abstract extends Mage_Adminhtml_Controller_Action
23
  {
app/code/community/Owebia/Shipping2/Model/Carrier/AbstractOwebiaShipping.php CHANGED
@@ -1,30 +1,53 @@
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-11 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;
@@ -33,8 +56,9 @@ class Magento_Product implements OS_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;
@@ -80,26 +104,11 @@ class Magento_Product implements OS_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;
@@ -126,11 +135,15 @@ class Magento_Product implements OS_Product {
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
  }
@@ -139,6 +152,27 @@ class Magento_Product implements OS_Product {
139
  return $this->cart_product->getName();
140
  }
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  public function getWeight() {
143
  return $this->cart_product->getWeight();
144
  }
@@ -160,8 +194,7 @@ class Magento_Product implements OS_Product {
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;
@@ -189,9 +222,11 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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(),
@@ -313,13 +348,22 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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'));
@@ -328,7 +372,6 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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);
@@ -337,24 +380,15 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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
  }
@@ -386,21 +420,12 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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(
@@ -409,6 +434,7 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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
  }
@@ -424,28 +450,24 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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
  }
@@ -468,6 +490,7 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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')
@@ -478,6 +501,7 @@ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
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');
1
  <?php
2
 
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
  // Pour g�rer les cas o� il y a eu compilation
23
  if (file_exists(dirname(__FILE__).'/Owebia_Shipping2_includes_OwebiaShippingHelper.php')) include_once 'Owebia_Shipping2_includes_OwebiaShippingHelper.php';
24
  else include_once Mage::getBaseDir('code').'/community/Owebia/Shipping2/includes/OwebiaShippingHelper.php';
25
 
26
 
27
+ class Magento_Category implements OS_Category {
28
+ private $id;
29
+ private $loaded_category;
30
+ public function __construct($id) {
31
+ $this->id = $id;
32
+ }
33
+
34
+ private function _loadCategory() {
35
+ if (!isset($this->loaded_category)) $this->loaded_category = Mage::getModel('catalog/category')->load($this->id);
36
+ return $this->loaded_category;
37
+ }
38
+
39
+ public function getId() {
40
+ return $this->id;
41
+ }
42
+ public function getName() {
43
+ $category = $this->_loadCategory();
44
+ return $category->getName();
45
+ }
46
+ public function toString() {
47
+ return $this->getName().' (id:'.$this->getId().', url_key:'.$this->_loadCategory()->getUrlKey().')';
48
+ }
49
+
50
+ }
51
 
52
  class Magento_Product implements OS_Product {
53
  private $parent_cart_item;
56
  private $loaded_product;
57
  private $quantity;
58
  private $options;
59
+ private $categories;
60
 
61
+ public function __construct($cart_item, $parent_cart_item) {
62
  $this->cart_item = $cart_item;
63
  $this->cart_product = $cart_item->getProduct();
64
  $this->parent_cart_item = $parent_cart_item;
104
  $options = $this->getProductOptions();
105
  if (isset($options[$option_name])) return $get_by_id ? $options[$option_name]['value_id'] : $options[$option_name]['value'];
106
  else return $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
108
 
109
  public function getAttribute($attribute_name, $get_by_id=false) {
110
  $value = null;
111
+ $product = $this->_loadProduct();
112
 
113
  if ($attribute_name=='price-tax+discount') {
114
  return $this->cart_item['base_original_price']-$this->cart_item['discount_amount']/$this->quantity;
135
  return $value;
136
  }
137
 
138
+ private function _loadProduct() {
139
  if (!isset($this->loaded_product)) $this->loaded_product = Mage::getModel('catalog/product')->load($this->cart_product->getId());
140
  return $this->loaded_product;
141
  }
142
 
143
+ public function toString() {
144
+ return $this->getName().' (id:'.$this->getId().', sku:'.$this->getSku().')';
145
+ }
146
+
147
  public function getQuantity() {
148
  return $this->quantity;
149
  }
152
  return $this->cart_product->getName();
153
  }
154
 
155
+ public function getId() {
156
+ return $this->cart_product->getId();
157
+ }
158
+
159
+ public function getCategory() {
160
+ $categories = $this->getCategories();
161
+ return $categories ? $categories[0] : null;
162
+ }
163
+
164
+ public function getCategories() {
165
+ if (!isset($this->categories)) {
166
+ $product = $this->_loadProduct();
167
+ $ids = $product->getCategoryIds();
168
+ $this->categories = array();
169
+ foreach ($ids as $id) {
170
+ $this->categories[] = new Magento_Category($id);
171
+ }
172
+ }
173
+ return $this->categories;
174
+ }
175
+
176
  public function getWeight() {
177
  return $this->cart_product->getWeight();
178
  }
194
  }
195
  }
196
 
197
+ abstract class Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping extends Mage_Shipping_Model_Carrier_Abstract
 
198
  {
199
  protected $_translate_inline;
200
  protected $_result;
222
  'cart.weight' => $request->_data['package_weight'],
223
  'cart.quantity' => $request->_data['package_qty'],
224
  'destination.country.code' => $request->_data['dest_country_id'],
225
+ 'destination.country.name' => $this->__getCountryName($request->_data['dest_country_id']),
226
  'destination.region.code' => $request->_data['dest_region_code'],
227
  'destination.postcode' => $request->_data['dest_postcode'],
228
  'origin.country.code' => $request->_data['country_id'],
229
+ 'origin.country.name' => $this->__getCountryName($request->_data['country_id']),
230
  'origin.region.code' => $request->_data['region_id'],
231
  'origin.postcode' => $request->_data['postcode'],
232
  'free_shipping' => $request->getFreeShipping(),
348
  if ($trackings = $tracking_result->getAllTrackings()) return $trackings[0];
349
  return false;
350
  }
351
+
352
+ public function getCustomVar($var) {
353
+ return Mage::getModel('core/variable')->loadByCode($var)->getValue('text');
354
+ }
355
 
356
  /***************************************************************************************************************************/
357
 
358
  protected function _process(&$process) {
359
+ $timestamp = $process['data']['date.timestamp'];
360
  $process['data'] = array_merge($process['data'],array(
361
+ 'date.year' => (int)date('Y',$timestamp),
362
+ 'date.month' => (int)date('m',$timestamp),
363
+ 'date.day' => (int)date('d',$timestamp),
364
+ 'date.hour' => (int)date('H',$timestamp),
365
+ 'date.minute' => (int)date('i',$timestamp),
366
+ 'date.second' => (int)date('s',$timestamp),
367
  ));
368
 
369
  $debug = (bool)(isset($_GET['debug']) ? $_GET['debug'] : $this->__getConfigData('debug'));
372
  $value_found = false;
373
  foreach ($process['config'] as $row) {
374
  $result = $this->_helper->processRow($process,$row);
 
375
  if ($result->success) {
376
  $value_found = true;
377
  $this->__appendMethod($process,$row,$result->result);
380
  }
381
 
382
  $http_request = Mage::app()->getFrontController()->getRequest();
383
+ if ($debug && $this->__checkRequest($http_request,'checkout/cart/index')) {
384
  Mage::getSingleton('core/session')->addNotice('DEBUG'.$this->_helper->getDebug());
385
  }
 
 
 
 
 
 
 
 
386
  }
387
 
388
  protected function _getConfig() {
389
  if (!isset($this->_config)) {
390
  $this->_helper = new OwebiaShippingHelper($this->__getConfigData('config'));
391
  $this->_config = $this->_helper->getConfig();
 
392
  }
393
  return $this->_config;
394
  }
420
  ));
421
  }
422
 
423
+ /***************************************************************************************************************************/
 
 
 
 
424
 
425
+ protected function __checkRequest($http_request, $path) {
426
+ list($router,$controller,$action) = explode('/',$path);
427
+ return $http_request->getRouteName()==$router && $http_request->getControllerName()==$controller && $http_request->getActionName()==$action;
 
 
 
428
  }
 
 
429
 
430
  protected function __getDefaultProcess() {
431
  $process = array(
434
  'data' => null,
435
  'result' => Mage::getModel('shipping/rate_result'),
436
  'stop_to_first_match' => $this->__getConfigData('stop_to_first_match'),
437
+ 'store_interface' => $this,
438
  );
439
  return $process;
440
  }
450
  if (isset($customer_group_id2)) $customer_group_id = $customer_group_id2;
451
  }
452
  $customer_group_code = Mage::getSingleton('customer/group')->load($customer_group_id)->getCode();
453
+
454
+ $properties = array_merge(array(
455
+ 'info.magento.version' => Mage::getVersion(),
456
+ ),
457
+ OwebiaShippingHelper::getDefaultProcessData(),
458
+ array(
459
+ 'info.module.version' => (string)$mage_config->getNode('modules/Owebia_Shipping2/version'),
460
+ 'info.carrier.code' => $this->_code,
461
+ 'cart.weight.unit' => Mage::getStoreConfig('owebia/shipping/weight_unit'),
462
+ 'cart.coupon' => Mage::getSingleton('checkout/session')->getQuote()->getCouponCode(),
463
+ 'customer.group.id' => $customer_group_id,
464
+ 'customer.group.code' => $customer_group_code,
465
+ 'store.id' => $store->getId(),
466
+ 'store.code' => $store->getCode(),
467
+ 'store.name' => $store->getConfig('general/store_information/name'),
468
+ 'store.address' => $store->getConfig('general/store_information/address'),
469
+ 'store.phone' => $store->getConfig('general/store_information/phone'),
470
+ 'date.timestamp' => Mage::getModel('core/date')->timestamp(),
 
 
 
 
471
  ));
472
  return $properties;
473
  }
490
  $process['result']->append($method);
491
  }
492
 
493
+ /*
494
  protected function __appendError(&$process, $message) {
495
  if (isset($process['result'])) {
496
  $error = Mage::getModel('shipping/rate_result_error')
501
  $process['result']->append($error);
502
  }
503
  }
504
+ */
505
 
506
  protected function __formatPrice($price) {
507
  if (!isset($this->_core_helper)) $this->_core_helper = Mage::helper('core');
app/code/community/Owebia/Shipping2/Model/Carrier/OwebiaShipping1.php CHANGED
@@ -1,29 +1,25 @@
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
- ?>
1
  <?php
2
 
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
+ class Owebia_Shipping2_Model_Carrier_OwebiaShipping1 extends Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
 
23
  {
24
  protected $_code = 'owebiashipping1';
25
  }
 
 
app/code/community/Owebia/Shipping2/Model/Carrier/OwebiaShipping2.php CHANGED
@@ -1,29 +1,25 @@
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
- ?>
1
  <?php
2
 
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
+ class Owebia_Shipping2_Model_Carrier_OwebiaShipping2 extends Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
 
23
  {
24
  protected $_code = 'owebiashipping2';
25
  }
 
 
app/code/community/Owebia/Shipping2/Model/Carrier/OwebiaShipping3.php CHANGED
@@ -1,29 +1,25 @@
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
- ?>
1
  <?php
2
 
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
+ class Owebia_Shipping2_Model_Carrier_OwebiaShipping3 extends Owebia_Shipping2_Model_Carrier_AbstractOwebiaShipping
 
23
  {
24
  protected $_code = 'owebiashipping3';
25
  }
 
 
app/code/community/Owebia/Shipping2/changelog CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  [2.4.1 - 24 ao�t 2011]
2
  Modification l�g�re du code php pour �viter un plantage avec certaines versions d'eAccelerator (cache php)
3
  $row = null;
1
+ [2.4.2 - 07 octobre 2011]
2
+ Support des nombres d�cimaux repr�sent�s sous la forme 5.3290705182E-15
3
+ Modification de la licence du code source (MIT au lieu de OSL 3.0)
4
+ Mise � jour des mentions de copyright et de licence
5
+ Nettoyage du code source (suppression de lignes de code en commentaire)
6
+ Initialisation des formules sum et count � 0 au lieu de null (pour �viter les erreurs de formule si aucun produit ne correpond)
7
+ Ajout des alias "a" et "attr" pour "attribute", "o" et "opt" pour "option", "p" pour "product", "c" pour "cart", "s" pour "selection"
8
+ Correction de la r�cup�ration des variables personnalis�es : getValue('text') au lieu de getValue('plain')
9
+ Support des cat�gories
10
+ product.categories dans les conditions de boucle foreach
11
+ {product.category} et {product.category.id} comme variables dans les boucles foreach
12
+ product.category, product.category.id, product.categories, product.categories.id dans les conditions des op�rations sum, count, min et max
13
+ Am�lioration du debug
14
+
15
  [2.4.1 - 24 ao�t 2011]
16
  Modification l�g�re du code php pour �viter un plantage avec certaines versions d'eAccelerator (cache php)
17
  $row = null;
app/code/community/Owebia/Shipping2/controllers/AjaxController.php CHANGED
@@ -1,24 +1,23 @@
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
  {
1
  <?php
2
 
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
  class Owebia_Shipping2_AjaxController extends Owebia_Shipping2_Controller_Abstract
23
  {
app/code/community/Owebia/Shipping2/controllers/Checkout/CartController.php CHANGED
@@ -1,5 +1,25 @@
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
 
@@ -24,8 +44,10 @@ class Owebia_Shipping2_Checkout_CartController extends Mage_Checkout_CartControl
24
  ->setRegion($region)
25
  ->setCollectShippingRates(true);
26
 
 
27
  // Recalcul des totaux
28
  $this->_getQuote()->collectTotals();
 
29
 
30
  $this->_getQuote()->save();
31
  $this->_goBack();
1
  <?php
2
 
3
+ /**
4
+ * Magento
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
+ * DISCLAIMER
17
+ *
18
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ * @author Magento, Owebia
21
+ */
22
+
23
  if (file_exists(dirname(__FILE__).'/Mage_Checkout_CartController.php')) include_once 'Mage_Checkout_CartController.php';
24
  else include_once Mage::getBaseDir('code').'/core/Mage/Checkout/controllers/CartController.php';
25
 
44
  ->setRegion($region)
45
  ->setCollectShippingRates(true);
46
 
47
+ /*<owebia>*/
48
  // Recalcul des totaux
49
  $this->_getQuote()->collectTotals();
50
+ /*</owebia>*/
51
 
52
  $this->_getQuote()->save();
53
  $this->_goBack();
app/code/community/Owebia/Shipping2/etc/adminhtml.xml CHANGED
@@ -1,4 +1,24 @@
1
  <?xml version="1.0" ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <!-- Magento 1.4.0 and upper -->
3
  <config>
4
  <acl>
1
  <?xml version="1.0" ?>
2
+ <!--
3
+ /**
4
+ * Copyright (c) 2008-11 Owebia
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
15
+ *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
18
+ * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
+ -->
22
  <!-- Magento 1.4.0 and upper -->
23
  <config>
24
  <acl>
app/code/community/Owebia/Shipping2/etc/config.xml CHANGED
@@ -1,29 +1,28 @@
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>
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
  -->
22
  <config>
23
  <modules>
24
  <Owebia_Shipping2>
25
+ <version>2.4.2</version>
26
  <depends>
27
  <Mage_Shipping />
28
  </depends>
app/code/community/Owebia/Shipping2/etc/system.xml CHANGED
@@ -1,26 +1,24 @@
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
-
24
  <config>
25
  <sections>
26
  <carriers>
1
  <?xml version="1.0"?>
2
  <!--
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
 
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
  -->
 
22
  <config>
23
  <sections>
24
  <carriers>
app/code/community/Owebia/Shipping2/includes/OS2_AddressFilter.php CHANGED
@@ -1,5 +1,23 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  class Country
5
  {
1
  <?php
2
 
3
+ /**
4
+ * Copyright (c) 2008-11 Owebia
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
15
+ *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
18
+ * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
  class Country
23
  {
app/code/community/Owebia/Shipping2/includes/OS2_CustomerGroup.php CHANGED
@@ -1,5 +1,23 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  class CustomerGroup
5
  {
1
  <?php
2
 
3
+ /**
4
+ * Copyright (c) 2008-11 Owebia
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
15
+ *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
18
+ * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
  class CustomerGroup
23
  {
app/code/community/Owebia/Shipping2/includes/OwebiaShippingHelper.php CHANGED
@@ -1,74 +1,53 @@
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
- * @copyright Copyright (c) 2008-11 Owebia (http://www.owebia.com)
18
  * @author Antoine Lemoine
19
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
- */
21
 
22
  class OwebiaShippingHelper
23
  {
 
 
 
 
 
 
 
 
 
24
  public static $DEBUG_INDEX_COUNTER = 0;
25
- public static $FLOAT_REGEX = '[-]?\d+(?:[.]\d+)?';
26
- public static $POSITIVE_FLOAT_REGEX = '\d+(?:[.]\d+)?';
27
- //public static $COUPLE_REGEX = '(?:[0-9.]+|\*)(?:\[|\])?\:[0-9.]+(?:\:[0-9.]+%?)*';
28
- public static $COUPLE_REGEX = '(?:[0-9.]+|\*) *(?:\[|\])? *\: *[0-9.]+';
29
  public static $UNCOMPRESSED_STRINGS = array(
30
  ' product.attribute.',
31
  ' product.option.',
32
- ' product.stock.',
33
  '{product.attribute.',
34
  '{product.option.',
35
- '{product.stock.',
36
- '{product.weight}',
37
- '{product.quantity}',
38
- '{cart.weight}',
39
- '{cart.quantity}',
40
- '{cart.price_including_tax}',
41
- '{cart.price_excluding_tax}',
42
  '{cart.',
43
- '{customvar.',
44
- '{selection.weight}',
45
- '{selection.quantity}',
46
  '{selection.',
47
- '{destination.country.',
48
- '{foreach ',
49
- '{/foreach}',
50
  );
51
  public static $COMPRESSED_STRINGS = array(
52
  ' p.a.',
53
  ' p.o.',
54
- ' p.s.',
55
  '{p.a.',
56
  '{p.o.',
57
- '{p.s.',
58
- '{p.w}',
59
- '{p.qty}',
60
- '{c.w}',
61
- '{c.qty}',
62
- '{c.pit}',
63
- '{c.pet}',
64
  '{c.',
65
- '{v.',
66
- '{s.w}',
67
- '{s.qty}',
68
  '{s.',
69
- '{dest.ctry.',
70
- '{each ',
71
- '{/each}',
72
  );
73
 
74
  public static function getDefaultProcessData() {
@@ -77,19 +56,19 @@ class OwebiaShippingHelper
77
  'info.server.os' => PHP_OS,
78
  'info.server.software' => $_SERVER['SERVER_SOFTWARE'],
79
  'info.php.version' => PHP_VERSION,
80
- 'info.magento.version' => '',
81
  'info.module.version' => '',
82
  'info.carrier.code' => '',
83
- 'cart.price_excluding_tax' => 0,
84
- 'cart.price_including_tax' => 0,
85
  'cart.price-tax+discount' => 0,
86
  'cart.price-tax-discount' => 0,
87
  'cart.price+tax+discount' => 0,
88
  'cart.price+tax-discount' => 0,
 
 
89
  'cart.weight' => 0,
90
  'cart.weight.for-charge' => 0,
91
  'cart.weight.unit' => 'kg',
92
  'cart.quantity' => 0,
 
93
  'destination.country.code' => '',
94
  'destination.country.name' => '',
95
  'destination.region.code' => '',
@@ -125,8 +104,9 @@ class OwebiaShippingHelper
125
  public $debug_code = null;
126
  public $debug_output = '';
127
  public $debug_header = null;
 
128
 
129
- public function OwebiaShippingHelper($input) {
130
  $this->_formula_cache = array();
131
  $this->_messages = array();
132
  $this->_input = $input;
@@ -134,19 +114,27 @@ class OwebiaShippingHelper
134
  $this->_parseInput();
135
  }
136
 
 
 
 
 
 
 
 
 
137
  public function debug($text) {
138
- $this->debug_output .= "<p>".$text."</p>";
139
  }
140
 
141
  public function getDebug() {
142
  $index = $this->debug_code.'-'.self::$DEBUG_INDEX_COUNTER++;
143
  $output = "<style rel=\"stylesheet\" type=\"text/css\">"
144
- .".osh-debug{background:#000;color:#bbb;-webkit-opacity:0.9;-moz-opacity:0.9;opacity:0.9;text-align:left;white-space:pre-wrap;}"
145
  .".osh-debug p{margin:2px 0;}"
146
- .".osh-debug .osh-formula{color:#f90;} .osh-key{color:#0099f7;}"
147
- .".osh-debug .osh-error{color:#f00;} .osh-warning{color:#ff0;} .osh-info{color:#7bf700;}"
148
- .".osh-debug .osh-debug-content{padding:10px;}"
149
- .".osh-debug .osh-replacement{color:#ff3000;}"
150
  ."</style>"
151
  ."<div id=\"osh-debug-".$index."\" class=\"osh-debug\"><pre class=\"osh-debug-content\"><span style=\"float:right;cursor:pointer;\" onclick=\"document.getElementById('osh-debug-".$index."').style.display = 'none';\">[<span style=\"padding:0 5px;color:#f00;\">X</span>]</span>"
152
  ."<p>".$this->debug_header."</p>".$this->debug_output."</pre></div>";
@@ -154,7 +142,7 @@ class OwebiaShippingHelper
154
  }
155
 
156
  public function initDebug($code, $data) {
157
- $header = 'DEBUG app/code/community/Owebia/Shipping2/includes/OwebiaShippingHelper.php<br/>';
158
  foreach ($data as $key => $data) {
159
  $header .= ' <span class="osh-key">'.str_replace('.','</span>.<span class="osh-key">',$key).'</span> = <span class="osh-formula">'.$this->_toString($data).'</span><br/>';
160
  }
@@ -220,7 +208,7 @@ class OwebiaShippingHelper
220
  public function processRow($process, &$row, $is_checking=false) {
221
  if (!isset($row['*code'])) return;
222
 
223
- self::debug('process row <span class="osh-key">'.$row['*code'].'</span>');
224
  if (!isset($row['label']['value'])) $row['label']['value'] = '***';
225
 
226
  $enabled = $this->getRowProperty($row,'enabled');
@@ -273,11 +261,11 @@ class OwebiaShippingHelper
273
  if (isset($customer_groups)) {
274
  $groups = explode(',',$customer_groups);
275
  $group_match = false;
276
- //self::debug('code:'.$process['data']['customer.group.code'].', id:'.$process['data']['customer.group.id']);
277
  foreach ($groups as $group) {
278
  $group = trim($group);
279
  if ($group=='*' || $group==$process['data']['customer.group.code'] || ctype_digit($group) && $group==$process['data']['customer.group.id']) {
280
- self::debug(' group <span class="osh-replacement">'.$process['data']['customer.group.code'].'</span>'
281
  .' (id:<span class="osh-replacement">'.$process['data']['customer.group.id'].'</span>) matches');
282
  $group_match = true;
283
  break;
@@ -293,7 +281,7 @@ class OwebiaShippingHelper
293
  if (isset($fees)) {
294
  $result = $this->_processFormula($process,$row,'fees',$fees,$is_checking);
295
  if (!$result->success) return $result;
296
- self::debug(' => <span class="osh-info">result = <span class="osh-formula">'.$this->_toString($result->result).'</span>');
297
  return new OS_Result(true,(float)$result->result);
298
  }
299
  return new OS_Result(false);
@@ -309,7 +297,7 @@ class OwebiaShippingHelper
309
  if (isset($row[$key]['value'])) {
310
  $property = $row[$key]['value'];
311
  $output = $property;
312
- self::debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">'.$this->_toString($property).'</span>');
313
  preg_match_all('/{([a-z0-9_]+)\.([a-z0-9_]+)}/i',$output,$result_set,PREG_SET_ORDER);
314
  foreach ($result_set as $result) {
315
  list($original,$ref_code,$ref_key) = $result;
@@ -332,7 +320,7 @@ class OwebiaShippingHelper
332
  }
333
  }
334
  } else {
335
- self::debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">null</span>');
336
  }
337
  return $output;
338
  }
@@ -347,7 +335,8 @@ class OwebiaShippingHelper
347
  if ($from===$to) return $input;
348
  if (strpos($input,$from)===false) return $input;
349
  $to = $this->_toString($to);
350
- self::debug(' replace <span class="osh-replacement">'.$this->_toString($from).'</span> by <span class="osh-replacement">'.$to.'</span> =&gt; <span class="osh-formula">'.str_replace($from,'<span class="osh-replacement">'.$to.'</span>',$input).'</span>');
 
351
  return str_replace($from,$to,$input);
352
  }
353
 
@@ -381,7 +370,6 @@ class OwebiaShippingHelper
381
  if ($use_cache) $this->setCache($formula_string,$result);
382
  return $result;
383
  }
384
- self::debug(' formula evaluation = <span class="osh-formula">'.$this->_toString($eval_result).'</span>');
385
  $result = new OS_Result(true,$eval_result);
386
  if ($use_cache) $this->setCache($formula_string,$result);
387
  return $result;
@@ -395,99 +383,163 @@ class OwebiaShippingHelper
395
  protected function setCache($expression, $value) {
396
  if ($value instanceof OS_Result) {
397
  $this->_formula_cache[$expression] = $value;
398
- self::debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$this->_toString($this->_formula_cache[$expression]).'</span>');
399
  } else {
400
  $value = $this->_toString($value);
401
  $this->_expression_cache[$expression] = $value;
402
- self::debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$value.'</span>');
403
  }
404
  }
405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  protected function _prepareFormula($process, $row, $property_key, $formula_string, $is_checking, $use_cache=true)
407
  {
408
  if ($use_cache && isset($this->_formula_cache[$formula_string])) {
409
  $result = $this->_formula_cache[$formula_string];
410
- self::debug(' get cached formula <span class="osh-replacement">'.$formula_string.'</span> = <span class="osh-formula">'.$this->_toString($result->result).'</span>');
411
  return $result;
412
  }
413
 
414
  $formula = $formula_string;
415
- //self::debug(' formula = <span class="osh-formula">'.$formula.'</span>');
416
 
417
- while (preg_match("#{foreach product\.((?:attribute|option)\.(?:[a-z0-9_]+))}(.*){/foreach}#i",$formula,$result)) {
 
418
  $original = $result[0];
419
  if ($use_cache && isset($this->_expression_cache[$original])) {
420
  $replacement = $this->_expression_cache[$original];
421
- self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>');
422
- }
423
- else {
424
  $replacement = 0;
425
- list($filter_property_type,$filter_property_name) = explode('.',$result[1]);
426
- $selections = array();
427
- self::debug(' :: foreach <span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span>');
428
- foreach ($process['cart.products'] as $product) {
429
- $tmp_value = $this->_getProductProperty($product,$filter_property_type,$filter_property_name,$get_by_id=false);
430
- self::debug(' products[<span class="osh-formula">'.$product->getName().'</span>].<span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span> = <span class="osh-formula">'.$this->_toString($tmp_value).'</span>');
431
- $key = 'val_'.$tmp_value;
432
- $sel = isset($selections[$key]) ? $selections[$key] : null;
433
- $selections[$key]['products'][] = $product;
434
- $selections[$key]['weight'] = (isset($sel['weight']) ? $sel['weight'] : 0)+$product->getAttribute('weight')*$product->getQuantity();
435
- $selections[$key]['quantity'] = (isset($sel['quantity']) ? $sel['quantity'] : 0)+$product->getQuantity();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  }
437
- self::debug(' :: start foreach');
438
- foreach ($selections as $selection) {
 
 
 
439
  $process2 = $process;
440
  $process2['cart.products'] = $selection['products'];
441
  $process2['data']['selection.quantity'] = $selection['quantity'];
442
  $process2['data']['selection.weight'] = $selection['weight'];
443
  $process_result = $this->_processFormula($process2,$row,$property_key,$result[2],$is_checking,$tmp_use_cache=false);
444
  $replacement += $process_result->result;
 
 
445
  }
446
- self::debug(' :: end foreach <span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span>');
 
447
  if ($use_cache) $this->setCache($original,$replacement);
448
  }
449
  $formula = $this->replace($original,$replacement,$formula);
450
  }
451
 
452
- $formula = str_replace(array("\n","\t"),array('',''),$formula);
453
-
454
- while (preg_match("#{customvar\.([a-z0-9_]+)}#i",$formula,$result)) {
455
  $original = $result[0];
456
- $replacement = Mage::getModel('core/variable')->loadByCode($result[1])->getValue('plain');
457
  $formula = $this->replace($original,$replacement,$formula);
458
  }
459
 
460
  $first_product = isset($process['cart.products'][0]) ? $process['cart.products'][0] : null;
461
  if (!isset($process['data']['selection.weight'])) $process['data']['selection.weight'] = $process['data']['cart.weight'];
462
  if (!isset($process['data']['selection.quantity'])) $process['data']['selection.quantity'] = $process['data']['cart.quantity'];
463
- $process['data']['product.weight'] = isset($first_product) ? $first_product->getAttribute('weight') : 0;
464
- $process['data']['product.quantity'] = isset($first_product) ? $first_product->getQuantity() : 0;
 
 
 
 
 
 
 
 
 
 
465
 
 
 
 
 
 
466
  foreach ($process['data'] as $original => $replacement) {
467
- $formula = $this->replace('{'.$original.'}',$replacement,$formula);
 
 
 
468
  }
469
 
470
  if (isset($first_product)) {
471
- while (preg_match("#{product\.(attribute|option|stock)\.([a-z0-9_+-]+)}#i",$formula,$result)) {
472
  $original = $result[0];
473
- switch ($result[1]) {
474
- case 'attribute': $replacement = $first_product->getAttribute($result[2]); break;
475
- case 'option': $replacement = $first_product->getOption($result[2]); break;
476
- case 'stock': $replacement = $first_product->getStockData($result[2]); break;
477
- }
478
  $formula = $this->replace($original,$replacement,$formula);
479
  }
480
  }
481
 
482
- while (preg_match("/{(count) products(?: where ([^}]+))?}/i",$formula,$result)
483
- // || preg_match("/{(sum|min|max|count distinct) product\.(?(attribute|option|stock)\.([a-z0-9_+-]+)|(quantity))(?: where ([^}]+))?}/i",$formula,$result)) {
484
- || preg_match("/{(sum|min|max|count distinct) product\.(attribute|option|stock)\.([a-z0-9_+-]+)(?: where ([^}]+))?}/i",$formula,$result)
485
- || preg_match("/{(sum|min|max|count distinct) product\.(quantity)()(?: where ([^}]+))?}/i",$formula,$result)
486
  ) {
487
  $original = $result[0];
488
  if ($use_cache && isset($this->_expression_cache[$original])) {
489
  $replacement = $this->_expression_cache[$original];
490
- self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>');
491
  } else {
492
  $replacement = $this->_processProductProperty($process['cart.products'],$result);
493
  if ($use_cache) $this->setCache($result[0],$replacement);
@@ -495,18 +547,18 @@ class OwebiaShippingHelper
495
  $formula = $this->replace($original,$replacement,$formula);
496
  }
497
 
498
- //while (preg_match("/{table '([^']+)' ([^}]+)}/",$formula,$result))
499
  while (preg_match("/{table ([^}]+) in ([0-9\.:,\*\[\] ]+)}/i",$formula,$result)) {
500
  $original = $result[0];
501
  if ($use_cache && isset($this->_expression_cache[$original])) {
502
  $replacement = $this->_expression_cache[$original];
503
- self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>');
504
  } else {
505
  $reference_value = $this->_evalFormula($result[1]);
506
  if (isset($reference_value)) {
507
  $fees_table_string = $result[2];
508
 
509
- if (!preg_match('#^'.self::$COUPLE_REGEX.'(?:, *'.self::$COUPLE_REGEX.')*$#',$fees_table_string)) {
510
  $this->addMessage('error',$row,$property_key,'Error in table %s','<span class="osh-formula">'.htmlentities($result[0]).'</span>');
511
  $result = new OS_Result(false);
512
  if ($use_cache) $this->setCache($formula_string,$result);
@@ -529,7 +581,7 @@ class OwebiaShippingHelper
529
  $max_value = str_replace(array('[',']'),'',$max_value);
530
 
531
  if ($max_value=='*' || $including_max_value && $reference_value<=$max_value || !$including_max_value && $reference_value<$max_value) {
532
- $replacement = $fee;//$this->_calculateFee($process,$fee,$var);
533
  break;
534
  }
535
  }
@@ -545,8 +597,8 @@ class OwebiaShippingHelper
545
 
546
  protected function _evalFormula($formula) {
547
  if (is_bool($formula)) return $formula;
548
- if (!preg_match('/^(?:floor|ceil|round|max|min|rand|pow|pi|sqrt|log|exp|abs|int|float|true|false|null|and|or|in|substr|strtolower'
549
- .'|in_array\(\'(?:[^\']*)\', *array\( *(?:\'(?:[^\']+)\') *(?: *, *\'(?:[^\']+)\')* *\) *\)'
550
  .'|\'[^\']*\'|[0-9,\'\.\-\(\)\*\/\?\:\+\<\>\=\&\|%! ])*$/',$formula)) {
551
  $errors = array(
552
  PREG_NO_ERROR => 'PREG_NO_ERROR',
@@ -558,7 +610,8 @@ class OwebiaShippingHelper
558
  );
559
  $error = preg_last_error();
560
  if (isset($errors[$error])) $error = $errors[$error];
561
- self::debug(' doesn\'t match ('.$error.')');
 
562
  return null;
563
  }
564
  $formula = str_replace(
@@ -568,6 +621,7 @@ class OwebiaShippingHelper
568
  );
569
  $eval_result = null;
570
  @eval('$eval_result = ('.$formula.');');
 
571
  return $eval_result;
572
  }
573
 
@@ -586,7 +640,8 @@ class OwebiaShippingHelper
586
  }
587
 
588
  public function compress($input) {
589
- /*if (preg_match_all("/{table (.*) in (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}/imsU",$input,$result,PREG_SET_ORDER)) {
 
590
  foreach ($result as $result_i) {
591
  $fees_table = explode(',',$result_i[2]);
592
  $value = null;
@@ -627,7 +682,8 @@ class OwebiaShippingHelper
627
  $input = gzuncompress(base64_decode(substr($input,4,strlen($input))));
628
  }
629
 
630
- /*if (preg_match_all("/{table (.*) in (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}/iU",$input,$result,PREG_SET_ORDER)) {
 
631
  foreach ($result as $result_i) {
632
  $fees_table = explode(',',$result_i[2]);
633
  $value = null;
@@ -654,7 +710,8 @@ class OwebiaShippingHelper
654
  $input = str_replace($result_i[1],trim($result_i[1]),$input);
655
  $input = str_replace($result_i[2],trim($result_i[2]),$input);
656
  }
657
- }*/
 
658
  return str_replace(
659
  self::$COMPRESSED_STRINGS,
660
  self::$UNCOMPRESSED_STRINGS,
@@ -701,7 +758,7 @@ class OwebiaShippingHelper
701
  while (preg_match('/'.$regex1.'/',$input,$resi)) $input = str_replace($resi[0],'{'.$resi[1].'.'.$resi[2].'}',$input);
702
  }
703
 
704
- $regex1 = "{(count|all|any) (attribute|option) '([^'\)]+)' ?((?:==|<=|>=|<|>|!=) ?(?:".self::$FLOAT_REGEX."|true|false|'[^'\)]*'))}";
705
  $regex2 = "{(sum) (attribute|option) '([^'\)]+)'}";
706
  if (preg_match('/'.$regex1.'/',$input,$resi) || preg_match('/'.$regex2.'/',$input,$resi)) {
707
  $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
@@ -723,7 +780,7 @@ class OwebiaShippingHelper
723
  }
724
  }
725
 
726
- $regex = "{table '([^']+)' (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}";
727
  if (preg_match('/'.$regex.'/',$input,$resi)) {
728
  $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
729
  while (preg_match('/'.$regex.'/',$input,$resi)) {
@@ -753,7 +810,7 @@ class OwebiaShippingHelper
753
  //echo ini_get('pcre.backtrack_limit');
754
  //exit;
755
 
756
- $row_regex = ' *([a-z0-9_]+)\\s*:\\s*("(?:(?:[^"]|\\\\")*[^\\\\])?"|'.self::$FLOAT_REGEX.'|false|true)\\s*(,)? *(?:\\n)?';
757
  if (!preg_match_all('/((?:#+[^{\\n]*\\s+)*)\\s*(#)?{\\s*('.$row_regex.')+\\s*}/i',$config_string,$result,PREG_SET_ORDER)) {
758
  $errors = array(
759
  PREG_NO_ERROR => 'PREG_NO_ERROR',
@@ -765,7 +822,7 @@ class OwebiaShippingHelper
765
  );
766
  $error = preg_last_error();
767
  if (isset($errors[$error])) $error = $errors[$error];
768
- self::debug(' preg_match_all error ('.$error.')');
769
  }
770
 
771
  $this->_config = array();
@@ -847,7 +904,7 @@ class OwebiaShippingHelper
847
  }
848
  }
849
 
850
- $float_value_regex = '\\s*('.self::$POSITIVE_FLOAT_REGEX.'|\*)\\s*';
851
  $conditions = array();
852
  if (isset($row['prices_range'])) {
853
  if (!in_array('prices_range',$deprecated_properties)) $deprecated_properties[] = 'prices_range';
@@ -888,7 +945,7 @@ class OwebiaShippingHelper
888
  }
889
  if (isset($row['product_properties'])) {
890
  if (!in_array('product_properties',$deprecated_properties)) $deprecated_properties[] = 'product_properties';
891
- $product_property_regex = "\\s*(and|or)? *\((?:(all|any|sum) )?(attribute|option) '([^'\)]+)' ?(==|=|<=|>=|<|>|!=) ?(".self::$FLOAT_REGEX."|true|false|'[^'\)]*')\)\\s*";
892
  if (preg_match('/^('.$product_property_regex.')+$/',$row['product_properties']['value'],$result)) {
893
  preg_match_all('/'.$product_property_regex.'/',$row['product_properties']['value'],$results,PREG_SET_ORDER);
894
  $product_properties_condition = '';
@@ -1035,7 +1092,7 @@ class OwebiaShippingHelper
1035
  }
1036
  }
1037
  $this->_messages[] = $message;
1038
- self::debug(' => <span class="osh-'.$message->type.'">'.$message->toString().'</span>');
1039
  }
1040
 
1041
  protected function _addRow(&$row) {
@@ -1043,7 +1100,6 @@ class OwebiaShippingHelper
1043
  $key = $row['code']['value'];
1044
  if (isset($this->_config[$key])) $this->addMessage('error',$row,'code','The property `code` must be unique, `%s` has been found twice',$key);
1045
  while (isset($this->_config[$key])) $key .= rand(0,9);
1046
- //$row['code'] = $key;
1047
  } else {
1048
  $i = 1;
1049
  do {
@@ -1070,7 +1126,7 @@ class OwebiaShippingHelper
1070
  );
1071
 
1072
  if ($address_filter=='*') {
1073
- self::debug(' country code <span class="osh-replacement">'.$address['country_code'].'</span> matches');
1074
  return true;
1075
  }
1076
 
@@ -1107,7 +1163,7 @@ class OwebiaShippingHelper
1107
  if (preg_match('#([A-Z]{2}) *(-)? *(?:\( *(-)? *(.*)\))?#s', $address_filter, $result)) {
1108
  $country_code = $result[1];
1109
  if ($address['country_code']==$country_code) {
1110
- self::debug(' country code <span class="osh-replacement">'.$address['country_code'].'</span> matches');
1111
  if (!isset($result[4]) || $result[4]=='') return !$excluding;
1112
  else {
1113
  $region_codes = explode(',',$result[4]);
@@ -1120,25 +1176,24 @@ class OwebiaShippingHelper
1120
  ));
1121
  $region_codes[$i] = $code;
1122
  if ($address['region_code']===$code) {
1123
- self::debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> matches');
1124
  $in_array = true;
1125
  } else if ($address['postcode']===$code) {
1126
- self::debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches');
1127
  $in_array = true;
1128
  } else if (mb_substr($code,0,1)=='/' && mb_substr($code,mb_strlen($code)-1,1)=='/' && @preg_match($code, $address['postcode'])) {
1129
- self::debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches <span class="osh-formula">'.htmlentities($code).'</span>');
1130
  $in_array = true;
1131
  } else if (strpos($code,'*')!==false && preg_match('/^'.str_replace('*','(?:.*)',$code).'$/',$address['postcode'])) {
1132
- self::debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches <span class="osh-formula">'.htmlentities($code).'</span>');
1133
  $in_array = true;
1134
  }
1135
  if ($in_array) break;
1136
  }
1137
  if (!$in_array) {
1138
- self::debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> and postcode <span class="osh-replacement">'.$address['postcode'].'</span> don\'t match');
1139
  }
1140
  // Vérification stricte
1141
- /*$in_array = in_array($address['region_code'],$region_codes,true) || in_array($address['postcode'],$region_codes,true);*/
1142
  $excluding_region = $result[2]=='-' || $result[3]=='-';
1143
  if ($excluding_region && !$in_array || !$excluding_region && $in_array) return !$excluding;
1144
  }
@@ -1149,11 +1204,16 @@ class OwebiaShippingHelper
1149
  }
1150
 
1151
  protected function _getProductProperty($product, $property_type, $property_name, $get_by_id=false) {
 
1152
  switch ($property_type) {
1153
- case 'attribute':
1154
- case 'attributes': return $product->getAttribute($property_name,$get_by_id);
1155
- case 'option':
1156
- case 'options': return $product->getOption($property_name,$get_by_id);
 
 
 
 
1157
  case 'stock': return $product->getStockData($property_name);
1158
  }
1159
  return null;
@@ -1162,6 +1222,7 @@ class OwebiaShippingHelper
1162
  protected function _processProductProperty($products, $regex_result) {
1163
  // count, sum, min, max, count distinct
1164
  $operation = strtolower($regex_result[1]);
 
1165
  switch ($operation) {
1166
  case 'sum':
1167
  case 'min':
@@ -1175,45 +1236,87 @@ class OwebiaShippingHelper
1175
  $conditions = isset($regex_result[2]) ? $regex_result[2] : null;
1176
  break;
1177
  }
 
 
 
 
 
 
 
1178
 
1179
- self::debug(' :: start <span class="osh-replacement">'.$regex_result[0].'</span>');
1180
-
1181
- $return_value = null;
1182
 
1183
- preg_match_all('/product\.(attribute(?:s)?|option(?:s)?|stock)\.([a-z0-9_+-]+)(?:\.(id))?/i',$conditions,$properties_regex_result,PREG_SET_ORDER);
1184
  $properties = array();
1185
  foreach ($properties_regex_result as $property_regex_result) {
1186
  $key = $property_regex_result[0];
1187
  if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1188
  }
1189
- preg_match_all('/product\.(quantity)/i',$conditions,$properties_regex_result,PREG_SET_ORDER);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1190
  foreach ($properties_regex_result as $property_regex_result) {
1191
  $key = $property_regex_result[0];
1192
  if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1193
  }
1194
 
1195
  foreach ($products as $product) {
 
 
1196
  if (isset($conditions) && $conditions!='') {
1197
  $formula = $conditions;
1198
  foreach ($properties as $property) {
1199
- if ($property[1]=='quantity') {
1200
- $value = $product->getQuantity();
1201
- } else {
1202
- $value = $this->_getProductProperty(
1203
- $product,
1204
- $tmp_property_type = $property[1],
1205
- $tmp_property_name = $property[2],
1206
- $get_by_id = isset($property[3]) && $property[3]=='id'
1207
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
1208
  }
1209
- //$formula = $this->replace($property[0],$value,$formula);
1210
  $from = $property[0];
1211
- $to = is_string($value) || empty($value) ? "'".$value."'" : $value;
 
 
 
 
 
 
 
 
 
1212
  $formula = str_replace($from,$to,$formula);
1213
- self::debug(' replace <span class="osh-replacement">'.$from.'</span> by <span class="osh-replacement">'.$to.'</span> =&gt; <span class="osh-formula">'.str_replace($from,'<span class="osh-replacement">'.$to.'</span>',$formula).'</span>');
1214
  }
1215
  $eval_result = $this->_evalFormula($formula);
1216
- if (!isset($eval_result)) return 'null';
1217
  }
1218
  else $eval_result = true;
1219
 
@@ -1234,7 +1337,7 @@ class OwebiaShippingHelper
1234
  if (!isset($return_value) || $value>$return_value) $return_value = $value;
1235
  break;
1236
  case 'sum':
1237
- //self::debug($product->getSku().'.'.$property_type.'.'.$property_name.' = "'.$value.'" x '.$product->getQuantity());
1238
  $return_value = (isset($return_value) ? $return_value : 0) + $value*$product->getQuantity();
1239
  break;
1240
  case 'count distinct':
@@ -1248,22 +1351,35 @@ class OwebiaShippingHelper
1248
  }
1249
  }
1250
  }
 
 
1251
  }
1252
 
1253
- self::debug(' :: end <span class="osh-replacement">'.$regex_result[0].'</span>');
 
1254
 
1255
  return $return_value;
1256
  }
1257
 
1258
  }
1259
 
 
 
 
 
 
 
1260
  interface OS_Product {
1261
  public function getOption($option);
1262
  public function getAttribute($attribute);
1263
  public function getName();
 
1264
  public function getSku();
1265
  public function getQuantity();
 
1266
  public function getStockData($key);
 
 
1267
  }
1268
 
1269
  class OS_Message {
1
  <?php
2
 
3
  /**
4
+ * Copyright (c) 2008-11 Owebia
5
  *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
  *
10
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
14
+ * IN THE SOFTWARE.
 
 
15
  *
16
+ * @website http://www.owebia.com/
17
+ * @project Magento Owebia Shipping 2 module
18
  * @author Antoine Lemoine
19
+ * @license http://www.opensource.org/licenses/MIT The MIT License (MIT)
20
+ **/
21
 
22
  class OwebiaShippingHelper
23
  {
24
+ const PRODUCT_REGEX = '(?:product|p)';
25
+ const ATTRIBUTE_REGEX = '(?:attribute|attr|a)';
26
+ const OPTION_REGEX = '(?:option|opt|o)';
27
+ const CATEGORIES_REGEX = '(?:categories)';
28
+ const CATEGORY_REGEX = '(?:category)';
29
+ const FLOAT_REGEX = '[-]?\d+(?:[.]\d+)?';
30
+ const POSITIVE_FLOAT_REGEX = '\d+(?:[.]\d+)?';
31
+ const COUPLE_REGEX = '(?:[0-9.]+|\*) *(?:\[|\])? *\: *[0-9.]+';
32
+
33
  public static $DEBUG_INDEX_COUNTER = 0;
 
 
 
 
34
  public static $UNCOMPRESSED_STRINGS = array(
35
  ' product.attribute.',
36
  ' product.option.',
 
37
  '{product.attribute.',
38
  '{product.option.',
39
+ '{product.',
 
 
 
 
 
 
40
  '{cart.',
 
 
 
41
  '{selection.',
 
 
 
42
  );
43
  public static $COMPRESSED_STRINGS = array(
44
  ' p.a.',
45
  ' p.o.',
 
46
  '{p.a.',
47
  '{p.o.',
48
+ '{p.',
 
 
 
 
 
 
49
  '{c.',
 
 
 
50
  '{s.',
 
 
 
51
  );
52
 
53
  public static function getDefaultProcessData() {
56
  'info.server.os' => PHP_OS,
57
  'info.server.software' => $_SERVER['SERVER_SOFTWARE'],
58
  'info.php.version' => PHP_VERSION,
 
59
  'info.module.version' => '',
60
  'info.carrier.code' => '',
 
 
61
  'cart.price-tax+discount' => 0,
62
  'cart.price-tax-discount' => 0,
63
  'cart.price+tax+discount' => 0,
64
  'cart.price+tax-discount' => 0,
65
+ 'cart.price_excluding_tax' => 0,
66
+ 'cart.price_including_tax' => 0,
67
  'cart.weight' => 0,
68
  'cart.weight.for-charge' => 0,
69
  'cart.weight.unit' => 'kg',
70
  'cart.quantity' => 0,
71
+ 'cart.coupon' => null,
72
  'destination.country.code' => '',
73
  'destination.country.name' => '',
74
  'destination.region.code' => '',
104
  public $debug_code = null;
105
  public $debug_output = '';
106
  public $debug_header = null;
107
+ protected $debug_prefix = '';
108
 
109
+ public function __construct($input) {
110
  $this->_formula_cache = array();
111
  $this->_messages = array();
112
  $this->_input = $input;
114
  $this->_parseInput();
115
  }
116
 
117
+ public function addDebugIndent() {
118
+ $this->debug_prefix .= ' ';
119
+ }
120
+
121
+ public function removeDebugIndent() {
122
+ $this->debug_prefix = substr($this->debug_prefix, 0, strlen($this->debug_prefix)-3);
123
+ }
124
+
125
  public function debug($text) {
126
+ $this->debug_output .= "<p>".$this->debug_prefix.$text."</p>";
127
  }
128
 
129
  public function getDebug() {
130
  $index = $this->debug_code.'-'.self::$DEBUG_INDEX_COUNTER++;
131
  $output = "<style rel=\"stylesheet\" type=\"text/css\">"
132
+ .".osh-debug{background:#000;color:#bbb;-webkit-opacity:0.9;-moz-opacity:0.9;opacity:0.9;text-align:left;white-space:pre-wrap;overflow:auto;}"
133
  .".osh-debug p{margin:2px 0;}"
134
+ .".osh-formula{color:#f90;} .osh-key{color:#0099f7;} .osh-loop{color:#ff0;}"
135
+ .".osh-error{color:#f00;} .osh-warning{color:#ff0;} .osh-info{color:#7bf700;}"
136
+ .".osh-debug-content{padding:10px;}"
137
+ .".osh-replacement{color:#ff3000;}"
138
  ."</style>"
139
  ."<div id=\"osh-debug-".$index."\" class=\"osh-debug\"><pre class=\"osh-debug-content\"><span style=\"float:right;cursor:pointer;\" onclick=\"document.getElementById('osh-debug-".$index."').style.display = 'none';\">[<span style=\"padding:0 5px;color:#f00;\">X</span>]</span>"
140
  ."<p>".$this->debug_header."</p>".$this->debug_output."</pre></div>";
142
  }
143
 
144
  public function initDebug($code, $data) {
145
+ $header = 'DEBUG OwebiaShippingHelper.php<br/>';
146
  foreach ($data as $key => $data) {
147
  $header .= ' <span class="osh-key">'.str_replace('.','</span>.<span class="osh-key">',$key).'</span> = <span class="osh-formula">'.$this->_toString($data).'</span><br/>';
148
  }
208
  public function processRow($process, &$row, $is_checking=false) {
209
  if (!isset($row['*code'])) return;
210
 
211
+ $this->debug('process row <span class="osh-key">'.$row['*code'].'</span>');
212
  if (!isset($row['label']['value'])) $row['label']['value'] = '***';
213
 
214
  $enabled = $this->getRowProperty($row,'enabled');
261
  if (isset($customer_groups)) {
262
  $groups = explode(',',$customer_groups);
263
  $group_match = false;
264
+ //$this->debug('code:'.$process['data']['customer.group.code'].', id:'.$process['data']['customer.group.id']);
265
  foreach ($groups as $group) {
266
  $group = trim($group);
267
  if ($group=='*' || $group==$process['data']['customer.group.code'] || ctype_digit($group) && $group==$process['data']['customer.group.id']) {
268
+ $this->debug(' group <span class="osh-replacement">'.$process['data']['customer.group.code'].'</span>'
269
  .' (id:<span class="osh-replacement">'.$process['data']['customer.group.id'].'</span>) matches');
270
  $group_match = true;
271
  break;
281
  if (isset($fees)) {
282
  $result = $this->_processFormula($process,$row,'fees',$fees,$is_checking);
283
  if (!$result->success) return $result;
284
+ $this->debug(' &raquo; <span class="osh-info">result</span> = <span class="osh-formula">'.$this->_toString($result->result).'</span>');
285
  return new OS_Result(true,(float)$result->result);
286
  }
287
  return new OS_Result(false);
297
  if (isset($row[$key]['value'])) {
298
  $property = $row[$key]['value'];
299
  $output = $property;
300
+ $this->debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">'.$this->_toString($property).'</span>');
301
  preg_match_all('/{([a-z0-9_]+)\.([a-z0-9_]+)}/i',$output,$result_set,PREG_SET_ORDER);
302
  foreach ($result_set as $result) {
303
  list($original,$ref_code,$ref_key) = $result;
320
  }
321
  }
322
  } else {
323
+ $this->debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">null</span>');
324
  }
325
  return $output;
326
  }
335
  if ($from===$to) return $input;
336
  if (strpos($input,$from)===false) return $input;
337
  $to = $this->_toString($to);
338
+ $to = preg_replace('/[\r\n\t]+/', ' ', $to);
339
+ $this->debug(' replace <span class="osh-replacement">'.$this->_toString($from).'</span> by <span class="osh-replacement">'.$to.'</span> =&gt; <span class="osh-formula">'.str_replace($from,'<span class="osh-replacement">'.$to.'</span>',$input).'</span>');
340
  return str_replace($from,$to,$input);
341
  }
342
 
370
  if ($use_cache) $this->setCache($formula_string,$result);
371
  return $result;
372
  }
 
373
  $result = new OS_Result(true,$eval_result);
374
  if ($use_cache) $this->setCache($formula_string,$result);
375
  return $result;
383
  protected function setCache($expression, $value) {
384
  if ($value instanceof OS_Result) {
385
  $this->_formula_cache[$expression] = $value;
386
+ $this->debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$this->_toString($this->_formula_cache[$expression]).'</span>');
387
  } else {
388
  $value = $this->_toString($value);
389
  $this->_expression_cache[$expression] = $value;
390
+ $this->debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$value.'</span>');
391
  }
392
  }
393
 
394
+ protected function _prepare_regexp($regexp) {
395
+ if (!isset($this->constants)) {
396
+ $reflector = new ReflectionClass(get_class($this));
397
+ $this->constants = $reflector->getConstants();
398
+ }
399
+ foreach ($this->constants as $name => $value) {
400
+ $regexp = str_replace('{'.$name.'}', $value, $regexp);
401
+ }
402
+ return $regexp;
403
+ }
404
+
405
+ protected function _preg_match($regexp, $input, &$result, $debug=false) {
406
+ $regexp = $this->_prepare_regexp($regexp);
407
+ if ($debug) $this->debug(' preg_match <span class="osh-replacement">'.$regexp.'</span>');
408
+ return preg_match($regexp, $input, $result);
409
+ }
410
+
411
+ protected function _preg_match_all($regexp, $input, &$result, $debug=false) {
412
+ $regexp = $this->_prepare_regexp($regexp);
413
+ if ($debug) $this->debug(' preg_match_all <span class="osh-replacement">'.$regexp.'</span>');
414
+ preg_match_all($regexp, $input, $result, PREG_SET_ORDER);
415
+ }
416
+
417
  protected function _prepareFormula($process, $row, $property_key, $formula_string, $is_checking, $use_cache=true)
418
  {
419
  if ($use_cache && isset($this->_formula_cache[$formula_string])) {
420
  $result = $this->_formula_cache[$formula_string];
421
+ $this->debug(' get cached formula <span class="osh-replacement">'.$formula_string.'</span> = <span class="osh-formula">'.$this->_toString($result->result).'</span>');
422
  return $result;
423
  }
424
 
425
  $formula = $formula_string;
426
+ //$this->debug(' formula = <span class="osh-formula">'.$formula.'</span>');
427
 
428
+ // foreach
429
+ while ($this->_preg_match("#{foreach {PRODUCT_REGEX}\.((?:{ATTRIBUTE_REGEX}|{OPTION_REGEX})\.(?:[a-z0-9_]+)|{CATEGORIES_REGEX})}(.*){/foreach}#i", $formula, $result)) {
430
  $original = $result[0];
431
  if ($use_cache && isset($this->_expression_cache[$original])) {
432
  $replacement = $this->_expression_cache[$original];
433
+ $this->debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>');
434
+ } else {
 
435
  $replacement = 0;
436
+ if ($result[1]=='categories') {
437
+ $selections = array();
438
+ $this->debug(' <span class="osh-loop">prepare foreach <span class="osh-key">categories</span></span>');
439
+ $this->addDebugIndent();
440
+ foreach ($process['cart.products'] as $product) {
441
+ $categories = $product->getCategories();
442
+ $categories_names = array();
443
+ foreach ($categories as $category) {
444
+ $key = $category->toString();
445
+ $categories_names[] = $this->_toString($key);
446
+ $sel = isset($selections[$key]) ? $selections[$key] : null;
447
+ $selections[$key]['products'][] = $product;
448
+ $selections[$key]['weight'] = (isset($sel['weight']) ? $sel['weight'] : 0)+$product->getAttribute('weight')*$product->getQuantity();
449
+ $selections[$key]['quantity'] = (isset($sel['quantity']) ? $sel['quantity'] : 0)+$product->getQuantity();
450
+ }
451
+ $this->debug(' products[<span class="osh-formula">'.$product->toString().'</span>].<span class="osh-key">categories</span> = array(<span class="osh-formula">'.join('</span>, <span class="osh-formula">', $categories_names).'</span>)');
452
+ }
453
+ $this->removeDebugIndent();
454
+ } else {
455
+ list($filter_property_type,$filter_property_name) = explode('.',$result[1]);
456
+ $selections = array();
457
+ $this->debug(' foreach <span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span>');
458
+ $this->addDebugIndent();
459
+ foreach ($process['cart.products'] as $product) {
460
+ $tmp_value = $this->_getProductProperty($product,$filter_property_type,$filter_property_name,$get_by_id=false);
461
+ $this->debug(' products[<span class="osh-formula">'.$product->toString().'</span>].<span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span> = <span class="osh-formula">'.$this->_toString($tmp_value).'</span>');
462
+ $key = 'val_'.$tmp_value;
463
+ $sel = isset($selections[$key]) ? $selections[$key] : null;
464
+ $selections[$key]['products'][] = $product;
465
+ $selections[$key]['weight'] = (isset($sel['weight']) ? $sel['weight'] : 0)+$product->getAttribute('weight')*$product->getQuantity();
466
+ $selections[$key]['quantity'] = (isset($sel['quantity']) ? $sel['quantity'] : 0)+$product->getQuantity();
467
+ }
468
+ $this->removeDebugIndent();
469
  }
470
+ $this->debug(' <span class="osh-loop">start foreach</span>');
471
+ $this->addDebugIndent();
472
+ foreach ($selections as $key => $selection) {
473
+ $this->debug(' <span class="osh-loop">&bull; value</span> = <span class="osh-formula">'.$key.'</span>');
474
+ $this->addDebugIndent();
475
  $process2 = $process;
476
  $process2['cart.products'] = $selection['products'];
477
  $process2['data']['selection.quantity'] = $selection['quantity'];
478
  $process2['data']['selection.weight'] = $selection['weight'];
479
  $process_result = $this->_processFormula($process2,$row,$property_key,$result[2],$is_checking,$tmp_use_cache=false);
480
  $replacement += $process_result->result;
481
+ $this->debug(' &raquo; <span class="osh-info">foreach sum result</span> = <span class="osh-formula">'.$replacement.'</span>');
482
+ $this->removeDebugIndent();
483
  }
484
+ $this->removeDebugIndent();
485
+ $this->debug(' <span class="osh-loop">end</span>');
486
  if ($use_cache) $this->setCache($original,$replacement);
487
  }
488
  $formula = $this->replace($original,$replacement,$formula);
489
  }
490
 
491
+ // customvar, variables
492
+ while ($this->_preg_match("#{customvar\.([a-z0-9_]+)}#i", $formula, $result)) {
 
493
  $original = $result[0];
494
+ $replacement = isset($process['store_interface']) ? $process['store_interface']->getCustomVar($result[1]) : null;
495
  $formula = $this->replace($original,$replacement,$formula);
496
  }
497
 
498
  $first_product = isset($process['cart.products'][0]) ? $process['cart.products'][0] : null;
499
  if (!isset($process['data']['selection.weight'])) $process['data']['selection.weight'] = $process['data']['cart.weight'];
500
  if (!isset($process['data']['selection.quantity'])) $process['data']['selection.quantity'] = $process['data']['cart.quantity'];
501
+ $process['data']['product.weight'] = 0;
502
+ $process['data']['product.quantity'] = 0;
503
+ $process['data']['product.category'] = null;
504
+ $process['data']['product.category.id'] = null;
505
+ if (isset($first_product)) {
506
+ $process['data']['product.weight'] = $first_product->getAttribute('weight');
507
+ $process['data']['product.quantity'] = $first_product->getQuantity();
508
+ if ($category = $first_product->getCategory()) {
509
+ $process['data']['product.category'] = $category->getName();
510
+ $process['data']['product.category.id'] = $category->getId();
511
+ }
512
+ }
513
 
514
+ $aliases = array(
515
+ 'p.' => 'product.',
516
+ 'c.' => 'cart.',
517
+ 's.' => 'selection.',
518
+ );
519
  foreach ($process['data'] as $original => $replacement) {
520
+ $formula = $this->replace('{'.$original.'}', $replacement, $formula);
521
+ foreach ($aliases as $from => $to) {
522
+ if (substr($original,0,strlen($to))==$to) $formula = $this->replace('{'.$from.substr($original,strlen($to),strlen($original)).'}', $replacement, $formula);
523
+ }
524
  }
525
 
526
  if (isset($first_product)) {
527
+ while ($this->_preg_match("#{{PRODUCT_REGEX}\.({ATTRIBUTE_REGEX}|{OPTION_REGEX}|stock)\.([a-z0-9_+-]+)}#i",$formula,$result)) {
528
  $original = $result[0];
529
+ $replacement = $this->_getProductProperty($first_product, $result[1], $result[2], $get_by_id=false);
 
 
 
 
530
  $formula = $this->replace($original,$replacement,$formula);
531
  }
532
  }
533
 
534
+ // count, sum, min, max
535
+ while ($this->_preg_match("/{(count) products(?: where ([^}]+))?}/i", $formula, $result)
536
+ || $this->_preg_match("/{(sum|min|max|count distinct) {PRODUCT_REGEX}\.({ATTRIBUTE_REGEX}|{OPTION_REGEX}|stock)\.([a-z0-9_+-]+)(?: where ([^}]+))?}/i", $formula, $result)
537
+ || $this->_preg_match("/{(sum|min|max|count distinct) {PRODUCT_REGEX}\.(quantity)()(?: where ([^}]+))?}/i", $formula, $result)
538
  ) {
539
  $original = $result[0];
540
  if ($use_cache && isset($this->_expression_cache[$original])) {
541
  $replacement = $this->_expression_cache[$original];
542
+ $this->debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>');
543
  } else {
544
  $replacement = $this->_processProductProperty($process['cart.products'],$result);
545
  if ($use_cache) $this->setCache($result[0],$replacement);
547
  $formula = $this->replace($original,$replacement,$formula);
548
  }
549
 
550
+ // table
551
  while (preg_match("/{table ([^}]+) in ([0-9\.:,\*\[\] ]+)}/i",$formula,$result)) {
552
  $original = $result[0];
553
  if ($use_cache && isset($this->_expression_cache[$original])) {
554
  $replacement = $this->_expression_cache[$original];
555
+ $this->debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>');
556
  } else {
557
  $reference_value = $this->_evalFormula($result[1]);
558
  if (isset($reference_value)) {
559
  $fees_table_string = $result[2];
560
 
561
+ if (!preg_match('#^'.self::COUPLE_REGEX.'(?:, *'.self::COUPLE_REGEX.')*$#',$fees_table_string)) {
562
  $this->addMessage('error',$row,$property_key,'Error in table %s','<span class="osh-formula">'.htmlentities($result[0]).'</span>');
563
  $result = new OS_Result(false);
564
  if ($use_cache) $this->setCache($formula_string,$result);
581
  $max_value = str_replace(array('[',']'),'',$max_value);
582
 
583
  if ($max_value=='*' || $including_max_value && $reference_value<=$max_value || !$including_max_value && $reference_value<$max_value) {
584
+ $replacement = $fee;
585
  break;
586
  }
587
  }
597
 
598
  protected function _evalFormula($formula) {
599
  if (is_bool($formula)) return $formula;
600
+ if (!preg_match('/^(?:E|floor|ceil|round|max|min|rand|pow|pi|sqrt|log|exp|abs|int|float|true|false|null|and|or|in|substr|strtolower'
601
+ .'|in_array\(\'(?:[^\']*)\', *array\( *(?:(?:\'(?:[^\']+)\') *(?: *, *\'(?:[^\']+)\')* *)?\) *\)'
602
  .'|\'[^\']*\'|[0-9,\'\.\-\(\)\*\/\?\:\+\<\>\=\&\|%! ])*$/',$formula)) {
603
  $errors = array(
604
  PREG_NO_ERROR => 'PREG_NO_ERROR',
610
  );
611
  $error = preg_last_error();
612
  if (isset($errors[$error])) $error = $errors[$error];
613
+ $this->debug(' eval <span class="osh-formula">'.$formula.'</span>');
614
+ $this->debug(' doesn\'t match ('.$error.')');
615
  return null;
616
  }
617
  $formula = str_replace(
621
  );
622
  $eval_result = null;
623
  @eval('$eval_result = ('.$formula.');');
624
+ $this->debug(' evaluate <span class="osh-formula">'.$formula.'</span> = <span class="osh-replacement">'.$this->_toString($eval_result).'</span>');
625
  return $eval_result;
626
  }
627
 
640
  }
641
 
642
  public function compress($input) {
643
+ /*
644
+ if (preg_match_all("/{table (.*) in (".self::COUPLE_REGEX."(?:, *".self::COUPLE_REGEX.")*)}/imsU",$input,$result,PREG_SET_ORDER)) {
645
  foreach ($result as $result_i) {
646
  $fees_table = explode(',',$result_i[2]);
647
  $value = null;
682
  $input = gzuncompress(base64_decode(substr($input,4,strlen($input))));
683
  }
684
 
685
+ /*
686
+ if (preg_match_all("/{table (.*) in (".self::COUPLE_REGEX."(?:, *".self::COUPLE_REGEX.")*)}/iU",$input,$result,PREG_SET_ORDER)) {
687
  foreach ($result as $result_i) {
688
  $fees_table = explode(',',$result_i[2]);
689
  $value = null;
710
  $input = str_replace($result_i[1],trim($result_i[1]),$input);
711
  $input = str_replace($result_i[2],trim($result_i[2]),$input);
712
  }
713
+ }
714
+ */
715
  return str_replace(
716
  self::$COMPRESSED_STRINGS,
717
  self::$UNCOMPRESSED_STRINGS,
758
  while (preg_match('/'.$regex1.'/',$input,$resi)) $input = str_replace($resi[0],'{'.$resi[1].'.'.$resi[2].'}',$input);
759
  }
760
 
761
+ $regex1 = "{(count|all|any) (attribute|option) '([^'\)]+)' ?((?:==|<=|>=|<|>|!=) ?(?:".self::FLOAT_REGEX."|true|false|'[^'\)]*'))}";
762
  $regex2 = "{(sum) (attribute|option) '([^'\)]+)'}";
763
  if (preg_match('/'.$regex1.'/',$input,$resi) || preg_match('/'.$regex2.'/',$input,$resi)) {
764
  $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
780
  }
781
  }
782
 
783
+ $regex = "{table '([^']+)' (".self::COUPLE_REGEX."(?:, *".self::COUPLE_REGEX.")*)}";
784
  if (preg_match('/'.$regex.'/',$input,$resi)) {
785
  $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
786
  while (preg_match('/'.$regex.'/',$input,$resi)) {
810
  //echo ini_get('pcre.backtrack_limit');
811
  //exit;
812
 
813
+ $row_regex = ' *([a-z0-9_]+)\\s*:\\s*("(?:(?:[^"]|\\\\")*[^\\\\])?"|'.self::FLOAT_REGEX.'|false|true)\\s*(,)? *(?:\\n)?';
814
  if (!preg_match_all('/((?:#+[^{\\n]*\\s+)*)\\s*(#)?{\\s*('.$row_regex.')+\\s*}/i',$config_string,$result,PREG_SET_ORDER)) {
815
  $errors = array(
816
  PREG_NO_ERROR => 'PREG_NO_ERROR',
822
  );
823
  $error = preg_last_error();
824
  if (isset($errors[$error])) $error = $errors[$error];
825
+ $this->debug(' preg_match_all error ('.$error.')');
826
  }
827
 
828
  $this->_config = array();
904
  }
905
  }
906
 
907
+ $float_value_regex = '\\s*('.self::POSITIVE_FLOAT_REGEX.'|\*)\\s*';
908
  $conditions = array();
909
  if (isset($row['prices_range'])) {
910
  if (!in_array('prices_range',$deprecated_properties)) $deprecated_properties[] = 'prices_range';
945
  }
946
  if (isset($row['product_properties'])) {
947
  if (!in_array('product_properties',$deprecated_properties)) $deprecated_properties[] = 'product_properties';
948
+ $product_property_regex = "\\s*(and|or)? *\((?:(all|any|sum) )?(attribute|option) '([^'\)]+)' ?(==|=|<=|>=|<|>|!=) ?(".self::FLOAT_REGEX."|true|false|'[^'\)]*')\)\\s*";
949
  if (preg_match('/^('.$product_property_regex.')+$/',$row['product_properties']['value'],$result)) {
950
  preg_match_all('/'.$product_property_regex.'/',$row['product_properties']['value'],$results,PREG_SET_ORDER);
951
  $product_properties_condition = '';
1092
  }
1093
  }
1094
  $this->_messages[] = $message;
1095
+ $this->debug(' => <span class="osh-'.$message->type.'">'.$message->toString().'</span>');
1096
  }
1097
 
1098
  protected function _addRow(&$row) {
1100
  $key = $row['code']['value'];
1101
  if (isset($this->_config[$key])) $this->addMessage('error',$row,'code','The property `code` must be unique, `%s` has been found twice',$key);
1102
  while (isset($this->_config[$key])) $key .= rand(0,9);
 
1103
  } else {
1104
  $i = 1;
1105
  do {
1126
  );
1127
 
1128
  if ($address_filter=='*') {
1129
+ $this->debug(' country code <span class="osh-replacement">'.$address['country_code'].'</span> matches');
1130
  return true;
1131
  }
1132
 
1163
  if (preg_match('#([A-Z]{2}) *(-)? *(?:\( *(-)? *(.*)\))?#s', $address_filter, $result)) {
1164
  $country_code = $result[1];
1165
  if ($address['country_code']==$country_code) {
1166
+ $this->debug(' country code <span class="osh-replacement">'.$address['country_code'].'</span> matches');
1167
  if (!isset($result[4]) || $result[4]=='') return !$excluding;
1168
  else {
1169
  $region_codes = explode(',',$result[4]);
1176
  ));
1177
  $region_codes[$i] = $code;
1178
  if ($address['region_code']===$code) {
1179
+ $this->debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> matches');
1180
  $in_array = true;
1181
  } else if ($address['postcode']===$code) {
1182
+ $this->debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches');
1183
  $in_array = true;
1184
  } else if (mb_substr($code,0,1)=='/' && mb_substr($code,mb_strlen($code)-1,1)=='/' && @preg_match($code, $address['postcode'])) {
1185
+ $this->debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches <span class="osh-formula">'.htmlentities($code).'</span>');
1186
  $in_array = true;
1187
  } else if (strpos($code,'*')!==false && preg_match('/^'.str_replace('*','(?:.*)',$code).'$/',$address['postcode'])) {
1188
+ $this->debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches <span class="osh-formula">'.htmlentities($code).'</span>');
1189
  $in_array = true;
1190
  }
1191
  if ($in_array) break;
1192
  }
1193
  if (!$in_array) {
1194
+ $this->debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> and postcode <span class="osh-replacement">'.$address['postcode'].'</span> don\'t match');
1195
  }
1196
  // Vérification stricte
 
1197
  $excluding_region = $result[2]=='-' || $result[3]=='-';
1198
  if ($excluding_region && !$in_array || !$excluding_region && $in_array) return !$excluding;
1199
  }
1204
  }
1205
 
1206
  protected function _getProductProperty($product, $property_type, $property_name, $get_by_id=false) {
1207
+ //$this->debug(' :: property_type <span class="osh-replacement">'.$property_type.'</span>');
1208
  switch ($property_type) {
1209
+ case 'a':
1210
+ case 'attr':
1211
+ case 'attributes':
1212
+ case 'attribute': return $product->getAttribute($property_name, $get_by_id);
1213
+ case 'o':
1214
+ case 'opt':
1215
+ case 'options':
1216
+ case 'option': return $product->getOption($property_name, $get_by_id);
1217
  case 'stock': return $product->getStockData($property_name);
1218
  }
1219
  return null;
1222
  protected function _processProductProperty($products, $regex_result) {
1223
  // count, sum, min, max, count distinct
1224
  $operation = strtolower($regex_result[1]);
1225
+ $return_value = null;
1226
  switch ($operation) {
1227
  case 'sum':
1228
  case 'min':
1236
  $conditions = isset($regex_result[2]) ? $regex_result[2] : null;
1237
  break;
1238
  }
1239
+ switch ($operation) {
1240
+ case 'sum':
1241
+ case 'count distinct':
1242
+ case 'count':
1243
+ $return_value = 0;
1244
+ break;
1245
+ }
1246
 
1247
+ $this->debug(' <span class="osh-loop">start <span class="osh-replacement">'.$operation.'</span> <span class="osh-key">product</span>.<span class="osh-key">'.$property_type.'</span>.<span class="osh-key">'.$property_name.'</span> where <span class="osh-replacement">'.$conditions.'</span></span>');
1248
+ $this->addDebugIndent();
 
1249
 
1250
+ $this->_preg_match_all('/{PRODUCT_REGEX}\.({ATTRIBUTE_REGEX}|{OPTION_REGEX}|stock)\.([a-z0-9_+-]+)(?:\.(id))?/i', $conditions, $properties_regex_result);
1251
  $properties = array();
1252
  foreach ($properties_regex_result as $property_regex_result) {
1253
  $key = $property_regex_result[0];
1254
  if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1255
  }
1256
+ $this->_preg_match_all('/{PRODUCT_REGEX}\.({CATEGORY_REGEX})(?:\.(id))?/i', $conditions, $properties_regex_result);
1257
+ $properties = array();
1258
+ foreach ($properties_regex_result as $property_regex_result) {
1259
+ $key = $property_regex_result[0];
1260
+ $property_regex_result[1] = 'category';
1261
+ if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1262
+ }
1263
+ $this->_preg_match_all('/{PRODUCT_REGEX}\.({CATEGORIES_REGEX})(?:\.(id))?/i', $conditions, $properties_regex_result);
1264
+ $properties = array();
1265
+ foreach ($properties_regex_result as $property_regex_result) {
1266
+ $key = $property_regex_result[0];
1267
+ $property_regex_result[1] = 'categories';
1268
+ if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1269
+ }
1270
+ $this->_preg_match_all('/{PRODUCT_REGEX}\.(quantity)/i', $conditions, $properties_regex_result);
1271
  foreach ($properties_regex_result as $property_regex_result) {
1272
  $key = $property_regex_result[0];
1273
  if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1274
  }
1275
 
1276
  foreach ($products as $product) {
1277
+ $this->debug(' <span class="osh-loop">&bull; product</span> = <span class="osh-formula">'.$product->toString().'</span>');
1278
+ $this->addDebugIndent();
1279
  if (isset($conditions) && $conditions!='') {
1280
  $formula = $conditions;
1281
  foreach ($properties as $property) {
1282
+ switch ($property[1]) {
1283
+ case 'quantity':
1284
+ $value = $product->getQuantity();
1285
+ break;
1286
+ case 'category':
1287
+ $get_by_id = isset($property[2]) && $property[2]=='id';
1288
+ $value = $get_by_id ? $category->getId() : $category->getName();
1289
+ break;
1290
+ case 'categories':
1291
+ $get_by_id = isset($property[2]) && $property[2]=='id';
1292
+ $value = array();
1293
+ foreach ($product->getCategories() as $category) {
1294
+ $value[] = $get_by_id ? $category->getId() : $category->getName();
1295
+ }
1296
+ break;
1297
+ default:
1298
+ $value = $this->_getProductProperty(
1299
+ $product,
1300
+ $tmp_property_type = $property[1],
1301
+ $tmp_property_name = $property[2],
1302
+ $get_by_id = isset($property[3]) && $property[3]=='id'
1303
+ );
1304
  }
 
1305
  $from = $property[0];
1306
+ if (is_array($value)) {
1307
+ $items = array();
1308
+ foreach ($value as $v) {
1309
+ $items[] = is_string($v) || empty($v) ? "'".$v."'" : $v;
1310
+ }
1311
+ $to = 'array('.join(',', $items).')';
1312
+ } else {
1313
+ $to = is_string($value) || empty($value) ? "'".$value."'" : $value;
1314
+ }
1315
+ $this->debug(' replace <span class="osh-replacement">'.$from.'</span> by <span class="osh-replacement">'.$to.'</span> =&gt; <span class="osh-formula">'.str_replace($from,'<span class="osh-replacement">'.$to.'</span>',$formula).'</span>');
1316
  $formula = str_replace($from,$to,$formula);
 
1317
  }
1318
  $eval_result = $this->_evalFormula($formula);
1319
+ if (!isset($eval_result)) $return_value = 'null';
1320
  }
1321
  else $eval_result = true;
1322
 
1337
  if (!isset($return_value) || $value>$return_value) $return_value = $value;
1338
  break;
1339
  case 'sum':
1340
+ //$this->debug($product->getSku().'.'.$property_type.'.'.$property_name.' = "'.$value.'" x '.$product->getQuantity());
1341
  $return_value = (isset($return_value) ? $return_value : 0) + $value*$product->getQuantity();
1342
  break;
1343
  case 'count distinct':
1351
  }
1352
  }
1353
  }
1354
+ $this->debug(' &raquo; <span class="osh-info">'.$operation.' result</span> = <span class="osh-formula">'.$return_value.'</span>');
1355
+ $this->removeDebugIndent();
1356
  }
1357
 
1358
+ $this->removeDebugIndent();
1359
+ $this->debug(' <span class="osh-loop">end</span>');
1360
 
1361
  return $return_value;
1362
  }
1363
 
1364
  }
1365
 
1366
+ interface OS_Category {
1367
+ public function getName();
1368
+ public function getId();
1369
+ public function toString();
1370
+ }
1371
+
1372
  interface OS_Product {
1373
  public function getOption($option);
1374
  public function getAttribute($attribute);
1375
  public function getName();
1376
+ public function getId();
1377
  public function getSku();
1378
  public function getQuantity();
1379
+ public function getCategory();
1380
  public function getStockData($key);
1381
+
1382
+ public function toString();
1383
  }
1384
 
1385
  class OS_Message {
app/locale/fr_FR/Owebia_Shipping2.csv CHANGED
@@ -107,12 +107,16 @@
107
  <li><a href=""#"" onclick=""os2editor.help('property.label');"">Le libellé : `label`</a></li>
108
  <li><a href=""#"" onclick=""os2editor.help('property.fees');"">Les frais de port : `fees`</a>
109
  <ul>
110
- <li><a href=""#"" onclick=""os2editor.help('more.formulas');"">Initiation aux formules</a></li>
111
- <li><a href=""#"" onclick=""os2editor.help('more.tables');"">Utilisation des tables de tarifs</a></li>
 
 
 
112
  <li><a href=""#"" onclick=""os2editor.help('more.copy');"">Faire une copie d'une propriété d'une autre méthode</a></li>
113
- <li><a href=""#"" onclick=""os2editor.help('more.special-functions');"">Fonctions spéciales dans les formules</a></li>
114
- <li class=""new""><a href=""#"" onclick=""os2editor.help('more.attributes-options');"">Utilisation des attributs ou des options des produits</a> (amélioration dans la version 2.3.10)</li>
115
  <li><a href=""#"" onclick=""os2editor.help('more.foreach');"">Utilisation des boucles foreach</a></li>
 
116
  <li><a href=""#"" onclick=""os2editor.help('more.custom-variables');"">Utilisation des variables personnalisées de Magento (Custom Variables)</a></li>
117
  </ul>
118
  </li>
@@ -526,6 +530,9 @@ Liste des fonctions spéciales :
526
  <p>
527
  Il est possible d'utiliser les attributs ou les options des produits à l'aide de la syntaxe ci-dessous.
528
  </p>
 
 
 
529
  <p>
530
  Vous pouvez utiliser cette technique dans les propriétés 'conditions' et 'fees'.
531
  </p>
@@ -621,6 +628,9 @@ conditions: <span class=""string"">""{count products where product.attribute.col
621
  Les boucles foreach permettent d'effectuer un calcul sur des groupes de produits plutôt que de tenir compte de tous les produits du panier.<br/>
622
  Le résultat global d'une boucle foreach est la somme des résultats de chaque passage dans la boucle.
623
  </p>
 
 
 
624
  <p>
625
  A l'intérieur d'une boucle foreach, il est possible d'utiliser de nouvelles variables :
626
  </p>
@@ -653,6 +663,50 @@ fees: <span class=""string"">""{foreach product.attribute.code_origin}{table {se
653
  fees: <span class=""string"">""{foreach product.attribute.sku}{product.attribute.shipping}*{product.quantity}{/foreach}""</span>,<br/>
654
  </div>
655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  <div class=""help-footer"">
657
  <p><a href=""#"" onclick=""os2editor.help('summary');"">Sommaire</a></p>
658
  </div>
107
  <li><a href=""#"" onclick=""os2editor.help('property.label');"">Le libellé : `label`</a></li>
108
  <li><a href=""#"" onclick=""os2editor.help('property.fees');"">Les frais de port : `fees`</a>
109
  <ul>
110
+ <li><a href=""#"" onclick=""os2editor.help('more.formulas');"">Initiation aux formules</a>
111
+ <ul>
112
+ <li><a href=""#"" onclick=""os2editor.help('more.special-functions');"">Fonctions spéciales dans les formules (min, max)</a></li>
113
+ </ul>
114
+ </li>
115
  <li><a href=""#"" onclick=""os2editor.help('more.copy');"">Faire une copie d'une propriété d'une autre méthode</a></li>
116
+ <li><a href=""#"" onclick=""os2editor.help('more.tables');"">Utilisation des tables de tarifs</a></li>
117
+ <li class=""new""><a href=""#"" onclick=""os2editor.help('more.attributes-options');"">Utilisation des attributs ou des options des produits (sum, count, min, max)</a> (amélioration dans la version 2.3.10)</li>
118
  <li><a href=""#"" onclick=""os2editor.help('more.foreach');"">Utilisation des boucles foreach</a></li>
119
+ <li class=""new""><a href=""#"" onclick=""os2editor.help('more.categories');"">Utilisation des catégories dans les boucles foreach ou dans les fonctions spéciales</a> (depuis la version 2.4.2)</li>
120
  <li><a href=""#"" onclick=""os2editor.help('more.custom-variables');"">Utilisation des variables personnalisées de Magento (Custom Variables)</a></li>
121
  </ul>
122
  </li>
530
  <p>
531
  Il est possible d'utiliser les attributs ou les options des produits à l'aide de la syntaxe ci-dessous.
532
  </p>
533
+ <p>
534
+ Pour utiliser les catégories des produits dans les conditions, voir la <a href=""#"" onclick=""os2editor.help('more.categories');"">rubrique explicative</a>.
535
+ </p>
536
  <p>
537
  Vous pouvez utiliser cette technique dans les propriétés 'conditions' et 'fees'.
538
  </p>
628
  Les boucles foreach permettent d'effectuer un calcul sur des groupes de produits plutôt que de tenir compte de tous les produits du panier.<br/>
629
  Le résultat global d'une boucle foreach est la somme des résultats de chaque passage dans la boucle.
630
  </p>
631
+ <p>
632
+ Pour utiliser les catégories des produits comme itération ou à l'intérieur des boucles foreach, voir la <a href=""#"" onclick=""os2editor.help('more.categories');"">rubrique explicative</a>.
633
+ </p>
634
  <p>
635
  A l'intérieur d'une boucle foreach, il est possible d'utiliser de nouvelles variables :
636
  </p>
663
  fees: <span class=""string"">""{foreach product.attribute.sku}{product.attribute.shipping}*{product.quantity}{/foreach}""</span>,<br/>
664
  </div>
665
 
666
+ <div class=""help-footer"">
667
+ <p><a href=""#"" onclick=""os2editor.help('summary');"">Sommaire</a></p>
668
+ </div>
669
+ "
670
+ "{os2editor.help.more.categories}","
671
+ <div class=""help-header"">
672
+ <p><a href=""#"" onclick=""os2editor.help('summary');"">Sommaire</a></p>
673
+ </div>
674
+
675
+ <h4>Utilisation des catégories dans les boucles foreach ou dans les fonctions spéciales</h4>
676
+
677
+ <p>
678
+ Depuis la version 2.4.2, il est possible d'utiliser les catégories des produits dans les formules.
679
+ </p>
680
+ <p>
681
+ <strong>Attention, il est à noter que dans Magento, un produit peut être dans plusieurs catégories.</strong> Faites donc particulièrement attention à la façon dont vous utilisez cette propriété.
682
+ </p>
683
+ <p>
684
+ Voici quelques exemples d'utilisation :
685
+ </p>
686
+ <div class=""code""><span class=""comment""># Boucle foreach dont l'itération se fait sur la catégorie</span><br/>
687
+ fees: <span class=""string"">""{foreach product.categories}{selection.weight}{/foreach}""</span>,<br/>
688
+ <br/>
689
+ <span class=""comment""># Utilisation de la catégorie à l'intérieur d'une boucle foreach</span><br/>
690
+ fees: <span class=""string"">""{foreach product.attribute.sku}({product.category}=='Test' ? 2.00 : 1.00)*{product.quantity}{/foreach}""</span>,<br/>
691
+ <span class=""comment""># Utilisation de l'id de la catégorie à l'intérieur d'une boucle foreach</span><br/>
692
+ fees: <span class=""string"">""{foreach product.attribute.sku}({product.category.id}==12 ? 2.00 : 1.00)*{product.quantity}{/foreach}""</span>,<br/>
693
+ <br/>
694
+ <span class=""comment""># Somme des attributs weight des produits de la catégorie 'Test'</span>,<br/>
695
+ <span class=""comment""># La fonction in_array() est utilisée car product.categories retourne un tableau</span><br/>
696
+ fees: <span class=""string"">""{sum product.attribute.weight where in_array('Test', product.categories)}""</span>,<br/>
697
+ <span class=""comment""># Somme des attributs weight des produits de la catégorie dont l'id est 12</span>,<br/>
698
+ <span class=""comment""># La fonction in_array() est utilisée car product.categories.id retourne un tableau</span><br/>
699
+ fees: <span class=""string"">""{sum product.attribute.weight where in_array(12, product.categories.id)}""</span>,<br/>
700
+ <br/>
701
+ <span class=""comment""># Somme des attributs weight des produits dont la première catégorie est 'Test'</span><br/>
702
+ <span class=""comment""># (préférez la solution ci-dessus si vos produits sont dans plusieurs catégories)</span><br/>
703
+ fees: <span class=""string"">""{sum product.attribute.weight where product.category=='Test'}""</span>,<br/>
704
+ <span class=""comment""># Somme des attributs weight des produits dont l'id de la première catégorie est 12</span><br/>
705
+ <span class=""comment""># (préférez la solution ci-dessus si vos produits sont dans plusieurs catégories)</span><br/>
706
+ fees: <span class=""string"">""{sum product.attribute.weight where product.category.id==12}""</span>,<br/>
707
+ <br/>
708
+ </div>
709
+
710
  <div class=""help-footer"">
711
  <p><a href=""#"" onclick=""os2editor.help('summary');"">Sommaire</a></p>
712
  </div>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Owebia_Shipping_2</name>
4
- <version>2.4.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
@@ -10,19 +10,23 @@
10
  <description>[EN] This module provides 3 shipping modes configurable with a very flexible syntax. The first method of delivery allows by default the management of Colissimo, Chronopost and Export 3J.
11
 
12
  [FR] Ce module met &#xE0; disposition 3 modes de livraison configurables avec une syntaxe tr&#xE8;s souple. Le premier mode de livraison permet par d&#xE9;faut la gestion des modes de livraison Colissimo, Chronopost et Export 3J.</description>
13
- <notes>[2.4.1 - 24 ao&#xFB;t 2011]
14
- Modification l&#xE9;g&#xE8;re du code php pour &#xE9;viter un plantage avec certaines versions d'eAccelerator (cache php)
15
- $row = null;
16
- $this-&gt;addMessage('info',$row,null,'Ignored lines %s','&lt;div class="code"&gt;'.trim($config_string).'&lt;/div&gt;');
17
- au lieu de ;
18
- $this-&gt;addMessage('info',$row=null,null,'Ignored lines %s','&lt;div class="code"&gt;'.trim($config_string).'&lt;/div&gt;');
19
- (cf http://www.magentocommerce.com/boards/viewthread/233202/)
20
- Ajout des variables de debug "info.server.os" et "info.server.software"
21
- Ajout de la possibilit&#xE9; de r&#xE9;cup&#xE9;rer la valeur minimum ou maximum de la quantit&#xE9; (ex: "{max product.quantity}")</notes>
 
 
 
 
22
  <authors><author><name>owebia</name><user>auto-converted</user><email>antoine.lemoine@owebia.com</email></author></authors>
23
- <date>2011-08-24</date>
24
- <time>09:46:29</time>
25
- <contents><target name="magelocale"><dir name="en_US"><file name="Owebia_Shipping2.csv" hash="4267e8feae738a7e06d06eed97d414fc"/></dir><dir name="fr_FR"><file name="Owebia_Shipping2.csv" hash="b8fa6dd7e21d4919b199417782d72778"/></dir></target><target name="mage"><dir name="js"><dir name="owebia"><dir name="shipping2"><file name="os2editor.css" hash="1c1b01fcf4971a50e730ad0588c0eb5b"/><file name="os2editor.js" hash="83f8726e9d8dc2edf8f9f00bb29d9045"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Owebia_Shipping2.xml" hash="586171bce13c5fb46298a7033f62bab6"/><file name="Owebia_Shipping_2.xml" hash="2f84a53934b37c860e25bc0c6217467f"/></dir></target><target name="magecommunity"><dir name="Owebia"><dir name="Shipping2"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Config.php" hash="b121bfb0d699d50440762146b135b319"/></dir></dir></dir></dir></dir></dir><dir name="Controller"><file name="Abstract.php" hash="c2cbd0a032ca5665b31e0cfcdc1638ec"/></dir><dir name="controllers"><dir name="Checkout"><file name="CartController.php" hash="ef72b286e9adda29f1dfd68ad0fa42ec"/></dir><file name="AjaxController.php" hash="eac44348f2fccf6d1cd18483c006c57e"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2a52eee2531db2e285716c9523c7cbf6"/><file name="config.xml" hash="64dcbdf449fe9592c16707172808e8cb"/><file name="system.xml" hash="c09780f68357ca1caf28b51fda4772eb"/></dir><dir name="includes"><dir name="cache"><file name="countries" hash="6b1a5494b6dddcc65f2946dbf0226c29"/></dir><file name="OS2_AddressFilter.php" hash="659c7155951b8415a963dfb778c782e5"/><file name="OS2_CustomerGroup.php" hash="c3aaf48316869ce51491c7e3af73f565"/><file name="OwebiaShippingHelper.php" hash="b1b5008ebbeed9c90fec2d2a547f2d44"/></dir><dir name="Model"><dir name="Carrier"><file name="AbstractOwebiaShipping.php" hash="bd9398b9debaed2df6b8b08cfa003376"/><file name="OwebiaShipping1.php" hash="e74757493b646425af9342b43997ff4e"/><file name="OwebiaShipping2.php" hash="cd9b8722ae65702f14435518f2c31af8"/><file name="OwebiaShipping3.php" hash="89d069078172aacc5b298e0bf68e575b"/></dir></dir><file name="changelog" hash="de1513d4d9228288f3f6de8fd2e870fa"/></dir></dir></target></contents>
26
  <compatible/>
27
  <dependencies/>
28
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Owebia_Shipping_2</name>
4
+ <version>2.4.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
  <channel>community</channel>
10
  <description>[EN] This module provides 3 shipping modes configurable with a very flexible syntax. The first method of delivery allows by default the management of Colissimo, Chronopost and Export 3J.
11
 
12
  [FR] Ce module met &#xE0; disposition 3 modes de livraison configurables avec une syntaxe tr&#xE8;s souple. Le premier mode de livraison permet par d&#xE9;faut la gestion des modes de livraison Colissimo, Chronopost et Export 3J.</description>
13
+ <notes>[2.4.2 - 07 octobre 2011]
14
+ Support des nombres d&#xE9;cimaux repr&#xE9;sent&#xE9;s sous la forme 5.3290705182E-15
15
+ Modification de la licence du code source (MIT au lieu de OSL 3.0)
16
+ Mise &#xE0; jour des mentions de copyright et de licence
17
+ Nettoyage du code source (suppression de lignes de code en commentaire)
18
+ Initialisation des formules sum et count &#xE0; 0 au lieu de null (pour &#xE9;viter les erreurs de formule si aucun produit ne correpond)
19
+ Ajout des alias "a" et "attr" pour "attribute", "o" et "opt" pour "option", "p" pour "product", "c" pour "cart", "s" pour "selection"
20
+ Correction de la r&#xE9;cup&#xE9;ration des variables personnalis&#xE9;es : getValue('text') au lieu de getValue('plain')
21
+ Support des cat&#xE9;gories
22
+ product.categories dans les conditions de boucle foreach
23
+ {product.category} et {product.category.id} comme variables dans les boucles foreach
24
+ product.category, product.category.id, product.categories, product.categories.id dans les conditions des op&#xE9;rations sum, count, min et max
25
+ Am&#xE9;lioration du debug</notes>
26
  <authors><author><name>owebia</name><user>auto-converted</user><email>antoine.lemoine@owebia.com</email></author></authors>
27
+ <date>2011-10-07</date>
28
+ <time>13:17:49</time>
29
+ <contents><target name="magelocale"><dir name="en_US"><file name="Owebia_Shipping2.csv" hash="4267e8feae738a7e06d06eed97d414fc"/></dir><dir name="fr_FR"><file name="Owebia_Shipping2.csv" hash="cfbb6a96b517b1e00478556dd6fdfb6d"/></dir></target><target name="mage"><dir name="js"><dir name="owebia"><dir name="shipping2"><file name="os2editor.css" hash="1c1b01fcf4971a50e730ad0588c0eb5b"/><file name="os2editor.js" hash="83f8726e9d8dc2edf8f9f00bb29d9045"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Owebia_Shipping2.xml" hash="586171bce13c5fb46298a7033f62bab6"/><file name="Owebia_Shipping_2.xml" hash="2f84a53934b37c860e25bc0c6217467f"/></dir></target><target name="magecommunity"><dir name="Owebia"><dir name="Shipping2"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Config.php" hash="fcff55f860bfb743b34245e6ce2e5d5b"/></dir></dir></dir></dir></dir></dir><dir name="Controller"><file name="Abstract.php" hash="f8fa0d63caf4585e9ac42fae2e970a23"/></dir><dir name="controllers"><dir name="Checkout"><file name="CartController.php" hash="8c6ee136298e0e2dd0052143887282ce"/></dir><file name="AjaxController.php" hash="aec2cb9e8c7f0fb2ab0ffad1fa3bb43e"/></dir><dir name="etc"><file name="adminhtml.xml" hash="ed61385695adc726513ecb0d80b5471b"/><file name="config.xml" hash="dda5f94f1d8445d146663bd1bb6c7f30"/><file name="system.xml" hash="67f66b677ed950ecce17d8dc50ea1061"/></dir><dir name="includes"><dir name="cache"><file name="countries" hash="6b1a5494b6dddcc65f2946dbf0226c29"/></dir><file name="OS2_AddressFilter.php" hash="bb26bb2da522049ea6da82092503e35e"/><file name="OS2_CustomerGroup.php" hash="f39c69309ea1d268654917231834f802"/><file name="OwebiaShippingHelper.php" hash="05c5e36454e0fa7766aee6138fce5d24"/></dir><dir name="Model"><dir name="Carrier"><file name="AbstractOwebiaShipping.php" hash="260523801ddadfeed1a54665e5fd905f"/><file name="OwebiaShipping1.php" hash="2e6caa067fdfae4673b8f8db52f7a3fe"/><file name="OwebiaShipping2.php" hash="310917d67dcf22bed6cbf5adefb90bde"/><file name="OwebiaShipping3.php" hash="e8ecfbac4088df56c609b04e688cc04b"/></dir></dir><file name="changelog" hash="43f76b5ba7f389bfcabe3516faf2bd8a"/></dir></dir></target></contents>
30
  <compatible/>
31
  <dependencies/>
32
  </package>