Chronopost - Version 0.1.8

Version Notes

Version destinée à Magento 1.5.X et antérieures
------------
Support du multi-shipping.
Correction sur le filtrage des commandes pour l'export.
Correction du nom de point relais manquant dans les exports.
Modification de libellé en admin pour explication du Quickcost.

Download this release

Release Info

Developer Benjamin GOSSELET
Extension Chronopost
Version 0.1.8
Comparing to
See all releases


Code changes from version 0.2.0 to 0.1.8

Files changed (52) hide show
  1. app/code/community/Chronopost/Chronorelais/Block/Adminhtml/System/Config/Form/Field/Config.php +43 -43
  2. app/code/community/Chronopost/Chronorelais/Block/Checkout/Multishipping/Shipping/Method/Chronorelais.php +2 -1
  3. app/code/community/Chronopost/Chronorelais/Block/Checkout/Onepage/Shipping/Method/Chronorelais.php +54 -54
  4. app/code/community/Chronopost/Chronorelais/Block/Detail.php +28 -28
  5. app/code/community/Chronopost/Chronorelais/Block/Export/Orders.php +21 -21
  6. app/code/community/Chronopost/Chronorelais/Block/Export/Orders/Grid.php +1 -1
  7. app/code/community/Chronopost/Chronorelais/Block/Filter.php +52 -52
  8. app/code/community/Chronopost/Chronorelais/Block/Import/Form.php +11 -11
  9. app/code/community/Chronopost/Chronorelais/Block/Sales/Impression.php +15 -15
  10. app/code/community/Chronopost/Chronorelais/Block/Sales/Order/Shipment/View.php +98 -98
  11. app/code/community/Chronopost/Chronorelais/Block/Sales/Shipment/Copy of Grid.php +139 -0
  12. app/code/community/Chronopost/Chronorelais/Block/Sales/Shipment/Grid-bkp-03-02-11.php +143 -0
  13. app/code/community/Chronopost/Chronorelais/Block/Sales/Shipment/Grid.php +37 -55
  14. app/code/community/Chronopost/Chronorelais/Controller/Abstract.php +125 -125
  15. app/code/community/Chronopost/Chronorelais/Helper/Data.php +177 -177
  16. app/code/community/Chronopost/Chronorelais/Model/Carrier/AbstractChronorelais.php +31 -31
  17. app/code/community/Chronopost/Chronorelais/Model/Carrier/AbstractChronorelaisShipping.php +488 -488
  18. app/code/community/Chronopost/Chronorelais/Model/Carrier/Chronoexpress.php +5 -5
  19. app/code/community/Chronopost/Chronorelais/Model/Carrier/Chronopost.php +5 -5
  20. app/code/community/Chronopost/Chronorelais/Model/Carrier/Chronorelais.php +5 -5
  21. app/code/community/Chronopost/Chronorelais/Model/Config/Source/Civility.php +12 -12
  22. app/code/community/Chronopost/Chronorelais/Model/Config/Source/EndOfLineCharacter.php +12 -12
  23. app/code/community/Chronopost/Chronorelais/Model/Config/Source/FieldDelimiter.php +12 -12
  24. app/code/community/Chronopost/Chronorelais/Model/Config/Source/FieldSeparator.php +11 -11
  25. app/code/community/Chronopost/Chronorelais/Model/Config/Source/FileCharset.php +12 -12
  26. app/code/community/Chronopost/Chronorelais/Model/Config/Source/FileExtension.php +12 -12
  27. app/code/community/Chronopost/Chronorelais/Model/Config/Source/PrintMode.php +12 -12
  28. app/code/community/Chronopost/Chronorelais/Model/Sales/Quote/Address/Total/Shipping.php +207 -207
  29. app/code/community/Chronopost/Chronorelais/controllers/AjaxController.php +409 -409
  30. app/code/community/Chronopost/Chronorelais/controllers/Checkout/MultishippingController.php +37 -3
  31. app/code/community/Chronopost/Chronorelais/controllers/Checkout/OnepageController.php +21 -17
  32. app/code/community/Chronopost/Chronorelais/controllers/ImportController.php +1 -1
  33. app/code/community/Chronopost/Chronorelais/controllers/RelaisController.php +31 -31
  34. app/code/community/Chronopost/Chronorelais/controllers/Sales/ImpressionController.php +519 -530
  35. app/code/community/Chronopost/Chronorelais/controllers/Sales/Order/ShipmentController.php +3 -9
  36. app/code/community/Chronopost/Chronorelais/includes/ChronorelaisShippingHelper.php +1265 -1265
  37. app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-install-0.1.0.php +14 -14
  38. app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.0-0.1.1.php +8 -8
  39. app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.1-0.1.2.php +8 -8
  40. app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.2-0.1.3.php +8 -8
  41. app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.3-0.1.4.php +13 -13
  42. app/design/adminhtml/default/default/template/chronorelais/import/form.phtml +65 -65
  43. app/design/frontend/default/default/template/chronorelais/checkout/multishipping/shipping.phtml +1 -1
  44. app/design/frontend/default/default/template/chronorelais/checkout/multishipping/shipping_method/chronorelais.phtml +4 -1
  45. app/design/frontend/default/default/template/chronorelais/checkout/onepage/shipping_method.phtml +92 -92
  46. app/design/frontend/default/default/template/chronorelais/checkout/onepage/shipping_method/available.phtml +93 -93
  47. app/design/frontend/default/default/template/chronorelais/sales/order/history.phtml +79 -79
  48. app/design/frontend/default/default/template/chronorelais/sales/order/recent.phtml +78 -78
  49. app/etc/modules/WSChronopost_Chronorelais.xml +27 -27
  50. js/chronopost/chronorelais/ocseditor.css +465 -465
  51. js/chronopost/chronorelais/ocseditor.js +676 -676
  52. package.xml +7 -7
app/code/community/Chronopost/Chronorelais/Block/Adminhtml/System/Config/Form/Field/Config.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
-
3
- class Chronopost_Chronorelais_Block_Adminhtml_System_Config_Form_Field_Config extends Mage_Adminhtml_Block_System_Config_Form_Field
4
- {
5
- private static $JS_INCLUDED = false;
6
-
7
- private function label($input) {
8
- return str_replace(array("\r\n","\r","\n","'"),array("\\n","\\n","\\n","\\'"),$this->__($input));
9
- }
10
-
11
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
- {
13
- $output = '';
14
- if (!self::$JS_INCLUDED) {
15
- $include_path = Mage::getBaseUrl('js').'chronopost/chronorelais';
16
- $output = "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js\"></script>\n"
17
- ."<script type=\"text/javascript\" src=\"".$include_path."/ocseditor.js?t=".time()."\"></script>\n"
18
- ."<script type=\"text/javascript\">\n"
19
- ."//<![CDATA[\n"
20
- ."jQuery.noConflict();\n"
21
- ."var ocseditor = new OCSEditor({\n"
22
- ."ajax_url: '".$this->getUrl('chronorelais/ajax')."?isAjax=true',\n"
23
- ."form_key: FORM_KEY,\n"
24
- ."menu_item_dissociate_label: '".$this->label('Dissociate')."',\n"
25
- ."menu_item_remove_label: '".$this->label('Remove')."',\n"
26
- ."menu_item_edit_label: '".$this->label('Edit')."',\n"
27
- ."prompt_new_value_label: '".$this->label('Enter the new value:')."',\n"
28
- ."default_row_label: '".$this->label('[No label]')."',\n"
29
- ."loading_label: '".$this->label('Loading...')."'\n"
30
- ."});\n"
31
- ."//]]>\n"
32
- ."</script>\n"
33
- ."<link type=\"text/css\" href=\"".$include_path."/ocseditor.css?t=".time()."\" rel=\"stylesheet\" media=\"all\"/>\n"
34
- ;
35
- self::$JS_INCLUDED = true;
36
- }
37
-
38
- return $output
39
- .'<div style="margin-bottom:1px;"><button type="button" class="scalable" onclick="ocseditor.open(this);"><span>'.$this->__("Open editor").'</span></button></div>'
40
- .$element->getElementHtml().'<br/>'
41
- ;
42
- }
43
- }
1
+ <?php
2
+
3
+ class Chronopost_Chronorelais_Block_Adminhtml_System_Config_Form_Field_Config extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ private static $JS_INCLUDED = false;
6
+
7
+ private function label($input) {
8
+ return str_replace(array("\r\n","\r","\n","'"),array("\\n","\\n","\\n","\\'"),$this->__($input));
9
+ }
10
+
11
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
12
+ {
13
+ $output = '';
14
+ if (!self::$JS_INCLUDED) {
15
+ $include_path = Mage::getBaseUrl('js').'chronopost/chronorelais';
16
+ $output = "<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js\"></script>\n"
17
+ ."<script type=\"text/javascript\" src=\"".$include_path."/ocseditor.js?t=".time()."\"></script>\n"
18
+ ."<script type=\"text/javascript\">\n"
19
+ ."//<![CDATA[\n"
20
+ ."jQuery.noConflict();\n"
21
+ ."var ocseditor = new OCSEditor({\n"
22
+ ."ajax_url: '".$this->getUrl('chronorelais/ajax')."?isAjax=true',\n"
23
+ ."form_key: FORM_KEY,\n"
24
+ ."menu_item_dissociate_label: '".$this->label('Dissociate')."',\n"
25
+ ."menu_item_remove_label: '".$this->label('Remove')."',\n"
26
+ ."menu_item_edit_label: '".$this->label('Edit')."',\n"
27
+ ."prompt_new_value_label: '".$this->label('Enter the new value:')."',\n"
28
+ ."default_row_label: '".$this->label('[No label]')."',\n"
29
+ ."loading_label: '".$this->label('Loading...')."'\n"
30
+ ."});\n"
31
+ ."//]]>\n"
32
+ ."</script>\n"
33
+ ."<link type=\"text/css\" href=\"".$include_path."/ocseditor.css?t=".time()."\" rel=\"stylesheet\" media=\"all\"/>\n"
34
+ ;
35
+ self::$JS_INCLUDED = true;
36
+ }
37
+
38
+ return $output
39
+ .'<div style="margin-bottom:1px;"><button type="button" class="scalable" onclick="ocseditor.open(this);"><span>'.$this->__("Open editor").'</span></button></div>'
40
+ .$element->getElementHtml().'<br/>'
41
+ ;
42
+ }
43
+ }
app/code/community/Chronopost/Chronorelais/Block/Checkout/Multishipping/Shipping/Method/Chronorelais.php CHANGED
@@ -39,7 +39,8 @@ class Chronopost_Chronorelais_Block_Checkout_Multishipping_Shipping_Method_Chron
39
  public function getChronorelais()
40
  {
41
  if (empty($this->_chronorelais)) {
42
- $postcode = Mage::getSingleton('core/session')->getMultiPostcode();
 
43
 
44
  $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
45
  $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$postcode,0));
39
  public function getChronorelais()
40
  {
41
  if (empty($this->_chronorelais)) {
42
+ $address = Mage::getSingleton('core/session')->getMultiAddress();
43
+ $postcode = $address->getPostcode();
44
 
45
  $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
46
  $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$postcode,0));
app/code/community/Chronopost/Chronorelais/Block/Checkout/Onepage/Shipping/Method/Chronorelais.php CHANGED
@@ -1,54 +1,54 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category Mage
22
- * @package Mage_Checkout
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- */
26
-
27
- /**
28
- * One page checkout status
29
- *
30
- * @category Mage
31
- * @category Mage
32
- * @package Mage_Checkout
33
- * @author Magento Core Team <core@magentocommerce.com>
34
- */
35
- class Chronopost_Chronorelais_Block_Checkout_Onepage_Shipping_Method_Chronorelais extends Mage_Checkout_Block_Onepage_Abstract
36
- {
37
- protected $_chronorelais;
38
-
39
- public function getChronorelais()
40
- {
41
- if (empty($this->_chronorelais)) {
42
- $quote = Mage::getSingleton('checkout/cart')->init()->getQuote();
43
- $address = $quote->getShippingAddress();
44
- $postcode = $address->getPostcode();
45
-
46
- $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
47
- $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$postcode,0));
48
- $this->_chronorelais = $webservbt;
49
- }
50
-
51
- return $this->_chronorelais;
52
- }
53
-
54
- }
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Checkout
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * One page checkout status
29
+ *
30
+ * @category Mage
31
+ * @category Mage
32
+ * @package Mage_Checkout
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Chronopost_Chronorelais_Block_Checkout_Onepage_Shipping_Method_Chronorelais extends Mage_Checkout_Block_Onepage_Abstract
36
+ {
37
+ protected $_chronorelais;
38
+
39
+ public function getChronorelais()
40
+ {
41
+ if (empty($this->_chronorelais)) {
42
+ $quote = Mage::getSingleton('checkout/cart')->init()->getQuote();
43
+ $address = $quote->getShippingAddress();
44
+ $postcode = $address->getPostcode();
45
+
46
+ $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
47
+ $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$postcode,0));
48
+ $this->_chronorelais = $webservbt;
49
+ }
50
+
51
+ return $this->_chronorelais;
52
+ }
53
+
54
+ }
app/code/community/Chronopost/Chronorelais/Block/Detail.php CHANGED
@@ -1,29 +1,29 @@
1
- <?php
2
- class Chronopost_Chronorelais_Block_Detail extends Mage_Core_Block_Template
3
- {
4
-
5
- public function _prepareLayout()
6
- {
7
- return parent::_prepareLayout();
8
- }
9
-
10
- public function getRelaisPoint(){
11
-
12
-
13
- $btcode = $this->getRequest()->getParam ( 'btcode' );
14
-
15
- if($btcode){
16
- $result = Mage::getModel('shipping/rate_result');
17
- ini_set("soap.wsdl_cache_enabled", "0");
18
- $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl");
19
- $webservbt = $client->__call("rechercheBtParIdChronopostA2Pas",array($btcode));
20
-
21
- return $webservbt[0];
22
- }
23
- else{
24
- return false;
25
- }
26
- }
27
-
28
- }
29
  ?>
1
+ <?php
2
+ class Chronopost_Chronorelais_Block_Detail extends Mage_Core_Block_Template
3
+ {
4
+
5
+ public function _prepareLayout()
6
+ {
7
+ return parent::_prepareLayout();
8
+ }
9
+
10
+ public function getRelaisPoint(){
11
+
12
+
13
+ $btcode = $this->getRequest()->getParam ( 'btcode' );
14
+
15
+ if($btcode){
16
+ $result = Mage::getModel('shipping/rate_result');
17
+ ini_set("soap.wsdl_cache_enabled", "0");
18
+ $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl");
19
+ $webservbt = $client->__call("rechercheBtParIdChronopostA2Pas",array($btcode));
20
+
21
+ return $webservbt[0];
22
+ }
23
+ else{
24
+ return false;
25
+ }
26
+ }
27
+
28
+ }
29
  ?>
app/code/community/Chronopost/Chronorelais/Block/Export/Orders.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- /**
3
- * Chronopost Chronorelais module
4
- *
5
- * @category Chronopost
6
- * @package Chronopost_Chronorelais
7
- * @license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
8
- */
9
- class Chronopost_Chronorelais_Block_Export_Orders extends Mage_Adminhtml_Block_Widget_Grid_Container
10
- {
11
-
12
- public function __construct()
13
- {
14
- $this->_blockGroup = 'chronorelais';
15
- $this->_controller = 'export_orders';
16
- $this->_headerText = Mage::helper('chronorelais')->__('Exporter vers ChronoShip Office ou ChronoShip Station');
17
- parent::__construct();
18
- $this->_removeButton('add');
19
- }
20
-
21
- }
1
+ <?php
2
+ /**
3
+ * Chronopost Chronorelais module
4
+ *
5
+ * @category Chronopost
6
+ * @package Chronopost_Chronorelais
7
+ * @license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License version 3
8
+ */
9
+ class Chronopost_Chronorelais_Block_Export_Orders extends Mage_Adminhtml_Block_Widget_Grid_Container
10
+ {
11
+
12
+ public function __construct()
13
+ {
14
+ $this->_blockGroup = 'chronorelais';
15
+ $this->_controller = 'export_orders';
16
+ $this->_headerText = Mage::helper('chronorelais')->__('Exporter vers ChronoShip Office ou ChronoShip Station');
17
+ parent::__construct();
18
+ $this->_removeButton('add');
19
+ }
20
+
21
+ }
app/code/community/Chronopost/Chronorelais/Block/Export/Orders/Grid.php CHANGED
@@ -34,7 +34,7 @@ class Chronopost_Chronorelais_Block_Export_Orders_Grid extends Mage_Adminhtml_Bl
34
  $collection->join('order_payment', 'main_table.entity_id = order_payment.parent_id', 'method');
35
  $collection->getSelect()->joinLeft(array('oes' => Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status')), 'main_table.entity_id = oes.order_id', array("if(isNull(oes.livraison_le_samedi), CASE LOWER(SUBSTRING_INDEX(order.shipping_method,'_','1')) WHEN 'chronopost' THEN '$_chronopost_deliver_saturday' WHEN 'chronorelais' THEN '$_chronorelais_deliver_saturday' WHEN 'chronoexpress' THEN '--' ELSE 'No' END, oes.livraison_le_samedi) as livraison_le_samedi"));
36
  $collection->getSelect()->where('order.shipping_method LIKE "chronorelais%" OR order.shipping_method LIKE "chronopost%" OR order.shipping_method LIKE "chronoexpress%"');
37
-
38
  $this->setCollection($collection);
39
  return parent::_prepareCollection();
40
  }
34
  $collection->join('order_payment', 'main_table.entity_id = order_payment.parent_id', 'method');
35
  $collection->getSelect()->joinLeft(array('oes' => Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status')), 'main_table.entity_id = oes.order_id', array("if(isNull(oes.livraison_le_samedi), CASE LOWER(SUBSTRING_INDEX(order.shipping_method,'_','1')) WHEN 'chronopost' THEN '$_chronopost_deliver_saturday' WHEN 'chronorelais' THEN '$_chronorelais_deliver_saturday' WHEN 'chronoexpress' THEN '--' ELSE 'No' END, oes.livraison_le_samedi) as livraison_le_samedi"));
36
  $collection->getSelect()->where('order.shipping_method LIKE "chronorelais%" OR order.shipping_method LIKE "chronopost%" OR order.shipping_method LIKE "chronoexpress%"');
37
+
38
  $this->setCollection($collection);
39
  return parent::_prepareCollection();
40
  }
app/code/community/Chronopost/Chronorelais/Block/Filter.php CHANGED
@@ -1,53 +1,53 @@
1
- <?php
2
- class Chronopost_Chronorelais_Block_Filter extends Mage_Core_Block_Template
3
- {
4
-
5
- public function _prepareLayout()
6
- {
7
- return parent::_prepareLayout();
8
- }
9
-
10
-
11
- public function getRelaisPoints(){
12
-
13
- $zipcode = $this->getRequest()->getParam ( 'zipcode' );
14
-
15
- if( $zipcode && $zipcode!="" ){
16
- $result = Mage::getModel('shipping/rate_result');
17
-
18
- try {
19
- $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
20
-
21
- $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$zipcode,0));
22
-
23
- } catch(SoapFault $fault){
24
-
25
- return false;
26
- }
27
-
28
-
29
- return $webservbt;
30
- }
31
- else{
32
- return false;
33
- }
34
- }
35
-
36
- public function getmethodeCode(){
37
-
38
- $zipcode = $this->getRequest()->getParam ( 'methodecode' );
39
-
40
- if($zipcode){
41
- $result = Mage::getModel('shipping/rate_result');
42
- ini_set("soap.wsdl_cache_enabled", "0");
43
- $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl");
44
- $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$zipcode,0));
45
- return $webservbt;
46
- }
47
- else{
48
- return false;
49
- }
50
- }
51
-
52
- }
53
  ?>
1
+ <?php
2
+ class Chronopost_Chronorelais_Block_Filter extends Mage_Core_Block_Template
3
+ {
4
+
5
+ public function _prepareLayout()
6
+ {
7
+ return parent::_prepareLayout();
8
+ }
9
+
10
+
11
+ public function getRelaisPoints(){
12
+
13
+ $zipcode = $this->getRequest()->getParam ( 'zipcode' );
14
+
15
+ if( $zipcode && $zipcode!="" ){
16
+ $result = Mage::getModel('shipping/rate_result');
17
+
18
+ try {
19
+ $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
20
+
21
+ $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$zipcode,0));
22
+
23
+ } catch(SoapFault $fault){
24
+
25
+ return false;
26
+ }
27
+
28
+
29
+ return $webservbt;
30
+ }
31
+ else{
32
+ return false;
33
+ }
34
+ }
35
+
36
+ public function getmethodeCode(){
37
+
38
+ $zipcode = $this->getRequest()->getParam ( 'methodecode' );
39
+
40
+ if($zipcode){
41
+ $result = Mage::getModel('shipping/rate_result');
42
+ ini_set("soap.wsdl_cache_enabled", "0");
43
+ $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl");
44
+ $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$zipcode,0));
45
+ return $webservbt;
46
+ }
47
+ else{
48
+ return false;
49
+ }
50
+ }
51
+
52
+ }
53
  ?>
app/code/community/Chronopost/Chronorelais/Block/Import/Form.php CHANGED
@@ -1,11 +1,11 @@
1
- <?php
2
- class Chronopost_Chronorelais_Block_Import_Form extends Mage_Adminhtml_Block_Widget
3
- {
4
-
5
- public function __construct()
6
- {
7
- parent::__construct();
8
- $this->setTemplate('chronorelais/import/form.phtml');
9
- }
10
-
11
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Block_Import_Form extends Mage_Adminhtml_Block_Widget
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setTemplate('chronorelais/import/form.phtml');
9
+ }
10
+
11
+ }
app/code/community/Chronopost/Chronorelais/Block/Sales/Impression.php CHANGED
@@ -1,16 +1,16 @@
1
- <?php
2
-
3
- class Chronopost_Chronorelais_Block_Sales_Impression extends Mage_Adminhtml_Block_Widget_Grid_Container
4
- {
5
-
6
-
7
- public function __construct()
8
- {
9
- $this->_blockGroup = 'chronorelais';
10
- $this->_controller = 'sales_shipment';
11
- $this->_headerText = Mage::helper('chronorelais')->__('Impressions des étiquettes Chronopost');
12
- parent::__construct();
13
- $this->_removeButton('add');
14
- }
15
-
16
  }
1
+ <?php
2
+
3
+ class Chronopost_Chronorelais_Block_Sales_Impression extends Mage_Adminhtml_Block_Widget_Grid_Container
4
+ {
5
+
6
+
7
+ public function __construct()
8
+ {
9
+ $this->_blockGroup = 'chronorelais';
10
+ $this->_controller = 'sales_shipment';
11
+ $this->_headerText = Mage::helper('chronorelais')->__('Impressions des étiquettes Chronopost');
12
+ parent::__construct();
13
+ $this->_removeButton('add');
14
+ }
15
+
16
  }
app/code/community/Chronopost/Chronorelais/Block/Sales/Order/Shipment/View.php CHANGED
@@ -1,99 +1,99 @@
1
- <?php
2
- class Chronopost_Chronorelais_Block_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Widget_Form_Container
3
- {
4
-
5
- public function __construct()
6
- {
7
- $this->_objectId = 'shipment_id';
8
- $this->_controller = 'sales_order_shipment';
9
- $this->_mode = 'view';
10
-
11
- parent::__construct();
12
-
13
- $this->_removeButton('reset');
14
- $this->_removeButton('delete');
15
- $this->_updateButton('save', 'label', Mage::helper('sales')->__('Send Tracking Information'));
16
- $this->_updateButton('save', 'onclick', "setLocation('".$this->getEmailUrl()."')");
17
-
18
- //Ajout de l'impression de l'étiquette
19
- $_order = $this->getShipment()->getOrder();
20
- $_shippingMethod = explode("_",$_order->getShippingMethod());
21
- if (($_shippingMethod[0] == 'chronorelais' || $_shippingMethod[0] == 'chronopost' || $_shippingMethod[0] == 'chronoexpress')) {
22
- $this->_addButton('etiquette', array(
23
- 'label' => Mage::helper('chronorelais')->__('Etiquette Chronopost'),
24
- 'class' => 'save',
25
- 'onclick' => 'setLocation(\'' . $this->getPrintMondialRelayUrl() . '\')'
26
- )
27
- );
28
- }
29
-
30
- if ($this->getShipment()->getId()) {
31
- $this->_addButton('print', array(
32
- 'label' => Mage::helper('sales')->__('Print'),
33
- 'class' => 'save',
34
- 'onclick' => 'setLocation(\''.$this->getPrintUrl().'\')'
35
- )
36
- );
37
- }
38
- }
39
-
40
- /**
41
- * Retrieve shipment model instance
42
- *
43
- * @return Mage_Sales_Model_Order_Shipment
44
- */
45
- public function getShipment()
46
- {
47
- return Mage::registry('current_shipment');
48
- }
49
-
50
- public function getHeaderText()
51
- {
52
- if ($this->getShipment()->getEmailSent()) {
53
- $emailSent = Mage::helper('sales')->__('Shipment email sent');
54
- }
55
- else {
56
- $emailSent = Mage::helper('sales')->__('Shipment email not sent');
57
- }
58
-
59
- $header = Mage::helper('sales')->__('Shipment #%s (%s)', $this->getShipment()->getIncrementId(), $emailSent);
60
- return $header;
61
- }
62
-
63
- public function getBackUrl()
64
- {
65
- return $this->getUrl(
66
- '*/sales_order/view',
67
- array(
68
- 'order_id' => $this->getShipment()->getOrderId(),
69
- 'active_tab'=> 'order_shipments'
70
- ));
71
- }
72
-
73
- public function getEmailUrl()
74
- {
75
- return $this->getUrl('*/sales_order_shipment/email', array('shipment_id' => $this->getShipment()->getId()));
76
- }
77
-
78
- public function getPrintUrl()
79
- {
80
- return $this->getUrl('*/*/print', array(
81
- 'invoice_id' => $this->getShipment()->getId()
82
- ));
83
- }
84
-
85
- public function getPrintMondialRelayUrl()
86
- {
87
- return $this->getUrl('chronorelais/sales_impression/print', array(
88
- 'shipment_id' => $this->getShipment()->getId()
89
- ));
90
- }
91
-
92
- public function updateBackButtonUrl($flag)
93
- {
94
- if ($flag) {
95
- return $this->_updateButton('back', 'onclick', 'setLocation(\'' . $this->getUrl('*/sales_shipment/') . '\')');
96
- }
97
- return $this;
98
- }
99
  }
1
+ <?php
2
+ class Chronopost_Chronorelais_Block_Sales_Order_Shipment_View extends Mage_Adminhtml_Block_Widget_Form_Container
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ $this->_objectId = 'shipment_id';
8
+ $this->_controller = 'sales_order_shipment';
9
+ $this->_mode = 'view';
10
+
11
+ parent::__construct();
12
+
13
+ $this->_removeButton('reset');
14
+ $this->_removeButton('delete');
15
+ $this->_updateButton('save', 'label', Mage::helper('sales')->__('Send Tracking Information'));
16
+ $this->_updateButton('save', 'onclick', "setLocation('".$this->getEmailUrl()."')");
17
+
18
+ //Ajout de l'impression de l'étiquette
19
+ $_order = $this->getShipment()->getOrder();
20
+ $_shippingMethod = explode("_",$_order->getShippingMethod());
21
+ if (($_shippingMethod[0] == 'chronorelais' || $_shippingMethod[0] == 'chronopost' || $_shippingMethod[0] == 'chronoexpress')) {
22
+ $this->_addButton('etiquette', array(
23
+ 'label' => Mage::helper('chronorelais')->__('Etiquette Chronopost'),
24
+ 'class' => 'save',
25
+ 'onclick' => 'setLocation(\'' . $this->getPrintMondialRelayUrl() . '\')'
26
+ )
27
+ );
28
+ }
29
+
30
+ if ($this->getShipment()->getId()) {
31
+ $this->_addButton('print', array(
32
+ 'label' => Mage::helper('sales')->__('Print'),
33
+ 'class' => 'save',
34
+ 'onclick' => 'setLocation(\''.$this->getPrintUrl().'\')'
35
+ )
36
+ );
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Retrieve shipment model instance
42
+ *
43
+ * @return Mage_Sales_Model_Order_Shipment
44
+ */
45
+ public function getShipment()
46
+ {
47
+ return Mage::registry('current_shipment');
48
+ }
49
+
50
+ public function getHeaderText()
51
+ {
52
+ if ($this->getShipment()->getEmailSent()) {
53
+ $emailSent = Mage::helper('sales')->__('Shipment email sent');
54
+ }
55
+ else {
56
+ $emailSent = Mage::helper('sales')->__('Shipment email not sent');
57
+ }
58
+
59
+ $header = Mage::helper('sales')->__('Shipment #%s (%s)', $this->getShipment()->getIncrementId(), $emailSent);
60
+ return $header;
61
+ }
62
+
63
+ public function getBackUrl()
64
+ {
65
+ return $this->getUrl(
66
+ '*/sales_order/view',
67
+ array(
68
+ 'order_id' => $this->getShipment()->getOrderId(),
69
+ 'active_tab'=> 'order_shipments'
70
+ ));
71
+ }
72
+
73
+ public function getEmailUrl()
74
+ {
75
+ return $this->getUrl('*/sales_order_shipment/email', array('shipment_id' => $this->getShipment()->getId()));
76
+ }
77
+
78
+ public function getPrintUrl()
79
+ {
80
+ return $this->getUrl('*/*/print', array(
81
+ 'invoice_id' => $this->getShipment()->getId()
82
+ ));
83
+ }
84
+
85
+ public function getPrintMondialRelayUrl()
86
+ {
87
+ return $this->getUrl('chronorelais/sales_impression/print', array(
88
+ 'shipment_id' => $this->getShipment()->getId()
89
+ ));
90
+ }
91
+
92
+ public function updateBackButtonUrl($flag)
93
+ {
94
+ if ($flag) {
95
+ return $this->_updateButton('back', 'onclick', 'setLocation(\'' . $this->getUrl('*/sales_shipment/') . '\')');
96
+ }
97
+ return $this;
98
+ }
99
  }
app/code/community/Chronopost/Chronorelais/Block/Sales/Shipment/Copy of Grid.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Chronopost_Chronorelais_Block_Sales_Shipment_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('sales_shipment_grid');
9
+ $this->setDefaultSort('order_created_at');
10
+ $this->setDefaultDir('DESC');
11
+ }
12
+
13
+ /**
14
+ * Retrieve collection class
15
+ *
16
+ * @return string
17
+ */
18
+ protected function _getCollectionClass()
19
+ {
20
+ return 'sales/order_shipment_grid_collection';
21
+ }
22
+
23
+ protected function _prepareCollection()
24
+ {
25
+ $collection = Mage::getResourceModel($this->_getCollectionClass());
26
+ $collection->getSelect()->columns(array('shipment_created_at' => 'main_table.created_at'));
27
+ $collection->getSelect()->columns(array('shipment_increment_id' => 'main_table.increment_id'));
28
+
29
+ $collection->getSelect()->joinLeft(array('ot' => $collection->getTable('sales/order')), 'main_table.order_id = ot.entity_id');
30
+ $collection->getSelect()->joinLeft(array('ost' => $collection->getTable('sales/shipment_track')), 'ot.entity_id = ost.order_id');
31
+
32
+ $collection->getSelect()->where('ot.shipping_method LIKE "chronorelais%" OR ot.shipping_method LIKE "chronopost%"');
33
+ $this->setCollection($collection);
34
+ return parent::_prepareCollection();
35
+ }
36
+
37
+ protected function _prepareColumns()
38
+ {
39
+ $this->addColumn('increment_id', array(
40
+ 'header' => Mage::helper('sales')->__('Shipment #'),
41
+ 'index' => 'shipment_increment_id',
42
+ 'type' => 'text',
43
+ ));
44
+
45
+ $this->addColumn('shipment_created_at', array(
46
+ 'header' => Mage::helper('sales')->__('Date Shipped'),
47
+ 'index' => 'shipment_created_at',
48
+ 'type' => 'datetime',
49
+ ));
50
+
51
+ $this->addColumn('order_increment_id', array(
52
+ 'header' => Mage::helper('sales')->__('Order #'),
53
+ 'index' => 'order_increment_id',
54
+ 'type' => 'number',
55
+ ));
56
+
57
+ $this->addColumn('order_created_at', array(
58
+ 'header' => Mage::helper('sales')->__('Order Date'),
59
+ 'index' => 'order_created_at',
60
+ 'type' => 'datetime',
61
+ ));
62
+
63
+ $this->addColumn('shipping_name', array(
64
+ 'header' => Mage::helper('sales')->__('Ship to Name'),
65
+ 'index' => 'shipping_name',
66
+ ));
67
+
68
+ $this->addColumn('total_qty', array(
69
+ 'header' => Mage::helper('sales')->__('Total Qty'),
70
+ 'index' => 'total_qty',
71
+ 'type' => 'number',
72
+ ));
73
+
74
+ $this->addColumn('number', array(
75
+ 'header' => Mage::helper('sales')->__('Tracking'),
76
+ 'index' => 'number',
77
+ ));
78
+
79
+ $this->addColumn('title', array(
80
+ 'header' => Mage::helper('sales')->__('Mode de transport'),
81
+ 'index' => 'title',
82
+ 'type' => 'text',
83
+ ));
84
+
85
+ $this->addColumn('download', array(
86
+ 'header' => Mage::helper('chronorelais')->__('Etiquettes'),
87
+ 'type' => 'action',
88
+ 'getter' => 'getParentId',
89
+ 'actions' => array(
90
+ array(
91
+ 'caption' => Mage::helper('chronorelais')->__('Imprimer'),
92
+ 'url' => array(
93
+ 'base'=>'chronorelais/sales_impression/print'
94
+ ),
95
+ 'field' => 'shipment_id'
96
+ )
97
+ ),
98
+ 'filter' => false,
99
+ 'sortable' => false,
100
+ 'index' => 'stores'
101
+ ));
102
+
103
+ return parent::_prepareColumns();
104
+ }
105
+
106
+ public function getRowUrl($row)
107
+ {
108
+ if (!Mage::getSingleton('admin/session')->isAllowed('sales/order/shipment')) {
109
+ return false;
110
+ }
111
+
112
+ return $this->getUrl('adminhtml/sales_shipment/view',
113
+ array(
114
+ 'shipment_id'=> $row->getParentId(),
115
+ )
116
+ );
117
+ }
118
+
119
+ protected function _prepareMassaction()
120
+ {
121
+ $this->setMassactionIdField('entity_id');
122
+ $this->getMassactionBlock()->setFormFieldName('shipment_ids');
123
+ $this->getMassactionBlock()->setUseSelectAll(false);
124
+
125
+ // Impression des étiquettes
126
+ /*$this->getMassactionBlock()->addItem('pdfshipments_order', array(
127
+ 'label'=> Mage::helper('sales')->__('Imprimer les étiquettes'),
128
+ 'url' => $this->getUrl('chronorelais/sales_impression/printMass'),
129
+ ));*/
130
+
131
+ return $this;
132
+ }
133
+
134
+ public function getGridUrl()
135
+ {
136
+ return $this->getUrl('*/*/*', array('_current' => true));
137
+ }
138
+
139
+ }
app/code/community/Chronopost/Chronorelais/Block/Sales/Shipment/Grid-bkp-03-02-11.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Chronopost_Chronorelais_Block_Sales_Shipment_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('sales_shipment_grid');
9
+ $this->setDefaultSort('shipment_created_at');
10
+ $this->setDefaultDir('DESC');
11
+ }
12
+
13
+ /**
14
+ * Retrieve collection class
15
+ *
16
+ * @return string
17
+ */
18
+ protected function _getCollectionClass()
19
+ {
20
+ return 'sales/order_collection';
21
+ }
22
+
23
+ protected function _prepareCollection()
24
+ {
25
+ $collection = Mage::getResourceModel($this->_getCollectionClass());
26
+ $collection->getSelect()->columns(array('shipment_created_at' => 'osg.created_at'));
27
+ $collection->getSelect()->columns(array('shipment_increment_id' => 'osg.increment_id'));
28
+ $collection->getSelect()->columns(array('shipping_method' => 'main_table.shipping_method'));
29
+
30
+ $collection->getSelect()->joinLeft(array('ost' => $collection->getTable('sales/shipment_track')), 'main_table.entity_id = ost.order_id', array('if(isNull(ost.number) , "--" , ost.number) as number', 'if(isNull(ost.title) , "--" , ost.title) as title'));
31
+ $collection->getSelect()->joinRight(array('osg' => $collection->getTable('sales/shipment_grid')), 'osg.order_id = main_table.entity_id');
32
+ $collection->getSelect()->where('shipping_method LIKE "chronorelais%" OR shipping_method LIKE "chronopost%"');
33
+ $collection->getSelect()->group('osg.entity_id');
34
+
35
+
36
+ $this->setCollection($collection);
37
+
38
+ return parent::_prepareCollection();
39
+ }
40
+
41
+ protected function _prepareColumns()
42
+ {
43
+ $this->addColumn('increment_id', array(
44
+ 'header' => Mage::helper('sales')->__('Shipment #'),
45
+ 'index' => 'shipment_increment_id',
46
+ 'type' => 'text',
47
+ ));
48
+
49
+ $this->addColumn('shipment_created_at', array(
50
+ 'header' => Mage::helper('sales')->__('Date Shipped'),
51
+ 'index' => 'shipment_created_at',
52
+ 'type' => 'datetime',
53
+ ));
54
+
55
+ $this->addColumn('order_increment_id', array(
56
+ 'header' => Mage::helper('sales')->__('Order #'),
57
+ 'index' => 'order_increment_id',
58
+ 'type' => 'number',
59
+ ));
60
+
61
+ $this->addColumn('order_created_at', array(
62
+ 'header' => Mage::helper('sales')->__('Order Date'),
63
+ 'index' => 'order_created_at',
64
+ 'type' => 'datetime',
65
+ ));
66
+
67
+ $this->addColumn('shipping_name', array(
68
+ 'header' => Mage::helper('sales')->__('Ship to Name'),
69
+ 'index' => 'shipping_name',
70
+ ));
71
+
72
+ $this->addColumn('total_qty', array(
73
+ 'header' => Mage::helper('sales')->__('Total Qty'),
74
+ 'index' => 'total_qty',
75
+ 'type' => 'number',
76
+ ));
77
+
78
+ $this->addColumn('number', array(
79
+ 'header' => Mage::helper('sales')->__('Tracking'),
80
+ 'index' => 'number',
81
+ ));
82
+
83
+ $this->addColumn('title', array(
84
+ 'header' => Mage::helper('sales')->__('Mode de transport'),
85
+ 'index' => 'title',
86
+ 'type' => 'text',
87
+ ));
88
+
89
+ $this->addColumn('download', array(
90
+ 'header' => Mage::helper('chronorelais')->__('Etiquettes'),
91
+ 'type' => 'action',
92
+ 'getter' => 'getId',
93
+ 'actions' => array(
94
+ array(
95
+ 'caption' => Mage::helper('chronorelais')->__('Imprimer'),
96
+ 'url' => array(
97
+ 'base'=>'chronorelais/sales_impression/print'
98
+ ),
99
+ 'field' => 'shipment_id'
100
+ )
101
+ ),
102
+ 'filter' => false,
103
+ 'sortable' => false,
104
+ 'index' => 'stores'
105
+ ));
106
+
107
+ return parent::_prepareColumns();
108
+ }
109
+
110
+ public function getRowUrl($row)
111
+ {
112
+ if (!Mage::getSingleton('admin/session')->isAllowed('sales/order/shipment')) {
113
+ return false;
114
+ }
115
+
116
+ return $this->getUrl('adminhtml/sales_shipment/view',
117
+ array(
118
+ 'shipment_id'=> $row->getId(),
119
+ )
120
+ );
121
+ }
122
+
123
+ protected function _prepareMassaction()
124
+ {
125
+ $this->setMassactionIdField('entity_id');
126
+ $this->getMassactionBlock()->setFormFieldName('shipment_ids');
127
+ $this->getMassactionBlock()->setUseSelectAll(false);
128
+
129
+ // Impression des étiquettes
130
+ /*$this->getMassactionBlock()->addItem('pdfshipments_order', array(
131
+ 'label'=> Mage::helper('sales')->__('Imprimer les étiquettes'),
132
+ 'url' => $this->getUrl('chronorelais/sales_impression/printMass'),
133
+ ));*/
134
+
135
+ return $this;
136
+ }
137
+
138
+ public function getGridUrl()
139
+ {
140
+ return $this->getUrl('*/*/*', array('_current' => true));
141
+ }
142
+
143
+ }
app/code/community/Chronopost/Chronorelais/Block/Sales/Shipment/Grid.php CHANGED
@@ -22,26 +22,26 @@ class Chronopost_Chronorelais_Block_Sales_Shipment_Grid extends Mage_Adminhtml_B
22
 
23
  protected function _prepareCollection()
24
  {
25
- $_chronopost_deliver_saturday = Mage::helper('chronorelais')->getConfigData('carriers/chronopost/deliver_on_saturday');
26
- $_chronorelais_deliver_saturday = Mage::helper('chronorelais')->getConfigData('carriers/chronorelais/deliver_on_saturday');
27
- if($_chronopost_deliver_saturday==1) { $_chronopost_deliver_saturday = 'Yes'; } else { $_chronopost_deliver_saturday = 'No';}
28
- if($_chronorelais_deliver_saturday==1) { $_chronorelais_deliver_saturday = 'Yes'; } else { $_chronorelais_deliver_saturday = 'No'; }
29
-
30
- $collection = Mage::getResourceModel($this->_getCollectionClass());
31
- $collection->getSelect()->joinLeft(array('og' => $collection->getTable('sales/order')), 'main_table.entity_id = og.entity_id', array('CASE LOWER(SUBSTRING_INDEX(og.shipping_method,"_","1")) WHEN "chronoexpress" THEN "Chrono Express" WHEN "chronorelais" THEN "Chrono Relais" ELSE CONCAT(UCASE(SUBSTRING(SUBSTRING_INDEX(og.shipping_method,"_","1"),1,1)),LOWER(SUBSTRING(SUBSTRING_INDEX(og.shipping_method,"_","1"), 2))) END as shipping_method', 'og.total_qty_ordered'));
32
- $collection->getSelect()->joinLeft(array('osg' => $collection->getTable('sales/shipment_grid')), 'main_table.entity_id = osg.order_id', array('if(isNull(osg.increment_id) , "--" , GROUP_CONCAT(DISTINCT osg.increment_id SEPARATOR \', \')) as shipment_increment_id', 'GROUP_CONCAT(DISTINCT osg.created_at SEPARATOR \', \') as shipment_created_at'));
33
- $collection->getSelect()->joinLeft(array('ost' => $collection->getTable('sales/shipment_track')), 'main_table.entity_id = ost.order_id', array('if(isNull(ost.track_number) , "--" , GROUP_CONCAT(DISTINCT ost.track_number SEPARATOR \', \')) as track_number', 'if(isNull(ost.title) , "--" , GROUP_CONCAT(DISTINCT ost.title SEPARATOR \', \')) as title'));
34
- $collection->getSelect()->joinLeft(array('oes' => Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status')), 'main_table.entity_id = oes.order_id', array("if(isNull(oes.livraison_le_samedi), CASE LOWER(SUBSTRING_INDEX(og.shipping_method,'_','1')) WHEN 'chronopost' THEN '$_chronopost_deliver_saturday' WHEN 'chronorelais' THEN '$_chronorelais_deliver_saturday' WHEN 'chronoexpress' THEN '--' ELSE 'No' END, oes.livraison_le_samedi) as livraison_le_samedi"));
35
- $collection->getSelect()->where('og.shipping_method LIKE "chronorelais%" OR og.shipping_method LIKE "chronopost%" OR og.shipping_method LIKE "chronoexpress%"');
36
- $collection->getSelect()->group('main_table.entity_id');
37
- $sql = $collection->getSelectSql(true);
38
- $collection->getSelect()->reset()->from(
39
- array('e' =>new Zend_Db_Expr("({$sql})")),
40
- array('e' => "*")
41
- );
42
-
43
- $this->setCollection($collection);
44
- return parent::_prepareCollection();
45
  }
46
 
47
  protected function _prepareColumns()
@@ -90,9 +90,9 @@ class Chronopost_Chronorelais_Block_Sales_Shipment_Grid extends Mage_Adminhtml_B
90
  'filter' => false,
91
  ));
92
 
93
- $this->addColumn('track_number', array(
94
  'header' => Mage::helper('sales')->__('Tracking'),
95
- 'index' => 'track_number',
96
  'filter' => false,
97
  ));
98
 
@@ -115,21 +115,21 @@ class Chronopost_Chronorelais_Block_Sales_Shipment_Grid extends Mage_Adminhtml_B
115
 
116
  $this->addColumn('download', array(
117
  'header' => Mage::helper('chronorelais')->__('Etiquettes'),
118
- 'type' => 'action',
119
- 'getter' => 'getId',
120
- 'actions' => array(
121
- array(
122
- 'caption' => Mage::helper('chronorelais')->__('Imprimer'),
123
- 'url' => array(
124
- 'base'=>'chronorelais/sales_impression/print'
125
- ),
126
- 'target' => '_blank',
127
- 'field' => 'order_id'
128
- )
129
- ),
130
- 'filter' => false,
131
- 'sortable' => false,
132
- 'index' => 'stores'
133
  ));
134
 
135
  return parent::_prepareColumns();
@@ -181,23 +181,5 @@ class Chronopost_Chronorelais_Block_Sales_Shipment_Grid extends Mage_Adminhtml_B
181
  {
182
  return $this->getUrl('*/*/*', array('_current' => true));
183
  }
184
-
185
- public function getAdditionalJavaScript()
186
- {
187
- echo "$$('#sales_order_grid_table tr td:nth-child(3)').each(function(item) {
188
- var chaine = item.innerHTML.replace(/^\s+/g,'').replace(/\s+$/g,'');
189
- if (chaine.split(', ').length > 1) {
190
- var content = '';
191
- var numbers = chaine.split(', ');
192
- var lien = $(item).next('.last').down('a');
193
- for (var i=0; i<numbers.length; i++) {
194
- content += '<a href=\"' + lien.href.replace(/\/order_id\/\d+\//, '/shipment_increment_id/' + numbers[i] + '/') + '\" target=\"_blank\">Exp&eacute;dition ' + numbers[i] + '</a><br />';
195
- }
196
- content += '';
197
- lien.up().innerHTML = content;
198
- //lien.writeAttribute('onclick', \"$(this).up().down('div').show(); return false;\");
199
- }
200
- });";
201
- }
202
 
203
  }
22
 
23
  protected function _prepareCollection()
24
  {
25
+ $_chronopost_deliver_saturday = Mage::helper('chronorelais')->getConfigData('carriers/chronopost/deliver_on_saturday');
26
+ $_chronorelais_deliver_saturday = Mage::helper('chronorelais')->getConfigData('carriers/chronorelais/deliver_on_saturday');
27
+ if($_chronopost_deliver_saturday==1) { $_chronopost_deliver_saturday = 'Yes'; } else { $_chronopost_deliver_saturday = 'No';}
28
+ if($_chronorelais_deliver_saturday==1) { $_chronorelais_deliver_saturday = 'Yes'; } else { $_chronorelais_deliver_saturday = 'No'; }
29
+
30
+ $collection = Mage::getResourceModel($this->_getCollectionClass());
31
+ $collection->getSelect()->joinLeft(array('og' => $collection->getTable('sales/order')), 'main_table.entity_id = og.entity_id', array('CASE LOWER(SUBSTRING_INDEX(og.shipping_method,"_","1")) WHEN "chronoexpress" THEN "Chrono Express" WHEN "chronorelais" THEN "Chrono Relais" ELSE CONCAT(UCASE(SUBSTRING(SUBSTRING_INDEX(og.shipping_method,"_","1"),1,1)),LOWER(SUBSTRING(SUBSTRING_INDEX(og.shipping_method,"_","1"), 2))) END as shipping_method', 'og.total_qty_ordered'));
32
+ $collection->getSelect()->joinLeft(array('osg' => $collection->getTable('sales/shipment_grid')), 'main_table.entity_id = osg.order_id', array('if(isNull(osg.increment_id) , "--" , osg.increment_id) as shipment_increment_id', 'osg.created_at as shipment_created_at'));
33
+ $collection->getSelect()->joinLeft(array('ost' => $collection->getTable('sales/shipment_track')), 'main_table.entity_id = ost.order_id', array('if(isNull(ost.number) , "--" , ost.number) as number', 'if(isNull(ost.title) , "--" , ost.title) as title'));
34
+ $collection->getSelect()->joinLeft(array('oes' => Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status')), 'main_table.entity_id = oes.order_id', array("if(isNull(oes.livraison_le_samedi), CASE LOWER(SUBSTRING_INDEX(og.shipping_method,'_','1')) WHEN 'chronopost' THEN '$_chronopost_deliver_saturday' WHEN 'chronorelais' THEN '$_chronorelais_deliver_saturday' WHEN 'chronoexpress' THEN '--' ELSE 'No' END, oes.livraison_le_samedi) as livraison_le_samedi"));
35
+ $collection->getSelect()->where('og.shipping_method LIKE "chronorelais%" OR og.shipping_method LIKE "chronopost%" OR og.shipping_method LIKE "chronoexpress%"');
36
+ $collection->getSelect()->group('main_table.entity_id');
37
+ $sql = $collection->getSelectSql(true);
38
+ $collection->getSelect()->reset()->from(
39
+ array('e' =>new Zend_Db_Expr("({$sql})")),
40
+ array('e' => "*")
41
+ );
42
+
43
+ $this->setCollection($collection);
44
+ return parent::_prepareCollection();
45
  }
46
 
47
  protected function _prepareColumns()
90
  'filter' => false,
91
  ));
92
 
93
+ $this->addColumn('number', array(
94
  'header' => Mage::helper('sales')->__('Tracking'),
95
+ 'index' => 'number',
96
  'filter' => false,
97
  ));
98
 
115
 
116
  $this->addColumn('download', array(
117
  'header' => Mage::helper('chronorelais')->__('Etiquettes'),
118
+ 'type' => 'action',
119
+ 'getter' => 'getId',
120
+ 'actions' => array(
121
+ array(
122
+ 'caption' => Mage::helper('chronorelais')->__('Imprimer'),
123
+ 'url' => array(
124
+ 'base'=>'chronorelais/sales_impression/print'
125
+ ),
126
+ 'target' => '_blank',
127
+ 'field' => 'order_id'
128
+ )
129
+ ),
130
+ 'filter' => false,
131
+ 'sortable' => false,
132
+ 'index' => 'stores'
133
  ));
134
 
135
  return parent::_prepareColumns();
181
  {
182
  return $this->getUrl('*/*/*', array('_current' => true));
183
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  }
app/code/community/Chronopost/Chronorelais/Controller/Abstract.php CHANGED
@@ -1,126 +1,126 @@
1
- <?php
2
-
3
- /**
4
- * Magento Chronopost Chronorelais 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 Chronopost
17
- * @package Chronopost_Chronorelais
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 Chronopost_Chronorelais_Controller_Abstract extends Mage_Adminhtml_Controller_Action
24
- {
25
- public function __() {
26
- $args = func_get_args();
27
- $message = array_shift($args);
28
- if ($message instanceof OS_Message) {
29
- $args = $message->args;
30
- $message = $message->message;
31
- }
32
-
33
- $output = Mage::helper('shipping')->__($message);
34
- if (count($args)==0) return $output;
35
-
36
- if (!isset($this->_translate_inline)) $this->_translate_inline = Mage::getSingleton('core/translate')->getTranslateInline();
37
- if ($this->_translate_inline) {
38
- $parts = explode('}}{{',$output);
39
- $parts[0] = vsprintf($parts[0],$args);
40
- return implode('}}{{',$parts);
41
- }
42
- else return vsprintf($output,$args);
43
- }
44
-
45
- protected function getIncludingPath($path) {
46
- if (file_exists(dirname(__FILE__).'/Chronopost_Chronorelais_includes_'.$path)) {
47
- return 'Chronopost_Chronorelais_includes_'.$path;
48
- } else {
49
- return Mage::getBaseDir('code').'/community/Chronopost/Chronorelais/includes/'.$path;
50
- }
51
- }
52
-
53
- protected function getMimeType($extension) {
54
- $mime_type_array = array(
55
- '.gz' => 'application/x-gzip',
56
- '.tgz' => 'application/x-gzip',
57
- '.zip' => 'application/zip',
58
- '.pdf' => 'application/pdf',
59
- '.png' => 'image/png',
60
- '.gif' => 'image/gif',
61
- '.jpg' => 'image/jpeg',
62
- '.jpeg' => 'image/jpeg',
63
- '.txt' => 'text/plain',
64
- '.htm' => 'text/html',
65
- '.html' => 'text/html',
66
- '.mpg' => 'video/mpeg',
67
- '.avi' => 'video/x-msvideo',
68
- );
69
- return isset($mime_type_array[$extension]) ? $mime_type_array[$extension] : 'application/octet-stream';
70
- }
71
-
72
- protected function forceDownload($filename, $content) {
73
- if (headers_sent()) {
74
- trigger_error('forceDownload($filename) - Headers have already been sent',E_USER_ERROR);
75
- return false;
76
- }
77
-
78
- $extension = strrchr($filename,'.');
79
- $mime_type = $this->getMimeType($extension);
80
-
81
- header('Content-disposition: attachment; filename="'.$filename.'"');
82
- header('Content-Type: application/force-download');
83
- header('Content-Transfer-Encoding: '.$mime_type."\n"); // Surtout ne pas enlever le \n
84
- //header('Content-Length: '.filesize($filename));
85
- header('Pragma: no-cache');
86
- header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
87
- header('Expires: 0');
88
- echo $content;
89
- return true;
90
- }
91
-
92
- protected function jsEscape($input) {
93
- return str_replace(array("\r\n","\r","\n","'"),array("\\n","\\n","\\n","\\'"),$input);
94
- }
95
-
96
- protected function cleanKey($key) {
97
- return preg_replace('/[^a-z0-9-_]/i','_-_',$key);
98
- }
99
-
100
- protected function page($id, $title, $content) {
101
- return "<div id=\"ocseditor-".$id."-page\" class=\"ocseditor-page\">"
102
- .$this->pageHeader($title,$this->button('Close',"ocseditor.closePage(this);",'cancel'))
103
- ."<div class=\"page-content\">".$content."</div>"
104
- ."</div>"
105
- ;
106
- }
107
-
108
- protected function pageHeader($title, $buttons) {
109
- return "<div class=\"content-header\">"
110
- ."<table cellspacing=\"0\"><tr>"
111
- ."<td><h3>".$this->__($title)."</h3></td>"
112
- ."<td class=\"form-buttons\">"
113
- .$buttons
114
- ."</td>"
115
- ."</tr></table>"
116
- ."</div>"
117
- ;
118
- }
119
-
120
- protected function button($label, $onclick, $class_name='') {
121
- $class_name = 'scalable'.($class_name!='' ? ' '.$class_name : '');
122
- return "<button type=\"button\" class=\"".$class_name."\" onclick=\"".$onclick."\"><span>".$this->__($label)."</span></button>";
123
- }
124
- }
125
-
126
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Magento Chronopost Chronorelais 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 Chronopost
17
+ * @package Chronopost_Chronorelais
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 Chronopost_Chronorelais_Controller_Abstract extends Mage_Adminhtml_Controller_Action
24
+ {
25
+ public function __() {
26
+ $args = func_get_args();
27
+ $message = array_shift($args);
28
+ if ($message instanceof OS_Message) {
29
+ $args = $message->args;
30
+ $message = $message->message;
31
+ }
32
+
33
+ $output = Mage::helper('shipping')->__($message);
34
+ if (count($args)==0) return $output;
35
+
36
+ if (!isset($this->_translate_inline)) $this->_translate_inline = Mage::getSingleton('core/translate')->getTranslateInline();
37
+ if ($this->_translate_inline) {
38
+ $parts = explode('}}{{',$output);
39
+ $parts[0] = vsprintf($parts[0],$args);
40
+ return implode('}}{{',$parts);
41
+ }
42
+ else return vsprintf($output,$args);
43
+ }
44
+
45
+ protected function getIncludingPath($path) {
46
+ if (file_exists(dirname(__FILE__).'/Chronopost_Chronorelais_includes_'.$path)) {
47
+ return 'Chronopost_Chronorelais_includes_'.$path;
48
+ } else {
49
+ return Mage::getBaseDir('code').'/community/Chronopost/Chronorelais/includes/'.$path;
50
+ }
51
+ }
52
+
53
+ protected function getMimeType($extension) {
54
+ $mime_type_array = array(
55
+ '.gz' => 'application/x-gzip',
56
+ '.tgz' => 'application/x-gzip',
57
+ '.zip' => 'application/zip',
58
+ '.pdf' => 'application/pdf',
59
+ '.png' => 'image/png',
60
+ '.gif' => 'image/gif',
61
+ '.jpg' => 'image/jpeg',
62
+ '.jpeg' => 'image/jpeg',
63
+ '.txt' => 'text/plain',
64
+ '.htm' => 'text/html',
65
+ '.html' => 'text/html',
66
+ '.mpg' => 'video/mpeg',
67
+ '.avi' => 'video/x-msvideo',
68
+ );
69
+ return isset($mime_type_array[$extension]) ? $mime_type_array[$extension] : 'application/octet-stream';
70
+ }
71
+
72
+ protected function forceDownload($filename, $content) {
73
+ if (headers_sent()) {
74
+ trigger_error('forceDownload($filename) - Headers have already been sent',E_USER_ERROR);
75
+ return false;
76
+ }
77
+
78
+ $extension = strrchr($filename,'.');
79
+ $mime_type = $this->getMimeType($extension);
80
+
81
+ header('Content-disposition: attachment; filename="'.$filename.'"');
82
+ header('Content-Type: application/force-download');
83
+ header('Content-Transfer-Encoding: '.$mime_type."\n"); // Surtout ne pas enlever le \n
84
+ //header('Content-Length: '.filesize($filename));
85
+ header('Pragma: no-cache');
86
+ header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
87
+ header('Expires: 0');
88
+ echo $content;
89
+ return true;
90
+ }
91
+
92
+ protected function jsEscape($input) {
93
+ return str_replace(array("\r\n","\r","\n","'"),array("\\n","\\n","\\n","\\'"),$input);
94
+ }
95
+
96
+ protected function cleanKey($key) {
97
+ return preg_replace('/[^a-z0-9-_]/i','_-_',$key);
98
+ }
99
+
100
+ protected function page($id, $title, $content) {
101
+ return "<div id=\"ocseditor-".$id."-page\" class=\"ocseditor-page\">"
102
+ .$this->pageHeader($title,$this->button('Close',"ocseditor.closePage(this);",'cancel'))
103
+ ."<div class=\"page-content\">".$content."</div>"
104
+ ."</div>"
105
+ ;
106
+ }
107
+
108
+ protected function pageHeader($title, $buttons) {
109
+ return "<div class=\"content-header\">"
110
+ ."<table cellspacing=\"0\"><tr>"
111
+ ."<td><h3>".$this->__($title)."</h3></td>"
112
+ ."<td class=\"form-buttons\">"
113
+ .$buttons
114
+ ."</td>"
115
+ ."</tr></table>"
116
+ ."</div>"
117
+ ;
118
+ }
119
+
120
+ protected function button($label, $onclick, $class_name='') {
121
+ $class_name = 'scalable'.($class_name!='' ? ' '.$class_name : '');
122
+ return "<button type=\"button\" class=\"".$class_name."\" onclick=\"".$onclick."\"><span>".$this->__($label)."</span></button>";
123
+ }
124
+ }
125
+
126
  ?>
app/code/community/Chronopost/Chronorelais/Helper/Data.php CHANGED
@@ -1,177 +1,177 @@
1
- <?php
2
- class Chronopost_Chronorelais_Helper_Data extends Mage_Core_Helper_Abstract
3
- {
4
- //Choronorelais settings for productCode
5
- const CHRONO_POST = '01'; // for France
6
- const CHRONO_EXPRESS = '17'; // for Interantional
7
- const CHRONORELAIS = '86'; // for Chronorelais
8
- const CHRONOPOST_13H = '13H'; // for France
9
- const CHRONOEXPRESS_EI = 'EI'; // for Interantional
10
- const CHRONORELAIS_PR = 'PR'; // for Chronorelais
11
- const CHRONOPOST_DEFAULT_COUNTRY = 'FR';
12
- const CHRONOPOST_TRACKING_URL = 'http://wsshipping.chronopost.fr/shipping/services/getReservedSkybill?reservationNumber={trackingNumber}';
13
- // if you are in a period outside thursday 18:00 to friday 15:00, there is no shipping on saturday
14
- var $SaturdayShippingDays = array(
15
- 'startday' => 'thursday',
16
- 'endday' => 'friday',
17
- 'starttime' => '18:00:00',
18
- 'endtime' => '15:00:00'
19
- );
20
-
21
- public function getConfigData($path) {
22
- return Mage::getStoreConfig($path, Mage::app()->getStore());
23
- }
24
- public function getSaturdayShippingDays() {
25
- return $this->SaturdayShippingDays;
26
- }
27
- public function getCurrentTimeByZone($timezone="Europe/Paris", $format="l H:i") {
28
- $d = new DateTime("now", new DateTimeZone($timezone));
29
- return $d->format($format);
30
- }
31
- public function isSendingDay() {
32
- $shipping_days = $this->getSaturdayShippingDays();
33
- $current_day = strtolower($this->getCurrentTimeByZone("Europe/Paris", "l"));
34
- $current_date = $this->getCurrentTimeByZone("Europe/Paris", "Y-m-d H:i:s");
35
- $current_datetime = explode(' ',$current_date);
36
-
37
- //get timestamps
38
- $start_timestamp = strtotime($current_datetime[0]." ".$shipping_days['starttime']);
39
- $end_timestamp = strtotime($current_datetime[0]." ".$shipping_days['endtime']);
40
- $current_timestamp = strtotime($current_date);
41
-
42
- $sending_day = false;
43
- if($shipping_days['startday']==$current_day && $current_timestamp>=$start_timestamp) {
44
- $sending_day = true;
45
- } elseif($shipping_days['endday']==$current_day && $current_timestamp<=$end_timestamp) {
46
- $sending_day = true;
47
- }
48
- return $sending_day;
49
- }
50
-
51
- /**
52
- * General Shipping configuration
53
- */
54
- public function getConfigurationAccountNumber() {
55
- return $this->getConfigData('chronorelais/shipping/account_number');
56
- }
57
- public function getConfigurationSubAccountNumber() {
58
- return $this->getConfigData('chronorelais/shipping/sub_account_number');
59
- }
60
- public function getConfigurationAccountPass() {
61
- return $this->getConfigData('chronorelais/shipping/account_pass');
62
- }
63
- public function getConfigurationTrackingViewUrl() {
64
- return $this->getConfigData('chronorelais/shipping/tracking_view_url');
65
- }
66
- public function getConfigurationGoogleMapAPIKey() {
67
- return $this->getConfigData('chronorelais/shipping/google_map_api');
68
- }
69
- public function getChronoProductCode($country, $code='') {
70
- $productcode = '';
71
- $code = strtolower($code);
72
- if($code=='chronorelais') {
73
- $productcode = self::CHRONORELAIS;
74
- } elseif($code=='chronopost') {
75
- $productcode = self::CHRONO_POST;
76
- } else {
77
- $productcode = self::CHRONO_EXPRESS;
78
- }
79
- return $productcode;
80
- }
81
- public function getChronoProductCodeString($code='') {
82
- $productcode = '';
83
- $code = strtolower($code);
84
- if($code=='chronorelais') {
85
- $productcode = self::CHRONORELAIS_PR;
86
- } elseif($code=='chronopost') {
87
- $productcode = self::CHRONOPOST_13H;
88
- } else {
89
- $productcode = self::CHRONOEXPRESS_EI;
90
- }
91
- return $productcode;
92
- }
93
- public function getConfigurationTrackingUrl() {
94
- return self::CHRONOPOST_TRACKING_URL;
95
- }
96
-
97
- /**
98
- * Export configuration
99
- */
100
- public function getConfigurationFileExtension($export_type='css') {
101
- return $this->getConfigData('chronorelais/export_'.$export_type.'/file_extension');
102
- }
103
- public function getConfigurationFileCharset($export_type='css') {
104
- return $this->getConfigData('chronorelais/export_'.$export_type.'/file_charset');
105
- }
106
- public function getConfigurationEndOfLineCharacter($export_type='css') {
107
- return $this->getConfigData('chronorelais/export_'.$export_type.'/endofline_character');
108
- }
109
- public function getConfigurationFieldDelimiter($export_type='css') {
110
- return $this->getConfigData('chronorelais/export_'.$export_type.'/field_delimiter');
111
- }
112
- public function getConfigurationFieldSeparator($export_type='css') {
113
- return $this->getConfigData('chronorelais/export_'.$export_type.'/field_separator');
114
- }
115
-
116
- /**
117
- * Import configuration
118
- */
119
- public function getConfigurationSendEmail() {
120
- return $this->getConfigData('chronorelais/import/send_email');
121
- }
122
- public function getConfigurationIncludeComment() {
123
- return $this->getConfigData('chronorelais/import/include_comment');
124
- }
125
- public function getConfigurationDefaultTrackingTitle() {
126
- return $this->getConfigData('chronorelais/import/default_tracking_title');
127
- }
128
- public function getConfigurationShippingComment() {
129
- return $this->getConfigData('chronorelais/import/shipping_comment');
130
- }
131
-
132
- /**
133
- * Shipper Information
134
- */
135
- public function getConfigurationShipperInfo($field) {
136
- $fieldValue = '';
137
- if($field) {
138
- if($this->getConfigData('chronorelais/shipperinformation/'.$field)) {
139
- $fieldValue = $this->getConfigData('chronorelais/shipperinformation/'.$field);
140
- }
141
- }
142
- return $fieldValue;
143
- }
144
-
145
- /**
146
- * Chronopost Customer Information
147
- */
148
- public function getConfigurationCustomerInfo($field) {
149
- $fieldValue = '';
150
- if($field) {
151
- if($this->getConfigData('chronorelais/customerinformation/'.$field)) {
152
- $fieldValue = $this->getConfigData('chronorelais/customerinformation/'.$field);
153
- }
154
- }
155
- return $fieldValue;
156
- }
157
-
158
- /**
159
- * Import configuration
160
- */
161
- public function getConfigurationSkybillParam() {
162
- return $this->getConfigData('chronorelais/skybillparam/mode');
163
- }
164
-
165
- /* Get Livraison le Samedi status by orderid */
166
- public function getLivraisonSamediStatus($order_id)
167
- {
168
- $_connection = Mage::getSingleton('core/resource')->getConnection('core_write');
169
- $_table = Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status');
170
- $select = $_connection->select()
171
- ->from($_table, 'livraison_le_samedi')
172
- ->where('order_id=?', $order_id);
173
- $status = $_connection->fetchOne($select);
174
- return $status;
175
- }
176
-
177
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ //Choronorelais settings for productCode
5
+ const CHRONO_POST = '01'; // for France
6
+ const CHRONO_EXPRESS = '17'; // for Interantional
7
+ const CHRONORELAIS = '86'; // for Chronorelais
8
+ const CHRONOPOST_13H = '13H'; // for France
9
+ const CHRONOEXPRESS_EI = 'EI'; // for Interantional
10
+ const CHRONORELAIS_PR = 'PR'; // for Chronorelais
11
+ const CHRONOPOST_DEFAULT_COUNTRY = 'FR';
12
+ const CHRONOPOST_TRACKING_URL = 'http://wsshipping.chronopost.fr/shipping/services/getReservedSkybill?reservationNumber={trackingNumber}';
13
+ // if you are in a period outside thursday 18:00 to friday 15:00, there is no shipping on saturday
14
+ var $SaturdayShippingDays = array(
15
+ 'startday' => 'thursday',
16
+ 'endday' => 'friday',
17
+ 'starttime' => '18:00:00',
18
+ 'endtime' => '15:00:00'
19
+ );
20
+
21
+ public function getConfigData($path) {
22
+ return Mage::getStoreConfig($path, Mage::app()->getStore());
23
+ }
24
+ public function getSaturdayShippingDays() {
25
+ return $this->SaturdayShippingDays;
26
+ }
27
+ public function getCurrentTimeByZone($timezone="Europe/Paris", $format="l H:i") {
28
+ $d = new DateTime("now", new DateTimeZone($timezone));
29
+ return $d->format($format);
30
+ }
31
+ public function isSendingDay() {
32
+ $shipping_days = $this->getSaturdayShippingDays();
33
+ $current_day = strtolower($this->getCurrentTimeByZone("Europe/Paris", "l"));
34
+ $current_date = $this->getCurrentTimeByZone("Europe/Paris", "Y-m-d H:i:s");
35
+ $current_datetime = explode(' ',$current_date);
36
+
37
+ //get timestamps
38
+ $start_timestamp = strtotime($current_datetime[0]." ".$shipping_days['starttime']);
39
+ $end_timestamp = strtotime($current_datetime[0]." ".$shipping_days['endtime']);
40
+ $current_timestamp = strtotime($current_date);
41
+
42
+ $sending_day = false;
43
+ if($shipping_days['startday']==$current_day && $current_timestamp>=$start_timestamp) {
44
+ $sending_day = true;
45
+ } elseif($shipping_days['endday']==$current_day && $current_timestamp<=$end_timestamp) {
46
+ $sending_day = true;
47
+ }
48
+ return $sending_day;
49
+ }
50
+
51
+ /**
52
+ * General Shipping configuration
53
+ */
54
+ public function getConfigurationAccountNumber() {
55
+ return $this->getConfigData('chronorelais/shipping/account_number');
56
+ }
57
+ public function getConfigurationSubAccountNumber() {
58
+ return $this->getConfigData('chronorelais/shipping/sub_account_number');
59
+ }
60
+ public function getConfigurationAccountPass() {
61
+ return $this->getConfigData('chronorelais/shipping/account_pass');
62
+ }
63
+ public function getConfigurationTrackingViewUrl() {
64
+ return $this->getConfigData('chronorelais/shipping/tracking_view_url');
65
+ }
66
+ public function getConfigurationGoogleMapAPIKey() {
67
+ return $this->getConfigData('chronorelais/shipping/google_map_api');
68
+ }
69
+ public function getChronoProductCode($country, $code='') {
70
+ $productcode = '';
71
+ $code = strtolower($code);
72
+ if($code=='chronorelais') {
73
+ $productcode = self::CHRONORELAIS;
74
+ } elseif($code=='chronopost') {
75
+ $productcode = self::CHRONO_POST;
76
+ } else {
77
+ $productcode = self::CHRONO_EXPRESS;
78
+ }
79
+ return $productcode;
80
+ }
81
+ public function getChronoProductCodeString($code='') {
82
+ $productcode = '';
83
+ $code = strtolower($code);
84
+ if($code=='chronorelais') {
85
+ $productcode = self::CHRONORELAIS_PR;
86
+ } elseif($code=='chronopost') {
87
+ $productcode = self::CHRONOPOST_13H;
88
+ } else {
89
+ $productcode = self::CHRONOEXPRESS_EI;
90
+ }
91
+ return $productcode;
92
+ }
93
+ public function getConfigurationTrackingUrl() {
94
+ return self::CHRONOPOST_TRACKING_URL;
95
+ }
96
+
97
+ /**
98
+ * Export configuration
99
+ */
100
+ public function getConfigurationFileExtension($export_type='css') {
101
+ return $this->getConfigData('chronorelais/export_'.$export_type.'/file_extension');
102
+ }
103
+ public function getConfigurationFileCharset($export_type='css') {
104
+ return $this->getConfigData('chronorelais/export_'.$export_type.'/file_charset');
105
+ }
106
+ public function getConfigurationEndOfLineCharacter($export_type='css') {
107
+ return $this->getConfigData('chronorelais/export_'.$export_type.'/endofline_character');
108
+ }
109
+ public function getConfigurationFieldDelimiter($export_type='css') {
110
+ return $this->getConfigData('chronorelais/export_'.$export_type.'/field_delimiter');
111
+ }
112
+ public function getConfigurationFieldSeparator($export_type='css') {
113
+ return $this->getConfigData('chronorelais/export_'.$export_type.'/field_separator');
114
+ }
115
+
116
+ /**
117
+ * Import configuration
118
+ */
119
+ public function getConfigurationSendEmail() {
120
+ return $this->getConfigData('chronorelais/import/send_email');
121
+ }
122
+ public function getConfigurationIncludeComment() {
123
+ return $this->getConfigData('chronorelais/import/include_comment');
124
+ }
125
+ public function getConfigurationDefaultTrackingTitle() {
126
+ return $this->getConfigData('chronorelais/import/default_tracking_title');
127
+ }
128
+ public function getConfigurationShippingComment() {
129
+ return $this->getConfigData('chronorelais/import/shipping_comment');
130
+ }
131
+
132
+ /**
133
+ * Shipper Information
134
+ */
135
+ public function getConfigurationShipperInfo($field) {
136
+ $fieldValue = '';
137
+ if($field) {
138
+ if($this->getConfigData('chronorelais/shipperinformation/'.$field)) {
139
+ $fieldValue = $this->getConfigData('chronorelais/shipperinformation/'.$field);
140
+ }
141
+ }
142
+ return $fieldValue;
143
+ }
144
+
145
+ /**
146
+ * Chronopost Customer Information
147
+ */
148
+ public function getConfigurationCustomerInfo($field) {
149
+ $fieldValue = '';
150
+ if($field) {
151
+ if($this->getConfigData('chronorelais/customerinformation/'.$field)) {
152
+ $fieldValue = $this->getConfigData('chronorelais/customerinformation/'.$field);
153
+ }
154
+ }
155
+ return $fieldValue;
156
+ }
157
+
158
+ /**
159
+ * Import configuration
160
+ */
161
+ public function getConfigurationSkybillParam() {
162
+ return $this->getConfigData('chronorelais/skybillparam/mode');
163
+ }
164
+
165
+ /* Get Livraison le Samedi status by orderid */
166
+ public function getLivraisonSamediStatus($order_id)
167
+ {
168
+ $_connection = Mage::getSingleton('core/resource')->getConnection('core_write');
169
+ $_table = Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status');
170
+ $select = $_connection->select()
171
+ ->from($_table, 'livraison_le_samedi')
172
+ ->where('order_id=?', $order_id);
173
+ $status = $_connection->fetchOne($select);
174
+ return $status;
175
+ }
176
+
177
+ }
app/code/community/Chronopost/Chronorelais/Model/Carrier/AbstractChronorelais.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- abstract class Chronopost_Chronorelais_Model_Carrier_AbstractChronorelais extends Varien_Object
3
- {
4
- protected $_code;
5
- protected $_rates = null;
6
- protected $_numBoxes = 1;
7
-
8
- /**
9
- * Whether this carrier has fixed rates calculation
10
- *
11
- * @var bool
12
- */
13
- protected $_isFixed = false;
14
-
15
- const HANDLING_TYPE_PERCENT = 'P';
16
- const HANDLING_TYPE_FIXED = 'F';
17
-
18
- const HANDLING_ACTION_PERPACKAGE = 'P';
19
- const HANDLING_ACTION_PERORDER = 'O';
20
-
21
- /**
22
- * Fields that should be replaced in debug with '***'
23
- *
24
- * @var array
25
- */
26
- protected $_debugReplacePrivateDataKeys = array();
27
-
28
- public function __construct()
29
- {
30
- }
31
- }
32
  ?>
1
+ <?php
2
+ abstract class Chronopost_Chronorelais_Model_Carrier_AbstractChronorelais extends Varien_Object
3
+ {
4
+ protected $_code;
5
+ protected $_rates = null;
6
+ protected $_numBoxes = 1;
7
+
8
+ /**
9
+ * Whether this carrier has fixed rates calculation
10
+ *
11
+ * @var bool
12
+ */
13
+ protected $_isFixed = false;
14
+
15
+ const HANDLING_TYPE_PERCENT = 'P';
16
+ const HANDLING_TYPE_FIXED = 'F';
17
+
18
+ const HANDLING_ACTION_PERPACKAGE = 'P';
19
+ const HANDLING_ACTION_PERORDER = 'O';
20
+
21
+ /**
22
+ * Fields that should be replaced in debug with '***'
23
+ *
24
+ * @var array
25
+ */
26
+ protected $_debugReplacePrivateDataKeys = array();
27
+
28
+ public function __construct()
29
+ {
30
+ }
31
+ }
32
  ?>
app/code/community/Chronopost/Chronorelais/Model/Carrier/AbstractChronorelaisShipping.php CHANGED
@@ -1,489 +1,489 @@
1
- <?php
2
-
3
- /**
4
- * Magento Chronopost Chronorelais 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 Chronopost
17
- * @package Chronopost_Chronorelais
18
- * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
19
- * @author Antoine Lemoine
20
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
- */
22
-
23
- // Pour g�rer les cas o� il y a eu compilation
24
- if (file_exists(dirname(__FILE__).'/Chronopost_Chronorelais_includes_ChronorelaisShippingHelper.php')) include_once 'Chronopost_Chronorelais_includes_ChronorelaisShippingHelper.php';
25
- else include_once Mage::getBaseDir('code').'/community/Chronopost/Chronorelais/includes/ChronorelaisShippingHelper.php';
26
-
27
-
28
-
29
- class OCS_Magento_Product implements OCS_Product {
30
- private $parent_cart_item;
31
- private $cart_item;
32
- private $cart_product;
33
- private $loaded_product;
34
- private $quantity;
35
-
36
- public function OCS_Magento_Product($cart_item, $parent_cart_item) {
37
- $this->cart_item = $cart_item;
38
- $this->cart_product = $cart_item->getProduct();
39
- $this->parent_cart_item = $parent_cart_item;
40
- $this->quantity = isset($parent_cart_item) ? $parent_cart_item->getQty() : $cart_item->getQty();
41
- }
42
-
43
- public function getOption($option_name, $get_by_id=false) {
44
- $value = null;
45
- $product = $this->cart_product;
46
- foreach ($product->getOptions() as $option) {
47
- if ($option->getTitle()==$option_name) {
48
- $custom_option = $product->getCustomOption('option_'.$option->getId());
49
- if ($custom_option) {
50
- $value = $custom_option->getValue();
51
- if ($option->getType()=='drop_down' && !$get_by_id) {
52
- $option_value = $option->getValueById($value);
53
- if ($option_value) $value = $option_value->getTitle();
54
- }
55
- }
56
- break;
57
- }
58
- }
59
- return $value;
60
- }
61
-
62
- public function getAttribute($attribute_name, $get_by_id=false) {
63
- $value = null;
64
- $product = $this->_getLoadedProduct();
65
- $attribute = $product->getResource()->getAttribute($attribute_name);
66
- if ($attribute) {
67
- $input_type = $attribute->getFrontend()->getInputType();
68
- switch ($input_type) {
69
- case 'select' :
70
- $value = $get_by_id ? $product->getData($attribute_name) : $product->getAttributeText($attribute_name);
71
- break;
72
- default :
73
- $value = $product->getData($attribute_name);
74
- break;
75
- }
76
- }
77
- return $value;
78
- }
79
-
80
- private function _getLoadedProduct() {
81
- if (!isset($this->loaded_product)) $this->loaded_product = Mage::getModel('catalog/product')->load($this->cart_product->getId());
82
- return $this->loaded_product;
83
- }
84
-
85
- public function getQuantity() {
86
- return $this->quantity;
87
- }
88
-
89
- public function getName() {
90
- return $this->cart_product->getName();
91
- }
92
-
93
- public function getSku() {
94
- return $this->cart_product->getSku();
95
- }
96
-
97
- public function getStockData($key) {
98
- $stock = $this->cart_product->getStockItem();
99
- switch ($key) {
100
- case 'is_in_stock':
101
- return (bool)$stock->getIsInStock();
102
- case 'quantity':
103
- $quantity = $stock->getQty();
104
- return $stock->getIsQtyDecimal() ? (float)$quantity : (int)$quantity;
105
- }
106
- return null;
107
- }
108
- }
109
-
110
- abstract class Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
111
- extends Mage_Shipping_Model_Carrier_Abstract
112
- {
113
- protected $_translate_inline;
114
- protected $_result;
115
- protected $_config;
116
- protected $_countries;
117
- protected $_helper;
118
- protected $_messages;
119
-
120
- /**
121
- * Collect rates for this shipping method based on information in $request
122
- *
123
- * @param Mage_Shipping_Model_Rate_Request $data
124
- * @return Mage_Shipping_Model_Rate_Result
125
- */
126
- public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
127
- // skip if not enabled
128
- if (!$this->__getConfigData('active')) return false;
129
-
130
- /*foreach ($request->_data as $key => $data) {
131
- echo $key.' => '.$data.'<br/>';
132
- }*/
133
-
134
- $process = array(
135
- 'request' => $request,
136
- 'result' => Mage::getModel('shipping/rate_result'),
137
- 'cart.items' => array(),
138
- 'products' => array(),
139
- 'data' => array(
140
- 'module.version' => null,
141
- 'carrier.code' => $this->_code,
142
- 'cart.price_excluding_tax' => $request->_data['package_value_with_discount'],
143
- 'cart.price_including_tax' => null,
144
- 'cart.weight' => $request->_data['package_weight'],
145
- 'cart.weight.unit' => null,
146
- 'cart.quantity' => $request->_data['package_qty'],
147
- 'destination.country.code' => $request->_data['dest_country_id'],
148
- 'destination.country.name' => null,
149
- 'destination.region.code' => $request->_data['dest_region_code'],
150
- 'destination.postcode' => $request->_data['dest_postcode'],
151
- 'origin.country.code' => $request->_data['country_id'],
152
- 'origin.country.name' => null,
153
- 'origin.region.code' => $request->_data['region_id'],
154
- 'origin.postcode' => $request->_data['postcode'],
155
- 'customer.group.id' => null,
156
- 'customer.group.code' => null,
157
- 'free_shipping' => $request->getFreeShipping(),
158
- 'store.id' => $request->_data['store_id'],
159
- 'store.code' => null,
160
- 'store.name' => null,
161
- 'store.address' => null,
162
- 'store.phone' => null,
163
- 'date.timestamp' => null,
164
- 'date.year' => null,
165
- 'date.month' => null,
166
- 'date.day' => null,
167
- 'date.hour' => null,
168
- 'date.minute' => null,
169
- 'date.second' => null,
170
- ),
171
- 'stop_to_first_match' => null,
172
- 'config' => null,
173
- );
174
-
175
- $items = $request->getAllItems();
176
- for ($i=0, $n=count($items); $i<$n; $i++) {
177
- $item = $items[$i];
178
- if ($item->getProduct() instanceof Mage_Catalog_Model_Product) $process['cart.items'][$item->getId()] = $item;
179
- }
180
-
181
- $process_result = $this->_process($process);
182
-
183
- return $process['result'];
184
- }
185
-
186
-
187
- public function getAllowedMethods() {
188
- $process = array();
189
- $config = $this->_getConfig();
190
- $allowed_methods = array();
191
- if (count($config)>0) {
192
- foreach ($config as $row) $allowed_methods[$row['*code']] = isset($row['label']) ? $row['label']['value'] : 'No label';
193
- }
194
- return $allowed_methods;
195
- }
196
-
197
- public function isTrackingAvailable() {
198
- return true;
199
- }
200
-
201
- public function getTrackingInfo($tracking_number) {
202
- $tracking_url = Mage::helper('chronorelais')->getConfigurationTrackingViewUrl();
203
- $parts = explode(':',$tracking_number);
204
- if (count($parts)>=2) {
205
- $tracking_number = $parts[1];
206
-
207
- $process = array();
208
- $config = $this->_getConfig();
209
-
210
- if (isset($config[$parts[0]]['tracking_url'])) {
211
- $row = $config[$parts[0]];
212
- $tmp_tracking_url = $this->_helper->getRowProperty($row,'tracking_url');
213
- if (isset($tmp_tracking_url)) $tracking_url = $tmp_tracking_url;
214
- }
215
- }
216
-
217
- $tracking_status = Mage::getModel('shipping/tracking_result_status')
218
- ->setCarrier($this->_code)
219
- ->setCarrierTitle($this->__getConfigData('title'))
220
- ->setTracking($tracking_number)
221
- ->addData(
222
- array(
223
- 'status'=>'<a target="_blank" href="'.str_replace('{tracking_number}',$tracking_number,$tracking_url).'">'.__('track the package').'</a>'
224
- )
225
- )
226
- ;
227
- $tracking_result = Mage::getModel('shipping/tracking_result')
228
- ->append($tracking_status)
229
- ;
230
-
231
- if ($trackings = $tracking_result->getAllTrackings()) return $trackings[0];
232
- return false;
233
- }
234
-
235
-
236
- /***************************************************************************************************************************/
237
-
238
- protected function _process(&$process) {
239
- $store = Mage::app()->getStore($process['data']['store.id']);
240
- $mage_config = Mage::getConfig();
241
- $timestamp = time();
242
- $customer_group_id = Mage::getSingleton('customer/session')->getCustomerGroupId();
243
- // Pour les commandes depuis Adminhtml
244
- if ($customer_group_id==0) {
245
- $customer_group_id2 = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getCustomerGroupId();
246
- if (isset($customer_group_id2)) $customer_group_id = $customer_group_id2;
247
- }
248
-
249
- $customer_group_code = Mage::getSingleton('customer/group')->load($customer_group_id)->getData('customer_group_code');
250
- $process['data'] = array_merge($process['data'],array(
251
- 'customer.group.id' => $customer_group_id,
252
- 'customer.group.code' => $customer_group_code,
253
- 'destination.country.name' => $this->__getCountryName($process['data']['destination.country.code']),
254
- 'origin.country.name' => $this->__getCountryName($process['data']['origin.country.code']),
255
- 'cart.weight.unit' => Mage::getStoreConfig('chronorelais/shipping/weight_unit'),
256
- 'store.code' => $store->getCode(),
257
- 'store.name' => $store->getConfig('general/store_information/name'),
258
- 'store.address' => $store->getConfig('general/store_information/address'),
259
- 'store.phone' => $store->getConfig('general/store_information/phone'),
260
- 'date.timestamp' => $timestamp,
261
- 'date.year' => (int)date('Y',$timestamp),
262
- 'date.month' => (int)date('m',$timestamp),
263
- 'date.day' => (int)date('d',$timestamp),
264
- 'date.hour' => (int)date('H',$timestamp),
265
- 'date.minute' => (int)date('i',$timestamp),
266
- 'date.second' => (int)date('s',$timestamp),
267
- 'module.version' => (string)$mage_config->getNode('modules/Chronopost_Chronorelais/version'),
268
- ));
269
-
270
- foreach ($process['cart.items'] as $id => $item) {
271
- if ($item->getProduct()->getTypeId()!='configurable') {
272
- $parent_item_id = $item->getParentItemId();
273
- $process['products'][] = new OCS_Magento_Product($item, isset($process['cart.items'][$parent_item_id]) ? $process['cart.items'][$parent_item_id] : null);
274
- }
275
- }
276
-
277
- if (!$process['data']['free_shipping']) {
278
- foreach ($process['cart.items'] as $item) {
279
- if ($item->getProduct() instanceof Mage_Catalog_Model_Product) {
280
- if ($item->getFreeShipping()) $process['data']['free_shipping'] = true;
281
- else {
282
- $process['data']['free_shipping'] = false;
283
- break;
284
- }
285
- }
286
- }
287
- }
288
-
289
- $process['data']['cart.price_including_tax'] = $this->__getCartTaxAmount($process)+$process['data']['cart.price_excluding_tax'];
290
- $process['stop_to_first_match'] = $this->__getConfigData('stop_to_first_match');
291
- $process['config'] = $this->_getConfig();
292
- $compression = $this->__getConfigData('auto_compression');
293
- if ($compression=='compress') {
294
- Mage::getConfig()->saveConfig('carriers/'.$this->_code.'/config',$this->_helper->formatConfig(true));
295
- } else if ($compression=='uncompress') {
296
- Mage::getConfig()->saveConfig('carriers/'.$this->_code.'/config',$this->_helper->formatConfig(false));
297
- }
298
-
299
- $this->_helper->debug = (int)(isset($_GET['debug']) ? $_GET['debug'] : $this->__getConfigData('debug'));
300
- $http_request = Mage::app()->getFrontController()->getRequest();
301
- $this->_helper->debug = $this->_helper->debug && $http_request->getRouteName()=='checkout' && $http_request->getControllerName()=='cart';
302
- if ($this->_helper->debug) $this->_helper->setDebugHeader($process);
303
-
304
- $value_found = false;
305
- $process_continue = true;
306
-
307
- //Set error messages if not any matching
308
- /*$errorMsg = '';
309
- $defaultErrorMsg = Mage::helper('shipping')->__('The shipping module is not available.');
310
- $configErrorMsg = $this->__getConfigData('specificerrmsg');
311
- $configErrorMsg = ($configErrorMsg ? $configErrorMsg : $defaultErrorMsg);*/
312
- $freeShippingEnable = $this->__getConfigData('free_shipping_enable');
313
- $freeShippingSubtotal = $this->__getConfigData('free_shipping_subtotal');
314
- $applicationFee = $this->__getConfigData('application_fee');
315
- $handlingFee = $this->__getConfigData('handling_fee');
316
-
317
- /* Check weight limit with cart weight*/
318
- $weight_limit = $this->__getConfigData('weight_limit');
319
- if($process['data']['cart.weight']>$weight_limit) {
320
- $value_found = false;
321
- $process_continue = false;
322
- }
323
-
324
- if($process_continue) {
325
- foreach ($process['config'] as $row) {
326
- $result = $this->_helper->processRow($process,$row);
327
- $this->_addMessages($this->_helper->getMessages());
328
- if ($result->success) {
329
- $value_found = true;
330
- $fees = $result->result;
331
- if($applicationFee) { $fees += $applicationFee; }
332
- if($handlingFee) { $fees += $handlingFee; }
333
- if($freeShippingEnable && ($freeShippingSubtotal<=$process['data']['cart.price_excluding_tax'])) {
334
- $fees = 0;
335
- }
336
- $this->__appendMethod($process,$row,$fees);
337
- if ($process['stop_to_first_match']) break;
338
- }
339
- }
340
- }
341
-
342
- $this->_helper->printDebug();
343
-
344
- //$this->_appendErrors($process,$this->_messages);
345
- //if (!$value_found) $this->__appendError($process,$this->__($configErrorMsg));
346
- }
347
-
348
- protected function _getConfig() {
349
- if (!isset($this->_config)) {
350
- $this->_helper = new ChronorelaisShippingHelper($this->__getConfigData('config'));
351
- $this->_config = $this->_helper->getConfig();
352
- $this->_addMessages($this->_helper->getMessages());
353
- }
354
- return $this->_config;
355
- }
356
-
357
- protected function _getMethodText($process, $row, $property) {
358
- if (!isset($row[$property])) return '';
359
-
360
- $output = '';
361
- /*$i = 0;
362
- foreach ($process['request']->_data as $key => $data) {
363
- if ($i>12) $output .= $key.' => '.$data.'<br/>';
364
- $i++;
365
- }*/
366
-
367
- return $output . ' '.$this->_helper->evalInput($process,$row,$property,str_replace(
368
- array('{cart.weight}','{cart.price_including_tax}','{cart.price_excluding_tax}'),
369
- array(
370
- $process['data']['cart.weight'].$process['data']['cart.weight.unit'],
371
- $this->__formatPrice($process['data']['cart.price_including_tax']),
372
- $this->__formatPrice($process['data']['cart.price_excluding_tax'])
373
- ),
374
- $this->_helper->getRowProperty($row,$property)
375
- ));
376
- }
377
-
378
- protected function _addMessages($messages) {
379
- if (!is_array($messages)) $messages = array($messages);
380
- if (!is_array($this->_messages)) $this->_messages = $messages;
381
- else $this->_messages = array_merge($this->_messages,$messages);
382
- }
383
-
384
- protected function _appendErrors(&$process, $messages) {
385
- if (is_array($messages)) {
386
- foreach ($messages as $message) {
387
- $this->__appendError($process,$this->__($message));
388
- }
389
- }
390
- }
391
-
392
- /***************************************************************************************************************************/
393
-
394
- protected function __getConfigData($key) {
395
- return $this->getConfigData($key);
396
- }
397
-
398
- protected function __appendMethod(&$process, $row, $fees) {
399
- $method = Mage::getModel('shipping/rate_result_method')
400
- ->setCarrier($this->_code)
401
- ->setCarrierTitle($this->__getConfigData('title'))
402
- ->setMethod($row['*code'])
403
- ->setMethodTitle($this->_getMethodText($process,$row,'label'))
404
- ->setMethodDescription($this->_getMethodText($process,$row,'description'))
405
- ->setMethodLogo($this->__getConfigData('logo_url'))
406
- ->setPrice($fees)
407
- ->setCost($fees)
408
- ;
409
- $process['result']->append($method);
410
- }
411
-
412
- protected function __appendError(&$process, $message) {
413
- if (isset($process['result'])) {
414
- $error = Mage::getModel('shipping/rate_result_error')
415
- ->setCarrier($this->_code)
416
- ->setCarrierTitle($this->__getConfigData('title'))
417
- ->setErrorMessage($message)
418
- ;
419
- $process['result']->append($error);
420
- }
421
- }
422
-
423
- protected function __formatPrice($price) {
424
- if (!isset($this->_core_helper)) $this->_core_helper = Mage::helper('core');
425
- return $this->_core_helper->currency($price);
426
- }
427
-
428
- protected function __($message) {
429
- $args = func_get_args();
430
- $message = array_shift($args);
431
- if ($message instanceof OCS_Message) {
432
- $args = $message->args;
433
- $message = $message->message;
434
- }
435
-
436
- $output = Mage::helper('shipping')->__($message);
437
- if (count($args)==0) return $output;
438
-
439
- if (!isset($this->_translate_inline)) $this->_translate_inline = Mage::getSingleton('core/translate')->getTranslateInline();
440
- if ($this->_translate_inline) {
441
- $parts = explode('}}{{',$output);
442
- $parts[0] = vsprintf($parts[0],$args);
443
- return implode('}}{{',$parts);
444
- }
445
- else return vsprintf($output,$args);
446
- }
447
-
448
- protected function __getCountryName($country_code) {
449
- return Mage::getModel('directory/country')->load($country_code)->getName();
450
- //return Mage::app()->getLocale()->getCountryTranslation($country_code);
451
- /*if (!isset($this->_countries)) {
452
- // deprecated
453
- //$this->_countries = Mage::getModel('core/locale')->getLocale()->getCountryTranslationList();
454
- $this->_countries = Mage::getModel('core/locale')->getLocale()->getTranslationList('territory',null,2);
455
- }
456
- return isset($this->_countries[$country_code]) ? $this->_countries[$country_code] : $country_code;*/
457
- }
458
-
459
- /*
460
- protected function __getCartTaxAmount($process) {
461
- $tax_amount = 0;
462
-
463
- foreach ($process['cart.items'] as $item) {
464
- $tax_class_id = $item->getProduct()->getTaxClassId();
465
- $request = Mage::getSingleton('tax/calculation')->getRateRequest();
466
- $request->setProductClassId($tax_class_id);
467
- $vat_rate = Mage::getSingleton('tax/calculation')->getRate($request);
468
- $vat_rate = isset($rates[$tax_class_id]) ? $rates[$tax_class_id] : 0;
469
-
470
- if ($vat_rate > 0) $vat_to_add = $item->getData('row_total_with_discount')*$vat_rate/100;
471
- else $vat_to_add = $item->getData('tax_amount');
472
- //echo $item->getProduct()->getName().', '.$item->getData('row_total_with_discount').', '.$vat_rate.', '.$vat_to_add.'<br />';
473
- $tax_amount += $vat_to_add;
474
- }
475
- //echo 'tax:'.$tax_amount.'<br />';
476
- return $tax_amount;
477
- }
478
- */
479
-
480
- protected function __getCartTaxAmount($process) {
481
- $tax_amount = 0;
482
- foreach ($process['cart.items'] as $item) {
483
- $tax_amount += $item->getData('tax_amount');
484
- }
485
- return $tax_amount;
486
- }
487
- }
488
-
489
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Magento Chronopost Chronorelais 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 Chronopost
17
+ * @package Chronopost_Chronorelais
18
+ * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
19
+ * @author Antoine Lemoine
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
+ */
22
+
23
+ // Pour g�rer les cas o� il y a eu compilation
24
+ if (file_exists(dirname(__FILE__).'/Chronopost_Chronorelais_includes_ChronorelaisShippingHelper.php')) include_once 'Chronopost_Chronorelais_includes_ChronorelaisShippingHelper.php';
25
+ else include_once Mage::getBaseDir('code').'/community/Chronopost/Chronorelais/includes/ChronorelaisShippingHelper.php';
26
+
27
+
28
+
29
+ class OCS_Magento_Product implements OCS_Product {
30
+ private $parent_cart_item;
31
+ private $cart_item;
32
+ private $cart_product;
33
+ private $loaded_product;
34
+ private $quantity;
35
+
36
+ public function OCS_Magento_Product($cart_item, $parent_cart_item) {
37
+ $this->cart_item = $cart_item;
38
+ $this->cart_product = $cart_item->getProduct();
39
+ $this->parent_cart_item = $parent_cart_item;
40
+ $this->quantity = isset($parent_cart_item) ? $parent_cart_item->getQty() : $cart_item->getQty();
41
+ }
42
+
43
+ public function getOption($option_name, $get_by_id=false) {
44
+ $value = null;
45
+ $product = $this->cart_product;
46
+ foreach ($product->getOptions() as $option) {
47
+ if ($option->getTitle()==$option_name) {
48
+ $custom_option = $product->getCustomOption('option_'.$option->getId());
49
+ if ($custom_option) {
50
+ $value = $custom_option->getValue();
51
+ if ($option->getType()=='drop_down' && !$get_by_id) {
52
+ $option_value = $option->getValueById($value);
53
+ if ($option_value) $value = $option_value->getTitle();
54
+ }
55
+ }
56
+ break;
57
+ }
58
+ }
59
+ return $value;
60
+ }
61
+
62
+ public function getAttribute($attribute_name, $get_by_id=false) {
63
+ $value = null;
64
+ $product = $this->_getLoadedProduct();
65
+ $attribute = $product->getResource()->getAttribute($attribute_name);
66
+ if ($attribute) {
67
+ $input_type = $attribute->getFrontend()->getInputType();
68
+ switch ($input_type) {
69
+ case 'select' :
70
+ $value = $get_by_id ? $product->getData($attribute_name) : $product->getAttributeText($attribute_name);
71
+ break;
72
+ default :
73
+ $value = $product->getData($attribute_name);
74
+ break;
75
+ }
76
+ }
77
+ return $value;
78
+ }
79
+
80
+ private function _getLoadedProduct() {
81
+ if (!isset($this->loaded_product)) $this->loaded_product = Mage::getModel('catalog/product')->load($this->cart_product->getId());
82
+ return $this->loaded_product;
83
+ }
84
+
85
+ public function getQuantity() {
86
+ return $this->quantity;
87
+ }
88
+
89
+ public function getName() {
90
+ return $this->cart_product->getName();
91
+ }
92
+
93
+ public function getSku() {
94
+ return $this->cart_product->getSku();
95
+ }
96
+
97
+ public function getStockData($key) {
98
+ $stock = $this->cart_product->getStockItem();
99
+ switch ($key) {
100
+ case 'is_in_stock':
101
+ return (bool)$stock->getIsInStock();
102
+ case 'quantity':
103
+ $quantity = $stock->getQty();
104
+ return $stock->getIsQtyDecimal() ? (float)$quantity : (int)$quantity;
105
+ }
106
+ return null;
107
+ }
108
+ }
109
+
110
+ abstract class Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
111
+ extends Mage_Shipping_Model_Carrier_Abstract
112
+ {
113
+ protected $_translate_inline;
114
+ protected $_result;
115
+ protected $_config;
116
+ protected $_countries;
117
+ protected $_helper;
118
+ protected $_messages;
119
+
120
+ /**
121
+ * Collect rates for this shipping method based on information in $request
122
+ *
123
+ * @param Mage_Shipping_Model_Rate_Request $data
124
+ * @return Mage_Shipping_Model_Rate_Result
125
+ */
126
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
127
+ // skip if not enabled
128
+ if (!$this->__getConfigData('active')) return false;
129
+
130
+ /*foreach ($request->_data as $key => $data) {
131
+ echo $key.' => '.$data.'<br/>';
132
+ }*/
133
+
134
+ $process = array(
135
+ 'request' => $request,
136
+ 'result' => Mage::getModel('shipping/rate_result'),
137
+ 'cart.items' => array(),
138
+ 'products' => array(),
139
+ 'data' => array(
140
+ 'module.version' => null,
141
+ 'carrier.code' => $this->_code,
142
+ 'cart.price_excluding_tax' => $request->_data['package_value_with_discount'],
143
+ 'cart.price_including_tax' => null,
144
+ 'cart.weight' => $request->_data['package_weight'],
145
+ 'cart.weight.unit' => null,
146
+ 'cart.quantity' => $request->_data['package_qty'],
147
+ 'destination.country.code' => $request->_data['dest_country_id'],
148
+ 'destination.country.name' => null,
149
+ 'destination.region.code' => $request->_data['dest_region_code'],
150
+ 'destination.postcode' => $request->_data['dest_postcode'],
151
+ 'origin.country.code' => $request->_data['country_id'],
152
+ 'origin.country.name' => null,
153
+ 'origin.region.code' => $request->_data['region_id'],
154
+ 'origin.postcode' => $request->_data['postcode'],
155
+ 'customer.group.id' => null,
156
+ 'customer.group.code' => null,
157
+ 'free_shipping' => $request->getFreeShipping(),
158
+ 'store.id' => $request->_data['store_id'],
159
+ 'store.code' => null,
160
+ 'store.name' => null,
161
+ 'store.address' => null,
162
+ 'store.phone' => null,
163
+ 'date.timestamp' => null,
164
+ 'date.year' => null,
165
+ 'date.month' => null,
166
+ 'date.day' => null,
167
+ 'date.hour' => null,
168
+ 'date.minute' => null,
169
+ 'date.second' => null,
170
+ ),
171
+ 'stop_to_first_match' => null,
172
+ 'config' => null,
173
+ );
174
+
175
+ $items = $request->getAllItems();
176
+ for ($i=0, $n=count($items); $i<$n; $i++) {
177
+ $item = $items[$i];
178
+ if ($item->getProduct() instanceof Mage_Catalog_Model_Product) $process['cart.items'][$item->getId()] = $item;
179
+ }
180
+
181
+ $process_result = $this->_process($process);
182
+
183
+ return $process['result'];
184
+ }
185
+
186
+
187
+ public function getAllowedMethods() {
188
+ $process = array();
189
+ $config = $this->_getConfig();
190
+ $allowed_methods = array();
191
+ if (count($config)>0) {
192
+ foreach ($config as $row) $allowed_methods[$row['*code']] = isset($row['label']) ? $row['label']['value'] : 'No label';
193
+ }
194
+ return $allowed_methods;
195
+ }
196
+
197
+ public function isTrackingAvailable() {
198
+ return true;
199
+ }
200
+
201
+ public function getTrackingInfo($tracking_number) {
202
+ $tracking_url = Mage::helper('chronorelais')->getConfigurationTrackingViewUrl();
203
+ $parts = explode(':',$tracking_number);
204
+ if (count($parts)>=2) {
205
+ $tracking_number = $parts[1];
206
+
207
+ $process = array();
208
+ $config = $this->_getConfig();
209
+
210
+ if (isset($config[$parts[0]]['tracking_url'])) {
211
+ $row = $config[$parts[0]];
212
+ $tmp_tracking_url = $this->_helper->getRowProperty($row,'tracking_url');
213
+ if (isset($tmp_tracking_url)) $tracking_url = $tmp_tracking_url;
214
+ }
215
+ }
216
+
217
+ $tracking_status = Mage::getModel('shipping/tracking_result_status')
218
+ ->setCarrier($this->_code)
219
+ ->setCarrierTitle($this->__getConfigData('title'))
220
+ ->setTracking($tracking_number)
221
+ ->addData(
222
+ array(
223
+ 'status'=>'<a target="_blank" href="'.str_replace('{tracking_number}',$tracking_number,$tracking_url).'">'.__('track the package').'</a>'
224
+ )
225
+ )
226
+ ;
227
+ $tracking_result = Mage::getModel('shipping/tracking_result')
228
+ ->append($tracking_status)
229
+ ;
230
+
231
+ if ($trackings = $tracking_result->getAllTrackings()) return $trackings[0];
232
+ return false;
233
+ }
234
+
235
+
236
+ /***************************************************************************************************************************/
237
+
238
+ protected function _process(&$process) {
239
+ $store = Mage::app()->getStore($process['data']['store.id']);
240
+ $mage_config = Mage::getConfig();
241
+ $timestamp = time();
242
+ $customer_group_id = Mage::getSingleton('customer/session')->getCustomerGroupId();
243
+ // Pour les commandes depuis Adminhtml
244
+ if ($customer_group_id==0) {
245
+ $customer_group_id2 = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getCustomerGroupId();
246
+ if (isset($customer_group_id2)) $customer_group_id = $customer_group_id2;
247
+ }
248
+
249
+ $customer_group_code = Mage::getSingleton('customer/group')->load($customer_group_id)->getData('customer_group_code');
250
+ $process['data'] = array_merge($process['data'],array(
251
+ 'customer.group.id' => $customer_group_id,
252
+ 'customer.group.code' => $customer_group_code,
253
+ 'destination.country.name' => $this->__getCountryName($process['data']['destination.country.code']),
254
+ 'origin.country.name' => $this->__getCountryName($process['data']['origin.country.code']),
255
+ 'cart.weight.unit' => Mage::getStoreConfig('chronorelais/shipping/weight_unit'),
256
+ 'store.code' => $store->getCode(),
257
+ 'store.name' => $store->getConfig('general/store_information/name'),
258
+ 'store.address' => $store->getConfig('general/store_information/address'),
259
+ 'store.phone' => $store->getConfig('general/store_information/phone'),
260
+ 'date.timestamp' => $timestamp,
261
+ 'date.year' => (int)date('Y',$timestamp),
262
+ 'date.month' => (int)date('m',$timestamp),
263
+ 'date.day' => (int)date('d',$timestamp),
264
+ 'date.hour' => (int)date('H',$timestamp),
265
+ 'date.minute' => (int)date('i',$timestamp),
266
+ 'date.second' => (int)date('s',$timestamp),
267
+ 'module.version' => (string)$mage_config->getNode('modules/Chronopost_Chronorelais/version'),
268
+ ));
269
+
270
+ foreach ($process['cart.items'] as $id => $item) {
271
+ if ($item->getProduct()->getTypeId()!='configurable') {
272
+ $parent_item_id = $item->getParentItemId();
273
+ $process['products'][] = new OCS_Magento_Product($item, isset($process['cart.items'][$parent_item_id]) ? $process['cart.items'][$parent_item_id] : null);
274
+ }
275
+ }
276
+
277
+ if (!$process['data']['free_shipping']) {
278
+ foreach ($process['cart.items'] as $item) {
279
+ if ($item->getProduct() instanceof Mage_Catalog_Model_Product) {
280
+ if ($item->getFreeShipping()) $process['data']['free_shipping'] = true;
281
+ else {
282
+ $process['data']['free_shipping'] = false;
283
+ break;
284
+ }
285
+ }
286
+ }
287
+ }
288
+
289
+ $process['data']['cart.price_including_tax'] = $this->__getCartTaxAmount($process)+$process['data']['cart.price_excluding_tax'];
290
+ $process['stop_to_first_match'] = $this->__getConfigData('stop_to_first_match');
291
+ $process['config'] = $this->_getConfig();
292
+ $compression = $this->__getConfigData('auto_compression');
293
+ if ($compression=='compress') {
294
+ Mage::getConfig()->saveConfig('carriers/'.$this->_code.'/config',$this->_helper->formatConfig(true));
295
+ } else if ($compression=='uncompress') {
296
+ Mage::getConfig()->saveConfig('carriers/'.$this->_code.'/config',$this->_helper->formatConfig(false));
297
+ }
298
+
299
+ $this->_helper->debug = (int)(isset($_GET['debug']) ? $_GET['debug'] : $this->__getConfigData('debug'));
300
+ $http_request = Mage::app()->getFrontController()->getRequest();
301
+ $this->_helper->debug = $this->_helper->debug && $http_request->getRouteName()=='checkout' && $http_request->getControllerName()=='cart';
302
+ if ($this->_helper->debug) $this->_helper->setDebugHeader($process);
303
+
304
+ $value_found = false;
305
+ $process_continue = true;
306
+
307
+ //Set error messages if not any matching
308
+ /*$errorMsg = '';
309
+ $defaultErrorMsg = Mage::helper('shipping')->__('The shipping module is not available.');
310
+ $configErrorMsg = $this->__getConfigData('specificerrmsg');
311
+ $configErrorMsg = ($configErrorMsg ? $configErrorMsg : $defaultErrorMsg);*/
312
+ $freeShippingEnable = $this->__getConfigData('free_shipping_enable');
313
+ $freeShippingSubtotal = $this->__getConfigData('free_shipping_subtotal');
314
+ $applicationFee = $this->__getConfigData('application_fee');
315
+ $handlingFee = $this->__getConfigData('handling_fee');
316
+
317
+ /* Check weight limit with cart weight*/
318
+ $weight_limit = $this->__getConfigData('weight_limit');
319
+ if($process['data']['cart.weight']>$weight_limit) {
320
+ $value_found = false;
321
+ $process_continue = false;
322
+ }
323
+
324
+ if($process_continue) {
325
+ foreach ($process['config'] as $row) {
326
+ $result = $this->_helper->processRow($process,$row);
327
+ $this->_addMessages($this->_helper->getMessages());
328
+ if ($result->success) {
329
+ $value_found = true;
330
+ $fees = $result->result;
331
+ if($applicationFee) { $fees += $applicationFee; }
332
+ if($handlingFee) { $fees += $handlingFee; }
333
+ if($freeShippingEnable && ($freeShippingSubtotal<=$process['data']['cart.price_excluding_tax'])) {
334
+ $fees = 0;
335
+ }
336
+ $this->__appendMethod($process,$row,$fees);
337
+ if ($process['stop_to_first_match']) break;
338
+ }
339
+ }
340
+ }
341
+
342
+ $this->_helper->printDebug();
343
+
344
+ //$this->_appendErrors($process,$this->_messages);
345
+ //if (!$value_found) $this->__appendError($process,$this->__($configErrorMsg));
346
+ }
347
+
348
+ protected function _getConfig() {
349
+ if (!isset($this->_config)) {
350
+ $this->_helper = new ChronorelaisShippingHelper($this->__getConfigData('config'));
351
+ $this->_config = $this->_helper->getConfig();
352
+ $this->_addMessages($this->_helper->getMessages());
353
+ }
354
+ return $this->_config;
355
+ }
356
+
357
+ protected function _getMethodText($process, $row, $property) {
358
+ if (!isset($row[$property])) return '';
359
+
360
+ $output = '';
361
+ /*$i = 0;
362
+ foreach ($process['request']->_data as $key => $data) {
363
+ if ($i>12) $output .= $key.' => '.$data.'<br/>';
364
+ $i++;
365
+ }*/
366
+
367
+ return $output . ' '.$this->_helper->evalInput($process,$row,$property,str_replace(
368
+ array('{cart.weight}','{cart.price_including_tax}','{cart.price_excluding_tax}'),
369
+ array(
370
+ $process['data']['cart.weight'].$process['data']['cart.weight.unit'],
371
+ $this->__formatPrice($process['data']['cart.price_including_tax']),
372
+ $this->__formatPrice($process['data']['cart.price_excluding_tax'])
373
+ ),
374
+ $this->_helper->getRowProperty($row,$property)
375
+ ));
376
+ }
377
+
378
+ protected function _addMessages($messages) {
379
+ if (!is_array($messages)) $messages = array($messages);
380
+ if (!is_array($this->_messages)) $this->_messages = $messages;
381
+ else $this->_messages = array_merge($this->_messages,$messages);
382
+ }
383
+
384
+ protected function _appendErrors(&$process, $messages) {
385
+ if (is_array($messages)) {
386
+ foreach ($messages as $message) {
387
+ $this->__appendError($process,$this->__($message));
388
+ }
389
+ }
390
+ }
391
+
392
+ /***************************************************************************************************************************/
393
+
394
+ protected function __getConfigData($key) {
395
+ return $this->getConfigData($key);
396
+ }
397
+
398
+ protected function __appendMethod(&$process, $row, $fees) {
399
+ $method = Mage::getModel('shipping/rate_result_method')
400
+ ->setCarrier($this->_code)
401
+ ->setCarrierTitle($this->__getConfigData('title'))
402
+ ->setMethod($row['*code'])
403
+ ->setMethodTitle($this->_getMethodText($process,$row,'label'))
404
+ ->setMethodDescription($this->_getMethodText($process,$row,'description'))
405
+ ->setMethodLogo($this->__getConfigData('logo_url'))
406
+ ->setPrice($fees)
407
+ ->setCost($fees)
408
+ ;
409
+ $process['result']->append($method);
410
+ }
411
+
412
+ protected function __appendError(&$process, $message) {
413
+ if (isset($process['result'])) {
414
+ $error = Mage::getModel('shipping/rate_result_error')
415
+ ->setCarrier($this->_code)
416
+ ->setCarrierTitle($this->__getConfigData('title'))
417
+ ->setErrorMessage($message)
418
+ ;
419
+ $process['result']->append($error);
420
+ }
421
+ }
422
+
423
+ protected function __formatPrice($price) {
424
+ if (!isset($this->_core_helper)) $this->_core_helper = Mage::helper('core');
425
+ return $this->_core_helper->currency($price);
426
+ }
427
+
428
+ protected function __($message) {
429
+ $args = func_get_args();
430
+ $message = array_shift($args);
431
+ if ($message instanceof OCS_Message) {
432
+ $args = $message->args;
433
+ $message = $message->message;
434
+ }
435
+
436
+ $output = Mage::helper('shipping')->__($message);
437
+ if (count($args)==0) return $output;
438
+
439
+ if (!isset($this->_translate_inline)) $this->_translate_inline = Mage::getSingleton('core/translate')->getTranslateInline();
440
+ if ($this->_translate_inline) {
441
+ $parts = explode('}}{{',$output);
442
+ $parts[0] = vsprintf($parts[0],$args);
443
+ return implode('}}{{',$parts);
444
+ }
445
+ else return vsprintf($output,$args);
446
+ }
447
+
448
+ protected function __getCountryName($country_code) {
449
+ return Mage::getModel('directory/country')->load($country_code)->getName();
450
+ //return Mage::app()->getLocale()->getCountryTranslation($country_code);
451
+ /*if (!isset($this->_countries)) {
452
+ // deprecated
453
+ //$this->_countries = Mage::getModel('core/locale')->getLocale()->getCountryTranslationList();
454
+ $this->_countries = Mage::getModel('core/locale')->getLocale()->getTranslationList('territory',null,2);
455
+ }
456
+ return isset($this->_countries[$country_code]) ? $this->_countries[$country_code] : $country_code;*/
457
+ }
458
+
459
+ /*
460
+ protected function __getCartTaxAmount($process) {
461
+ $tax_amount = 0;
462
+
463
+ foreach ($process['cart.items'] as $item) {
464
+ $tax_class_id = $item->getProduct()->getTaxClassId();
465
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest();
466
+ $request->setProductClassId($tax_class_id);
467
+ $vat_rate = Mage::getSingleton('tax/calculation')->getRate($request);
468
+ $vat_rate = isset($rates[$tax_class_id]) ? $rates[$tax_class_id] : 0;
469
+
470
+ if ($vat_rate > 0) $vat_to_add = $item->getData('row_total_with_discount')*$vat_rate/100;
471
+ else $vat_to_add = $item->getData('tax_amount');
472
+ //echo $item->getProduct()->getName().', '.$item->getData('row_total_with_discount').', '.$vat_rate.', '.$vat_to_add.'<br />';
473
+ $tax_amount += $vat_to_add;
474
+ }
475
+ //echo 'tax:'.$tax_amount.'<br />';
476
+ return $tax_amount;
477
+ }
478
+ */
479
+
480
+ protected function __getCartTaxAmount($process) {
481
+ $tax_amount = 0;
482
+ foreach ($process['cart.items'] as $item) {
483
+ $tax_amount += $item->getData('tax_amount');
484
+ }
485
+ return $tax_amount;
486
+ }
487
+ }
488
+
489
  ?>
app/code/community/Chronopost/Chronorelais/Model/Carrier/Chronoexpress.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Carrier_Chronoexpress extends Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
3
- {
4
- protected $_code = 'chronoexpress';
5
-
6
  }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Carrier_Chronoexpress extends Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
3
+ {
4
+ protected $_code = 'chronoexpress';
5
+
6
  }
app/code/community/Chronopost/Chronorelais/Model/Carrier/Chronopost.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Carrier_Chronopost extends Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
3
- {
4
- protected $_code = 'chronopost';
5
-
6
  }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Carrier_Chronopost extends Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
3
+ {
4
+ protected $_code = 'chronopost';
5
+
6
  }
app/code/community/Chronopost/Chronorelais/Model/Carrier/Chronorelais.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Carrier_Chronorelais extends Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
3
- {
4
- protected $_code = 'chronorelais';
5
-
6
  }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Carrier_Chronorelais extends Chronopost_Chronorelais_Model_Carrier_AbstractChronorelaisShipping
3
+ {
4
+ protected $_code = 'chronorelais';
5
+
6
  }
app/code/community/Chronopost/Chronorelais/Model/Config/Source/Civility.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Config_Source_Civility
3
- {
4
- public function toOptionArray()
5
- {
6
- return array(
7
- array('value'=>'E', 'label'=>Mage::helper('chronorelais')->__('Madame')),
8
- array('value'=>'L', 'label'=>Mage::helper('chronorelais')->__('Mademoiselle')),
9
- array('value'=>'M', 'label'=>Mage::helper('chronorelais')->__('Monsieur'))
10
- );
11
- }
12
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Config_Source_Civility
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>'E', 'label'=>Mage::helper('chronorelais')->__('Madame')),
8
+ array('value'=>'L', 'label'=>Mage::helper('chronorelais')->__('Mademoiselle')),
9
+ array('value'=>'M', 'label'=>Mage::helper('chronorelais')->__('Monsieur'))
10
+ );
11
+ }
12
+ }
app/code/community/Chronopost/Chronorelais/Model/Config/Source/EndOfLineCharacter.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Config_Source_EndOfLineCharacter
3
- {
4
- public function toOptionArray()
5
- {
6
- return array(
7
- array('value'=>'lf', 'label'=>Mage::helper('chronorelais')->__('LF')),
8
- array('value'=>'cr', 'label'=>Mage::helper('chronorelais')->__('CR')),
9
- array('value'=>'crlf', 'label'=>Mage::helper('chronorelais')->__('CR+LF'))
10
- );
11
- }
12
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Config_Source_EndOfLineCharacter
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>'lf', 'label'=>Mage::helper('chronorelais')->__('LF')),
8
+ array('value'=>'cr', 'label'=>Mage::helper('chronorelais')->__('CR')),
9
+ array('value'=>'crlf', 'label'=>Mage::helper('chronorelais')->__('CR+LF'))
10
+ );
11
+ }
12
+ }
app/code/community/Chronopost/Chronorelais/Model/Config/Source/FieldDelimiter.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Config_Source_FieldDelimiter
3
- {
4
- public function toOptionArray()
5
- {
6
- return array(
7
- array('value'=>'none', 'label'=>Mage::helper('chronorelais')->__('None')),
8
- array('value'=>'simple_quote', 'label'=>Mage::helper('chronorelais')->__('Simple Quote')),
9
- array('value'=>'double_quotes', 'label'=>Mage::helper('chronorelais')->__('Double Quotes'))
10
- );
11
- }
12
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Config_Source_FieldDelimiter
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>'none', 'label'=>Mage::helper('chronorelais')->__('None')),
8
+ array('value'=>'simple_quote', 'label'=>Mage::helper('chronorelais')->__('Simple Quote')),
9
+ array('value'=>'double_quotes', 'label'=>Mage::helper('chronorelais')->__('Double Quotes'))
10
+ );
11
+ }
12
+ }
app/code/community/Chronopost/Chronorelais/Model/Config/Source/FieldSeparator.php CHANGED
@@ -1,11 +1,11 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Config_Source_FieldSeparator
3
- {
4
- public function toOptionArray()
5
- {
6
- return array(
7
- array('value'=>';', 'label'=>Mage::helper('chronorelais')->__('Semicolon')),
8
- array('value'=>',', 'label'=>Mage::helper('chronorelais')->__('Comma'))
9
- );
10
- }
11
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Config_Source_FieldSeparator
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>';', 'label'=>Mage::helper('chronorelais')->__('Semicolon')),
8
+ array('value'=>',', 'label'=>Mage::helper('chronorelais')->__('Comma'))
9
+ );
10
+ }
11
+ }
app/code/community/Chronopost/Chronorelais/Model/Config/Source/FileCharset.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Config_Source_FileCharset
3
- {
4
- public function toOptionArray()
5
- {
6
- return array(
7
- array('value'=>'ISO-8859-1', 'label'=>Mage::helper('chronorelais')->__('ISO-8859-1')),
8
- array('value'=>'UTF-8', 'label'=>Mage::helper('chronorelais')->__('UTF-8')),
9
- array('value'=>'ASCII-7', 'label'=>Mage::helper('chronorelais')->__('ASCII-7 Bits'))
10
- );
11
- }
12
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Config_Source_FileCharset
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>'ISO-8859-1', 'label'=>Mage::helper('chronorelais')->__('ISO-8859-1')),
8
+ array('value'=>'UTF-8', 'label'=>Mage::helper('chronorelais')->__('UTF-8')),
9
+ array('value'=>'ASCII-7', 'label'=>Mage::helper('chronorelais')->__('ASCII-7 Bits'))
10
+ );
11
+ }
12
+ }
app/code/community/Chronopost/Chronorelais/Model/Config/Source/FileExtension.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Config_Source_FileExtension
3
- {
4
- public function toOptionArray()
5
- {
6
- return array(
7
- array('value'=>'.txt', 'label'=>Mage::helper('chronorelais')->__('.txt')),
8
- array('value'=>'.csv', 'label'=>Mage::helper('chronorelais')->__('.csv')),
9
- array('value'=>'.chr', 'label'=>Mage::helper('chronorelais')->__('.chr'))
10
- );
11
- }
12
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Config_Source_FileExtension
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>'.txt', 'label'=>Mage::helper('chronorelais')->__('.txt')),
8
+ array('value'=>'.csv', 'label'=>Mage::helper('chronorelais')->__('.csv')),
9
+ array('value'=>'.chr', 'label'=>Mage::helper('chronorelais')->__('.chr'))
10
+ );
11
+ }
12
+ }
app/code/community/Chronopost/Chronorelais/Model/Config/Source/PrintMode.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- class Chronopost_Chronorelais_Model_Config_Source_PrintMode
3
- {
4
- public function toOptionArray()
5
- {
6
- return array(
7
- array('value'=>'PDF', 'label'=>Mage::helper('chronorelais')->__('Print PDF Laser with proof')),
8
- array('value'=>'SPD', 'label'=>Mage::helper('chronorelais')->__('Print PDF laser without proof')),
9
- array('value'=>'THE', 'label'=>Mage::helper('chronorelais')->__('Print PDF thermal'))
10
- );
11
- }
12
- }
1
+ <?php
2
+ class Chronopost_Chronorelais_Model_Config_Source_PrintMode
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array('value'=>'PDF', 'label'=>Mage::helper('chronorelais')->__('Print PDF Laser with proof')),
8
+ array('value'=>'SPD', 'label'=>Mage::helper('chronorelais')->__('Print PDF laser without proof')),
9
+ array('value'=>'THE', 'label'=>Mage::helper('chronorelais')->__('Print PDF thermal'))
10
+ );
11
+ }
12
+ }
app/code/community/Chronopost/Chronorelais/Model/Sales/Quote/Address/Total/Shipping.php CHANGED
@@ -1,207 +1,207 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * that is bundled with this package in the file LICENSE.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/osl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category Mage
22
- * @package Mage_Sales
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
- */
26
-
27
-
28
- class Chronopost_Chronorelais_Model_Sales_Quote_Address_Total_Shipping extends Mage_Sales_Model_Quote_Address_Total_Abstract
29
- {
30
- public function __construct()
31
- {
32
- $this->setCode('shipping');
33
- }
34
-
35
- /**
36
- * Collect totals information about shipping
37
- *
38
- * @param Mage_Sales_Model_Quote_Address $address
39
- * @return Mage_Sales_Model_Quote_Address_Total_Shipping
40
- */
41
- public function collect(Mage_Sales_Model_Quote_Address $address)
42
- {
43
- parent::collect($address);
44
-
45
- $oldWeight = $address->getWeight();
46
- $address->setWeight(0);
47
- $address->setFreeMethodWeight(0);
48
- $this->_setAmount(0)
49
- ->_setBaseAmount(0);
50
-
51
- $items = $this->_getAddressItems($address);
52
- if (!count($items)) {
53
- return $this;
54
- }
55
-
56
- $method = $address->getShippingMethod();
57
- $freeAddress= $address->getFreeShipping();
58
-
59
- $addressWeight = $address->getWeight();
60
- $freeMethodWeight = $address->getFreeMethodWeight();
61
-
62
- $addressQty = 0;
63
-
64
- foreach ($items as $item) {
65
- /**
66
- * Skip if this item is virtual
67
- */
68
- if ($item->getProduct()->isVirtual()) {
69
- continue;
70
- }
71
-
72
- /**
73
- * Children weight we calculate for parent
74
- */
75
- if ($item->getParentItem()) {
76
- continue;
77
- }
78
-
79
- if ($item->getHasChildren() && $item->isShipSeparately()) {
80
- foreach ($item->getChildren() as $child) {
81
- if ($child->getProduct()->isVirtual()) {
82
- continue;
83
- }
84
- $addressQty += $child->getTotalQty();
85
-
86
- if (!$item->getProduct()->getWeightType()) {
87
- $itemWeight = $child->getWeight();
88
- $itemQty = $child->getTotalQty();
89
- $rowWeight = $itemWeight*$itemQty;
90
- $addressWeight += $rowWeight;
91
- if ($freeAddress || $child->getFreeShipping()===true) {
92
- $rowWeight = 0;
93
- } elseif (is_numeric($child->getFreeShipping())) {
94
- $freeQty = $child->getFreeShipping();
95
- if ($itemQty>$freeQty) {
96
- $rowWeight = $itemWeight*($itemQty-$freeQty);
97
- }
98
- else {
99
- $rowWeight = 0;
100
- }
101
- }
102
- $freeMethodWeight += $rowWeight;
103
- $item->setRowWeight($rowWeight);
104
- }
105
- }
106
- if ($item->getProduct()->getWeightType()) {
107
- $itemWeight = $item->getWeight();
108
- $rowWeight = $itemWeight*$item->getQty();
109
- $addressWeight+= $rowWeight;
110
- if ($freeAddress || $item->getFreeShipping()===true) {
111
- $rowWeight = 0;
112
- } elseif (is_numeric($item->getFreeShipping())) {
113
- $freeQty = $item->getFreeShipping();
114
- if ($item->getQty()>$freeQty) {
115
- $rowWeight = $itemWeight*($item->getQty()-$freeQty);
116
- }
117
- else {
118
- $rowWeight = 0;
119
- }
120
- }
121
- $freeMethodWeight+= $rowWeight;
122
- $item->setRowWeight($rowWeight);
123
- }
124
- }
125
- else {
126
- if (!$item->getProduct()->isVirtual()) {
127
- $addressQty += $item->getQty();
128
- }
129
- $itemWeight = $item->getWeight();
130
- $rowWeight = $itemWeight*$item->getQty();
131
- $addressWeight+= $rowWeight;
132
- if ($freeAddress || $item->getFreeShipping()===true) {
133
- $rowWeight = 0;
134
- } elseif (is_numeric($item->getFreeShipping())) {
135
- $freeQty = $item->getFreeShipping();
136
- if ($item->getQty()>$freeQty) {
137
- $rowWeight = $itemWeight*($item->getQty()-$freeQty);
138
- }
139
- else {
140
- $rowWeight = 0;
141
- }
142
- }
143
- $freeMethodWeight+= $rowWeight;
144
- $item->setRowWeight($rowWeight);
145
- }
146
- }
147
-
148
- if (isset($addressQty)) {
149
- $address->setItemQty($addressQty);
150
- }
151
-
152
- $address->setWeight($addressWeight);
153
- $address->setFreeMethodWeight($freeMethodWeight);
154
-
155
- $address->collectShippingRates();
156
-
157
- $this->_setAmount(0)
158
- ->_setBaseAmount(0);
159
-
160
- $method = $address->getShippingMethod();
161
-
162
- if ($method) {
163
- foreach ($address->getAllShippingRates() as $rate) {
164
- if ($rate->getCode()==$method) {
165
- $amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
166
- $this->_setAmount($amountPrice);
167
- $this->_setBaseAmount($rate->getPrice());
168
- if(!$address->getShippingDescription()) {
169
- $address->setShippingDescription($rate->getCarrierTitle().' - '.$rate->getMethodTitle());
170
- }
171
- break;
172
- }
173
- }
174
- }
175
-
176
- return $this;
177
- }
178
-
179
- /**
180
- * Add shipping totals information to address object
181
- *
182
- * @param Mage_Sales_Model_Quote_Address $address
183
- * @return Mage_Sales_Model_Quote_Address_Total_Shipping
184
- */
185
- public function fetch(Mage_Sales_Model_Quote_Address $address)
186
- {
187
- $amount = $address->getShippingAmount();
188
- if ($amount!=0 || $address->getShippingDescription()) {
189
- $address->addTotal(array(
190
- 'code'=>$this->getCode(),
191
- 'title'=>Mage::helper('sales')->__('Shipping & Handling').' ('.$address->getShippingDescription().')',
192
- 'value'=>$address->getShippingAmount()
193
- ));
194
- }
195
- return $this;
196
- }
197
-
198
- /**
199
- * Get Shipping label
200
- *
201
- * @return string
202
- */
203
- public function getLabel()
204
- {
205
- return Mage::helper('sales')->__('Shipping');
206
- }
207
- }
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Sales
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Chronopost_Chronorelais_Model_Sales_Quote_Address_Total_Shipping extends Mage_Sales_Model_Quote_Address_Total_Abstract
29
+ {
30
+ public function __construct()
31
+ {
32
+ $this->setCode('shipping');
33
+ }
34
+
35
+ /**
36
+ * Collect totals information about shipping
37
+ *
38
+ * @param Mage_Sales_Model_Quote_Address $address
39
+ * @return Mage_Sales_Model_Quote_Address_Total_Shipping
40
+ */
41
+ public function collect(Mage_Sales_Model_Quote_Address $address)
42
+ {
43
+ parent::collect($address);
44
+
45
+ $oldWeight = $address->getWeight();
46
+ $address->setWeight(0);
47
+ $address->setFreeMethodWeight(0);
48
+ $this->_setAmount(0)
49
+ ->_setBaseAmount(0);
50
+
51
+ $items = $this->_getAddressItems($address);
52
+ if (!count($items)) {
53
+ return $this;
54
+ }
55
+
56
+ $method = $address->getShippingMethod();
57
+ $freeAddress= $address->getFreeShipping();
58
+
59
+ $addressWeight = $address->getWeight();
60
+ $freeMethodWeight = $address->getFreeMethodWeight();
61
+
62
+ $addressQty = 0;
63
+
64
+ foreach ($items as $item) {
65
+ /**
66
+ * Skip if this item is virtual
67
+ */
68
+ if ($item->getProduct()->isVirtual()) {
69
+ continue;
70
+ }
71
+
72
+ /**
73
+ * Children weight we calculate for parent
74
+ */
75
+ if ($item->getParentItem()) {
76
+ continue;
77
+ }
78
+
79
+ if ($item->getHasChildren() && $item->isShipSeparately()) {
80
+ foreach ($item->getChildren() as $child) {
81
+ if ($child->getProduct()->isVirtual()) {
82
+ continue;
83
+ }
84
+ $addressQty += $child->getTotalQty();
85
+
86
+ if (!$item->getProduct()->getWeightType()) {
87
+ $itemWeight = $child->getWeight();
88
+ $itemQty = $child->getTotalQty();
89
+ $rowWeight = $itemWeight*$itemQty;
90
+ $addressWeight += $rowWeight;
91
+ if ($freeAddress || $child->getFreeShipping()===true) {
92
+ $rowWeight = 0;
93
+ } elseif (is_numeric($child->getFreeShipping())) {
94
+ $freeQty = $child->getFreeShipping();
95
+ if ($itemQty>$freeQty) {
96
+ $rowWeight = $itemWeight*($itemQty-$freeQty);
97
+ }
98
+ else {
99
+ $rowWeight = 0;
100
+ }
101
+ }
102
+ $freeMethodWeight += $rowWeight;
103
+ $item->setRowWeight($rowWeight);
104
+ }
105
+ }
106
+ if ($item->getProduct()->getWeightType()) {
107
+ $itemWeight = $item->getWeight();
108
+ $rowWeight = $itemWeight*$item->getQty();
109
+ $addressWeight+= $rowWeight;
110
+ if ($freeAddress || $item->getFreeShipping()===true) {
111
+ $rowWeight = 0;
112
+ } elseif (is_numeric($item->getFreeShipping())) {
113
+ $freeQty = $item->getFreeShipping();
114
+ if ($item->getQty()>$freeQty) {
115
+ $rowWeight = $itemWeight*($item->getQty()-$freeQty);
116
+ }
117
+ else {
118
+ $rowWeight = 0;
119
+ }
120
+ }
121
+ $freeMethodWeight+= $rowWeight;
122
+ $item->setRowWeight($rowWeight);
123
+ }
124
+ }
125
+ else {
126
+ if (!$item->getProduct()->isVirtual()) {
127
+ $addressQty += $item->getQty();
128
+ }
129
+ $itemWeight = $item->getWeight();
130
+ $rowWeight = $itemWeight*$item->getQty();
131
+ $addressWeight+= $rowWeight;
132
+ if ($freeAddress || $item->getFreeShipping()===true) {
133
+ $rowWeight = 0;
134
+ } elseif (is_numeric($item->getFreeShipping())) {
135
+ $freeQty = $item->getFreeShipping();
136
+ if ($item->getQty()>$freeQty) {
137
+ $rowWeight = $itemWeight*($item->getQty()-$freeQty);
138
+ }
139
+ else {
140
+ $rowWeight = 0;
141
+ }
142
+ }
143
+ $freeMethodWeight+= $rowWeight;
144
+ $item->setRowWeight($rowWeight);
145
+ }
146
+ }
147
+
148
+ if (isset($addressQty)) {
149
+ $address->setItemQty($addressQty);
150
+ }
151
+
152
+ $address->setWeight($addressWeight);
153
+ $address->setFreeMethodWeight($freeMethodWeight);
154
+
155
+ $address->collectShippingRates();
156
+
157
+ $this->_setAmount(0)
158
+ ->_setBaseAmount(0);
159
+
160
+ $method = $address->getShippingMethod();
161
+
162
+ if ($method) {
163
+ foreach ($address->getAllShippingRates() as $rate) {
164
+ if ($rate->getCode()==$method) {
165
+ $amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
166
+ $this->_setAmount($amountPrice);
167
+ $this->_setBaseAmount($rate->getPrice());
168
+ if(!$address->getShippingDescription()) {
169
+ $address->setShippingDescription($rate->getCarrierTitle().' - '.$rate->getMethodTitle());
170
+ }
171
+ break;
172
+ }
173
+ }
174
+ }
175
+
176
+ return $this;
177
+ }
178
+
179
+ /**
180
+ * Add shipping totals information to address object
181
+ *
182
+ * @param Mage_Sales_Model_Quote_Address $address
183
+ * @return Mage_Sales_Model_Quote_Address_Total_Shipping
184
+ */
185
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
186
+ {
187
+ $amount = $address->getShippingAmount();
188
+ if ($amount!=0 || $address->getShippingDescription()) {
189
+ $address->addTotal(array(
190
+ 'code'=>$this->getCode(),
191
+ 'title'=>Mage::helper('sales')->__('Shipping & Handling').' ('.$address->getShippingDescription().')',
192
+ 'value'=>$address->getShippingAmount()
193
+ ));
194
+ }
195
+ return $this;
196
+ }
197
+
198
+ /**
199
+ * Get Shipping label
200
+ *
201
+ * @return string
202
+ */
203
+ public function getLabel()
204
+ {
205
+ return Mage::helper('sales')->__('Shipping');
206
+ }
207
+ }
app/code/community/Chronopost/Chronorelais/controllers/AjaxController.php CHANGED
@@ -1,409 +1,409 @@
1
- <?php
2
-
3
- /**
4
- * Magento Chronopost Chronorelais 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 Chronopost
17
- * @package Chronopost_Chronorelais
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 Chronopost_Chronorelais_AjaxController extends Chronopost_Chronorelais_Controller_Abstract
24
- {
25
- private function getPropertyHelper($row_id, $property_key, $property) {
26
- $cleaned_property = $this->cleanKey($property_key);
27
- $prefix = "r-".$row_id."-p-".$cleaned_property;
28
- $value = isset($property['original_value']) ? $property['original_value'] : (isset($property['value']) ? $property['value'] : '');
29
-
30
- switch ($property_key) {
31
- case 'enabled':
32
- $enabled = $value!==false;
33
- return "<p><select id=\"".$prefix."\" class=\"field\">"
34
- ."<option value=\"0\"".($enabled ? '' : ' selected="selected"').">".$this->__('Disabled')."</option>"
35
- ."<option value=\"1\"".($enabled ? ' selected="selected"' : '').">".$this->__('Enabled')."</option>"
36
- ."</select><p>";
37
- break;
38
- case 'label':
39
- case 'description':
40
- return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
41
- ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
42
- ."<p>"
43
- .$this->button('Destination country',"ocseditor.insertAtCaret(this,'{destination.country.name}');")
44
- .$this->button('Cart weight',"ocseditor.insertAtCaret(this,'{cart.weight}');")
45
- .$this->button('Cart quantity',"ocseditor.insertAtCaret(this,'{cart.quantity}');")
46
- .$this->button('Price including tax',"ocseditor.insertAtCaret(this,'{cart.price_including_tax}');")
47
- .$this->button('Price excluding tax',"ocseditor.insertAtCaret(this,'{cart.price_excluding_tax}');")
48
- ."</p>"
49
- ."</fieldset>";
50
- break;
51
- case 'fees':
52
- return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
53
- ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
54
- ."<p><span class=\"buttons-set-label\">".$this->__('Cart')."</span>"
55
- .$this->button('Weight',"ocseditor.insertAtCaret(this,'{cart.weight}');")
56
- .$this->button('Products quantity',"ocseditor.insertAtCaret(this,'{cart.quantity}');")
57
- .$this->button('Price including tax',"ocseditor.insertAtCaret(this,'{cart.price_including_tax}');")
58
- .$this->button('Price excluding tax',"ocseditor.insertAtCaret(this,'{cart.price_excluding_tax}');")
59
- ."</p>"
60
- ."<p><span class=\"buttons-set-label\">".$this->__('Selection')."</span>"
61
- .$this->button('Weight',"ocseditor.insertAtCaret(this,'{selection.weight}');")
62
- .$this->button('Products quantity',"ocseditor.insertAtCaret(this,'{selection.quantity}');")
63
- ."</p>"
64
- ."<p><span class=\"buttons-set-label\">".$this->__('Product')."</span>"
65
- .$this->button('Weight',"ocseditor.insertAtCaret(this,'{product.weight}');")
66
- .$this->button('Quantity',"ocseditor.insertAtCaret(this,'{product.quantity}');")
67
- ."</p>"
68
- ."</fieldset>";
69
- break;
70
- case 'conditions':
71
- return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
72
- ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
73
- ."<p><span class=\"buttons-set-label\">".$this->__('Cart')."</span>"
74
- .$this->button('Weight',"ocseditor.insertAtCaret(this,'{cart.weight}');")
75
- .$this->button('Products quantity',"ocseditor.insertAtCaret(this,'{cart.quantity}');")
76
- .$this->button('Price including tax',"ocseditor.insertAtCaret(this,'{cart.price_including_tax}');")
77
- .$this->button('Price excluding tax',"ocseditor.insertAtCaret(this,'{cart.price_excluding_tax}');")
78
- ."</p>"
79
- ."</fieldset>";
80
- break;
81
- case 'customer_groups':
82
- return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
83
- ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
84
- ."<p>"
85
- .$this->button('Not logged in',"ocseditor.insertAtCaret(this,'NOT LOGGED IN');")
86
- ."</p>"
87
- ."</fieldset>";
88
- break;
89
- case 'tracking_url':
90
- return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
91
- ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
92
- ."<p>"
93
- .$this->button('Tracking number',"ocseditor.insertAtCaret(this,'{tracking_number}');")
94
- ."</p>"
95
- ."</fieldset>";
96
- break;
97
- case 'destination':
98
- case 'origin':
99
- $parsed_value = $this->parseAddressFilter($value);
100
- $excluding = $parsed_value['excluding'];
101
- return "<div class=\"address-filters-property\"><p>"
102
- ."<input type=\"radio\" class=\"excluding\" id=\"".$prefix."-exluding-0\" name=\"".$prefix."-exluding\""
103
- ." value=\"0\"".(!$excluding ? " checked=\"checked\"" : '')." onclick=\"ocseditor.updateCountries(this);\"/>"
104
- ."<label for=\"".$prefix."-exluding-0\"> ".$this->__('Limit to')."</label> &nbsp; "
105
- ."<input type=\"radio\" class=\"excluding\" id=\"".$prefix."-exluding-1\" name=\"".$prefix."-exluding\""
106
- ." value=\"1\"".($excluding ? " checked=\"checked\"" : '')." onclick=\"ocseditor.updateCountries(this);\"/>"
107
- ."<label for=\"".$prefix."-exluding-1\"> ".$this->__('Exclude')."</label></p>"
108
- ."<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
109
- ."<fieldset class=\"buttons-set\"><legend>".$this->__('Display')."</legend>"
110
- ."<p>"
111
- .$this->button('Display original input',"ocseditor.displayCountry('original-value',this,false);")
112
- .$this->button('Display corrected names',"ocseditor.displayCountry('full-value',this,false);")
113
- .$this->button('Display codes',"ocseditor.displayCountry('compact-value',this,true);")
114
- ."</p>"
115
- ."</fieldset>"
116
- ."<fieldset class=\"buttons-set\"><legend>".$this->__('Preview')."</legend>"
117
- ."<div class=\"address-filter-list\">".$this->getAddressFilters($parsed_value)."</div>"
118
- ."</fieldset>"
119
- ."</div>"
120
- ;
121
- break;
122
- case '*comment' :
123
- $lines = explode("\n",trim($value));
124
- for ($i=0; $i<count($lines); $i++) {
125
- $lines[$i] = preg_replace('/^# ?/','',$lines[$i]);
126
- }
127
- $value = implode("\n",$lines);
128
- return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>";
129
- default :
130
- return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>";
131
- }
132
- }
133
-
134
- private function getAddressFilters($data) {
135
- $address_filters = array();
136
- foreach ($data['countries'] as $country) {
137
- $address_filters[] = new AddressFilter($country);
138
- }
139
- return implode('',$address_filters);
140
- }
141
-
142
- private function parseAddressFilter($address_filter) {
143
- $output = array(
144
- 'excluding' => false,
145
- 'countries' => array(),
146
- 'original' => $address_filter,
147
- );
148
-
149
- $address_filter = str_replace(array("\r\n","\r","\n"),array(',',',',','),$address_filter);
150
-
151
- if (preg_match('# *\* *- *\((.*)\) *#s',$address_filter,$result)) {
152
- $address_filter = $result[1];
153
- $output['excluding'] = true;
154
- }
155
-
156
- $tmp_address_filter_array = explode(',',trim($address_filter));
157
-
158
- $concat = false;
159
- $concatened = '';
160
- $address_filter_array = array();
161
- $i = 0;
162
-
163
- foreach ($tmp_address_filter_array as $address_filter) {
164
- if ($concat) $concatened .= ','.$address_filter;
165
- else {
166
- if ($i<count($tmp_address_filter_array)-1 && preg_match('#\(#',$address_filter)) {
167
- $concat = true;
168
- $concatened .= $address_filter;
169
- } else $address_filter_array[] = $address_filter;
170
- }
171
- if (preg_match('#\)#',$address_filter)) {
172
- $address_filter_array[] = $concatened;
173
- $concatened = '';
174
- $concat = false;
175
- }
176
- $i++;
177
- }
178
-
179
- foreach ($address_filter_array as $address_filter) {
180
- $address_filter = trim($address_filter);
181
- if (trim($address_filter)!='') {
182
- if (preg_match('# *([^,(]+) *(-)? *(?:\( *(-)? *(.*)\))? *#s',$address_filter,$result)) {
183
- $country_code = $result[1];
184
-
185
- $region_codes = explode(',',$result[4]);
186
- $in_array = false;
187
- for ($i=count($region_codes); --$i>=0;) {
188
- $code = trim($region_codes[$i]);
189
- $region_codes[$i] = $code;
190
- }
191
- /*$in_array = in_array($address['region_code'],$region_codes,true) || in_array($address['postcode'],$region_codes,true);*/
192
- $excluding_region = $result[2]=='-' || $result[3]=='-';
193
- $output['countries'][] = array(
194
- 'excluding' => $excluding_region,
195
- 'country_code' => $country_code,
196
- 'region_codes' => implode(',',$region_codes),
197
- 'original' => $address_filter,
198
- );
199
- } else {
200
- $output['countries'][] = array(
201
- 'excluding' => null,
202
- 'country_code' => $address_filter,
203
- 'region_codes' => null,
204
- 'original' => $address_filter,
205
- );
206
- }
207
- }
208
- }
209
- return $output;
210
- }
211
-
212
- private function getRowUI($row, $selected) {
213
- $row['_ID_']['value'] = isset($row['_ID_']['value']) ? $row['_ID_']['value'] : uniqid('c');
214
- $row_id = $row['_ID_']['value'];
215
-
216
- if (isset($row['lines'])) {
217
- $output = "<div id=\"r-".$row_id."-container\" class=\"row-container has-error ignored-lines".($selected ? ' selected' : '')."\">"
218
- ."<div class=\"row-header\" onclick=\"ocseditor.selectRow('".$row_id."');\">"
219
- ."<div class=\"row-actions\">"
220
- .$this->button('Apply changes',"ocseditor.applyChanges();")
221
- .$this->button('Delete',"ocseditor.removeRow(this);",'delete')
222
- ."</div>"
223
- ."<div class=\"row-title\">".$this->__('Ignored lines')."</div></div>"
224
- ."<div class=\"properties-container\"><textarea class=\"field\">".$row['lines']."</textarea></div></div>";
225
- return $output;
226
- }
227
-
228
- if (!isset($row['label'])) {
229
- $row['label']['value'] = $this->__('New shipping method');
230
- }
231
-
232
- $properties = array(
233
- 'enabled' => 'Enabled',
234
- 'code' => 'Code',
235
- 'label' => 'Label',
236
- 'description' => 'Description',
237
- 'destination' => 'Destination',
238
- 'origin' => 'Origin',
239
- 'conditions' => 'Conditions',
240
- 'fees' => 'Fees',
241
- 'customer_groups' => 'Customer groups',
242
- 'tracking_url' => 'Tracking url',
243
- '*comment' => 'Comment',
244
- );
245
-
246
- $label = $row['label']['value'];
247
- $output = "<div id=\"r-".$row_id."-container\" class=\"row-container".($selected ? ' selected' : '')."\">"
248
- ."<div class=\"row-header\" onclick=\"ocseditor.selectRow('".$row_id."');\">"
249
- ."<div class=\"row-actions\">".$this->button('Delete',"ocseditor.removeRow(this);",'delete')."</div><div class=\"row-title\">".$label."</div></div>"
250
- ."<div class=\"properties-container\">";
251
- $list = "<ul class=\"properties-list\">";
252
- $j = 0;
253
- foreach ($properties as $property_key => $label) {
254
- $cleaned_property = $this->cleanKey($property_key);
255
- $value = isset($row[$property_key]) ? trim($row[$property_key]['value']) : '';
256
- $list .= "<li id=\"r-".$row_id."-p-".$cleaned_property."-item\" class=\"property-item".($j==0 ? ' selected' : '')
257
- .(empty($value) ? ' empty' : '')
258
- ."\" onclick=\"ocseditor.selectProperty('".$row_id."','".$cleaned_property."');\">".$this->__($label)."</li>";
259
- $output .= "<div id=\"r-".$row_id."-p-".$cleaned_property."-container\" class=\"property-container"
260
- .($j==0 ? ' selected' : '')."\" property-name=\"".$property_key."\">"
261
- ."<div class=\"buttons-set\" style=\"text-align:right;\">".$this->button('Help',"ocseditor.help('property.".$property_key."');",'help')."</div>"
262
- .$this->getPropertyHelper($row_id,$property_key,$row[$property_key])."</div>";
263
- $j++;
264
- }
265
- foreach ($row as $property_key => $property) {
266
- if (!isset($properties[$property_key]) && substr($property_key,0,1)!='*') {
267
- $label = $property_key;
268
- $cleaned_property = $this->cleanKey($property_key);
269
- $value = isset($row[$property_key]) ? trim($row[$property_key]['value']) : '';
270
- $list .= "<li id=\"r-".$row_id."-p-".$cleaned_property."-item\" class=\"property-item".($j==0 ? ' selected' : '')
271
- .(empty($value) ? ' empty' : '').($cleaned_property=='_ID_' ? ' hide' : '')
272
- ."\" onclick=\"ocseditor.selectProperty('".$row_id."','".$cleaned_property."');\">".$this->__($label)."</li>";
273
- $output .= "<div id=\"r-".$row_id."-p-".$cleaned_property."-container\" class=\"property-container"
274
- .($j==0 ? ' selected' : '')."\" property-name=\"".$property_key."\">"
275
- ."<div class=\"buttons-set\" style=\"text-align:right;\">".$this->button('Help',"ocseditor.help('property.".$property_key."');",'help')."</div>"
276
- .$this->getPropertyHelper($row_id,$property_key,$property)."</div>";
277
- $j++;
278
- }
279
- }
280
- $output .= $list."</div></div>";
281
- return $output;
282
- }
283
-
284
- private function getConfigErrors($config) {
285
- $script = "ocseditor.resetErrors();";
286
- foreach ($config as $row_code => $row) {
287
- if (isset($row['*messages'])) {
288
- $error = '';
289
- foreach ($row['*messages'] as $message) {
290
- $error .= "<p>".$this->__($message)."</p>";
291
- }
292
- if ($error!='') $script .= "ocseditor.setError('".$row['_ID_']['value']."','','".$this->jsEscape($error)."');";
293
- }
294
- foreach ($row as $property_key => $property) {
295
- if (isset($property['messages'])) {
296
- $error = '';
297
- foreach ($property['messages'] as $message) {
298
- $error .= "<p>".$this->__($message)."</p>";
299
- }
300
- if ($error!='') {
301
- $script .= "ocseditor.setError('".$row['_ID_']['value']."','".$property_key."','"
302
- .$this->jsEscape($error
303
- .($property['value']!=$property['original_value'] ?
304
- "<p>"
305
- .$this->button('Correct',"ocseditor.correct('".$row['_ID_']['value']."','".$property_key."','".$this->jsEscape($property['value'])."');")
306
- ."</p>" : '')
307
- )."');";
308
- }
309
- }
310
- }
311
- }
312
- //$script .= "alert('".str_replace(array("\r\n","\n","\'","'"),array(" "," ","\\\'","\'"),$script)."');";
313
- return $script;
314
- }
315
-
316
- private function loadConfig($input) {
317
- include_once $this->getIncludingPath('ChronorelaisShippingHelper.php');
318
-
319
- $helper = new ChronorelaisShippingHelper($input);
320
- $helper->checkConfig();
321
- $config = $helper->getConfig();
322
- //print_r($config);
323
-
324
- $output = "<div class=\"buttons-set\">"
325
- .$this->button('Add a shipping method',"ocseditor.addRow();",'add')
326
- ."</div><div class=\"config-container\">";
327
- $i = 0;
328
- foreach ($config as &$row) {
329
- $output .= $this->getRowUI($row,$i==0);
330
- $i++;
331
- }
332
- $output .= "</div><script type=\"text/javascript\">".$this->getConfigErrors($config)."</script>";
333
- return $output;
334
- }
335
-
336
- public function indexAction() {
337
- header('Content-Type: text/html; charset=UTF-8');
338
-
339
- include_once $this->getIncludingPath('countries.inc.php');
340
-
341
- switch ($_POST['what']) {
342
- case 'open':
343
- $output = ""
344
- // Donate page
345
- //.$this->page('donate',"Support the development of Chronorelais Shipping extension",$this->__('{ocseditor.donate-page.content}'))
346
- // Help page
347
- .$this->page('help',"Chronorelais Shipping extension help",'')
348
- // Main page
349
- .$this->pageHeader("Chronorelais Shipping configuration editor",
350
- $this->button('Save',"ocseditor.save();",'save')
351
- .$this->button('Export',"ocseditor.saveToFile();",'')
352
- .$this->button('Load',"ocseditor.showConfigLoader();",'')
353
- .$this->button('Close',"ocseditor.close();",'cancel')
354
- )
355
- ."<div id=\"ocs-editor-config-loader\">"
356
- ."<textarea></textarea>"
357
- ."<div class=\"buttons-set\">"
358
- .$this->button('Load',"ocseditor.loadConfig();",'')
359
- .$this->button('Cancel',"ocseditor.hideConfigLoader();",'cancel')
360
- ."</div>"
361
- ."</div>"
362
- ."<div id=\"ocs-editor-config-container\">".$this->loadConfig($_POST['input'])."</div>"
363
- /*."<div class=\"donate-container\">"
364
- ."<table cellspacing=\"0\"><tr>"
365
- ."<td>".$this->__('You appreciate this extension and would like to help?')."</td>"
366
- ."<td class=\"form-buttons\">"
367
- .$this->button('Donate',"ocseditor.openPage('donate');",'donate')
368
- ."</td>"
369
- ."</tr></table>"
370
- ."</div>"*/
371
- ;
372
- echo $output;
373
- exit;
374
- case 'help':
375
- echo $this->__('{ocseditor.help.'.$_POST['input'].'}');
376
- exit;
377
- case 'add-row':
378
- echo $this->getRowUI(array(),true);
379
- exit;
380
- case 'load-config':
381
- echo $this->loadConfig($_POST['config']);
382
- exit;
383
- case 'check-config':
384
- include_once $this->getIncludingPath('ChronorelaisShippingHelper.php');
385
-
386
- $helper = new ChronorelaisShippingHelper(urldecode($_POST['config']));
387
- $helper->checkConfig();
388
- print_r($helper->getConfig(),$out);
389
- //$script = "alert('".$this->jsEscape(urldecode($_POST['config']))."');";
390
- $script = $this->getConfigErrors($helper->getConfig());
391
- //$script = "alert('".$this->jsEscape($this->getConfigErrors($helper->getConfig()))."');";
392
- break;
393
- case 'save-to-file':
394
- include_once $this->getIncludingPath('ChronorelaisShippingHelper.php');
395
-
396
- $helper = new ChronorelaisShippingHelper(urldecode($_POST['config']));
397
- $formatted_config = $helper->formatConfig(false);
398
- $this->forceDownload('chronorelais-shipping-config.txt',$formatted_config);
399
- exit;
400
- case 'get-address-filters':
401
- $result = $this->parseAddressFilter($_POST['input']);
402
- echo $this->getAddressFilters($result);
403
- exit;
404
- }
405
-
406
- echo "<script type=\"text/javascript\">".$script."</script>";
407
- exit;
408
- }
409
- }
1
+ <?php
2
+
3
+ /**
4
+ * Magento Chronopost Chronorelais 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 Chronopost
17
+ * @package Chronopost_Chronorelais
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 Chronopost_Chronorelais_AjaxController extends Chronopost_Chronorelais_Controller_Abstract
24
+ {
25
+ private function getPropertyHelper($row_id, $property_key, $property) {
26
+ $cleaned_property = $this->cleanKey($property_key);
27
+ $prefix = "r-".$row_id."-p-".$cleaned_property;
28
+ $value = isset($property['original_value']) ? $property['original_value'] : (isset($property['value']) ? $property['value'] : '');
29
+
30
+ switch ($property_key) {
31
+ case 'enabled':
32
+ $enabled = $value!==false;
33
+ return "<p><select id=\"".$prefix."\" class=\"field\">"
34
+ ."<option value=\"0\"".($enabled ? '' : ' selected="selected"').">".$this->__('Disabled')."</option>"
35
+ ."<option value=\"1\"".($enabled ? ' selected="selected"' : '').">".$this->__('Enabled')."</option>"
36
+ ."</select><p>";
37
+ break;
38
+ case 'label':
39
+ case 'description':
40
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
41
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
42
+ ."<p>"
43
+ .$this->button('Destination country',"ocseditor.insertAtCaret(this,'{destination.country.name}');")
44
+ .$this->button('Cart weight',"ocseditor.insertAtCaret(this,'{cart.weight}');")
45
+ .$this->button('Cart quantity',"ocseditor.insertAtCaret(this,'{cart.quantity}');")
46
+ .$this->button('Price including tax',"ocseditor.insertAtCaret(this,'{cart.price_including_tax}');")
47
+ .$this->button('Price excluding tax',"ocseditor.insertAtCaret(this,'{cart.price_excluding_tax}');")
48
+ ."</p>"
49
+ ."</fieldset>";
50
+ break;
51
+ case 'fees':
52
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
53
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
54
+ ."<p><span class=\"buttons-set-label\">".$this->__('Cart')."</span>"
55
+ .$this->button('Weight',"ocseditor.insertAtCaret(this,'{cart.weight}');")
56
+ .$this->button('Products quantity',"ocseditor.insertAtCaret(this,'{cart.quantity}');")
57
+ .$this->button('Price including tax',"ocseditor.insertAtCaret(this,'{cart.price_including_tax}');")
58
+ .$this->button('Price excluding tax',"ocseditor.insertAtCaret(this,'{cart.price_excluding_tax}');")
59
+ ."</p>"
60
+ ."<p><span class=\"buttons-set-label\">".$this->__('Selection')."</span>"
61
+ .$this->button('Weight',"ocseditor.insertAtCaret(this,'{selection.weight}');")
62
+ .$this->button('Products quantity',"ocseditor.insertAtCaret(this,'{selection.quantity}');")
63
+ ."</p>"
64
+ ."<p><span class=\"buttons-set-label\">".$this->__('Product')."</span>"
65
+ .$this->button('Weight',"ocseditor.insertAtCaret(this,'{product.weight}');")
66
+ .$this->button('Quantity',"ocseditor.insertAtCaret(this,'{product.quantity}');")
67
+ ."</p>"
68
+ ."</fieldset>";
69
+ break;
70
+ case 'conditions':
71
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
72
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
73
+ ."<p><span class=\"buttons-set-label\">".$this->__('Cart')."</span>"
74
+ .$this->button('Weight',"ocseditor.insertAtCaret(this,'{cart.weight}');")
75
+ .$this->button('Products quantity',"ocseditor.insertAtCaret(this,'{cart.quantity}');")
76
+ .$this->button('Price including tax',"ocseditor.insertAtCaret(this,'{cart.price_including_tax}');")
77
+ .$this->button('Price excluding tax',"ocseditor.insertAtCaret(this,'{cart.price_excluding_tax}');")
78
+ ."</p>"
79
+ ."</fieldset>";
80
+ break;
81
+ case 'customer_groups':
82
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
83
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
84
+ ."<p>"
85
+ .$this->button('Not logged in',"ocseditor.insertAtCaret(this,'NOT LOGGED IN');")
86
+ ."</p>"
87
+ ."</fieldset>";
88
+ break;
89
+ case 'tracking_url':
90
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
91
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Insert')."</legend>"
92
+ ."<p>"
93
+ .$this->button('Tracking number',"ocseditor.insertAtCaret(this,'{tracking_number}');")
94
+ ."</p>"
95
+ ."</fieldset>";
96
+ break;
97
+ case 'destination':
98
+ case 'origin':
99
+ $parsed_value = $this->parseAddressFilter($value);
100
+ $excluding = $parsed_value['excluding'];
101
+ return "<div class=\"address-filters-property\"><p>"
102
+ ."<input type=\"radio\" class=\"excluding\" id=\"".$prefix."-exluding-0\" name=\"".$prefix."-exluding\""
103
+ ." value=\"0\"".(!$excluding ? " checked=\"checked\"" : '')." onclick=\"ocseditor.updateCountries(this);\"/>"
104
+ ."<label for=\"".$prefix."-exluding-0\"> ".$this->__('Limit to')."</label> &nbsp; "
105
+ ."<input type=\"radio\" class=\"excluding\" id=\"".$prefix."-exluding-1\" name=\"".$prefix."-exluding\""
106
+ ." value=\"1\"".($excluding ? " checked=\"checked\"" : '')." onclick=\"ocseditor.updateCountries(this);\"/>"
107
+ ."<label for=\"".$prefix."-exluding-1\"> ".$this->__('Exclude')."</label></p>"
108
+ ."<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>"
109
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Display')."</legend>"
110
+ ."<p>"
111
+ .$this->button('Display original input',"ocseditor.displayCountry('original-value',this,false);")
112
+ .$this->button('Display corrected names',"ocseditor.displayCountry('full-value',this,false);")
113
+ .$this->button('Display codes',"ocseditor.displayCountry('compact-value',this,true);")
114
+ ."</p>"
115
+ ."</fieldset>"
116
+ ."<fieldset class=\"buttons-set\"><legend>".$this->__('Preview')."</legend>"
117
+ ."<div class=\"address-filter-list\">".$this->getAddressFilters($parsed_value)."</div>"
118
+ ."</fieldset>"
119
+ ."</div>"
120
+ ;
121
+ break;
122
+ case '*comment' :
123
+ $lines = explode("\n",trim($value));
124
+ for ($i=0; $i<count($lines); $i++) {
125
+ $lines[$i] = preg_replace('/^# ?/','',$lines[$i]);
126
+ }
127
+ $value = implode("\n",$lines);
128
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>";
129
+ default :
130
+ return "<textarea id=\"".$prefix."\" class=\"field\">".$value."</textarea>";
131
+ }
132
+ }
133
+
134
+ private function getAddressFilters($data) {
135
+ $address_filters = array();
136
+ foreach ($data['countries'] as $country) {
137
+ $address_filters[] = new AddressFilter($country);
138
+ }
139
+ return implode('',$address_filters);
140
+ }
141
+
142
+ private function parseAddressFilter($address_filter) {
143
+ $output = array(
144
+ 'excluding' => false,
145
+ 'countries' => array(),
146
+ 'original' => $address_filter,
147
+ );
148
+
149
+ $address_filter = str_replace(array("\r\n","\r","\n"),array(',',',',','),$address_filter);
150
+
151
+ if (preg_match('# *\* *- *\((.*)\) *#s',$address_filter,$result)) {
152
+ $address_filter = $result[1];
153
+ $output['excluding'] = true;
154
+ }
155
+
156
+ $tmp_address_filter_array = explode(',',trim($address_filter));
157
+
158
+ $concat = false;
159
+ $concatened = '';
160
+ $address_filter_array = array();
161
+ $i = 0;
162
+
163
+ foreach ($tmp_address_filter_array as $address_filter) {
164
+ if ($concat) $concatened .= ','.$address_filter;
165
+ else {
166
+ if ($i<count($tmp_address_filter_array)-1 && preg_match('#\(#',$address_filter)) {
167
+ $concat = true;
168
+ $concatened .= $address_filter;
169
+ } else $address_filter_array[] = $address_filter;
170
+ }
171
+ if (preg_match('#\)#',$address_filter)) {
172
+ $address_filter_array[] = $concatened;
173
+ $concatened = '';
174
+ $concat = false;
175
+ }
176
+ $i++;
177
+ }
178
+
179
+ foreach ($address_filter_array as $address_filter) {
180
+ $address_filter = trim($address_filter);
181
+ if (trim($address_filter)!='') {
182
+ if (preg_match('# *([^,(]+) *(-)? *(?:\( *(-)? *(.*)\))? *#s',$address_filter,$result)) {
183
+ $country_code = $result[1];
184
+
185
+ $region_codes = explode(',',$result[4]);
186
+ $in_array = false;
187
+ for ($i=count($region_codes); --$i>=0;) {
188
+ $code = trim($region_codes[$i]);
189
+ $region_codes[$i] = $code;
190
+ }
191
+ /*$in_array = in_array($address['region_code'],$region_codes,true) || in_array($address['postcode'],$region_codes,true);*/
192
+ $excluding_region = $result[2]=='-' || $result[3]=='-';
193
+ $output['countries'][] = array(
194
+ 'excluding' => $excluding_region,
195
+ 'country_code' => $country_code,
196
+ 'region_codes' => implode(',',$region_codes),
197
+ 'original' => $address_filter,
198
+ );
199
+ } else {
200
+ $output['countries'][] = array(
201
+ 'excluding' => null,
202
+ 'country_code' => $address_filter,
203
+ 'region_codes' => null,
204
+ 'original' => $address_filter,
205
+ );
206
+ }
207
+ }
208
+ }
209
+ return $output;
210
+ }
211
+
212
+ private function getRowUI($row, $selected) {
213
+ $row['_ID_']['value'] = isset($row['_ID_']['value']) ? $row['_ID_']['value'] : uniqid('c');
214
+ $row_id = $row['_ID_']['value'];
215
+
216
+ if (isset($row['lines'])) {
217
+ $output = "<div id=\"r-".$row_id."-container\" class=\"row-container has-error ignored-lines".($selected ? ' selected' : '')."\">"
218
+ ."<div class=\"row-header\" onclick=\"ocseditor.selectRow('".$row_id."');\">"
219
+ ."<div class=\"row-actions\">"
220
+ .$this->button('Apply changes',"ocseditor.applyChanges();")
221
+ .$this->button('Delete',"ocseditor.removeRow(this);",'delete')
222
+ ."</div>"
223
+ ."<div class=\"row-title\">".$this->__('Ignored lines')."</div></div>"
224
+ ."<div class=\"properties-container\"><textarea class=\"field\">".$row['lines']."</textarea></div></div>";
225
+ return $output;
226
+ }
227
+
228
+ if (!isset($row['label'])) {
229
+ $row['label']['value'] = $this->__('New shipping method');
230
+ }
231
+
232
+ $properties = array(
233
+ 'enabled' => 'Enabled',
234
+ 'code' => 'Code',
235
+ 'label' => 'Label',
236
+ 'description' => 'Description',
237
+ 'destination' => 'Destination',
238
+ 'origin' => 'Origin',
239
+ 'conditions' => 'Conditions',
240
+ 'fees' => 'Fees',
241
+ 'customer_groups' => 'Customer groups',
242
+ 'tracking_url' => 'Tracking url',
243
+ '*comment' => 'Comment',
244
+ );
245
+
246
+ $label = $row['label']['value'];
247
+ $output = "<div id=\"r-".$row_id."-container\" class=\"row-container".($selected ? ' selected' : '')."\">"
248
+ ."<div class=\"row-header\" onclick=\"ocseditor.selectRow('".$row_id."');\">"
249
+ ."<div class=\"row-actions\">".$this->button('Delete',"ocseditor.removeRow(this);",'delete')."</div><div class=\"row-title\">".$label."</div></div>"
250
+ ."<div class=\"properties-container\">";
251
+ $list = "<ul class=\"properties-list\">";
252
+ $j = 0;
253
+ foreach ($properties as $property_key => $label) {
254
+ $cleaned_property = $this->cleanKey($property_key);
255
+ $value = isset($row[$property_key]) ? trim($row[$property_key]['value']) : '';
256
+ $list .= "<li id=\"r-".$row_id."-p-".$cleaned_property."-item\" class=\"property-item".($j==0 ? ' selected' : '')
257
+ .(empty($value) ? ' empty' : '')
258
+ ."\" onclick=\"ocseditor.selectProperty('".$row_id."','".$cleaned_property."');\">".$this->__($label)."</li>";
259
+ $output .= "<div id=\"r-".$row_id."-p-".$cleaned_property."-container\" class=\"property-container"
260
+ .($j==0 ? ' selected' : '')."\" property-name=\"".$property_key."\">"
261
+ ."<div class=\"buttons-set\" style=\"text-align:right;\">".$this->button('Help',"ocseditor.help('property.".$property_key."');",'help')."</div>"
262
+ .$this->getPropertyHelper($row_id,$property_key,$row[$property_key])."</div>";
263
+ $j++;
264
+ }
265
+ foreach ($row as $property_key => $property) {
266
+ if (!isset($properties[$property_key]) && substr($property_key,0,1)!='*') {
267
+ $label = $property_key;
268
+ $cleaned_property = $this->cleanKey($property_key);
269
+ $value = isset($row[$property_key]) ? trim($row[$property_key]['value']) : '';
270
+ $list .= "<li id=\"r-".$row_id."-p-".$cleaned_property."-item\" class=\"property-item".($j==0 ? ' selected' : '')
271
+ .(empty($value) ? ' empty' : '').($cleaned_property=='_ID_' ? ' hide' : '')
272
+ ."\" onclick=\"ocseditor.selectProperty('".$row_id."','".$cleaned_property."');\">".$this->__($label)."</li>";
273
+ $output .= "<div id=\"r-".$row_id."-p-".$cleaned_property."-container\" class=\"property-container"
274
+ .($j==0 ? ' selected' : '')."\" property-name=\"".$property_key."\">"
275
+ ."<div class=\"buttons-set\" style=\"text-align:right;\">".$this->button('Help',"ocseditor.help('property.".$property_key."');",'help')."</div>"
276
+ .$this->getPropertyHelper($row_id,$property_key,$property)."</div>";
277
+ $j++;
278
+ }
279
+ }
280
+ $output .= $list."</div></div>";
281
+ return $output;
282
+ }
283
+
284
+ private function getConfigErrors($config) {
285
+ $script = "ocseditor.resetErrors();";
286
+ foreach ($config as $row_code => $row) {
287
+ if (isset($row['*messages'])) {
288
+ $error = '';
289
+ foreach ($row['*messages'] as $message) {
290
+ $error .= "<p>".$this->__($message)."</p>";
291
+ }
292
+ if ($error!='') $script .= "ocseditor.setError('".$row['_ID_']['value']."','','".$this->jsEscape($error)."');";
293
+ }
294
+ foreach ($row as $property_key => $property) {
295
+ if (isset($property['messages'])) {
296
+ $error = '';
297
+ foreach ($property['messages'] as $message) {
298
+ $error .= "<p>".$this->__($message)."</p>";
299
+ }
300
+ if ($error!='') {
301
+ $script .= "ocseditor.setError('".$row['_ID_']['value']."','".$property_key."','"
302
+ .$this->jsEscape($error
303
+ .($property['value']!=$property['original_value'] ?
304
+ "<p>"
305
+ .$this->button('Correct',"ocseditor.correct('".$row['_ID_']['value']."','".$property_key."','".$this->jsEscape($property['value'])."');")
306
+ ."</p>" : '')
307
+ )."');";
308
+ }
309
+ }
310
+ }
311
+ }
312
+ //$script .= "alert('".str_replace(array("\r\n","\n","\'","'"),array(" "," ","\\\'","\'"),$script)."');";
313
+ return $script;
314
+ }
315
+
316
+ private function loadConfig($input) {
317
+ include_once $this->getIncludingPath('ChronorelaisShippingHelper.php');
318
+
319
+ $helper = new ChronorelaisShippingHelper($input);
320
+ $helper->checkConfig();
321
+ $config = $helper->getConfig();
322
+ //print_r($config);
323
+
324
+ $output = "<div class=\"buttons-set\">"
325
+ .$this->button('Add a shipping method',"ocseditor.addRow();",'add')
326
+ ."</div><div class=\"config-container\">";
327
+ $i = 0;
328
+ foreach ($config as &$row) {
329
+ $output .= $this->getRowUI($row,$i==0);
330
+ $i++;
331
+ }
332
+ $output .= "</div><script type=\"text/javascript\">".$this->getConfigErrors($config)."</script>";
333
+ return $output;
334
+ }
335
+
336
+ public function indexAction() {
337
+ header('Content-Type: text/html; charset=UTF-8');
338
+
339
+ include_once $this->getIncludingPath('countries.inc.php');
340
+
341
+ switch ($_POST['what']) {
342
+ case 'open':
343
+ $output = ""
344
+ // Donate page
345
+ //.$this->page('donate',"Support the development of Chronorelais Shipping extension",$this->__('{ocseditor.donate-page.content}'))
346
+ // Help page
347
+ .$this->page('help',"Chronorelais Shipping extension help",'')
348
+ // Main page
349
+ .$this->pageHeader("Chronorelais Shipping configuration editor",
350
+ $this->button('Save',"ocseditor.save();",'save')
351
+ .$this->button('Export',"ocseditor.saveToFile();",'')
352
+ .$this->button('Load',"ocseditor.showConfigLoader();",'')
353
+ .$this->button('Close',"ocseditor.close();",'cancel')
354
+ )
355
+ ."<div id=\"ocs-editor-config-loader\">"
356
+ ."<textarea></textarea>"
357
+ ."<div class=\"buttons-set\">"
358
+ .$this->button('Load',"ocseditor.loadConfig();",'')
359
+ .$this->button('Cancel',"ocseditor.hideConfigLoader();",'cancel')
360
+ ."</div>"
361
+ ."</div>"
362
+ ."<div id=\"ocs-editor-config-container\">".$this->loadConfig($_POST['input'])."</div>"
363
+ /*."<div class=\"donate-container\">"
364
+ ."<table cellspacing=\"0\"><tr>"
365
+ ."<td>".$this->__('You appreciate this extension and would like to help?')."</td>"
366
+ ."<td class=\"form-buttons\">"
367
+ .$this->button('Donate',"ocseditor.openPage('donate');",'donate')
368
+ ."</td>"
369
+ ."</tr></table>"
370
+ ."</div>"*/
371
+ ;
372
+ echo $output;
373
+ exit;
374
+ case 'help':
375
+ echo $this->__('{ocseditor.help.'.$_POST['input'].'}');
376
+ exit;
377
+ case 'add-row':
378
+ echo $this->getRowUI(array(),true);
379
+ exit;
380
+ case 'load-config':
381
+ echo $this->loadConfig($_POST['config']);
382
+ exit;
383
+ case 'check-config':
384
+ include_once $this->getIncludingPath('ChronorelaisShippingHelper.php');
385
+
386
+ $helper = new ChronorelaisShippingHelper(urldecode($_POST['config']));
387
+ $helper->checkConfig();
388
+ print_r($helper->getConfig(),$out);
389
+ //$script = "alert('".$this->jsEscape(urldecode($_POST['config']))."');";
390
+ $script = $this->getConfigErrors($helper->getConfig());
391
+ //$script = "alert('".$this->jsEscape($this->getConfigErrors($helper->getConfig()))."');";
392
+ break;
393
+ case 'save-to-file':
394
+ include_once $this->getIncludingPath('ChronorelaisShippingHelper.php');
395
+
396
+ $helper = new ChronorelaisShippingHelper(urldecode($_POST['config']));
397
+ $formatted_config = $helper->formatConfig(false);
398
+ $this->forceDownload('chronorelais-shipping-config.txt',$formatted_config);
399
+ exit;
400
+ case 'get-address-filters':
401
+ $result = $this->parseAddressFilter($_POST['input']);
402
+ echo $this->getAddressFilters($result);
403
+ exit;
404
+ }
405
+
406
+ echo "<script type=\"text/javascript\">".$script."</script>";
407
+ exit;
408
+ }
409
+ }
app/code/community/Chronopost/Chronorelais/controllers/Checkout/MultishippingController.php CHANGED
@@ -78,15 +78,15 @@ class Chronopost_Chronorelais_Checkout_MultishippingController extends Mage_Chec
78
  $addresses = $this->_getCheckout()->getQuote()->getAllShippingAddresses();
79
  foreach ($addresses as $address) {
80
  if ($address->getId() == $this->getRequest()->get('index')) {
81
- /*$address->setPostcode($postcode)
82
  ->save()
83
- ->setCollectShippingRates(true);*/
84
 
85
  $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
86
  $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$postcode,0));
87
 
88
  if ($webservbt) {
89
- Mage::getSingleton('core/session')->setMultiPostcode($postcode);
90
  $this->loadLayout('checkout_multishipping_shippingchronorelais');
91
  $result['update_section'] = array(
92
  'name' => 'checkout-shipping-method-chronorelais-load_'.$this->getRequest()->get('index'),
@@ -111,4 +111,38 @@ class Chronopost_Chronorelais_Checkout_MultishippingController extends Mage_Chec
111
  }
112
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
113
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  }
78
  $addresses = $this->_getCheckout()->getQuote()->getAllShippingAddresses();
79
  foreach ($addresses as $address) {
80
  if ($address->getId() == $this->getRequest()->get('index')) {
81
+ $address->setPostcode($postcode)/*
82
  ->save()
83
+ ->setCollectShippingRates(true)*/;
84
 
85
  $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
86
  $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$postcode,0));
87
 
88
  if ($webservbt) {
89
+ Mage::getSingleton('core/session')->setMultiAddress($address);
90
  $this->loadLayout('checkout_multishipping_shippingchronorelais');
91
  $result['update_section'] = array(
92
  'name' => 'checkout-shipping-method-chronorelais-load_'.$this->getRequest()->get('index'),
111
  }
112
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
113
  }
114
+
115
+ /**
116
+ * Change shipping postal code
117
+ * /
118
+ public function changeMultiPostalCodeAction()
119
+ {
120
+ $result = array();
121
+ $webservbt = array();
122
+ $postcode = $this->getRequest()->get('zip');
123
+ if($postcode) {
124
+ $quote = $this->_getCheckout()->getQuote();
125
+ $address = $quote->getShippingAddress();
126
+ //$address = $quote->getAddressById($this->getRequest()->get('index'));
127
+ $address->setPostcode($postcode)/*
128
+ ->save()
129
+ ->setCollectShippingRates(true)* /;
130
+
131
+ $client = new SoapClient("http://wsshipping.chronopost.fr/soap.point.relais/services/ServiceRechercheBt?wsdl",array('trace'=> 0,'connection_timeout'=>10));
132
+ $webservbt = $client->__call("rechercheBtParCodeproduitEtCodepostalEtDate",array(0,$postcode,0));
133
+ }
134
+ if ($webservbt) {
135
+ $this->loadLayout('checkout_multishipping_shippingchronorelais');
136
+ $result['update_section'] = array(
137
+ 'name' => 'checkout-shipping-method-chronorelais-load_'.$this->getRequest()->get('index'),
138
+ 'html' => str_replace("%%id%%", $this->getRequest()->get('index'), $this->_getChronoRelaisHtml())
139
+ );
140
+ $result['relaypoints'] = $webservbt;
141
+ } else {
142
+ $result['error'] = true;
143
+ $result['message'] = $this->__('No point relay is associated with this postcode');
144
+ }
145
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
146
+ }
147
+ */
148
  }
app/code/community/Chronopost/Chronorelais/controllers/Checkout/OnepageController.php CHANGED
@@ -44,9 +44,8 @@ class Chronopost_Chronorelais_Checkout_OnepageController extends Mage_Checkout_O
44
  return;
45
  }
46
  if ($this->getRequest()->isPost()) {
47
- // $postData = $this->getRequest()->getPost('billing', array());
48
- // $data = $this->_filterPostData($postData);
49
- $data = $this->getRequest()->getPost('billing', array());
50
  $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
51
 
52
  if (isset($data['email'])) {
@@ -103,6 +102,9 @@ class Chronopost_Chronorelais_Checkout_OnepageController extends Mage_Checkout_O
103
  if ($this->getRequest()->isPost()) {
104
  $data = $this->getRequest()->getPost('shipping', array());
105
  $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
 
 
 
106
  $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
107
 
108
  if (!isset($result['error'])) {
@@ -135,6 +137,7 @@ class Chronopost_Chronorelais_Checkout_OnepageController extends Mage_Checkout_O
135
  if ($this->_expireAjax()) {
136
  return;
137
  }
 
138
  if ($this->getRequest()->isPost()) {
139
 
140
  //WEC chronorelais
@@ -151,7 +154,9 @@ class Chronopost_Chronorelais_Checkout_OnepageController extends Mage_Checkout_O
151
  $quote = Mage::getSingleton('checkout/cart')->init()->getQuote();
152
  $address = $quote->getShippingAddress();
153
 
 
154
  if( substr($this->getRequest()->getParam('shipping_method'),0,12) == "chronorelais" ){
 
155
  $relaisId = $this->getRequest()->getParam('shipping_method_chronorelais');
156
  if($relaisId!=""){
157
 
@@ -185,31 +190,30 @@ class Chronopost_Chronorelais_Checkout_OnepageController extends Mage_Checkout_O
185
  }
186
  }
187
  }
 
188
  //ENDWEC chronorelais
189
 
190
  $data = $this->getRequest()->getPost('shipping_method', '');
 
191
  $result = $this->getOnepage()->saveShippingMethod($data);
 
192
  /*
193
- $result will have erro data if shipping method is empty
194
- */
195
  if(!$result) {
196
- Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method',
197
- array('request'=>$this->getRequest(),
198
- 'quote'=>$this->getOnepage()->getQuote()));
199
- $this->getOnepage()->getQuote()->collectTotals();
200
- $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
201
 
202
- $result['goto_section'] = 'payment';
203
- $result['update_section'] = array(
204
- 'name' => 'payment-method',
205
- 'html' => $this->_getPaymentMethodsHtml()
206
- );
207
  }
208
- $this->getOnepage()->getQuote()->collectTotals()->save();
209
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
210
  }
211
  }
212
-
213
  /**
214
  * Get relais
215
  */
44
  return;
45
  }
46
  if ($this->getRequest()->isPost()) {
47
+ $postData = $this->getRequest()->getPost('billing', array());
48
+ $data = $this->_filterPostData($postData);
 
49
  $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
50
 
51
  if (isset($data['email'])) {
102
  if ($this->getRequest()->isPost()) {
103
  $data = $this->getRequest()->getPost('shipping', array());
104
  $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
105
+
106
+
107
+
108
  $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
109
 
110
  if (!isset($result['error'])) {
137
  if ($this->_expireAjax()) {
138
  return;
139
  }
140
+
141
  if ($this->getRequest()->isPost()) {
142
 
143
  //WEC chronorelais
154
  $quote = Mage::getSingleton('checkout/cart')->init()->getQuote();
155
  $address = $quote->getShippingAddress();
156
 
157
+ //if( substr($this->getRequest()->getParam('shipping_method'),0,25) == "chronorelais_chronorelais" ){
158
  if( substr($this->getRequest()->getParam('shipping_method'),0,12) == "chronorelais" ){
159
+
160
  $relaisId = $this->getRequest()->getParam('shipping_method_chronorelais');
161
  if($relaisId!=""){
162
 
190
  }
191
  }
192
  }
193
+
194
  //ENDWEC chronorelais
195
 
196
  $data = $this->getRequest()->getPost('shipping_method', '');
197
+
198
  $result = $this->getOnepage()->saveShippingMethod($data);
199
+
200
  /*
201
+ $result will have erro data if shipping method is empty
202
+ */
203
  if(!$result) {
204
+ Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$this->getRequest(), 'quote'=>$this->getOnepage()->getQuote()));
205
+ // $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 
 
 
206
 
207
+ $result['goto_section'] = 'payment';
208
+ $result['update_section'] = array(
209
+ 'name' => 'payment-method',
210
+ 'html' => $this->_getPaymentMethodsHtml()
211
+ );
212
  }
 
213
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
214
  }
215
  }
216
+
217
  /**
218
  * Get relais
219
  */
app/code/community/Chronopost/Chronorelais/controllers/ImportController.php CHANGED
@@ -202,7 +202,7 @@ class Chronopost_Chronorelais_ImportController extends Mage_Adminhtml_Controller
202
  }
203
 
204
  $track = Mage::getModel('sales/order_shipment_track')
205
- ->setNumber($trackingNumber) //setTrackingNumber ?
206
  ->setCarrierCode($carrier_code)
207
  ->setTitle($trackingTitle)
208
  ->setPopup($popup);
202
  }
203
 
204
  $track = Mage::getModel('sales/order_shipment_track')
205
+ ->setNumber($trackingNumber)
206
  ->setCarrierCode($carrier_code)
207
  ->setTitle($trackingTitle)
208
  ->setPopup($popup);
app/code/community/Chronopost/Chronorelais/controllers/RelaisController.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- class Chronopost_Chronorelais_RelaisController extends Mage_Core_Controller_Front_Action {
3
-
4
- public function filterAction() {
5
- $this->loadLayout();
6
- $this->renderLayout();
7
- }
8
-
9
- public function detailAction() {
10
- $this->loadLayout();
11
- $this->renderLayout();
12
- }
13
-
14
- /**
15
- * Go to the tacking page
16
- * external function for mail link "Track Your Order" in shipment mail
17
- */
18
- public function trackingAction()
19
- {
20
- if($this->getRequest()->isGet()) {
21
- if($hash = $this->getRequest()->getParam('hash')) {
22
- $req_values = Mage::helper('shipping')->decodeTrackingHash($hash);
23
- if($req_values) {
24
- $order = Mage::getModel('sales/order')->load($req_values['id']);
25
- $popup_url = Mage::helper('shipping')->getTrackingPopupUrlBySalesModel($order);
26
- header('location: '.$popup_url); exit();
27
- }
28
- }
29
- }
30
- }
31
-
32
  }
1
+ <?php
2
+ class Chronopost_Chronorelais_RelaisController extends Mage_Core_Controller_Front_Action {
3
+
4
+ public function filterAction() {
5
+ $this->loadLayout();
6
+ $this->renderLayout();
7
+ }
8
+
9
+ public function detailAction() {
10
+ $this->loadLayout();
11
+ $this->renderLayout();
12
+ }
13
+
14
+ /**
15
+ * Go to the tacking page
16
+ * external function for mail link "Track Your Order" in shipment mail
17
+ */
18
+ public function trackingAction()
19
+ {
20
+ if($this->getRequest()->isGet()) {
21
+ if($hash = $this->getRequest()->getParam('hash')) {
22
+ $req_values = Mage::helper('shipping')->decodeTrackingHash($hash);
23
+ if($req_values) {
24
+ $order = Mage::getModel('sales/order')->load($req_values['id']);
25
+ $popup_url = Mage::helper('shipping')->getTrackingPopupUrlBySalesModel($order);
26
+ header('location: '.$popup_url); exit();
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
  }
app/code/community/Chronopost/Chronorelais/controllers/Sales/ImpressionController.php CHANGED
@@ -1,567 +1,556 @@
1
  <?php
2
-
3
  require_once 'Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php';
4
-
5
- class Chronopost_Chronorelais_Sales_ImpressionController extends Mage_Adminhtml_Sales_Order_ShipmentController {
6
-
7
- protected $_trackingNumbers = '';
8
-
9
- /**
10
- * Additional initialization
11
- *
12
- */
13
- protected function _construct() {
14
- $this->setUsedModuleName('Chronopost_Chronorelais');
15
- }
16
-
17
- /**
18
- * Shipping grid
19
- */
20
- public function indexAction() {
21
- if (!extension_loaded('soap')) {
22
- $this->_getSession()->addError($this->__('The SOAP extension is not installed in the server. Please contact the site administrator. Sorry for inconvenience.'));
23
- return $this->_redirectReferer();
24
  }
25
- $this->loadLayout()
 
 
 
 
 
 
 
 
 
 
26
  ->_setActiveMenu('sales/chronorelais')
27
  ->_addContent($this->getLayout()->createBlock('chronorelais/sales_impression'))
28
  ->renderLayout();
29
- }
30
-
31
- /**
32
- * Save shipment and order in one transaction
33
- * @param Mage_Sales_Model_Order_Shipment $shipment
34
- */
35
- protected function _saveShipment($shipment) {
36
- $shipment->getOrder()->setIsInProcess(true);
37
- $transactionSave = Mage::getModel('core/resource_transaction')
 
38
  ->addObject($shipment)
39
  ->addObject($shipment->getOrder())
40
  ->save();
41
 
42
- return $this;
43
- }
44
-
45
- protected function _processDownload($resource, $resourceType) {
46
- $helper = Mage::helper('downloadable/download');
47
- /* @var $helper Mage_Downloadable_Helper_Download */
 
48
 
49
- $helper->setResource($resource, $resourceType);
50
 
51
- $fileName = $helper->getFilename();
52
- $contentType = $helper->getContentType();
53
 
54
- $this->getResponse()
55
  ->setHttpResponseCode(200)
56
  ->setHeader('Pragma', 'public', true)
57
  ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
58
  ->setHeader('Content-type', $contentType, true);
59
 
60
- if ($fileSize = $helper->getFilesize()) {
61
- $this->getResponse()
62
- ->setHeader('Content-Length', $fileSize);
63
- }
64
 
65
- if ($contentDisposition = $helper->getContentDisposition()) {
66
- $this->getResponse()
67
- ->setHeader('Content-Disposition', $contentDisposition . '; filename=' . $fileName);
68
- }
69
 
70
- $this->getResponse()
71
  ->clearBody();
72
- $this->getResponse()
73
  ->sendHeaders();
74
 
75
- $helper->output();
76
- }
77
-
78
- protected function getTrackingNumber($shipmentId) {
79
- $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
80
-
81
- //On récupère le numéro de tracking
82
- $tracks = $shipment->getTracksCollection();
83
- foreach ($tracks as $track) {
84
- if ($track->getParentId() == $shipmentId) {
85
- $this->_trackingNumbers .= $track->getnumber();
86
- }
87
- }
88
-
89
- return $this->_trackingNumbers;
90
- }
91
-
92
- protected function getFilledValue($value) {
93
- if ($value) {
94
- return $this->removeaccents(trim($value));
95
- } else {
96
- return '';
97
- }
98
- }
99
-
100
- protected function checkMobileNumber($value) {
101
- if ($reqvalue = trim($value)) {
102
- $_number = substr($reqvalue, 0, 2);
103
- $fixed_array = array('01', '02', '03', '04', '05', '06', '06');
104
- if (in_array($_number, $fixed_array)) {
105
- return $reqvalue;
106
- } else {
107
- return '';
108
- }
109
- }
110
- }
111
-
112
- protected function getExpeditionParams($shipment, $_shippingMethod) {
113
- $_order = $shipment->getOrder();
114
- $_shippingAddress = $shipment->getShippingAddress();
115
- $_billingAddress = $shipment->getBillingAddress();
116
- $_helper = Mage::helper('chronorelais');
117
-
118
- if ($_shippingMethod[0] == 'chronorelais' || $_shippingMethod[0] == 'chronopost' || $_shippingMethod[0] == 'chronoexpress') {
119
- $esdParams = $header = $shipper = $customer = $recipient = $ref = $skybill = $skybillParams = $password = array();
120
-
121
- //esdParams parameters
122
- $esdParams = array(
123
- 'height' => '',
124
- 'width' => '',
125
- 'length' => ''
126
- );
127
-
128
- //header parameters
129
- $header = array(
130
- 'idEmit' => 'CHRFR',
131
- 'accountNumber' => $_helper->getConfigurationAccountNumber(),
132
- 'subAccount' => $_helper->getConfigurationSubAccountNumber()
133
- );
134
-
135
- //shipper parameters
136
- $shipperMobilePhone = $this->checkMobileNumber($_helper->getConfigurationShipperInfo('mobilephone'));
137
- $shipper = array(
138
- 'shipperAdress1' => $_helper->getConfigurationShipperInfo('address1'),
139
- 'shipperAdress2' => $_helper->getConfigurationShipperInfo('address2'),
140
- 'shipperCity' => $_helper->getConfigurationShipperInfo('city'),
141
- 'shipperCivility' => $_helper->getConfigurationShipperInfo('civility'),
142
- 'shipperContactName' => $_helper->getConfigurationShipperInfo('contactname'),
143
- 'shipperCountry' => $_helper->getConfigurationShipperInfo('country'),
144
- 'shipperEmail' => $_helper->getConfigurationShipperInfo('email'),
145
- 'shipperMobilePhone' => $shipperMobilePhone,
146
- 'shipperName' => $_helper->getConfigurationShipperInfo('name'),
147
- 'shipperName2' => $_helper->getConfigurationShipperInfo('name2'),
148
- 'shipperPhone' => $_helper->getConfigurationShipperInfo('phone'),
149
- 'shipperPreAlert' => '',
150
- 'shipperZipCode' => $_helper->getConfigurationShipperInfo('zipcode')
151
- );
152
-
153
- //customer parameters
154
- $customerMobilePhone = $this->checkMobileNumber($_helper->getConfigurationCustomerInfo('mobilephone'));
155
- $customer = array(
156
- 'customerAdress1' => $_helper->getConfigurationCustomerInfo('address1'),
157
- 'customerAdress2' => $_helper->getConfigurationCustomerInfo('address2'),
158
- 'customerCity' => $_helper->getConfigurationCustomerInfo('city'),
159
- 'customerCivility' => $_helper->getConfigurationCustomerInfo('civility'),
160
- 'customerContactName' => $_helper->getConfigurationCustomerInfo('contactname'),
161
- 'customerCountry' => $_helper->getConfigurationCustomerInfo('country'),
162
- 'customerEmail' => $_helper->getConfigurationCustomerInfo('email'),
163
- 'customerMobilePhone' => $customerMobilePhone,
164
- 'customerName' => $_helper->getConfigurationCustomerInfo('name'),
165
- 'customerName2' => $_helper->getConfigurationCustomerInfo('name2'),
166
- 'customerPhone' => $_helper->getConfigurationCustomerInfo('phone'),
167
- 'customerPreAlert' => '',
168
- 'customerZipCode' => $_helper->getConfigurationCustomerInfo('zipcode')
169
- );
170
-
171
- //recipient parameters
172
- $recipient_address = $_shippingAddress->getStreet();
173
- if (!isset($recipient_address[1])) {
174
- $recipient_address[1] = '';
175
- }
176
- $customer_email = ($_shippingAddress->getEmail()) ? $_shippingAddress->getEmail() : ($_billingAddress->getEmail() ? $_billingAddress->getEmail() : $_order->getCustomerEmail());
177
- $recipientMobilePhone = $this->checkMobileNumber($_shippingAddress->getTelephone());
178
- $recipientName = $this->getFilledValue($_shippingAddress->getCompany()); //RelayPoint Name if chronorelais or Companyname if chronopost and
179
- $recipientName2 = $this->getFilledValue($_shippingAddress->getFirstname() . ' ' . $_shippingAddress->getLastname());
180
- //remove any alphabets in phone number
181
- $recipientPhone = trim(ereg_replace("[^0-9.-]", " ", $_shippingAddress->getTelephone()));
182
-
183
- $recipient = array(
184
- 'recipientAdress1' => substr($this->getFilledValue($recipient_address[0]), 0, 38),
185
- 'recipientAdress2' => substr($this->getFilledValue($recipient_address[1]), 0, 38),
186
- 'recipientCity' => $this->getFilledValue($_shippingAddress->getCity()),
187
- 'recipientContactName' => $recipientName2,
188
- 'recipientCountry' => $this->getFilledValue($_shippingAddress->getCountryId()),
189
- 'recipientEmail' => $customer_email,
190
- 'recipientMobilePhone' => $recipientMobilePhone,
191
- 'recipientName' => $recipientName,
192
- 'recipientName2' => $recipientName2,
193
- 'recipientPhone' => $recipientPhone,
194
- 'recipientPreAlert' => '',
195
- 'recipientZipCode' => $this->getFilledValue($_shippingAddress->getPostcode()),
196
- );
197
-
198
- //ref parameters
199
- $recipientRef = $this->getFilledValue($_shippingAddress->getWRelayPointCode());
200
- if (!$recipientRef) {
201
- $recipientRef = $_order->getCustomerId();
202
- }
203
- $shipperRef = $_order->getRealOrderId();
204
-
205
- $ref = array(
206
- 'recipientRef' => $recipientRef,
207
- 'shipperRef' => $shipperRef
208
- );
209
-
210
- //skybill parameters
211
- /* Livraison Samedi (Delivery Saturday) field */
212
- $SaturdayShipping = 0; //default value for the saturday shipping
213
- $send_day = strtolower(date('l'));
214
- if ($_shippingMethod[0] == "chronopost" || $_shippingMethod[0] == "chronorelais") {
215
- if (!$_deliver_on_saturday = Mage::helper('chronorelais')->getLivraisonSamediStatus($_order->getEntityId())) {
216
- $_deliver_on_saturday = Mage::helper('chronorelais')->getConfigData('carriers/' . $_shippingMethod[0] . '/deliver_on_saturday');
217
- } else {
218
- if ($_deliver_on_saturday == 'Yes') {
219
- $_deliver_on_saturday = 1;
220
- } else {
221
- $_deliver_on_saturday = 0;
222
- }
223
- }
224
- $is_sending_day = Mage::helper('chronorelais')->isSendingDay();
225
- if ($_deliver_on_saturday && $is_sending_day) {
226
- $SaturdayShipping = 6;
227
- } elseif (!$_deliver_on_saturday && $is_sending_day) {
228
- $SaturdayShipping = 1;
229
- }
230
- }
231
-
232
- $weight = 0;
233
- foreach ($shipment->getItemsCollection() as $item) {
234
- $weight += $item->weight * $item->qty;
235
- }
236
-
237
- $skybill = array(
238
- 'codCurrency' => 'EUR',
239
- 'codValue' => '',
240
- 'content1' => '',
241
- 'content2' => '',
242
- 'content3' => '',
243
- 'content4' => '',
244
- 'content5' => '',
245
- 'customsCurrency' => 'EUR',
246
- 'customsValue' => '',
247
- 'evtCode' => 'DC',
248
- 'insuredCurrency' => 'EUR',
249
- 'insuredValue' => '',
250
- 'objectType' => 'MAR',
251
- 'productCode' => $_helper->getChronoProductCode($_shippingAddress->getCountryId(), $_shippingMethod[0]),
252
- 'service' => $SaturdayShipping,
253
- 'shipDate' => date('c'),
254
- 'shipHour' => date('H'),
255
- 'weight' => $weight,
256
- 'weightUnit' => 'KGM'
257
- );
258
-
259
- $skybillParams = array(
260
- 'mode' => $_helper->getConfigurationSkybillParam()
261
- );
262
-
263
- $expeditionArray = array(
264
- 'esdParams' => $esdParams,
265
- 'header' => $header,
266
- 'shipper' => $shipper,
267
- 'customer' => $customer,
268
- 'recipient' => $recipient,
269
- 'ref' => $ref,
270
- 'skybill' => $skybill,
271
- 'skybillParams' => $skybillParams,
272
- 'password' => $_helper->getConfigurationAccountPass(),
273
- 'option' => '0'
274
- );
275
- //printArray($expeditionArray); exit;
276
- return $expeditionArray;
277
  }
278
- }
279
-
280
- protected function getEtiquetteUrl($shipmentId) {
281
- //On récupère les infos d'expédition
282
- $reservationNumber = '';
283
- $_helper = Mage::helper('chronorelais');
284
-
285
- $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
286
- if ($_shipTracks = $shipment->getAllTracks()) {
287
- foreach ($_shipTracks as $_shipTrack) {
288
- if ($_shipTrack->getNumber() && $_shipTrack->getChronoReservationNumber()) {
289
- $reservationNumber = $_shipTrack->getChronoReservationNumber();
290
- break;
291
  }
292
- }
293
- if ($reservationNumber) {
294
- return $reservationNumber;
295
- }
296
  }
297
-
298
- $_order = $shipment->getOrder();
299
- $_shippingMethod = explode("_", $_order->getShippingMethod());
300
-
301
- $expeditionArray = $this->getExpeditionParams($shipment, $_shippingMethod);
302
- $tracking_number = '';
303
- if ($expeditionArray) {
304
- $client = new SoapClient("http://wsshipping.chronopost.fr/shipping/services/services/ServiceEProcurement?wsdl", array('trace' => true));
305
- try {
306
- $webservbt = $client->__call("reservationExpeditionV2", $expeditionArray);
307
- if (!$webservbt->errorCode && $webservbt->reservationNumber) {
308
- $tracking_number = $webservbt->skybillNumber;
309
- // Add tracking number for the shipment if not already exists.
310
- if (!$this->_trackingNumbers && $webservbt->skybillNumber) {
311
- $track = Mage::getModel('sales/order_shipment_track')
312
- ->setNumber($webservbt->skybillNumber)
313
- ->setCarrier(ucwords($_shippingMethod[0]))
314
- ->setCarrierCode($_shippingMethod[0])
315
- ->setTitle(ucwords($_shippingMethod[0]))
316
- ->setChronoReservationNumber($webservbt->reservationNumber)
317
- ->setPopup(1);
318
- $shipment->addTrack($track);
319
-
320
- $tracking_url = str_replace('{tracking_number}', $tracking_number, Mage::helper('chronorelais')->getConfigurationTrackingViewUrl());
321
- $tracking_title = $this->__('Track Your Order');
322
- $tracking_order = '<p><a title="' . $tracking_title . '" href="' . $tracking_url . '"><b>' . $tracking_title . '</b></a></p>';
323
-
324
- //$shipment->register();
325
- $comment = '';
326
- $shipment->setEmailSent(true);
327
- $this->_saveShipment($shipment);
328
- $shipment->sendEmail(1, $tracking_order . $comment);
329
- }
330
- return $webservbt->reservationNumber;
331
- } else {
332
- $this->_getSession()->addError($_helper->__($webservbt->errorMessage));
333
- }
334
- } catch (SoapFault $fault) {
335
- $this->_getSession()->addError($_helper->__($fault->faultstring));
336
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
- }
339
-
340
- public function getShipmentByOrderId($orderId) {
341
- $_shipment = Mage::getResourceModel('sales/order_shipment_grid_collection')
342
  ->addAttributeToFilter('order_id', $orderId)
343
  ->getAllIds();
344
- return $_shipment;
345
- }
346
-
347
- public function getShipmentByIncrementId($incrementId) {
348
- $_shipment = Mage::getResourceModel('sales/order_shipment_grid_collection')
349
- ->addAttributeToFilter('increment_id', $incrementId)
350
- ->getAllIds();
351
- return $_shipment;
352
- }
353
-
354
- public function initShipment($orderId) {
355
- $order = Mage::getModel('sales/order')->load($orderId);
356
-
357
- /**
358
- * Check order existing
359
- */
360
- if (!$order->getId()) {
361
- $this->_getSession()->addError($this->__('The order no longer exists.'));
362
- return false;
363
- }
364
- /**
365
- * Check shipment is available to create separate from invoice
366
- */
367
- if ($order->getForcedDoShipmentWithInvoice()) {
368
- $this->_getSession()->addError($this->__('Cannot do shipment for the order separately from invoice.'));
369
- return false;
370
- }
371
- /**
372
- * Check shipment create availability
373
- */
374
- /* if (!$order->canShip()) {
375
- $this->_getSession()->addError($this->__('Cannot do shipment for the order.'));
376
- return false;
377
- } */
378
- $savedQtys = $this->_getItemQtys();
379
- $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($savedQtys);
380
-
381
- Mage::register('current_shipment', $shipment);
382
- return $shipment;
383
- }
384
-
385
- public function createNewShipment($orderId) {
386
- $_helper = Mage::helper('chronorelais');
387
- $reservationNumber = '';
388
- try {
389
- if ($shipment = $this->initShipment($orderId)) {
390
- $shipment->register();
391
-
392
- $_order = $shipment->getOrder();
393
- $_shippingMethod = explode("_", $_order->getShippingMethod());
394
-
395
- $expeditionArray = $this->getExpeditionParams($shipment, $_shippingMethod);
396
- $tracking_number = '';
397
- if ($expeditionArray) {
398
-
399
- $client = new SoapClient("http://wsshipping.chronopost.fr/shipping/services/services/ServiceEProcurement?wsdl", array('trace' => true));
400
- try {
401
- $expedition = $client->__call("reservationExpeditionV2", $expeditionArray);
402
- if (!$expedition->errorCode && $expedition->skybillNumber) {
403
- $tracking_number = $expedition->skybillNumber;
404
- $track = Mage::getModel('sales/order_shipment_track')
405
- ->setNumber($expedition->skybillNumber)
406
- ->setCarrier(ucwords($_shippingMethod[0]))
407
- ->setCarrierCode($_shippingMethod[0])
408
- ->setTitle(ucwords($_shippingMethod[0]))
409
- ->setChronoReservationNumber($expedition->reservationNumber)
410
- ->setPopup(1);
411
- $shipment->addTrack($track);
412
- $reservationNumber = $expedition->reservationNumber;
413
- } else {
414
- $this->_getSession()->addError($_helper->__($expedition->errorMessage));
415
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
416
  }
417
- } catch (SoapFault $fault) {
418
- $this->_getSession()->addError($_helper->__($fault->faultstring));
419
- return;
420
- }
421
  }
422
-
423
- $tracking_url = str_replace('{tracking_number}', $tracking_number, Mage::helper('chronorelais')->getConfigurationTrackingViewUrl());
424
- $tracking_title = $this->__('Track Your Order');
425
- $tracking_order = '<p><a title="' . $tracking_title . '" href="' . $tracking_url . '"><b>' . $tracking_title . '</b></a></p>';
426
-
427
- $comment = '';
428
- $shipment->setEmailSent(true);
429
- $this->_saveShipment($shipment);
430
- $shipment->sendEmail(1, $tracking_order . $comment);
431
- $this->_getSession()->addSuccess($this->__('Shipment was successfully created.'));
432
- return $reservationNumber;
433
- } else {
434
- $this->_forward('noRoute');
435
- return;
436
- }
437
- } catch (Mage_Core_Exception $e) {
438
- $this->_getSession()->addError($e->getMessage());
439
- return;
440
- } catch (Exception $e) {
441
- $this->_getSession()->addError($this->__('Can not save shipment: ' . $e->getMessage()));
442
- return;
443
- }
444
- }
445
-
446
- public function printMassAction() {
447
- $shipmentsIds = $this->getRequest()->getPost('shipment_ids');
448
- try {
449
- $trackingNumber = $this->getEtiquetteUrl($shipmentsIds);
450
- if ($trackingNumber) {
451
- $tracking_url = str_replace('{trackingNumber}', $trackingNumber, Mage::helper('chronorelais')->getConfigurationTrackingUrl());
452
- $this->_processDownload($tracking_url, 'url');
453
- exit(0);
454
- }
455
- } catch (Mage_Core_Exception $e) {
456
- $this->_getSession()->addError(Mage::helper('chronorelais')->__('Désolé, une erreure est survenu lors de la récupération de l\'étiquetes. Merci de contacter Chronopost ou de réessayer plus tard'));
457
- }
458
- return $this->_redirectReferer();
459
- }
460
-
461
- public function printAction() {
462
- // Appel via order_id
463
- $orderId = $this->getRequest()->getParam('order_id');
464
- if ($orderId) {
465
- if ($_shipments = $this->getShipmentByOrderId($orderId)) {
466
- if (count($_shipments) == 1) {
467
- $shipmentId = $_shipments[0];
468
- $trackingNumber = $this->getEtiquetteUrl($shipmentId);
469
- } else {
470
- $track = "Cette commande contient plusieurs expéditions, cliquez sur chaque lien pour obtenir les étiquettes :<br>";
471
- foreach ($_shipments as $_shipment) {
472
- $url = str_replace('{trackingNumber}', $this->getEtiquetteUrl($_shipment), Mage::helper('chronorelais')->getConfigurationTrackingUrl());
473
- $track .= '<a target="_blank" href="'.$url.'">'.$url.'</a><br />';
474
- }
475
- echo $track;
476
- return;
477
  }
478
- } else {
479
- $trackingNumber = $this->createNewShipment($orderId);
480
- }
481
- } else {
482
- $shipmentId = $this->getRequest()->getParam('shipment_id');
483
- if ($shipmentId) {
484
- $trackingNumber = $this->getEtiquetteUrl($shipmentId);
485
- } else {
486
- $shipmentIncrementId = $this->getRequest()->getParam('shipment_increment_id');
487
- $shipmentId = $this->getShipmentByIncrementId($shipmentIncrementId);
488
- $trackingNumber = $this->getEtiquetteUrl($shipmentId[0]);
489
- }
490
- }
491
-
492
-
493
- if ($trackingNumber) {
494
- try {
495
- $tracking_url = str_replace('{trackingNumber}', $trackingNumber, Mage::helper('chronorelais')->getConfigurationTrackingUrl());
496
- $this->_processDownload($tracking_url, 'url');
497
- exit(0);
498
- } catch (Mage_Core_Exception $e) {
499
- $this->_getSession()->addError(Mage::helper('chronorelais')->__('Désolé, une erreure est survenu lors de la récupération de l\'étiquetes. Merci de contacter Chronopost ou de réessayer plus tard'));
500
- }
501
- }
502
- return $this->_redirectReferer();
503
- }
504
-
505
- public function massLivraisonSamediStatusAction() {
506
- if ($this->getRequest()->getPost('status')) {
507
- $this->saveLivraisonSamediStatusAction();
508
- }
509
- }
510
-
511
- /* Save the Livraison le Samedi status to orders */
512
-
513
- public function saveLivraisonSamediStatusAction() {
514
- /* get the orders */
515
- $orderIds = $this->getRequest()->getPost('order_ids');
516
- $status = $this->getRequest()->getPost('status');
517
- $_connection = Mage::getSingleton('core/resource')->getConnection('core_write');
518
- $_table = Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status');
519
- $exceptions = array();
520
-
521
- foreach ($orderIds as $orderId) {
522
- $order_details = Mage::getModel('sales/order')->load($orderId);
523
- $shipping_method = '';
524
- $livraison_le_samedi = $status;
525
- if ($shipping_method = $order_details->getShippingMethod()) {
526
- $shipping_method = explode('_', $shipping_method);
527
- if ($shipping_method[0] == 'chronoexpress') {
528
- $livraison_le_samedi = '--';
529
  }
530
- }
531
- $condition = array(
532
- $_connection->quoteInto('order_id = ?', $orderId),
533
- );
534
- $_connection->delete($_table, $condition);
535
-
536
- $dataLine = array(
537
- 'order_id' => $orderId,
538
- 'livraison_le_samedi' => $livraison_le_samedi
539
- );
540
- try {
541
- $_connection->insert($_table, $dataLine);
542
- } catch (Exception $e) {
543
- $exceptions[] = Mage::helper('chronorelais')->__('Order assigning error: ' . $e->getMessage());
544
- }
545
- }
546
- if ($exceptions) {
547
- $this->_getSession()->addError($exceptions);
548
- } else {
549
- $this->_getSession()->addSuccess($this->__('Livraison le Samedi statut a &eacute;t&eacute; ajout&eacute;'));
550
  }
551
- $this->_redirect('*/*/index');
552
- }
553
 
554
- /* Remove accents characters */
555
-
556
- public function removeaccents($string) {
557
- $stringToReturn = str_replace(
558
- array('à', 'á', 'â', 'ã', 'ä', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', '/', '\xa8'), array('a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', ' ', 'e'), $string);
559
- // Remove all remaining other unknown characters
560
- $stringToReturn = preg_replace('/[^a-zA-Z0-9\-]/', ' ', $stringToReturn);
561
- $stringToReturn = preg_replace('/^[\-]+/', '', $stringToReturn);
562
- $stringToReturn = preg_replace('/[\-]+$/', '', $stringToReturn);
563
- $stringToReturn = preg_replace('/[\-]{2,}/', ' ', $stringToReturn);
564
- return $stringToReturn;
565
- }
 
 
 
 
 
 
 
 
 
 
566
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  }
1
  <?php
 
2
  require_once 'Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php';
3
+ class Chronopost_Chronorelais_Sales_ImpressionController extends Mage_Adminhtml_Sales_Order_ShipmentController
4
+ {
5
+ protected $_trackingNumbers = '';
6
+
7
+ /**
8
+ * Additional initialization
9
+ *
10
+ */
11
+ protected function _construct()
12
+ {
13
+ $this->setUsedModuleName('Chronopost_Chronorelais');
 
 
 
 
 
 
 
 
 
14
  }
15
+
16
+ /**
17
+ * Shipping grid
18
+ */
19
+ public function indexAction()
20
+ {
21
+ if (!extension_loaded('soap')) {
22
+ $this->_getSession()->addError($this->__('The SOAP extension is not installed in the server. Please contact the site administrator. Sorry for inconvenience.'));
23
+ return $this->_redirectReferer();
24
+ }
25
+ $this->loadLayout()
26
  ->_setActiveMenu('sales/chronorelais')
27
  ->_addContent($this->getLayout()->createBlock('chronorelais/sales_impression'))
28
  ->renderLayout();
29
+ }
30
+
31
+ /**
32
+ * Save shipment and order in one transaction
33
+ * @param Mage_Sales_Model_Order_Shipment $shipment
34
+ */
35
+ protected function _saveShipment($shipment)
36
+ {
37
+ $shipment->getOrder()->setIsInProcess(true);
38
+ $transactionSave = Mage::getModel('core/resource_transaction')
39
  ->addObject($shipment)
40
  ->addObject($shipment->getOrder())
41
  ->save();
42
 
43
+ return $this;
44
+ }
45
+
46
+ protected function _processDownload($resource, $resourceType)
47
+ {
48
+ $helper = Mage::helper('downloadable/download');
49
+ /* @var $helper Mage_Downloadable_Helper_Download */
50
 
51
+ $helper->setResource($resource, $resourceType);
52
 
53
+ $fileName = $helper->getFilename();
54
+ $contentType = $helper->getContentType();
55
 
56
+ $this->getResponse()
57
  ->setHttpResponseCode(200)
58
  ->setHeader('Pragma', 'public', true)
59
  ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
60
  ->setHeader('Content-type', $contentType, true);
61
 
62
+ if ($fileSize = $helper->getFilesize()) {
63
+ $this->getResponse()
64
+ ->setHeader('Content-Length', $fileSize);
65
+ }
66
 
67
+ if ($contentDisposition = $helper->getContentDisposition()) {
68
+ $this->getResponse()
69
+ ->setHeader('Content-Disposition', $contentDisposition . '; filename='.$fileName);
70
+ }
71
 
72
+ $this->getResponse()
73
  ->clearBody();
74
+ $this->getResponse()
75
  ->sendHeaders();
76
 
77
+ $helper->output();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
+
80
+ protected function getTrackingNumber($shipmentId)
81
+ {
82
+ $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
83
+
84
+ //On récupère le numéro de tracking
85
+ $tracks = $shipment->getTracksCollection();
86
+ foreach ($tracks as $track) {
87
+ if ( $track->getParentId() == $shipmentId)
88
+ {
89
+ $this->_trackingNumbers .= $track->getnumber();
90
+ }
 
91
  }
92
+
93
+ return $this->_trackingNumbers;
 
 
94
  }
95
+
96
+ protected function getFilledValue($value)
97
+ {
98
+ if($value) {
99
+ return $this->removeaccents(trim($value));
100
+ } else {
101
+ return '';
102
+ }
103
+ }
104
+
105
+ protected function checkMobileNumber($value)
106
+ {
107
+ if($reqvalue = trim($value)) {
108
+ $_number = substr($reqvalue, 0, 2);
109
+ $fixed_array = array('01','02','03','04','05','06','06');
110
+ if(in_array($_number, $fixed_array)) {
111
+ return $reqvalue;
112
+ } else {
113
+ return '';
114
+ }
115
+ }
116
+ }
117
+
118
+ protected function getExpeditionParams($_order, $_shippingMethod)
119
+ {
120
+ $_shippingAddress = $_order->getShippingAddress();
121
+ $_billingAddress = $_order->getBillingAddress();
122
+ $_helper = Mage::helper('chronorelais');
123
+
124
+ if ($_shippingMethod[0] == 'chronorelais' || $_shippingMethod[0] == 'chronopost' || $_shippingMethod[0] == 'chronoexpress') {
125
+ $esdParams = $header = $shipper = $customer = $recipient = $ref = $skybill = $skybillParams = $password = array();
126
+
127
+ //esdParams parameters
128
+ $esdParams = array(
129
+ 'height' => '',
130
+ 'width' => '',
131
+ 'length' => ''
132
+ );
133
+
134
+ //header parameters
135
+ $header = array(
136
+ 'idEmit' => 'CHRFR',
137
+ 'accountNumber' => $_helper->getConfigurationAccountNumber(),
138
+ 'subAccount' => $_helper->getConfigurationSubAccountNumber()
139
+ );
140
+
141
+ //shipper parameters
142
+ $shipperMobilePhone = $this->checkMobileNumber($_helper->getConfigurationShipperInfo('mobilephone'));
143
+ $shipper = array(
144
+ 'shipperAdress1' => $_helper->getConfigurationShipperInfo('address1'),
145
+ 'shipperAdress2' => $_helper->getConfigurationShipperInfo('address2'),
146
+ 'shipperCity' => $_helper->getConfigurationShipperInfo('city'),
147
+ 'shipperCivility' => $_helper->getConfigurationShipperInfo('civility'),
148
+ 'shipperContactName'=> $_helper->getConfigurationShipperInfo('contactname'),
149
+ 'shipperCountry' => $_helper->getConfigurationShipperInfo('country'),
150
+ 'shipperEmail' => $_helper->getConfigurationShipperInfo('email'),
151
+ 'shipperMobilePhone'=> $shipperMobilePhone,
152
+ 'shipperName' => $_helper->getConfigurationShipperInfo('name'),
153
+ 'shipperName2' => $_helper->getConfigurationShipperInfo('name2'),
154
+ 'shipperPhone' => $_helper->getConfigurationShipperInfo('phone'),
155
+ 'shipperPreAlert' => '',
156
+ 'shipperZipCode' => $_helper->getConfigurationShipperInfo('zipcode')
157
+ );
158
+
159
+ //customer parameters
160
+ $customerMobilePhone = $this->checkMobileNumber($_helper->getConfigurationCustomerInfo('mobilephone'));
161
+ $customer = array(
162
+ 'customerAdress1' => $_helper->getConfigurationCustomerInfo('address1'),
163
+ 'customerAdress2' => $_helper->getConfigurationCustomerInfo('address2'),
164
+ 'customerCity' => $_helper->getConfigurationCustomerInfo('city'),
165
+ 'customerCivility' => $_helper->getConfigurationCustomerInfo('civility'),
166
+ 'customerContactName'=> $_helper->getConfigurationCustomerInfo('contactname'),
167
+ 'customerCountry' => $_helper->getConfigurationCustomerInfo('country'),
168
+ 'customerEmail' => $_helper->getConfigurationCustomerInfo('email'),
169
+ 'customerMobilePhone'=> $customerMobilePhone,
170
+ 'customerName' => $_helper->getConfigurationCustomerInfo('name'),
171
+ 'customerName2' => $_helper->getConfigurationCustomerInfo('name2'),
172
+ 'customerPhone' => $_helper->getConfigurationCustomerInfo('phone'),
173
+ 'customerPreAlert' => '',
174
+ 'customerZipCode' => $_helper->getConfigurationCustomerInfo('zipcode')
175
+ );
176
+
177
+ //recipient parameters
178
+ $recipient_address = $_shippingAddress->getStreet();
179
+ if (!isset($recipient_address[1])) {
180
+ $recipient_address[1] = '';
181
+ }
182
+ $customer_email = ($_shippingAddress->getEmail()) ? $_shippingAddress->getEmail() : ($_billingAddress->getEmail() ? $_billingAddress->getEmail() : $_order->getCustomerEmail());
183
+ $recipientMobilePhone = $this->checkMobileNumber($_shippingAddress->getTelephone());
184
+ $recipientName = $this->getFilledValue($_shippingAddress->getCompany()); //RelayPoint Name if chronorelais or Companyname if chronopost and
185
+ $recipientName2 = $this->getFilledValue($_shippingAddress->getFirstname() . ' ' . $_shippingAddress->getLastname());
186
+ //remove any alphabets in phone number
187
+ $recipientPhone = trim(ereg_replace("[^0-9.-]", " ", $_shippingAddress->getTelephone()));
188
+
189
+ $recipient = array(
190
+ 'recipientAdress1' => $this->getFilledValue($recipient_address[0]),
191
+ 'recipientAdress2' => $this->getFilledValue($recipient_address[1]),
192
+ 'recipientCity' => $this->getFilledValue($_shippingAddress->getCity()),
193
+ 'recipientContactName' => $recipientName2,
194
+ 'recipientCountry' => $this->getFilledValue($_shippingAddress->getCountryId()),
195
+ 'recipientEmail' => $customer_email,
196
+ 'recipientMobilePhone' => $recipientMobilePhone,
197
+ 'recipientName' => $recipientName,
198
+ 'recipientName2' => $recipientName2,
199
+ 'recipientPhone' => $recipientPhone,
200
+ 'recipientPreAlert' => '',
201
+ 'recipientZipCode' => $this->getFilledValue($_shippingAddress->getPostcode()),
202
+ );
203
+
204
+ //ref parameters
205
+ $recipientRef = $this->getFilledValue($_shippingAddress->getWRelayPointCode());
206
+ if(!$recipientRef) {
207
+ $recipientRef = $_order->getCustomerId();
208
+ }
209
+ $shipperRef = $_order->getRealOrderId();
210
+
211
+ $ref = array(
212
+ 'recipientRef' => $recipientRef,
213
+ 'shipperRef' => $shipperRef
214
+ );
215
+
216
+ //skybill parameters
217
+ /* Livraison Samedi (Delivery Saturday) field*/
218
+ $SaturdayShipping = 0; //default value for the saturday shipping
219
+ $send_day = strtolower(date('l'));
220
+ if($_shippingMethod[0] == "chronopost" || $_shippingMethod[0] == "chronorelais") {
221
+ if(!$_deliver_on_saturday = Mage::helper('chronorelais')->getLivraisonSamediStatus($_order->getEntityId())) {
222
+ $_deliver_on_saturday = Mage::helper('chronorelais')->getConfigData('carriers/'.$_shippingMethod[0].'/deliver_on_saturday');
223
+ } else {
224
+ if($_deliver_on_saturday=='Yes') {
225
+ $_deliver_on_saturday = 1;
226
+ } else {
227
+ $_deliver_on_saturday = 0;
228
+ }
229
+ }
230
+ $is_sending_day = Mage::helper('chronorelais')->isSendingDay();
231
+ if($_deliver_on_saturday && $is_sending_day) {
232
+ $SaturdayShipping = 6;
233
+ } elseif(!$_deliver_on_saturday && $is_sending_day) {
234
+ $SaturdayShipping = 1;
235
+ }
236
+ }
237
+
238
+ $skybill = array(
239
+ 'codCurrency' => 'EUR',
240
+ 'codValue' => '',
241
+ 'content1' => '',
242
+ 'content2' => '',
243
+ 'content3' => '',
244
+ 'content4' => '',
245
+ 'content5' => '',
246
+ 'customsCurrency' => 'EUR',
247
+ 'customsValue' => '',
248
+ 'evtCode' => 'DC',
249
+ 'insuredCurrency' => 'EUR',
250
+ 'insuredValue' => '',
251
+ 'objectType' => 'MAR',
252
+ 'productCode' => $_helper->getChronoProductCode($_shippingAddress->getCountryId(),$_shippingMethod[0]),
253
+ 'service' => $SaturdayShipping,
254
+ 'shipDate' => date('c'),
255
+ 'shipHour' => date('H'),
256
+ 'weight' => $_order->getWeight(),
257
+ 'weightUnit' => 'KGM'
258
+ );
259
+
260
+ $skybillParams = array(
261
+ 'mode' => $_helper->getConfigurationSkybillParam()
262
+ );
263
+
264
+ $expeditionArray = array(
265
+ 'esdParams' => $esdParams,
266
+ 'header' => $header,
267
+ 'shipper' => $shipper,
268
+ 'customer' => $customer,
269
+ 'recipient' => $recipient,
270
+ 'ref' => $ref,
271
+ 'skybill' => $skybill,
272
+ 'skybillParams' => $skybillParams,
273
+ 'password' => $_helper->getConfigurationAccountPass(),
274
+ 'option' => '0'
275
+ );
276
+ //printArray($expeditionArray); exit;
277
+ return $expeditionArray;
278
+ }
279
+ }
280
+
281
+ protected function getEtiquetteUrl($shipmentId)
282
+ {
283
+ //On récupère les infos d'expédition
284
+ $reservationNumber = '';
285
+ $_helper = Mage::helper('chronorelais');
286
+
287
+ $shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
288
+ if($_shipTracks = $shipment->getAllTracks()) {
289
+ foreach($_shipTracks as $_shipTrack) {
290
+ if($_shipTrack->getNumber() && $_shipTrack->getChronoReservationNumber()) {
291
+ $reservationNumber = $_shipTrack->getChronoReservationNumber();
292
+ break;
293
+ }
294
+ }
295
+ if($reservationNumber) {
296
+ return $reservationNumber;
297
+ }
298
+ }
299
+
300
+ $_order = $shipment->getOrder();
301
+ $_shippingMethod = explode("_",$_order->getShippingMethod());
302
+
303
+ $expeditionArray = $this->getExpeditionParams($_order, $_shippingMethod);
304
+ $tracking_number = '';
305
+ if($expeditionArray) {
306
+ $client = new SoapClient("http://wsshipping.chronopost.fr/shipping/services/services/ServiceEProcurement?wsdl", array('trace' => true));
307
+ try
308
+ {
309
+ $webservbt = $client->__call("reservationExpeditionV2",$expeditionArray);
310
+ if(!$webservbt->errorCode && $webservbt->reservationNumber) {
311
+ $tracking_number = $webservbt->skybillNumber;
312
+ // Add tracking number for the shipment if not already exists.
313
+ if(!$this->_trackingNumbers && $webservbt->skybillNumber) {
314
+ $track = Mage::getModel('sales/order_shipment_track')
315
+ ->setNumber($webservbt->skybillNumber)
316
+ ->setCarrier(ucwords($_shippingMethod[0]))
317
+ ->setCarrierCode($_shippingMethod[0])
318
+ ->setTitle(ucwords($_shippingMethod[0]))
319
+ ->setChronoReservationNumber($webservbt->reservationNumber)
320
+ ->setPopup(1);
321
+ $shipment->addTrack($track);
322
+
323
+ $tracking_url = str_replace('{tracking_number}', $tracking_number, Mage::helper('chronorelais')->getConfigurationTrackingViewUrl());
324
+ $tracking_title = $this->__('Track Your Order');
325
+ $tracking_order = '<p><a title="'.$tracking_title.'" href="'.$tracking_url.'"><b>'.$tracking_title.'</b></a></p>';
326
+
327
+ //$shipment->register();
328
+ $comment = '';
329
+ $shipment->setEmailSent(true);
330
+ $this->_saveShipment($shipment);
331
+ $shipment->sendEmail(1, $tracking_order.$comment);
332
+ }
333
+ return $webservbt->reservationNumber;
334
+ } else {
335
+ $this->_getSession()->addError($_helper->__($webservbt->errorMessage));
336
+ }
337
+ }
338
+ catch(SoapFault $fault)
339
+ {
340
+ $this->_getSession()->addError($_helper->__($fault->faultstring));
341
+ }
342
+ }
343
  }
344
+
345
+ public function getShipmentByOrderId($orderId) {
346
+ $_shipment = Mage::getResourceModel('sales/order_shipment_grid_collection')
 
347
  ->addAttributeToFilter('order_id', $orderId)
348
  ->getAllIds();
349
+ return $_shipment;
350
+ }
351
+
352
+ public function initShipment($orderId)
353
+ {
354
+ $order = Mage::getModel('sales/order')->load($orderId);
355
+
356
+ /**
357
+ * Check order existing
358
+ */
359
+ if (!$order->getId()) {
360
+ $this->_getSession()->addError($this->__('The order no longer exists.'));
361
+ return false;
362
+ }
363
+ /**
364
+ * Check shipment is available to create separate from invoice
365
+ */
366
+
367
+ if ($order->getForcedDoShipmentWithInvoice()) {
368
+ $this->_getSession()->addError($this->__('Cannot do shipment for the order separately from invoice.'));
369
+ return false;
370
+ }
371
+ /**
372
+ * Check shipment create availability
373
+ */
374
+ /*if (!$order->canShip()) {
375
+ $this->_getSession()->addError($this->__('Cannot do shipment for the order.'));
376
+ return false;
377
+ }*/
378
+ $savedQtys = $this->_getItemQtys();
379
+ $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($savedQtys);
380
+
381
+ Mage::register('current_shipment', $shipment);
382
+ return $shipment;
383
+ }
384
+
385
+ public function createNewShipment($orderId) {
386
+ $_helper = Mage::helper('chronorelais');
387
+ $reservationNumber = '';
388
+ try {
389
+ if ($shipment = $this->initShipment($orderId)) {
390
+ $shipment->register();
391
+
392
+ $_order = $shipment->getOrder();
393
+ $_shippingMethod = explode("_",$_order->getShippingMethod());
394
+
395
+ $expeditionArray = $this->getExpeditionParams($_order, $_shippingMethod);
396
+ $tracking_number = '';
397
+ if($expeditionArray) {
398
+
399
+ $client = new SoapClient("http://wsshipping.chronopost.fr/shipping/services/services/ServiceEProcurement?wsdl", array('trace' => true));
400
+ try
401
+ {
402
+ $expedition = $client->__call("reservationExpeditionV2",$expeditionArray);
403
+ if(!$expedition->errorCode && $expedition->skybillNumber) {
404
+ $tracking_number = $expedition->skybillNumber;
405
+ $track = Mage::getModel('sales/order_shipment_track')
406
+ ->setNumber($expedition->skybillNumber)
407
+ ->setCarrier(ucwords($_shippingMethod[0]))
408
+ ->setCarrierCode($_shippingMethod[0])
409
+ ->setTitle(ucwords($_shippingMethod[0]))
410
+ ->setChronoReservationNumber($expedition->reservationNumber)
411
+ ->setPopup(1);
412
+ $shipment->addTrack($track);
413
+ $reservationNumber = $expedition->reservationNumber;
414
+ } else {
415
+ $this->_getSession()->addError($_helper->__($expedition->errorMessage));
416
+ return;
417
+ }
418
+ }
419
+ catch(SoapFault $fault)
420
+ {
421
+ $this->_getSession()->addError($_helper->__($fault->faultstring));
422
+ return;
423
+ }
424
+ }
425
+
426
+ $tracking_url = str_replace('{tracking_number}', $tracking_number, Mage::helper('chronorelais')->getConfigurationTrackingViewUrl());
427
+ $tracking_title = $this->__('Track Your Order');
428
+ $tracking_order = '<p><a title="'.$tracking_title.'" href="'.$tracking_url.'"><b>'.$tracking_title.'</b></a></p>';
429
+
430
+ $comment = '';
431
+ $shipment->setEmailSent(true);
432
+ $this->_saveShipment($shipment);
433
+ $shipment->sendEmail(1, $tracking_order.$comment);
434
+ $this->_getSession()->addSuccess($this->__('Shipment was successfully created.'));
435
+ return $reservationNumber;
436
+
437
+ }else {
438
+ $this->_forward('noRoute');
439
+ return;
440
  }
 
 
 
 
441
  }
442
+ catch (Mage_Core_Exception $e) {
443
+ $this->_getSession()->addError($e->getMessage());
444
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  }
446
+ catch (Exception $e) {
447
+ $this->_getSession()->addError($this->__('Can not save shipment: '.$e->getMessage()));
448
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  }
450
+ }
451
+
452
+ public function printMassAction()
453
+ {
454
+ $shipmentsIds = $this->getRequest()->getPost('shipment_ids');
455
+ try {
456
+ $trackingNumber = $this->getEtiquetteUrl($shipmentsIds);
457
+ if($trackingNumber) {
458
+ $tracking_url = str_replace('{trackingNumber}', $trackingNumber, Mage::helper('chronorelais')->getConfigurationTrackingUrl());
459
+ $this->_processDownload($tracking_url, 'url');
460
+ exit(0);
461
+ }
462
+ } catch (Mage_Core_Exception $e) {
463
+ $this->_getSession()->addError(Mage::helper('chronorelais')->__('Désolé, une erreure est survenu lors de la récupération de l\'étiquetes. Merci de contacter Chronopost ou de réessayer plus tard'));
464
+ }
465
+ return $this->_redirectReferer();
466
+
 
 
 
467
  }
 
 
468
 
469
+ public function printAction()
470
+ {
471
+ $orderId = $this->getRequest()->getParam('order_id');
472
+
473
+ if($_shipments = $this->getShipmentByOrderId($orderId)) {
474
+ $shipmentId = $_shipments[0];
475
+ $trackingNumber = $this->getEtiquetteUrl($shipmentId);
476
+ } else {
477
+ $trackingNumber = $this->createNewShipment($orderId);
478
+ }
479
+
480
+ if($trackingNumber) {
481
+ try {
482
+ $tracking_url = str_replace('{trackingNumber}', $trackingNumber, Mage::helper('chronorelais')->getConfigurationTrackingUrl());
483
+ $this->_processDownload($tracking_url, 'url');
484
+ exit(0);
485
+ } catch (Mage_Core_Exception $e) {
486
+ $this->_getSession()->addError(Mage::helper('chronorelais')->__('Désolé, une erreure est survenu lors de la récupération de l\'étiquetes. Merci de contacter Chronopost ou de réessayer plus tard'));
487
+ }
488
+ }
489
+ return $this->_redirectReferer();
490
+ }
491
 
492
+ public function massLivraisonSamediStatusAction()
493
+ {
494
+ if($this->getRequest()->getPost('status')) {
495
+ $this->saveLivraisonSamediStatusAction();
496
+ }
497
+ }
498
+
499
+ /* Save the Livraison le Samedi status to orders */
500
+ public function saveLivraisonSamediStatusAction()
501
+ {
502
+ /* get the orders */
503
+ $orderIds = $this->getRequest()->getPost('order_ids');
504
+ $status = $this->getRequest()->getPost('status');
505
+ $_connection = Mage::getSingleton('core/resource')->getConnection('core_write');
506
+ $_table = Mage::getSingleton('core/resource')->getTableName('sales_chronopost_order_export_status');
507
+ $exceptions = array();
508
+
509
+ foreach($orderIds as $orderId) {
510
+ $order_details = Mage::getModel('sales/order')->load($orderId);
511
+ $shipping_method = '';
512
+ $livraison_le_samedi = $status;
513
+ if($shipping_method = $order_details->getShippingMethod()) {
514
+ $shipping_method = explode('_',$shipping_method);
515
+ if($shipping_method[0]=='chronoexpress') {
516
+ $livraison_le_samedi = '--';
517
+ }
518
+ }
519
+ $condition = array(
520
+ $_connection->quoteInto('order_id = ?', $orderId),
521
+ );
522
+ $_connection->delete($_table, $condition);
523
+
524
+ $dataLine = array(
525
+ 'order_id' => $orderId,
526
+ 'livraison_le_samedi' => $livraison_le_samedi
527
+ );
528
+ try {
529
+ $_connection->insert($_table, $dataLine);
530
+ }
531
+ catch (Exception $e) {
532
+ $exceptions[] = Mage::helper('chronorelais')->__('Order assigning error: ' . $e->getMessage());
533
+ }
534
+ }
535
+ if($exceptions) {
536
+ $this->_getSession()->addError($exceptions);
537
+ } else {
538
+ $this->_getSession()->addSuccess($this->__('Livraison le Samedi statut a &eacute;t&eacute; ajout&eacute;'));
539
+ }
540
+ $this->_redirect('*/*/index');
541
+ }
542
+
543
+ /* Remove accents characters */
544
+ public function removeaccents($string){
545
+ $stringToReturn = str_replace(
546
+ array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Á','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'Ì','Í','Î','Ï', 'Ñ', 'Ò','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ý','/','\xa8'),
547
+ array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y',' ','e'), $string);
548
+ // Remove all remaining other unknown characters
549
+ $stringToReturn = preg_replace('/[^a-zA-Z0-9\-]/', ' ', $stringToReturn);
550
+ $stringToReturn = preg_replace('/^[\-]+/', '', $stringToReturn);
551
+ $stringToReturn = preg_replace('/[\-]+$/', '', $stringToReturn);
552
+ $stringToReturn = preg_replace('/[\-]{2,}/', ' ', $stringToReturn);
553
+ return $stringToReturn;
554
+ }
555
+
556
  }
app/code/community/Chronopost/Chronorelais/controllers/Sales/Order/ShipmentController.php CHANGED
@@ -43,8 +43,8 @@ class Chronopost_Chronorelais_Sales_Order_ShipmentController extends Mage_Adminh
43
  $_order = $shipment->getOrder();
44
  $_shippingMethod = explode("_",$_order->getShippingMethod());
45
 
46
- $_shippingAddress = $shipment->getShippingAddress();
47
- $_billingAddress = $shipment->getBillingAddress();
48
  $_helper = Mage::helper('chronorelais');
49
 
50
  if ($_shippingMethod[0] == 'chronorelais' || $_shippingMethod[0] == 'chronopost' || $_shippingMethod[0] == 'chronoexpress') {
@@ -161,12 +161,6 @@ class Chronopost_Chronorelais_Sales_Order_ShipmentController extends Mage_Adminh
161
  $SaturdayShipping = 6;
162
  }
163
  }
164
-
165
- $weight = 0;
166
- foreach ($shipment->getItemsCollection() as $item) {
167
- $weight += $item->weight * $item->qty;
168
- }
169
-
170
  $skybill = array(
171
  'codCurrency' => 'EUR',
172
  'codValue' => '',
@@ -185,7 +179,7 @@ class Chronopost_Chronorelais_Sales_Order_ShipmentController extends Mage_Adminh
185
  'service' => $SaturdayShipping,
186
  'shipDate' => date('c'),
187
  'shipHour' => date('H'),
188
- 'weight' => $weight,
189
  'weightUnit' => 'KGM'
190
  );
191
 
43
  $_order = $shipment->getOrder();
44
  $_shippingMethod = explode("_",$_order->getShippingMethod());
45
 
46
+ $_shippingAddress = $_order->getShippingAddress();
47
+ $_billingAddress = $_order->getBillingAddress();
48
  $_helper = Mage::helper('chronorelais');
49
 
50
  if ($_shippingMethod[0] == 'chronorelais' || $_shippingMethod[0] == 'chronopost' || $_shippingMethod[0] == 'chronoexpress') {
161
  $SaturdayShipping = 6;
162
  }
163
  }
 
 
 
 
 
 
164
  $skybill = array(
165
  'codCurrency' => 'EUR',
166
  'codValue' => '',
179
  'service' => $SaturdayShipping,
180
  'shipDate' => date('c'),
181
  'shipHour' => date('H'),
182
+ 'weight' => $_order->getWeight(),
183
  'weightUnit' => 'KGM'
184
  );
185
 
app/code/community/Chronopost/Chronorelais/includes/ChronorelaisShippingHelper.php CHANGED
@@ -1,1266 +1,1266 @@
1
- <?php
2
-
3
- /**
4
- * Magento Chronopost Chronorelais 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 Chronopost
17
- * @package Chronopost_Chronorelais
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 ChronorelaisShippingHelper
24
- {
25
- public static $DEBUG_INDEX_COUNTER = 0;
26
- public static $FLOAT_REGEX = '[-]?\d+(?:[.]\d+)?';
27
- public static $POSITIVE_FLOAT_REGEX = '\d+(?:[.]\d+)?';
28
- //public static $COUPLE_REGEX = '(?:[0-9.]+|\*)(?:\[|\])?\:[0-9.]+(?:\:[0-9.]+%?)*';
29
- public static $COUPLE_REGEX = '(?:[0-9.]+|\*) *(?:\[|\])? *\: *[0-9.]+';
30
- public static $UNCOMPRESSED_STRINGS = array(
31
- ' product.attribute.',
32
- ' product.option.',
33
- ' product.stock.',
34
- '{product.attribute.',
35
- '{product.option.',
36
- '{product.stock.',
37
- '{product.weight}',
38
- '{product.quantity}',
39
- '{cart.weight}',
40
- '{cart.quantity}',
41
- '{cart.price_including_tax}',
42
- '{cart.price_excluding_tax}',
43
- '{cart.',
44
- '{customvar.',
45
- '{selection.weight}',
46
- '{selection.quantity}',
47
- '{selection.',
48
- '{destination.country.',
49
- '{foreach ',
50
- '{/foreach}',
51
- );
52
- public static $COMPRESSED_STRINGS = array(
53
- ' p.a.',
54
- ' p.o.',
55
- ' p.s.',
56
- '{p.a.',
57
- '{p.o.',
58
- '{p.s.',
59
- '{p.w}',
60
- '{p.qty}',
61
- '{c.w}',
62
- '{c.qty}',
63
- '{c.pit}',
64
- '{c.pet}',
65
- '{c.',
66
- '{v.',
67
- '{s.w}',
68
- '{s.qty}',
69
- '{s.',
70
- '{dest.ctry.',
71
- '{each ',
72
- '{/each}',
73
- );
74
-
75
- protected $_input;
76
- protected $_config;
77
- protected $_messages;
78
- protected $_formula_cache;
79
- protected $_expression_cache;
80
- public $debug = 0;
81
- public $debug_output = '';
82
- public $debug_header = null;
83
-
84
- public function ChronorelaisShippingHelper($input) {
85
- $this->_formula_cache = array();
86
- $this->_messages = array();
87
- $this->_input = $input;
88
- $this->_config = array();
89
- $this->_parseInput();
90
- }
91
-
92
- private function debug($text, $level=10) {
93
- if ($this->debug>=$level) $this->debug_output .= "<p>".$text."</p>";
94
- }
95
-
96
- public function printDebug() {
97
- if ($this->debug>0) {
98
- $index = self::$DEBUG_INDEX_COUNTER++;
99
- echo "<style rel=\"stylesheet\" type=\"text/css\">"
100
- .".osh-formula{color:#f90;} .osh-key{color:#0099f7;}"
101
- .".osh-error{color:#f00;} .osh-warning{color:#ff0;} .osh-info{color:#7bf700;}"
102
- .".osh-debug{background:#000;color:#bbb;position:absolute;top:0;left:0;width:100%;z-index:100;-moz-opacity:0.9;opacity:0.9;text-align:left;white-space:pre-wrap;}"
103
- .".osh-debug-content{padding:10px;}"
104
- .".osh-replacement{color:#ff3000;}"
105
- ."</style>"
106
- ."<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>"
107
- ."<p>".$this->debug_header."</p>".$this->debug_output."</pre></div>";
108
- }
109
- }
110
-
111
- public function setDebugHeader($process) {
112
- $header = 'DEBUG app/code/community/Chronopost/Chronorelais/Model/Carrier/ChronorelaisShippingHelper.php<br/>';
113
- foreach ($process['data'] as $key => $data) {
114
- $header .= ' <span class="osh-key">'.$key.'</span> = <span class="osh-formula">'.$this->_toString($data).'</span><br/>';
115
- }
116
- $this->debug_header = $header;
117
- }
118
-
119
- public function getConfig() {
120
- return $this->_config;
121
- }
122
-
123
- public function getMessages() {
124
- $messages = $this->_messages;
125
- $this->_messages = array();
126
- return $messages;
127
- }
128
-
129
- public function formatConfig($compress) {
130
- $output = '';
131
- foreach ($this->_config as $code => $row) {
132
- if (!isset($row['lines'])) {
133
- if (isset($row['*comment']['value'])) {
134
- $output .= trim($row['*comment']['value'])."\n";
135
- }
136
- $output .= '{'.($compress ? '' : "\n");
137
- foreach ($row as $key => $property) {
138
- if (substr($key,0,1)!='*') {
139
- $value = $property['value'];
140
- if (isset($property['comment'])) $output .= ($compress ? '' : "\t").'/* '.$property['comment'].' */'.($compress ? '' : "\n");
141
- $output .= ($compress ? '' : "\t").$key.':'.($compress ? '' : ' ');
142
- if (is_bool($value)) $output .= $value ? 'true' : 'false';
143
- else if (is_int($value)) $output .= $value;
144
- else if ((string)((float)$value)==$value) $output .= $value;
145
- else $output .= '"'.str_replace('"','\\"',$value).'"';
146
- $output .= ','.($compress ? '' : "\n");
147
- }
148
- }
149
- if ($compress) $output = preg_replace('/,$/','',$output);
150
- $output .= "}\n".($compress ? '' : "\n");
151
- } else {
152
- $output .= $row['lines']."\n";
153
- }
154
- }
155
- return $compress ? $this->compress($output) : $this->uncompress($output);
156
- }
157
-
158
- public function checkConfig() {
159
- $process = array(
160
- 'result' => null,
161
- 'data' => array(
162
- 'cart.price_excluding_tax' => 0,
163
- 'cart.price_including_tax' => 0,
164
- 'destination.country.code' => '',
165
- 'destination.country.name' => '',
166
- 'destination.region.code' => '',
167
- 'destination.postcode' => '',
168
- 'origin.country.code' => '',
169
- 'origin.country.name' => '',
170
- 'origin.region.code' => '',
171
- 'origin.postcode' => '',
172
- 'free_shipping' => false,
173
- 'customer.group.id' => '',
174
- 'customer.group.code' => '',
175
- 'cart.weight' => 0,
176
- 'cart.weight.unit' => 'kg',
177
- 'cart.quantity' => 0,
178
- ),
179
- 'cart.items' => array(),
180
- 'products' => array(),
181
- 'config' => $this->_config,
182
- );
183
- foreach ($this->_config as $code => &$row) {
184
- $this->processRow($process,$row,$check_all_conditions=true);
185
- foreach ($row as $property_key => $property_value) {
186
- if (substr($property_key,0,1)!='*') $this->getRowProperty($row,$property_key);
187
- }
188
- }
189
- }
190
-
191
- public function processRow($process, &$row, $is_checking=false) {
192
- if (!isset($row['*code'])) return;
193
-
194
- self::debug('process row <span class="osh-key">'.$row['*code'].'</span>',1);
195
- if (!isset($row['label']['value'])) $row['label']['value'] = '***';
196
-
197
- $enabled = $this->getRowProperty($row,'enabled');
198
- if (isset($enabled)) {
199
- if (!$is_checking && !$enabled) {
200
- $this->addMessage('info',$row,'enabled','Configuration disabled');
201
- return new OCS_Result(false);
202
- }
203
- }
204
-
205
- $conditions = $this->getRowProperty($row,'conditions');
206
- if (isset($conditions)) {
207
- $result = $this->_processFormula($process,$row,'conditions',$conditions,$is_checking);
208
- if (!$is_checking) {
209
- if (!$result->success) return $result;
210
- if (!$result->result) {
211
- $this->addMessage('info',$row,'conditions',"The cart doesn't match conditions");
212
- return new OCS_Result(false);
213
- }
214
- }
215
- }
216
-
217
- $destination = $this->getRowProperty($row,'destination');
218
- if (isset($destination)) {
219
- $destination_match = $this->_addressMatch($destination,array(
220
- 'country_code' => $process['data']['destination.country.code'],
221
- 'region_code' => $process['data']['destination.region.code'],
222
- 'postcode' => $process['data']['destination.postcode']
223
- ));
224
- if (!$is_checking && !$destination_match) {
225
- $this->addMessage('info',$row,'destination',"The shipping method doesn't cover the zone");
226
- return new OCS_Result(false);
227
- }
228
- }
229
-
230
- $origin = $this->getRowProperty($row,'origin');
231
- if (isset($origin)) {
232
- $origin_match = $this->_addressMatch($origin,array(
233
- 'country_code' => $process['data']['origin.country.code'],
234
- 'region_code' => $process['data']['origin.region.code'],
235
- 'postcode' => $process['data']['origin.postcode']
236
- ));
237
- if (!$is_checking && !$origin_match) {
238
- $this->addMessage('info',$row,'origin',"The shipping method doesn't match to shipping origin");
239
- return new OCS_Result(false);
240
- }
241
- }
242
-
243
- $customer_groups = $this->getRowProperty($row,'customer_groups');
244
- if (isset($customer_groups)) {
245
- $groups = explode(',',$customer_groups);
246
- $group_match = false;
247
- //self::debug('code:'.$process['data']['customer.group.code'].', id:'.$process['data']['customer.group.id']);
248
- foreach ($groups as $group) {
249
- $group = trim($group);
250
- if ($group==$process['data']['customer.group.code'] || is_int($group) && $group==$process['data']['customer.group.id'] || $group=='*') {
251
- $group_match = true;
252
- break;
253
- }
254
- }
255
- if (!$is_checking && !$group_match) {
256
- $this->addMessage('info',$row,'customer_groups',"The shipping method doesn't match to customer group (%s)",$process['data']['customer.group.code']);
257
- return new OCS_Result(false);
258
- }
259
- }
260
-
261
- //Chronopost quickcost method for dynamic price if it is set enabled
262
- $quickcost = Mage::getStoreConfig('carriers/'.$process['data']['carrier.code'].'/quickcost');
263
- if($quickcost) {
264
- if($quickCostValues = $this->getQuickCostValue($process['data'])) {
265
- if($quickCostValues->errorCode==0) {
266
- return new OCS_Result(true,(float)$quickCostValues->amountTTC);
267
- } else {
268
- $this->addMessage('error',$row,'chronopost',$quickCostValues->errorMessage);
269
- return new OCS_Result(false);
270
- }
271
- } else {
272
- return new OCS_Result(false);
273
- }
274
- }
275
-
276
- $fees = $this->getRowProperty($row,'fees');
277
- if (isset($fees)) {
278
- $result = $this->_processFormula($process,$row,'fees',$fees,$is_checking);
279
- if (!$result->success) return $result;
280
- self::debug(' => <span class="osh-info">result = <span class="osh-formula">'.$this->_toString($result->result).'</span>',1);
281
- return new OCS_Result(true,(float)$result->result);
282
- }
283
-
284
- return new OCS_Result(false);
285
- }
286
-
287
- public function getQuickCostValue($processData) {
288
- $quickCost = array();
289
- $_helper = Mage::helper('chronorelais');
290
- $account_number = $_helper->getConfigurationAccountNumber();
291
- $password = $_helper->getConfigurationAccountPass();
292
- $productCode = $_helper->getChronoProductCode($processData['destination.country.code'], $processData['carrier.code']);
293
- $origin_postcode = $_helper->getConfigurationShipperInfo('zipcode');
294
-
295
- //to get arrival code
296
- $arrCode = $processData['destination.postcode'];
297
- if($processData['carrier.code']=='chronoexpress') {
298
- $arrCode = $processData['destination.country.code'];
299
- }
300
-
301
- $quickCost = array(
302
- 'contratNumber' => $account_number,
303
- 'depCode' => $origin_postcode,
304
- 'arrCode' => $arrCode,
305
- 'weight' => $processData['cart.weight'],
306
- 'productCode' => $productCode,
307
- 'type' => 'M',
308
- 'password' => $password
309
- );
310
-
311
- try {
312
- $quickcost_url = Mage::helper('chronorelais')->getConfigData('carriers/'.$process['data']['carrier.code'].'/quickcost_url');
313
- if(!$quickcost_url) { $quickcost_url = "http://wsshipping.chronopost.fr/wsQuickcost/services/ServiceQuickCost?wsdl"; }
314
- $client = new SoapClient($quickcost_url);
315
- $webservbt = $client->__call("quickCost",$quickCost);
316
- return $webservbt;
317
- } catch(SoapFault $fault) {
318
- $this->addMessage('info',$row,'chronopost',$fault->faultstring);
319
- return false;
320
- }
321
- }
322
-
323
- public function getRowProperty(&$row, $key, $original_row=null, $original_key=null) {
324
- $property = null;
325
- $output = null;
326
- if (isset($original_row) && isset($original_key) && $original_row['*code']==$row['*code'] && $original_key==$key) {
327
- $this->addMessage('error',$row,$key,'Infinite loop %s',"<span class=\"code\">{".$row['*code'].'.'.$key."}</span>");
328
- return array('error' => 'Infinite loop');
329
- }
330
- if (isset($row[$key]['value'])) {
331
- $property = $row[$key]['value'];
332
- $output = $property;
333
- self::debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">'.$this->_toString($property).'</span>',5);
334
- preg_match_all('/{([a-z0-9_]+)\.([a-z0-9_]+)}/i',$output,$result_set,PREG_SET_ORDER);
335
- foreach ($result_set as $result) {
336
- list($original,$ref_code,$ref_key) = $result;
337
- if (!in_array($ref_code,array('module','date','store','cart','product','selection','customvar'))) {
338
- if ($ref_code==$row['code']['value'] && $ref_key==$key) {
339
- $this->addMessage('error',$row,$key,'Infinite loop %s',"<span class=\"code\">".$original."</span>");
340
- return null;
341
- }
342
- if (isset($this->_config[$ref_code][$ref_key]['value'])) {
343
- $replacement = $this->getRowProperty($this->_config[$ref_code],$ref_key,
344
- isset($original_row) ? $original_row : $row,isset($original_key) ? $original_key : $key);
345
- if (is_array($replacement) && isset($replacement['error'])) {
346
- return isset($original_row) ? $replacement : 'false';
347
- }
348
- } else {
349
- $this->addMessage('error',$row,$key,'Non-existent property %s',"<span class=\"code\">".$original."</span>");
350
- $replacement = 'null';
351
- }
352
- $output = $this->replace($original,$replacement,$output);
353
- }
354
- }
355
- } else {
356
- self::debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">null</span>',5);
357
- }
358
- return $output;
359
- }
360
-
361
- protected function _toString($value) {
362
- if (!isset($value)) return 'null';
363
- else if (is_bool($value)) return $value ? 'true' : 'false';
364
- else return $value;
365
- }
366
-
367
- protected function replace($from, $to, $input) {
368
- if ($from===$to) return $input;
369
- if (strpos($input,$from)===false) return $input;
370
- $to = $this->_toString($to);
371
- 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>',5);
372
- return str_replace($from,$to,$input);
373
- }
374
-
375
- protected function _min() {
376
- $args = func_get_args();
377
- $min = null;
378
- foreach ($args as $arg) {
379
- if (isset($arg) && (!isset($min) || $min>$arg)) $min = $arg;
380
- }
381
- return $min;
382
- }
383
-
384
- protected function _max() {
385
- $args = func_get_args();
386
- $max = null;
387
- foreach ($args as $arg) {
388
- if (isset($arg) && (!isset($max) || $max<$arg)) $max = $arg;
389
- }
390
- return $max;
391
- }
392
-
393
- protected function _processFormula($process, &$row, $property_key, $formula_string, $is_checking, $use_cache=true)
394
- {
395
- $result = $this->_prepareFormula($process,$row,$property_key,$formula_string,$is_checking,$use_cache);
396
- if (!$result->success) return $result;
397
-
398
- $eval_result = $this->_evalFormula($result->result);
399
- if (!isset($eval_result)) {
400
- $this->addMessage('error',$row,$property_key,'Invalid formula');
401
- $result = new OCS_Result(false);
402
- if ($use_cache) $this->setCache($formula_string,$result);
403
- return $result;
404
- }
405
- self::debug(' formula evaluation = <span class="osh-formula">'.$this->_toString($eval_result).'</span>',10);
406
- $result = new OCS_Result(true,$eval_result);
407
- if ($use_cache) $this->setCache($formula_string,$result);
408
- return $result;
409
- }
410
-
411
- public function evalInput($process, $row, $property_key, $input) {
412
- $result = $this->_prepareFormula($process,$row,$property_key,$input,$is_checking=false,$use_cache=true);
413
- return $result->success ? $result->result : $input;
414
- }
415
-
416
- protected function setCache($expression, $value) {
417
- if ($value instanceof OCS_Result) {
418
- $this->_formula_cache[$expression] = $value;
419
- self::debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$this->_toString($this->_formula_cache[$expression]).'</span>',10);
420
- } else {
421
- $value = $this->_toString($value);
422
- $this->_expression_cache[$expression] = $value;
423
- self::debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$value.'</span>',10);
424
- }
425
- }
426
-
427
- protected function _prepareFormula($process, $row, $property_key, $formula_string, $is_checking, $use_cache=true)
428
- {
429
- if ($use_cache && isset($this->_formula_cache[$formula_string])) {
430
- $result = $this->_formula_cache[$formula_string];
431
- self::debug(' get cached formula <span class="osh-replacement">'.$formula_string.'</span> = <span class="osh-formula">'.$this->_toString($result->result).'</span>',10);
432
- return $result;
433
- }
434
-
435
- $formula = $formula_string;
436
- //self::debug(' formula = <span class="osh-formula">'.$formula.'</span>',10);
437
-
438
- while (preg_match("#{foreach product\.((?:attribute|option)\.(?:[a-z0-9_]+))}(.*){/foreach}#i",$formula,$result)) {
439
- $original = $result[0];
440
- if ($use_cache && isset($this->_expression_cache[$original])) {
441
- $replacement = $this->_expression_cache[$original];
442
- self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>',10);
443
- }
444
- else {
445
- $replacement = 0;
446
- list($filter_property_type,$filter_property_name) = explode('.',$result[1]);
447
- $selections = array();
448
- self::debug(' :: foreach <span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span>',10);
449
- foreach ($process['products'] as $product) {
450
- $tmp_value = $this->_getProductProperty($product,$filter_property_type,$filter_property_name,$get_by_id=false);
451
- 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>',10);
452
- $key = 'val_'.$tmp_value;
453
- $sel = isset($selections[$key]) ? $selections[$key] : null;
454
- $selections[$key]['products'][] = $product;
455
- $selections[$key]['weight'] = (isset($sel['weight']) ? $sel['weight'] : 0)+$product->getAttribute('weight')*$product->getQuantity();
456
- $selections[$key]['quantity'] = (isset($sel['quantity']) ? $sel['quantity'] : 0)+$product->getQuantity();
457
- }
458
- self::debug(' :: start foreach',10);
459
- foreach ($selections as $selection) {
460
- $process2 = $process;
461
- $process2['products'] = $selection['products'];
462
- $process2['data']['selection.quantity'] = $selection['quantity'];
463
- $process2['data']['selection.weight'] = $selection['weight'];
464
- $process_result = $this->_processFormula($process2,$row,$property_key,$result[2],$is_checking,$tmp_use_cache=false);
465
- $replacement += $process_result->result;
466
- }
467
- self::debug(' :: end foreach <span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span>',10);
468
- if ($use_cache) $this->setCache($original,$replacement);
469
- }
470
- $formula = $this->replace($original,$replacement,$formula);
471
- }
472
-
473
- $formula = str_replace(array("\n","\t"),array('',''),$formula);
474
-
475
- while (preg_match("#{customvar\.([a-z0-9_]+)}#i",$formula,$result)) {
476
- $original = $result[0];
477
- $replacement = Mage::getModel('core/variable')->loadByCode($result[1])->getValue('plain');
478
- $formula = $this->replace($original,$replacement,$formula);
479
- }
480
-
481
- $first_product = isset($process['products'][0]) ? $process['products'][0] : null;
482
- if (!isset($process['data']['selection.weight'])) $process['data']['selection.weight'] = $process['data']['cart.weight'];
483
- if (!isset($process['data']['selection.quantity'])) $process['data']['selection.quantity'] = $process['data']['cart.quantity'];
484
- $process['data']['product.weight'] = isset($first_product) ? $first_product->getAttribute('weight') : 0;
485
- $process['data']['product.quantity'] = isset($first_product) ? $first_product->getQuantity() : 0;
486
-
487
- foreach ($process['data'] as $original => $replacement) {
488
- $formula = $this->replace('{'.$original.'}',$replacement,$formula);
489
- }
490
-
491
- if (isset($first_product)) {
492
- while (preg_match("#{product\.(attribute|option|stock)\.([a-z0-9_]+)}#i",$formula,$result)) {
493
- $original = $result[0];
494
- switch ($result[1]) {
495
- case 'attribute': $replacement = $first_product->getAttribute($result[2]); break;
496
- case 'option': $replacement = $first_product->getOption($result[2]); break;
497
- case 'stock': $replacement = $first_product->getStockData($result[2]); break;
498
- }
499
- $formula = $this->replace($original,$replacement,$formula);
500
- }
501
- }
502
-
503
- //while (preg_match("/{(count|all|any) (attribute|option) '([^'\)]+)' ?(==|<=|>=|<|>|!=) ?(".self::$FLOAT_REGEX."|true|false|'[^'\)]*')}/",$formula,$result)
504
- // || preg_match("/{(sum|count distinct) (attribute|option) '([^'\)]+)'}/",$formula,$result))
505
- while (preg_match("/{(count) products(?: where ([^}]+))?}/i",$formula,$result)
506
- || preg_match("/{(sum|count distinct) product\.(attribute|option)\.([a-z0-9_]+)(?: where ([^}]+))?}/i",$formula,$result)) {
507
- $original = $result[0];
508
- if ($use_cache && isset($this->_expression_cache[$original])) {
509
- $replacement = $this->_expression_cache[$original];
510
- self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>',10);
511
- }
512
- else {
513
- $replacement = $this->_processProductProperty($process['products'],$result);
514
- if ($use_cache) $this->setCache($result[0],$replacement);
515
- }
516
- $formula = $this->replace($original,$replacement,$formula);
517
- }
518
-
519
- //while (preg_match("/{table '([^']+)' ([^}]+)}/",$formula,$result))
520
- while (preg_match("/{table ([^}]+) in ([0-9\.:,\*\[\] ]+)}/i",$formula,$result)) {
521
- $original = $result[0];
522
- if ($use_cache && isset($this->_expression_cache[$original])) {
523
- $replacement = $this->_expression_cache[$original];
524
- self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>',10);
525
- } else {
526
- $reference_value = $this->_evalFormula($result[1]);
527
- if (isset($reference_value)) {
528
- $fees_table_string = $result[2];
529
-
530
- if (!preg_match('#^'.self::$COUPLE_REGEX.'(?:, *'.self::$COUPLE_REGEX.')*$#',$fees_table_string)) {
531
- $this->addMessage('error',$row,$property_key,'Error in table %s','<span class="osh-formula">'.htmlentities($result[0]).'</span>');
532
- $result = new OCS_Result(false);
533
- if ($use_cache) $this->setCache($formula_string,$result);
534
- return $result;
535
- }
536
- $fees_table = explode(',',$fees_table_string);
537
-
538
- $replacement = null;
539
- foreach ($fees_table as $item) {
540
- $fee_data = explode(':',$item);
541
-
542
- $fee = trim($fee_data[1]);
543
- $max_value = trim($fee_data[0]);
544
-
545
- $last_char = $max_value{strlen($max_value)-1};
546
- if ($last_char=='[') $including_max_value = false;
547
- else if ($last_char==']') $including_max_value = true;
548
- else $including_max_value = true;
549
-
550
- $max_value = str_replace(array('[',']'),'',$max_value);
551
-
552
- if ($max_value=='*' || $including_max_value && $reference_value<=$max_value || !$including_max_value && $reference_value<$max_value) {
553
- $replacement = $fee;//$this->_calculateFee($process,$fee,$var);
554
- break;
555
- }
556
- }
557
- }
558
- $replacement = $this->_toString($replacement);
559
- if ($use_cache) $this->setCache($original,$replacement);
560
- }
561
- $formula = $this->replace($original,$replacement,$formula);
562
- }
563
- $result = new OCS_Result(true,$formula);
564
- return $result;
565
- }
566
-
567
- protected function _evalFormula($formula) {
568
- if (is_bool($formula)) return $formula;
569
- 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'
570
- .'|in_array\(\'(?:[^\']*)\', *array\( *(?:\'(?:[^\']+)\') *(?: *, *\'(?:[^\']+)\')* *\) *\)'
571
- .'|\'[^\']*\'|[0-9,\'\.\-\(\)\*\/\?\:\+\<\>\=\&\|%! ])*$/',$formula)) {
572
- $errors = array(
573
- PREG_NO_ERROR => 'PREG_NO_ERROR',
574
- PREG_INTERNAL_ERROR => 'PREG_INTERNAL_ERROR',
575
- PREG_BACKTRACK_LIMIT_ERROR => 'PREG_BACKTRACK_LIMIT_ERROR',
576
- PREG_RECURSION_LIMIT_ERROR => 'PREG_RECURSION_LIMIT_ERROR',
577
- PREG_BAD_UTF8_ERROR => 'PREG_BAD_UTF8_ERROR',
578
- PREG_BAD_UTF8_OFFSET_ERROR => 'PREG_BAD_UTF8_OFFSET_ERROR',
579
- );
580
- $error = preg_last_error();
581
- if (isset($errors[$error])) $error = $errors[$error];
582
- self::debug(' doesn\'t match ('.$error.')',10);
583
- return null;
584
- }
585
- $formula = str_replace(
586
- array('min','max'),
587
- array('$this->_min','$this->_max'),
588
- $formula
589
- );
590
- $eval_result = null;
591
- @eval('$eval_result = ('.$formula.');');
592
- return $eval_result;
593
- }
594
-
595
- protected function _getOptionsAndData($string) {
596
- if (preg_match('/^(\\s*\(\\s*([^\] ]*)\\s*\)\\s*)/',$string,$result)) {
597
- $options = $result[2];
598
- $data = str_replace($result[1],'',$string);
599
- } else {
600
- $options = '';
601
- $data = $string;
602
- }
603
- return array(
604
- 'options' => $options,
605
- 'data' => $data,
606
- );
607
- }
608
-
609
- public function compress($input) {
610
- if (preg_match_all("/{table (.*) in (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}/imsU",$input,$result,PREG_SET_ORDER)) {
611
- foreach ($result as $result_i) {
612
- $fees_table = explode(',',$result_i[2]);
613
- $value = null;
614
- foreach ($fees_table as $index => $item) {
615
- list($max_value,$fee) = explode(':',$item);
616
- $last_char = $max_value{strlen($max_value)-1};
617
- if (in_array($last_char,array('[',']'))) {
618
- $including_char = $last_char;
619
- $max_value = str_replace(array('[',']'),'',$max_value);
620
- } else $including_char = '';
621
- $fees_table[$index] = ((float)$max_value).$including_char.':'.((float)$fee);
622
- }
623
- $input = str_replace($result_i[2],implode(',',$fees_table),$input);
624
- $input = str_replace($result_i[1],trim($result_i[1]),$input);
625
- }
626
- }
627
- if (preg_match_all("#{foreach ([^}]*)}(.*){/foreach}#imsU",$input,$result,PREG_SET_ORDER)) {
628
- foreach ($result as $result_i) {
629
- $input = str_replace($result_i[1],trim($result_i[1]),$input);
630
- $input = str_replace($result_i[2],trim($result_i[2]),$input);
631
- }
632
- }
633
- return '$$'.str_replace(
634
- self::$UNCOMPRESSED_STRINGS,
635
- self::$COMPRESSED_STRINGS,
636
- $input
637
- );
638
- }
639
-
640
- public function uncompress($input) {
641
- if (preg_match_all("/{table (.*) in (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}/iU",$input,$result,PREG_SET_ORDER)) {
642
- foreach ($result as $result_i) {
643
- $fees_table = explode(',',$result_i[2]);
644
- $value = null;
645
- foreach ($fees_table as $index => $item) {
646
- list($max_value,$fee) = explode(':',$item);
647
- $last_char = $max_value{strlen($max_value)-1};
648
- if (in_array($last_char,array('[',']'))) {
649
- $including_char = $last_char;
650
- $max_value = str_replace(array('[',']'),'',$max_value);
651
- } else $including_char = '';
652
- $max_value = (float)$max_value;
653
- $fee = (float)$fee;
654
- $new_max_value = number_format($max_value,2,'.','');
655
- $new_fee = number_format($fee,2,'.','');
656
- $fees_table[$index] = (((float)$new_max_value)==$max_value ? $new_max_value : $max_value).$including_char.':'
657
- .(((float)$new_fee)==$fee ? $new_fee : $fee);
658
- }
659
- $input = str_replace($result_i[2],implode(', ',$fees_table),$input);
660
- $input = str_replace($result_i[1],trim($result_i[1]),$input);
661
- }
662
- }
663
- if (preg_match_all("#{foreach ([^}]*)}(.*){/foreach}#iU",$input,$result,PREG_SET_ORDER)) {
664
- foreach ($result as $result_i) {
665
- $input = str_replace($result_i[1],trim($result_i[1]),$input);
666
- $input = str_replace($result_i[2],trim($result_i[2]),$input);
667
- }
668
- }
669
- return str_replace(
670
- self::$COMPRESSED_STRINGS,
671
- self::$UNCOMPRESSED_STRINGS,
672
- $input
673
- );
674
- }
675
-
676
- public function parseProperty($input) {
677
- $value = $input==='false' || $input==='true' ? $input=='true' : str_replace('\"','"',preg_replace('/^(?:"|\')(.*)(?:"|\')$/s','$1',$input));
678
- return $value==='' ? null : $value;
679
- }
680
-
681
- public function cleanProperty(&$row, $key) {
682
- $input = $row[$key]['value'];
683
- if (is_string($input)) {
684
- $input = str_replace(array("\n"),array(''),$input);
685
- while (preg_match('/({TABLE |{SUM |{COUNT | DISTINCT | IN )/',$input,$resi)) {
686
- $input = str_replace($resi[0],strtolower($resi[0]),$input);
687
- }
688
-
689
- while (preg_match('/{{customVar code=([a-zA-Z0-9_-]+)}}/',$input,$resi)) {
690
- $input = str_replace($resi[0],'{customvar.'.$resi[1].'}',$input);
691
- }
692
-
693
- $regex = "{(weight|products_quantity|price_including_tax|price_excluding_tax|country)}";
694
- if (preg_match('/'.$regex.'/',$input,$resi)) {
695
- $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
696
- while (preg_match('/'.$regex.'/',$input,$resi)) {
697
- switch ($resi[1]) {
698
- case 'price_including_tax':
699
- case 'price_excluding_tax':
700
- case 'weight':
701
- $input = str_replace($resi[0],"{cart.".$resi[1]."}",$input);
702
- break;
703
- case 'products_quantity': $input = str_replace($resi[0],"{cart.quantity}",$input); break;
704
- case 'country': $input = str_replace($resi[0],"{destination.country.name}",$input); break;
705
- }
706
- }
707
- }
708
-
709
- $regex1 = "{copy '([a-zA-Z0-9_]+)'\.'([a-zA-Z0-9_]+)'}";
710
- if (preg_match('/'.$regex1.'/',$input,$resi)) {
711
- $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
712
- while (preg_match('/'.$regex1.'/',$input,$resi)) $input = str_replace($resi[0],'{'.$resi[1].'.'.$resi[2].'}',$input);
713
- }
714
-
715
- $regex1 = "{(count|all|any) (attribute|option) '([^'\)]+)' ?((?:==|<=|>=|<|>|!=) ?(?:".self::$FLOAT_REGEX."|true|false|'[^'\)]*'))}";
716
- $regex2 = "{(sum) (attribute|option) '([^'\)]+)'}";
717
- if (preg_match('/'.$regex1.'/',$input,$resi) || preg_match('/'.$regex2.'/',$input,$resi)) {
718
- $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
719
- while (preg_match('/'.$regex1.'/',$input,$resi) || preg_match('/'.$regex2.'/',$input,$resi)) {
720
- switch ($resi[1]) {
721
- case 'count': $input = str_replace($resi[0],"{count products where product.".$resi[2]."s.".$resi[3].$resi[4]."}",$input); break;
722
- case 'all': $input = str_replace($resi[0],"{count products where product.".$resi[2]."s.".$resi[3].$resi[4]."}=={products_quantity}",$input); break;
723
- case 'any': $input = str_replace($resi[0],"{count products where product.".$resi[2]."s.".$resi[3].$resi[4]."}>0",$input); break;
724
- case 'sum': $input = str_replace($resi[0],"{sum product.".$resi[2].".".$resi[3]."}",$input); break;
725
- }
726
- }
727
- }
728
-
729
- $regex = "((?:{| )product.(?:attribute|option))s.";
730
- if (preg_match('/'.$regex.'/',$input,$resi)) {
731
- $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
732
- while (preg_match('/'.$regex.'/',$input,$resi)) {
733
- $input = str_replace($resi[0],$resi[1].'.',$input);
734
- }
735
- }
736
-
737
- $regex = "{table '([^']+)' (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}";
738
- if (preg_match('/'.$regex.'/',$input,$resi)) {
739
- $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
740
- while (preg_match('/'.$regex.'/',$input,$resi)) {
741
- switch ($resi[1]) {
742
- case 'products_quantity':
743
- $input = str_replace($resi[0],"{table {cart.weight} in ".$resi[2]."}*{cart.quantity}",$input);
744
- break;
745
- default:
746
- $input = str_replace($resi[0],"{table {cart.".$resi[1]."} in ".$resi[2]."}",$input);
747
- break;
748
- }
749
- }
750
- }
751
- }
752
- $row[$key]['value'] = $input;
753
- }
754
-
755
- protected function _parseInput() {
756
- $config_string = str_replace(
757
- array('&gt;','&lt;','“','”',utf8_encode(chr(147)),utf8_encode(chr(148)),'&laquo;','&raquo;',"\r\n","\t"),
758
- array('>','<','"','"','"','"','"','"',"\n",' '),
759
- $this->_input
760
- );
761
-
762
- if (substr($config_string,0,2)=='$$') $config_string = $this->uncompress(substr($config_string,2,strlen($config_string)));
763
-
764
- //echo ini_get('pcre.backtrack_limit');
765
- //exit;
766
-
767
- $row_regex = ' *([a-z0-9_]+)\\s*:\\s*("(?:(?:[^"]|\\\\")*[^\\\\])?"|'.self::$FLOAT_REGEX.'|false|true)\\s*(,)? *(?:\\n)?';
768
- if (!preg_match_all('/((?:#+[^{\\n]*\\s+)*)\\s*(#)?{\\s*('.$row_regex.')+\\s*}/i',$config_string,$result,PREG_SET_ORDER)) {
769
- $errors = array(
770
- PREG_NO_ERROR => 'PREG_NO_ERROR',
771
- PREG_INTERNAL_ERROR => 'PREG_INTERNAL_ERROR',
772
- PREG_BACKTRACK_LIMIT_ERROR => 'PREG_BACKTRACK_LIMIT_ERROR',
773
- PREG_RECURSION_LIMIT_ERROR => 'PREG_RECURSION_LIMIT_ERROR',
774
- PREG_BAD_UTF8_ERROR => 'PREG_BAD_UTF8_ERROR',
775
- PREG_BAD_UTF8_OFFSET_ERROR => 'PREG_BAD_UTF8_OFFSET_ERROR',
776
- );
777
- $error = preg_last_error();
778
- if (isset($errors[$error])) $error = $errors[$error];
779
- self::debug(' preg_match_all error ('.$error.')',10);
780
- }
781
-
782
- $this->_config = array();
783
- $available_keys = array(
784
- 'code','label','enabled','description','fees','conditions','destination','origin','customer_groups','tracking_url',
785
- 'fees_table','fees_formula','fixed_fees','reference_value',
786
- 'prices_range','weights_range','product_properties',
787
- 'free_shipping__fees_table','free_shipping__fees_formula','free_shipping__fixed_fees','free_shipping__label',
788
- );
789
-
790
- foreach ($result as $block) {
791
- $deprecated_properties = array();
792
- $unknown_properties = array();
793
- $missing_semicolon = array();
794
- $obsolete_disabling_method = array();
795
-
796
- //$before = strstr($config_string,$block[0],true); // Seulement compatible avec PHP 5.3.0
797
- list($before) = explode($block[0],$config_string,2);
798
- if ($before!==false && trim($before)!='') {
799
- $config_string = substr($config_string,strlen($before));
800
- $this->_addIgnoredLines(trim($before));
801
- $this->addMessage('info',$row=null,null,'Ignored lines %s','<div class="code">'.trim($before).'</div>');
802
- }
803
-
804
- $config_string = str_replace($block[0], '', $config_string);
805
- preg_match_all('/'.$row_regex.'/i',$block[0],$result2,PREG_SET_ORDER);
806
- $block_string = $block[0];
807
-
808
- $row = array();
809
- $i = 1;
810
- foreach ($result2 as $data) {
811
- $key = $data[1];
812
- if (in_array($key,$available_keys) || substr($key,0,1)=='_') {
813
- $property = $this->parseProperty($data[2]);
814
- if (isset($property)) {
815
- $row[$key] = array('value' => $property, 'original_value' => $property);
816
- $this->cleanProperty($row,$key);
817
- }
818
- if ($i>2) {
819
- $block_string = str_replace($data[0],$i==3 ? "...\n" : '',$block_string);
820
- }
821
- if ($i!=count($result2) && !isset($data[3]) || isset($data[3]) && $data[3]!=',') {
822
- if (preg_match('/^("|\')(.{40})(.*)("|\')$/s',$data[2],$resultx))
823
- $missing_semicolon[] = trim(str_replace($data[2],$resultx[1].$resultx[2].' ...'.$resultx[4],$data[0]));
824
- else $missing_semicolon[] = trim($data[0]);
825
- }
826
- } else {
827
- if (!in_array($key,$unknown_properties)) $unknown_properties[] = $key;
828
- }
829
- $i++;
830
- }
831
- if ($block[1]!='') $row['*comment']['value'] = $block[1];
832
- if ($block[2]=='#' && !isset($row['enabled'])) {
833
- $row['enabled'] = array('value' => false);
834
- $obsolete_disabling_method[] = $block_string;
835
- }
836
-
837
- $formula_fields_to_check = array();
838
- if (isset($row['conditions'])) $formula_fields_to_check[] = 'conditions';
839
- if (isset($row['fees'])) $formula_fields_to_check[] = 'fees';
840
-
841
- if (count($formula_fields_to_check)>0) {
842
- foreach ($formula_fields_to_check as $property) {
843
- $property_value = $row[$property]['value'];
844
- if (preg_match('/{ +/',$property_value)) {
845
- $this->addMessage('warning',$row,$property,'There are unwanted spaces after char `%s`','{');
846
- $property_value = preg_replace('/{ +/','{',$property_value);
847
- }
848
- if (preg_match('/ +}/',$property_value)) {
849
- $this->addMessage('warning',$row,$property,'There are unwanted spaces before char `%s`','}');
850
- $property_value = preg_replace('/ +}/','}',$property_value);
851
- }
852
- if (preg_match('/ +/',$property_value)) {
853
- $this->addMessage('warning',$row,$property,'There are unwanted multiples spaces `%s`',preg_replace('/( +)/','<span class="osh-formula">*$1*</span>',$property_value));
854
- $property_value = preg_replace('/ +/',' ',$property_value);
855
- }
856
- $row[$property]['value'] = trim($property_value);
857
- }
858
- }
859
-
860
- $float_value_regex = '\\s*('.self::$POSITIVE_FLOAT_REGEX.'|\*)\\s*';
861
- $conditions = array();
862
- if (isset($row['prices_range'])) {
863
- if (!in_array('prices_range',$deprecated_properties)) $deprecated_properties[] = 'prices_range';
864
-
865
- $result = $this->_getOptionsAndData($row['prices_range']['value']);
866
- $options = $result['options'];
867
- $prices_range = $result['data'];
868
-
869
- if (($options=='' || in_array($options,array('incl.tax','ttc')))
870
- && preg_match('/^\\s*(\[|\])?'.$float_value_regex.'=>'.$float_value_regex.'(\[|\])?\\s*$/',$prices_range,$result)) {
871
- $min_price_included = $result[1]=='[';
872
- $min_price = $result[2]=='*' ? -1 : (float)$result[2];
873
- $max_price = $result[3]=='*' ? -1 : (float)$result[3];
874
- $max_price_included = !isset($result[4]) || $result[4]==']' || $result[4]=='';
875
-
876
- $tax_included = $options!='' && in_array($options,array('incl.tax','ttc')) || isset($row['reference_value']) && $row['reference_value']['value']=='price_including_tax';
877
- $price = $tax_included ? '{cart.price_including_tax}' : '{cart.price_excluding_tax}';
878
-
879
- if ($min_price!=-1) $conditions[] = $price.'>'.($min_price_included ? '=' : '').$min_price;
880
- if ($max_price!=-1) $conditions[] = $price.'<'.($max_price_included ? '=' : '').$max_price;
881
- }
882
- else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">prices_range</span>','<span class="osh-formula">'.$row['prices_range']['value'].'</span>');
883
- unset($row['prices_range']);
884
- }
885
- if (isset($row['weights_range'])) {
886
- if (!in_array('weights_range',$deprecated_properties)) $deprecated_properties[] = 'weights_range';
887
- if (preg_match('/^\\s*(\[|\])?'.$float_value_regex.'=>'.$float_value_regex.'(\[|\])?\\s*$/',$row['weights_range']['value'],$result)) {
888
- $min_weight_included = $result[1]=='[';
889
- $min_weight = $result[2]=='*' ? -1 : (float)$result[2];
890
- $max_weight = $result[3]=='*' ? -1 : (float)$result[3];
891
- $max_weight_included = !isset($result[4]) || $result[4]==']' || $result[4]=='';
892
-
893
- if ($min_weight!=-1) $conditions[] = '{cart.weight}>'.($min_weight_included ? '=' : '').$min_weight;
894
- if ($max_weight!=-1) $conditions[] = '{cart.weight}<'.($max_weight_included ? '=' : '').$max_weight;
895
- }
896
- else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">weights_range</span>','<span class="osh-formula">'.$row['weights_range']['value'].'</span>');
897
- unset($row['weights_range']);
898
- }
899
- if (isset($row['product_properties'])) {
900
- if (!in_array('product_properties',$deprecated_properties)) $deprecated_properties[] = 'product_properties';
901
- $product_property_regex = "\\s*(and|or)? *\((?:(all|any|sum) )?(attribute|option) '([^'\)]+)' ?(==|=|<=|>=|<|>|!=) ?(".self::$FLOAT_REGEX."|true|false|'[^'\)]*')\)\\s*";
902
- if (preg_match('/^('.$product_property_regex.')+$/',$row['product_properties']['value'],$result)) {
903
- preg_match_all('/'.$product_property_regex.'/',$row['product_properties']['value'],$results,PREG_SET_ORDER);
904
- $product_properties_condition = '';
905
- foreach ($results as $result) {
906
- $and_or = $result[1];
907
- if ($and_or=='') $and_or = 'and';
908
- $any_all_sum = $result[2];
909
- if ($any_all_sum=='') $any_all_sum = 'any';
910
- $property_type = $result[3];
911
- $property_name = $result[4];
912
- $cmp_symbol = $result[5];
913
- if ($cmp_symbol=='=') $cmp_symbol = '==';
914
- $cmp_value = $result[6];
915
-
916
- $product_properties_condition .= $product_properties_condition=='' ? '' : ' '.$and_or.' ';
917
- switch ($any_all_sum) {
918
- case 'sum':
919
- $product_properties_condition .= "{sum product.".$property_type.".".$property_name."}".$cmp_symbol.$cmp_value;
920
- break;
921
- case 'all':
922
- $product_properties_condition .= "{count products where product.".$property_type.".".$property_name.$cmp_symbol.$cmp_value."}=={products_quantity}";
923
- break;
924
- case 'any':
925
- $product_properties_condition .= "{count products where product.".$property_type.".".$property_name.$cmp_symbol.$cmp_value."}>0";
926
- break;
927
- }
928
- }
929
- if ($product_properties_condition!='') $conditions[] = $product_properties_condition;
930
- }
931
- else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">product_properties</span>','<span class="osh-formula">'.$row['product_properties']['value'].'</span>');
932
- unset($row['product_properties']);
933
- }
934
- if (count($conditions)>0) $row['conditions'] = array('value' => count($conditions)==1 ? $conditions[0] : '('.implode(') && (',$conditions).')');
935
-
936
- $fees = array();
937
- if (isset($row['fees_table'])) {
938
- if (!in_array('fees_table',$deprecated_properties)) $deprecated_properties[] = 'fees_table';
939
- $options_and_data = $this->_getOptionsAndData($row['fees_table']['value']);
940
- $options = $options_and_data['options'];
941
- $fees_table_string = $options_and_data['data'];
942
-
943
- $var = null;
944
- if ($options=='') $var = (isset($row['reference_value']) ? $row['reference_value']['value'] : 'weight');
945
- else if (in_array($options,array('incl.tax','ttc'))) $var = 'price_including_tax';
946
- else if (in_array($options,array('excl.tax','ht'))) $var = 'price_excluding_tax';
947
-
948
- if (isset($var)) {
949
- if ($var=='price') $var = 'price_excluding_tax';
950
- if ($var=='products_quantity') $var = 'quantity';
951
- if (preg_match('/^[[:space:]]*\*[[:space:]]*:[[:space:]]*('.$float_value_regex.')[[:space:]]*$/s',$fees_table_string,$result)) $fees[] = $result[1];
952
- else $fees[] = "{table {cart.".$var."} in ".str_replace(' ','',$fees_table_string)."}".($var=='quantity' ? '*{cart.quantity}' : '');
953
- }
954
- else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">fees_table</span>','<span class="osh-formula">'.$row['fees_table']['value'].'</span>');
955
- unset($row['fees_table']);
956
- }
957
- if (isset($row['fees_formula'])) {
958
- if (!in_array('fees_formula',$deprecated_properties)) $deprecated_properties[] = 'fees_formula';
959
- $fees[] = str_replace(' ','',$row['fees_formula']['value']);
960
- unset($row['fees_formula']);
961
- }
962
- if (isset($row['fixed_fees'])) {
963
- if (!in_array('fixed_fees',$deprecated_properties)) $deprecated_properties[] = 'fixed_fees';
964
- if ($row['fixed_fees']['value']!=0 || count($fees)==0) $fees[] = str_replace(' ','',$row['fixed_fees']['value']);
965
- unset($row['fixed_fees']);
966
- }
967
- if (!isset($row['fees']) && count($fees)>0) $row['fees'] = array('value' => implode('+',$fees));
968
-
969
- $fs_fees = array();
970
- if (isset($row['free_shipping__fees_table'])) {
971
- if (!in_array('free_shipping__fees_table',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__fees_table';
972
- $options_and_data = $this->_getOptionsAndData($row['free_shipping__fees_table']['value']);
973
- $options = $options_and_data['options'];
974
- $fees_table_string = $options_and_data['data'];
975
-
976
- $var = null;
977
- if ($options=='') $var = isset($row['reference_value']) ? $row['reference_value']['value'] : 'weight';
978
- else if (in_array($options,array('incl.tax','ttc'))) $var = 'price_including_tax';
979
- else if (in_array($options,array('excl.tax','ht'))) $var = 'price_excluding_tax';
980
- if ($var=='price') $var = 'price_excluding_tax';
981
-
982
- if (isset($var)) {
983
- if ($var=='price') $var = 'price_excluding_tax';
984
- if ($var=='products_quantity') $var = 'quantity';
985
- if (preg_match('/^[[:space:]]*\*[[:space:]]*:[[:space:]]*('.$float_value_regex.')[[:space:]]*$/s',$fees_table_string,$result)) $fs_fees[] = $result[1];
986
- else $fs_fees[] = "{table {cart.".$var."} in ".str_replace(' ','',$fees_table_string)."}".($var=='quantity' ? '*{cart.quantity}' : '');
987
- }
988
- else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">free_shipping__fees_table</span>','<span class="osh-formula">'.$row['free_shipping__fees_table']['value'].'</span>');
989
- unset($row['free_shipping__fees_table']);
990
- }
991
- if (isset($row['free_shipping__fees_formula'])) {
992
- if (!in_array('free_shipping__fees_formula',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__fees_formula';
993
- $fs_fees[] = str_replace(' ','',$row['free_shipping__fees_formula']['value']);
994
- unset($row['free_shipping__fees_formula']);
995
- }
996
- if (isset($row['free_shipping__fixed_fees'])) {
997
- if (!in_array('free_shipping__fixed_fees',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__fixed_fees';
998
- if ($row['free_shipping__fixed_fees']['value']!=0 || count($fees)==0) $fs_fees[] = str_replace(' ','',$row['free_shipping__fixed_fees']['value']);
999
- unset($row['free_shipping__fixed_fees']);
1000
- }
1001
-
1002
- if (isset($row['reference_value'])) {
1003
- if (!in_array('reference_value',$deprecated_properties)) $deprecated_properties[] = 'reference_value';
1004
- unset($row['reference_value']);
1005
- }
1006
-
1007
- if (count($fs_fees)>0) {
1008
- $row2 = $row;
1009
- if (isset($row['code'])) $row2['code']['value'] = $row['code']['value'].'__free_shipping';
1010
- $row2['fees']['value'] = implode('+',$fs_fees);
1011
- $row2['conditions']['value'] = isset($row2['conditions']) ? '('.$row2['conditions']+') and {free_shipping}' : '{free_shipping}';
1012
- $row['conditions']['value'] = isset($row['conditions']) ? '('.$row['conditions']+') and !{free_shipping}' : '!{free_shipping}';
1013
- if (isset($row['free_shipping__label'])) {
1014
- if (!in_array('free_shipping__label',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__label';
1015
- $row2['label']['value'] = $row['free_shipping__label']['value'];
1016
- unset($row['free_shipping__label']);
1017
- unset($row2['free_shipping__label']);
1018
- }
1019
- $this->_addRow($row2);
1020
- }
1021
- if (count($unknown_properties)>0) $this->addMessage('error',$row,null,'Usage of unknown properties %s',': <span class="osh-key">'.implode('</span>, <span class="osh-key">',$unknown_properties).'</span>');
1022
- if (count($deprecated_properties)>0) $this->addMessage('warning',$row,null,'Usage of deprecated properties %s',': <span class="osh-key">'.implode('</span>, <span class="osh-key">',$deprecated_properties).'</span>');
1023
- if (count($obsolete_disabling_method)>0) $this->addMessage('warning',$row,null,'Usage of obsolete method to disabling a shipping method (`#` before `{`)%s','<div class="code">'.implode('<br />',$obsolete_disabling_method).'</div>');
1024
- if (count($missing_semicolon)>0) $this->addMessage('warning',$row,null,'A semicolon is missing at the end of following lines %s','<div class="code">'.implode('<br />',$missing_semicolon).'</div>');
1025
- $this->_addRow($row);
1026
- }
1027
- if (trim($config_string)!='') {
1028
- $this->_addIgnoredLines(trim($config_string));
1029
- $this->addMessage('info',$row=null,null,'Ignored lines %s','<div class="code">'.trim($config_string).'</div>');
1030
- }
1031
- }
1032
-
1033
- public function addMessage($type, &$row, $property) {
1034
- $args = func_get_args();
1035
- array_shift($args);
1036
- array_shift($args);
1037
- array_shift($args);
1038
- $message = new OCS_Message($type,$args);
1039
- if (isset($row)) {
1040
- if (isset($property)) {
1041
- $row[$property]['messages'][] = $message;
1042
- } else {
1043
- $row['*messages'][] = $message;
1044
- }
1045
- }
1046
- $this->_messages[] = $message;
1047
- self::debug(' => <span class="osh-'.$message->type.'">'.$message->toString().'</span>',1);
1048
- }
1049
-
1050
- protected function _addRow(&$row) {
1051
- if (isset($row['code'])) {
1052
- $key = $row['code']['value'];
1053
- if (isset($this->_config[$key])) $this->addMessage('error',$row,'code','The property `code` must be unique, `%s` has been found twice',$key);
1054
- while (isset($this->_config[$key])) $key .= rand(0,9);
1055
- //$row['code'] = $key;
1056
- } else {
1057
- $i = 1;
1058
- do {
1059
- $key = 'code_auto'.sprintf('%03d',$i);
1060
- $i++;
1061
- } while (isset($this->_config[$key]));
1062
- }
1063
- $row['*code'] = $key;
1064
- $this->_config[$key] = $row;
1065
- }
1066
-
1067
- protected function _addIgnoredLines($lines) {
1068
- $this->_config[] = array('lines' => $lines);
1069
- }
1070
-
1071
- protected function _addressMatch($address_filter, $address) {
1072
- $excluding = false;
1073
- if (preg_match('# *\* *- *\((.*)\) *#s',$address_filter,$result)) {
1074
- $address_filter = $result[1];
1075
- $excluding = true;
1076
- }
1077
-
1078
- $tmp_address_filter_array = explode(',',trim($address_filter));
1079
-
1080
- $concat = false;
1081
- $concatened = '';
1082
- $address_filter_array = array();
1083
- $i = 0;
1084
-
1085
- foreach ($tmp_address_filter_array as $address_filter) {
1086
- if ($concat) $concatened .= ','.$address_filter;
1087
- else {
1088
- if ($i<count($tmp_address_filter_array)-1 && preg_match('#\(#',$address_filter)) {
1089
- $concat = true;
1090
- $concatened .= $address_filter;
1091
- } else $address_filter_array[] = $address_filter;
1092
- }
1093
- if (preg_match('#\)#',$address_filter)) {
1094
- $address_filter_array[] = $concatened;
1095
- $concatened = '';
1096
- $concat = false;
1097
- }
1098
- $i++;
1099
- }
1100
-
1101
- foreach ($address_filter_array as $address_filter) {
1102
- if (preg_match('# *([A-Z]{2}) *(-)? *(?:\( *(-)? *(.*)\))? *#s',$address_filter,$result)) {
1103
- $country_code = $result[1];
1104
- if ($address['country_code']==$country_code) {
1105
- self::debug(' country code <span class="osh-replacement">'.$address['country_code'].'</span> matches',5);
1106
- if (!isset($result[4]) || $result[4]=='') return !$excluding;
1107
- else {
1108
- $region_codes = explode(',',$result[4]);
1109
- $in_array = false;
1110
- for ($i=count($region_codes); --$i>=0;) {
1111
- $code = trim($region_codes[$i]);
1112
- $region_codes[$i] = $code;
1113
- if ($address['region_code']===$code) {
1114
- self::debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> matches',5);
1115
- $in_array = true;
1116
- } else if ($address['postcode']===$code) {
1117
- self::debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches',5);
1118
- $in_array = true;
1119
- } else if (strpos($code,'*')!==false && preg_match('/^'.str_replace('*','(?:.*)',$code).'$/',$address['postcode'])) {
1120
- self::debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches <span class="osh-formula">'.$code.'</span>',5);
1121
- $in_array = true;
1122
- }
1123
- if ($in_array) break;
1124
- }
1125
- if (!$in_array) {
1126
- self::debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> and postcode <span class="osh-replacement">'.$address['postcode'].'</span> don\'t match',5);
1127
- }
1128
- // Vérification stricte
1129
- /*$in_array = in_array($address['region_code'],$region_codes,true) || in_array($address['postcode'],$region_codes,true);*/
1130
- $excluding_region = $result[2]=='-' || $result[3]=='-';
1131
- if ($excluding_region && !$in_array || !$excluding_region && $in_array) return !$excluding;
1132
- }
1133
- }
1134
- }
1135
- }
1136
- return $excluding;
1137
- }
1138
-
1139
- protected function _getProductProperty($product, $property_type, $property_name, $get_by_id=false) {
1140
- switch ($property_type) {
1141
- case 'attribute':
1142
- case 'attributes': return $product->getAttribute($property_name,$get_by_id);
1143
- case 'option':
1144
- case 'options': return $product->getOption($property_name,$get_by_id);
1145
- case 'stock': return $product->getStockData($property_name);
1146
- }
1147
- return null;
1148
- }
1149
-
1150
- protected function _processProductProperty($products, $regex_result) {
1151
- // COUNT, SUM or COUNT DISTINCT
1152
- $operation = strtolower($regex_result[1]);
1153
- switch ($operation) {
1154
- case 'sum':
1155
- case 'count distinct':
1156
- $property_type = $regex_result[2];
1157
- $property_name = $regex_result[3];
1158
- $conditions = isset($regex_result[4]) ? $regex_result[4] : null;
1159
- break;
1160
- case 'count':
1161
- $conditions = isset($regex_result[2]) ? $regex_result[2] : null;
1162
- break;
1163
- }
1164
-
1165
- self::debug(' :: start <span class="osh-replacement">'.$regex_result[0].'</span>',10);
1166
-
1167
- $return_value = 0;
1168
-
1169
- preg_match_all('/product\.(attribute(?:s)?|option(?:s)?|stock)\.([a-z0-9_]+)(?:\.(id))?/i',$conditions,$properties_regex_result,PREG_SET_ORDER);
1170
- $properties = array();
1171
- foreach ($properties_regex_result as $property_regex_result) {
1172
- $key = $property_regex_result[0];
1173
- if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1174
- }
1175
-
1176
- foreach ($products as $product) {
1177
- if (isset($conditions) && $conditions!='') {
1178
- $formula = $conditions;
1179
- foreach ($properties as $property) {
1180
- $value = $this->_getProductProperty(
1181
- $product,
1182
- $tmp_property_type = $property[1],
1183
- $tmp_property_name = $property[2],
1184
- $get_by_id = isset($property[3]) && $property[3]=='id'
1185
- );
1186
- //$formula = $this->replace($property[0],$value,$formula);
1187
- $from = $property[0];
1188
- $to = is_string($value) || empty($value) ? "'".$value."'" : $value;
1189
- $formula = str_replace($from,$to,$formula);
1190
- 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>',5);
1191
- }
1192
- $eval_result = $this->_evalFormula($formula);
1193
- if (!isset($eval_result)) return 'null';
1194
- }
1195
- else $eval_result = true;
1196
-
1197
- if ($eval_result==true) {
1198
- switch ($operation) {
1199
- case 'sum':
1200
- $value = $this->_getProductProperty($product,$property_type,$property_name);
1201
- //self::debug($product->getSku().'.'.$property_type.'.'.$property_name.' = "'.$value.'" x '.$product->getQuantity(),10);
1202
- $return_value += $value*$product->getQuantity();
1203
- break;
1204
- case 'count distinct':
1205
- if (!isset($distinct_values)) $distinct_values = array();
1206
- $value = $this->_getProductProperty($product,$property_type,$property_name);
1207
- if (!in_array($value,$distinct_values)) {
1208
- $distinct_values[] = $value;
1209
- $return_value++;
1210
- }
1211
- break;
1212
- case 'count':
1213
- $return_value += $product->getQuantity();
1214
- break;
1215
- }
1216
- }
1217
- }
1218
-
1219
- self::debug(' :: end <span class="osh-replacement">'.$regex_result[0].'</span>',10);
1220
-
1221
- return $return_value;
1222
- }
1223
-
1224
- }
1225
-
1226
- interface OCS_Product {
1227
- public function getOption($option);
1228
- public function getAttribute($attribute);
1229
- public function getName();
1230
- public function getSku();
1231
- public function getQuantity();
1232
- public function getStockData($key);
1233
- }
1234
-
1235
- class OCS_Message {
1236
- public $type;
1237
- public $message;
1238
- public $args;
1239
-
1240
- public function OCS_Message($type, $args) {
1241
- $this->type = $type;
1242
- $this->message = array_shift($args);
1243
- $this->args = $args;
1244
- }
1245
-
1246
- public function toString() {
1247
- return vsprintf($this->message,$this->args);
1248
- }
1249
- }
1250
-
1251
- class OCS_Result {
1252
- public $success;
1253
- public $result;
1254
-
1255
- public function OCS_Result($success, $result=null) {
1256
- $this->success = $success;
1257
- $this->result = $result;
1258
- }
1259
-
1260
- public function __toString() {
1261
- return is_bool($this->result) ? ($this->result ? 'true' : 'false') : (string)$this->result;
1262
- }
1263
- }
1264
-
1265
-
1266
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Magento Chronopost Chronorelais 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 Chronopost
17
+ * @package Chronopost_Chronorelais
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 ChronorelaisShippingHelper
24
+ {
25
+ public static $DEBUG_INDEX_COUNTER = 0;
26
+ public static $FLOAT_REGEX = '[-]?\d+(?:[.]\d+)?';
27
+ public static $POSITIVE_FLOAT_REGEX = '\d+(?:[.]\d+)?';
28
+ //public static $COUPLE_REGEX = '(?:[0-9.]+|\*)(?:\[|\])?\:[0-9.]+(?:\:[0-9.]+%?)*';
29
+ public static $COUPLE_REGEX = '(?:[0-9.]+|\*) *(?:\[|\])? *\: *[0-9.]+';
30
+ public static $UNCOMPRESSED_STRINGS = array(
31
+ ' product.attribute.',
32
+ ' product.option.',
33
+ ' product.stock.',
34
+ '{product.attribute.',
35
+ '{product.option.',
36
+ '{product.stock.',
37
+ '{product.weight}',
38
+ '{product.quantity}',
39
+ '{cart.weight}',
40
+ '{cart.quantity}',
41
+ '{cart.price_including_tax}',
42
+ '{cart.price_excluding_tax}',
43
+ '{cart.',
44
+ '{customvar.',
45
+ '{selection.weight}',
46
+ '{selection.quantity}',
47
+ '{selection.',
48
+ '{destination.country.',
49
+ '{foreach ',
50
+ '{/foreach}',
51
+ );
52
+ public static $COMPRESSED_STRINGS = array(
53
+ ' p.a.',
54
+ ' p.o.',
55
+ ' p.s.',
56
+ '{p.a.',
57
+ '{p.o.',
58
+ '{p.s.',
59
+ '{p.w}',
60
+ '{p.qty}',
61
+ '{c.w}',
62
+ '{c.qty}',
63
+ '{c.pit}',
64
+ '{c.pet}',
65
+ '{c.',
66
+ '{v.',
67
+ '{s.w}',
68
+ '{s.qty}',
69
+ '{s.',
70
+ '{dest.ctry.',
71
+ '{each ',
72
+ '{/each}',
73
+ );
74
+
75
+ protected $_input;
76
+ protected $_config;
77
+ protected $_messages;
78
+ protected $_formula_cache;
79
+ protected $_expression_cache;
80
+ public $debug = 0;
81
+ public $debug_output = '';
82
+ public $debug_header = null;
83
+
84
+ public function ChronorelaisShippingHelper($input) {
85
+ $this->_formula_cache = array();
86
+ $this->_messages = array();
87
+ $this->_input = $input;
88
+ $this->_config = array();
89
+ $this->_parseInput();
90
+ }
91
+
92
+ private function debug($text, $level=10) {
93
+ if ($this->debug>=$level) $this->debug_output .= "<p>".$text."</p>";
94
+ }
95
+
96
+ public function printDebug() {
97
+ if ($this->debug>0) {
98
+ $index = self::$DEBUG_INDEX_COUNTER++;
99
+ echo "<style rel=\"stylesheet\" type=\"text/css\">"
100
+ .".osh-formula{color:#f90;} .osh-key{color:#0099f7;}"
101
+ .".osh-error{color:#f00;} .osh-warning{color:#ff0;} .osh-info{color:#7bf700;}"
102
+ .".osh-debug{background:#000;color:#bbb;position:absolute;top:0;left:0;width:100%;z-index:100;-moz-opacity:0.9;opacity:0.9;text-align:left;white-space:pre-wrap;}"
103
+ .".osh-debug-content{padding:10px;}"
104
+ .".osh-replacement{color:#ff3000;}"
105
+ ."</style>"
106
+ ."<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>"
107
+ ."<p>".$this->debug_header."</p>".$this->debug_output."</pre></div>";
108
+ }
109
+ }
110
+
111
+ public function setDebugHeader($process) {
112
+ $header = 'DEBUG app/code/community/Chronopost/Chronorelais/Model/Carrier/ChronorelaisShippingHelper.php<br/>';
113
+ foreach ($process['data'] as $key => $data) {
114
+ $header .= ' <span class="osh-key">'.$key.'</span> = <span class="osh-formula">'.$this->_toString($data).'</span><br/>';
115
+ }
116
+ $this->debug_header = $header;
117
+ }
118
+
119
+ public function getConfig() {
120
+ return $this->_config;
121
+ }
122
+
123
+ public function getMessages() {
124
+ $messages = $this->_messages;
125
+ $this->_messages = array();
126
+ return $messages;
127
+ }
128
+
129
+ public function formatConfig($compress) {
130
+ $output = '';
131
+ foreach ($this->_config as $code => $row) {
132
+ if (!isset($row['lines'])) {
133
+ if (isset($row['*comment']['value'])) {
134
+ $output .= trim($row['*comment']['value'])."\n";
135
+ }
136
+ $output .= '{'.($compress ? '' : "\n");
137
+ foreach ($row as $key => $property) {
138
+ if (substr($key,0,1)!='*') {
139
+ $value = $property['value'];
140
+ if (isset($property['comment'])) $output .= ($compress ? '' : "\t").'/* '.$property['comment'].' */'.($compress ? '' : "\n");
141
+ $output .= ($compress ? '' : "\t").$key.':'.($compress ? '' : ' ');
142
+ if (is_bool($value)) $output .= $value ? 'true' : 'false';
143
+ else if (is_int($value)) $output .= $value;
144
+ else if ((string)((float)$value)==$value) $output .= $value;
145
+ else $output .= '"'.str_replace('"','\\"',$value).'"';
146
+ $output .= ','.($compress ? '' : "\n");
147
+ }
148
+ }
149
+ if ($compress) $output = preg_replace('/,$/','',$output);
150
+ $output .= "}\n".($compress ? '' : "\n");
151
+ } else {
152
+ $output .= $row['lines']."\n";
153
+ }
154
+ }
155
+ return $compress ? $this->compress($output) : $this->uncompress($output);
156
+ }
157
+
158
+ public function checkConfig() {
159
+ $process = array(
160
+ 'result' => null,
161
+ 'data' => array(
162
+ 'cart.price_excluding_tax' => 0,
163
+ 'cart.price_including_tax' => 0,
164
+ 'destination.country.code' => '',
165
+ 'destination.country.name' => '',
166
+ 'destination.region.code' => '',
167
+ 'destination.postcode' => '',
168
+ 'origin.country.code' => '',
169
+ 'origin.country.name' => '',
170
+ 'origin.region.code' => '',
171
+ 'origin.postcode' => '',
172
+ 'free_shipping' => false,
173
+ 'customer.group.id' => '',
174
+ 'customer.group.code' => '',
175
+ 'cart.weight' => 0,
176
+ 'cart.weight.unit' => 'kg',
177
+ 'cart.quantity' => 0,
178
+ ),
179
+ 'cart.items' => array(),
180
+ 'products' => array(),
181
+ 'config' => $this->_config,
182
+ );
183
+ foreach ($this->_config as $code => &$row) {
184
+ $this->processRow($process,$row,$check_all_conditions=true);
185
+ foreach ($row as $property_key => $property_value) {
186
+ if (substr($property_key,0,1)!='*') $this->getRowProperty($row,$property_key);
187
+ }
188
+ }
189
+ }
190
+
191
+ public function processRow($process, &$row, $is_checking=false) {
192
+ if (!isset($row['*code'])) return;
193
+
194
+ self::debug('process row <span class="osh-key">'.$row['*code'].'</span>',1);
195
+ if (!isset($row['label']['value'])) $row['label']['value'] = '***';
196
+
197
+ $enabled = $this->getRowProperty($row,'enabled');
198
+ if (isset($enabled)) {
199
+ if (!$is_checking && !$enabled) {
200
+ $this->addMessage('info',$row,'enabled','Configuration disabled');
201
+ return new OCS_Result(false);
202
+ }
203
+ }
204
+
205
+ $conditions = $this->getRowProperty($row,'conditions');
206
+ if (isset($conditions)) {
207
+ $result = $this->_processFormula($process,$row,'conditions',$conditions,$is_checking);
208
+ if (!$is_checking) {
209
+ if (!$result->success) return $result;
210
+ if (!$result->result) {
211
+ $this->addMessage('info',$row,'conditions',"The cart doesn't match conditions");
212
+ return new OCS_Result(false);
213
+ }
214
+ }
215
+ }
216
+
217
+ $destination = $this->getRowProperty($row,'destination');
218
+ if (isset($destination)) {
219
+ $destination_match = $this->_addressMatch($destination,array(
220
+ 'country_code' => $process['data']['destination.country.code'],
221
+ 'region_code' => $process['data']['destination.region.code'],
222
+ 'postcode' => $process['data']['destination.postcode']
223
+ ));
224
+ if (!$is_checking && !$destination_match) {
225
+ $this->addMessage('info',$row,'destination',"The shipping method doesn't cover the zone");
226
+ return new OCS_Result(false);
227
+ }
228
+ }
229
+
230
+ $origin = $this->getRowProperty($row,'origin');
231
+ if (isset($origin)) {
232
+ $origin_match = $this->_addressMatch($origin,array(
233
+ 'country_code' => $process['data']['origin.country.code'],
234
+ 'region_code' => $process['data']['origin.region.code'],
235
+ 'postcode' => $process['data']['origin.postcode']
236
+ ));
237
+ if (!$is_checking && !$origin_match) {
238
+ $this->addMessage('info',$row,'origin',"The shipping method doesn't match to shipping origin");
239
+ return new OCS_Result(false);
240
+ }
241
+ }
242
+
243
+ $customer_groups = $this->getRowProperty($row,'customer_groups');
244
+ if (isset($customer_groups)) {
245
+ $groups = explode(',',$customer_groups);
246
+ $group_match = false;
247
+ //self::debug('code:'.$process['data']['customer.group.code'].', id:'.$process['data']['customer.group.id']);
248
+ foreach ($groups as $group) {
249
+ $group = trim($group);
250
+ if ($group==$process['data']['customer.group.code'] || is_int($group) && $group==$process['data']['customer.group.id'] || $group=='*') {
251
+ $group_match = true;
252
+ break;
253
+ }
254
+ }
255
+ if (!$is_checking && !$group_match) {
256
+ $this->addMessage('info',$row,'customer_groups',"The shipping method doesn't match to customer group (%s)",$process['data']['customer.group.code']);
257
+ return new OCS_Result(false);
258
+ }
259
+ }
260
+
261
+ //Chronopost quickcost method for dynamic price if it is set enabled
262
+ $quickcost = Mage::getStoreConfig('carriers/'.$process['data']['carrier.code'].'/quickcost');
263
+ if($quickcost) {
264
+ if($quickCostValues = $this->getQuickCostValue($process['data'])) {
265
+ if($quickCostValues->errorCode==0) {
266
+ return new OCS_Result(true,(float)$quickCostValues->amountTTC);
267
+ } else {
268
+ $this->addMessage('error',$row,'chronopost',$quickCostValues->errorMessage);
269
+ return new OCS_Result(false);
270
+ }
271
+ } else {
272
+ return new OCS_Result(false);
273
+ }
274
+ }
275
+
276
+ $fees = $this->getRowProperty($row,'fees');
277
+ if (isset($fees)) {
278
+ $result = $this->_processFormula($process,$row,'fees',$fees,$is_checking);
279
+ if (!$result->success) return $result;
280
+ self::debug(' => <span class="osh-info">result = <span class="osh-formula">'.$this->_toString($result->result).'</span>',1);
281
+ return new OCS_Result(true,(float)$result->result);
282
+ }
283
+
284
+ return new OCS_Result(false);
285
+ }
286
+
287
+ public function getQuickCostValue($processData) {
288
+ $quickCost = array();
289
+ $_helper = Mage::helper('chronorelais');
290
+ $account_number = $_helper->getConfigurationAccountNumber();
291
+ $password = $_helper->getConfigurationAccountPass();
292
+ $productCode = $_helper->getChronoProductCode($processData['destination.country.code'], $processData['carrier.code']);
293
+ $origin_postcode = $_helper->getConfigurationShipperInfo('zipcode');
294
+
295
+ //to get arrival code
296
+ $arrCode = $processData['destination.postcode'];
297
+ if($processData['carrier.code']=='chronoexpress') {
298
+ $arrCode = $processData['destination.country.code'];
299
+ }
300
+
301
+ $quickCost = array(
302
+ 'contratNumber' => $account_number,
303
+ 'depCode' => $origin_postcode,
304
+ 'arrCode' => $arrCode,
305
+ 'weight' => $processData['cart.weight'],
306
+ 'productCode' => $productCode,
307
+ 'type' => 'M',
308
+ 'password' => $password
309
+ );
310
+
311
+ try {
312
+ $quickcost_url = Mage::helper('chronorelais')->getConfigData('carriers/'.$process['data']['carrier.code'].'/quickcost_url');
313
+ if(!$quickcost_url) { $quickcost_url = "http://wsshipping.chronopost.fr/wsQuickcost/services/ServiceQuickCost?wsdl"; }
314
+ $client = new SoapClient($quickcost_url);
315
+ $webservbt = $client->__call("quickCost",$quickCost);
316
+ return $webservbt;
317
+ } catch(SoapFault $fault) {
318
+ $this->addMessage('info',$row,'chronopost',$fault->faultstring);
319
+ return false;
320
+ }
321
+ }
322
+
323
+ public function getRowProperty(&$row, $key, $original_row=null, $original_key=null) {
324
+ $property = null;
325
+ $output = null;
326
+ if (isset($original_row) && isset($original_key) && $original_row['*code']==$row['*code'] && $original_key==$key) {
327
+ $this->addMessage('error',$row,$key,'Infinite loop %s',"<span class=\"code\">{".$row['*code'].'.'.$key."}</span>");
328
+ return array('error' => 'Infinite loop');
329
+ }
330
+ if (isset($row[$key]['value'])) {
331
+ $property = $row[$key]['value'];
332
+ $output = $property;
333
+ self::debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">'.$this->_toString($property).'</span>',5);
334
+ preg_match_all('/{([a-z0-9_]+)\.([a-z0-9_]+)}/i',$output,$result_set,PREG_SET_ORDER);
335
+ foreach ($result_set as $result) {
336
+ list($original,$ref_code,$ref_key) = $result;
337
+ if (!in_array($ref_code,array('module','date','store','cart','product','selection','customvar'))) {
338
+ if ($ref_code==$row['code']['value'] && $ref_key==$key) {
339
+ $this->addMessage('error',$row,$key,'Infinite loop %s',"<span class=\"code\">".$original."</span>");
340
+ return null;
341
+ }
342
+ if (isset($this->_config[$ref_code][$ref_key]['value'])) {
343
+ $replacement = $this->getRowProperty($this->_config[$ref_code],$ref_key,
344
+ isset($original_row) ? $original_row : $row,isset($original_key) ? $original_key : $key);
345
+ if (is_array($replacement) && isset($replacement['error'])) {
346
+ return isset($original_row) ? $replacement : 'false';
347
+ }
348
+ } else {
349
+ $this->addMessage('error',$row,$key,'Non-existent property %s',"<span class=\"code\">".$original."</span>");
350
+ $replacement = 'null';
351
+ }
352
+ $output = $this->replace($original,$replacement,$output);
353
+ }
354
+ }
355
+ } else {
356
+ self::debug(' get <span class="osh-key">'.$row['*code'].'</span>.<span class="osh-key">'.$key.'</span> = <span class="osh-formula">null</span>',5);
357
+ }
358
+ return $output;
359
+ }
360
+
361
+ protected function _toString($value) {
362
+ if (!isset($value)) return 'null';
363
+ else if (is_bool($value)) return $value ? 'true' : 'false';
364
+ else return $value;
365
+ }
366
+
367
+ protected function replace($from, $to, $input) {
368
+ if ($from===$to) return $input;
369
+ if (strpos($input,$from)===false) return $input;
370
+ $to = $this->_toString($to);
371
+ 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>',5);
372
+ return str_replace($from,$to,$input);
373
+ }
374
+
375
+ protected function _min() {
376
+ $args = func_get_args();
377
+ $min = null;
378
+ foreach ($args as $arg) {
379
+ if (isset($arg) && (!isset($min) || $min>$arg)) $min = $arg;
380
+ }
381
+ return $min;
382
+ }
383
+
384
+ protected function _max() {
385
+ $args = func_get_args();
386
+ $max = null;
387
+ foreach ($args as $arg) {
388
+ if (isset($arg) && (!isset($max) || $max<$arg)) $max = $arg;
389
+ }
390
+ return $max;
391
+ }
392
+
393
+ protected function _processFormula($process, &$row, $property_key, $formula_string, $is_checking, $use_cache=true)
394
+ {
395
+ $result = $this->_prepareFormula($process,$row,$property_key,$formula_string,$is_checking,$use_cache);
396
+ if (!$result->success) return $result;
397
+
398
+ $eval_result = $this->_evalFormula($result->result);
399
+ if (!isset($eval_result)) {
400
+ $this->addMessage('error',$row,$property_key,'Invalid formula');
401
+ $result = new OCS_Result(false);
402
+ if ($use_cache) $this->setCache($formula_string,$result);
403
+ return $result;
404
+ }
405
+ self::debug(' formula evaluation = <span class="osh-formula">'.$this->_toString($eval_result).'</span>',10);
406
+ $result = new OCS_Result(true,$eval_result);
407
+ if ($use_cache) $this->setCache($formula_string,$result);
408
+ return $result;
409
+ }
410
+
411
+ public function evalInput($process, $row, $property_key, $input) {
412
+ $result = $this->_prepareFormula($process,$row,$property_key,$input,$is_checking=false,$use_cache=true);
413
+ return $result->success ? $result->result : $input;
414
+ }
415
+
416
+ protected function setCache($expression, $value) {
417
+ if ($value instanceof OCS_Result) {
418
+ $this->_formula_cache[$expression] = $value;
419
+ self::debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$this->_toString($this->_formula_cache[$expression]).'</span>',10);
420
+ } else {
421
+ $value = $this->_toString($value);
422
+ $this->_expression_cache[$expression] = $value;
423
+ self::debug(' cache <span class="osh-replacement">'.$expression.'</span> = <span class="osh-formula">'.$value.'</span>',10);
424
+ }
425
+ }
426
+
427
+ protected function _prepareFormula($process, $row, $property_key, $formula_string, $is_checking, $use_cache=true)
428
+ {
429
+ if ($use_cache && isset($this->_formula_cache[$formula_string])) {
430
+ $result = $this->_formula_cache[$formula_string];
431
+ self::debug(' get cached formula <span class="osh-replacement">'.$formula_string.'</span> = <span class="osh-formula">'.$this->_toString($result->result).'</span>',10);
432
+ return $result;
433
+ }
434
+
435
+ $formula = $formula_string;
436
+ //self::debug(' formula = <span class="osh-formula">'.$formula.'</span>',10);
437
+
438
+ while (preg_match("#{foreach product\.((?:attribute|option)\.(?:[a-z0-9_]+))}(.*){/foreach}#i",$formula,$result)) {
439
+ $original = $result[0];
440
+ if ($use_cache && isset($this->_expression_cache[$original])) {
441
+ $replacement = $this->_expression_cache[$original];
442
+ self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>',10);
443
+ }
444
+ else {
445
+ $replacement = 0;
446
+ list($filter_property_type,$filter_property_name) = explode('.',$result[1]);
447
+ $selections = array();
448
+ self::debug(' :: foreach <span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span>',10);
449
+ foreach ($process['products'] as $product) {
450
+ $tmp_value = $this->_getProductProperty($product,$filter_property_type,$filter_property_name,$get_by_id=false);
451
+ 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>',10);
452
+ $key = 'val_'.$tmp_value;
453
+ $sel = isset($selections[$key]) ? $selections[$key] : null;
454
+ $selections[$key]['products'][] = $product;
455
+ $selections[$key]['weight'] = (isset($sel['weight']) ? $sel['weight'] : 0)+$product->getAttribute('weight')*$product->getQuantity();
456
+ $selections[$key]['quantity'] = (isset($sel['quantity']) ? $sel['quantity'] : 0)+$product->getQuantity();
457
+ }
458
+ self::debug(' :: start foreach',10);
459
+ foreach ($selections as $selection) {
460
+ $process2 = $process;
461
+ $process2['products'] = $selection['products'];
462
+ $process2['data']['selection.quantity'] = $selection['quantity'];
463
+ $process2['data']['selection.weight'] = $selection['weight'];
464
+ $process_result = $this->_processFormula($process2,$row,$property_key,$result[2],$is_checking,$tmp_use_cache=false);
465
+ $replacement += $process_result->result;
466
+ }
467
+ self::debug(' :: end foreach <span class="osh-key">'.$filter_property_type.'</span>.<span class="osh-key">'.$filter_property_name.'</span>',10);
468
+ if ($use_cache) $this->setCache($original,$replacement);
469
+ }
470
+ $formula = $this->replace($original,$replacement,$formula);
471
+ }
472
+
473
+ $formula = str_replace(array("\n","\t"),array('',''),$formula);
474
+
475
+ while (preg_match("#{customvar\.([a-z0-9_]+)}#i",$formula,$result)) {
476
+ $original = $result[0];
477
+ $replacement = Mage::getModel('core/variable')->loadByCode($result[1])->getValue('plain');
478
+ $formula = $this->replace($original,$replacement,$formula);
479
+ }
480
+
481
+ $first_product = isset($process['products'][0]) ? $process['products'][0] : null;
482
+ if (!isset($process['data']['selection.weight'])) $process['data']['selection.weight'] = $process['data']['cart.weight'];
483
+ if (!isset($process['data']['selection.quantity'])) $process['data']['selection.quantity'] = $process['data']['cart.quantity'];
484
+ $process['data']['product.weight'] = isset($first_product) ? $first_product->getAttribute('weight') : 0;
485
+ $process['data']['product.quantity'] = isset($first_product) ? $first_product->getQuantity() : 0;
486
+
487
+ foreach ($process['data'] as $original => $replacement) {
488
+ $formula = $this->replace('{'.$original.'}',$replacement,$formula);
489
+ }
490
+
491
+ if (isset($first_product)) {
492
+ while (preg_match("#{product\.(attribute|option|stock)\.([a-z0-9_]+)}#i",$formula,$result)) {
493
+ $original = $result[0];
494
+ switch ($result[1]) {
495
+ case 'attribute': $replacement = $first_product->getAttribute($result[2]); break;
496
+ case 'option': $replacement = $first_product->getOption($result[2]); break;
497
+ case 'stock': $replacement = $first_product->getStockData($result[2]); break;
498
+ }
499
+ $formula = $this->replace($original,$replacement,$formula);
500
+ }
501
+ }
502
+
503
+ //while (preg_match("/{(count|all|any) (attribute|option) '([^'\)]+)' ?(==|<=|>=|<|>|!=) ?(".self::$FLOAT_REGEX."|true|false|'[^'\)]*')}/",$formula,$result)
504
+ // || preg_match("/{(sum|count distinct) (attribute|option) '([^'\)]+)'}/",$formula,$result))
505
+ while (preg_match("/{(count) products(?: where ([^}]+))?}/i",$formula,$result)
506
+ || preg_match("/{(sum|count distinct) product\.(attribute|option)\.([a-z0-9_]+)(?: where ([^}]+))?}/i",$formula,$result)) {
507
+ $original = $result[0];
508
+ if ($use_cache && isset($this->_expression_cache[$original])) {
509
+ $replacement = $this->_expression_cache[$original];
510
+ self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>',10);
511
+ }
512
+ else {
513
+ $replacement = $this->_processProductProperty($process['products'],$result);
514
+ if ($use_cache) $this->setCache($result[0],$replacement);
515
+ }
516
+ $formula = $this->replace($original,$replacement,$formula);
517
+ }
518
+
519
+ //while (preg_match("/{table '([^']+)' ([^}]+)}/",$formula,$result))
520
+ while (preg_match("/{table ([^}]+) in ([0-9\.:,\*\[\] ]+)}/i",$formula,$result)) {
521
+ $original = $result[0];
522
+ if ($use_cache && isset($this->_expression_cache[$original])) {
523
+ $replacement = $this->_expression_cache[$original];
524
+ self::debug(' get cached expression <span class="osh-replacement">'.$original.'</span> = <span class="osh-formula">'.$replacement.'</span>',10);
525
+ } else {
526
+ $reference_value = $this->_evalFormula($result[1]);
527
+ if (isset($reference_value)) {
528
+ $fees_table_string = $result[2];
529
+
530
+ if (!preg_match('#^'.self::$COUPLE_REGEX.'(?:, *'.self::$COUPLE_REGEX.')*$#',$fees_table_string)) {
531
+ $this->addMessage('error',$row,$property_key,'Error in table %s','<span class="osh-formula">'.htmlentities($result[0]).'</span>');
532
+ $result = new OCS_Result(false);
533
+ if ($use_cache) $this->setCache($formula_string,$result);
534
+ return $result;
535
+ }
536
+ $fees_table = explode(',',$fees_table_string);
537
+
538
+ $replacement = null;
539
+ foreach ($fees_table as $item) {
540
+ $fee_data = explode(':',$item);
541
+
542
+ $fee = trim($fee_data[1]);
543
+ $max_value = trim($fee_data[0]);
544
+
545
+ $last_char = $max_value{strlen($max_value)-1};
546
+ if ($last_char=='[') $including_max_value = false;
547
+ else if ($last_char==']') $including_max_value = true;
548
+ else $including_max_value = true;
549
+
550
+ $max_value = str_replace(array('[',']'),'',$max_value);
551
+
552
+ if ($max_value=='*' || $including_max_value && $reference_value<=$max_value || !$including_max_value && $reference_value<$max_value) {
553
+ $replacement = $fee;//$this->_calculateFee($process,$fee,$var);
554
+ break;
555
+ }
556
+ }
557
+ }
558
+ $replacement = $this->_toString($replacement);
559
+ if ($use_cache) $this->setCache($original,$replacement);
560
+ }
561
+ $formula = $this->replace($original,$replacement,$formula);
562
+ }
563
+ $result = new OCS_Result(true,$formula);
564
+ return $result;
565
+ }
566
+
567
+ protected function _evalFormula($formula) {
568
+ if (is_bool($formula)) return $formula;
569
+ 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'
570
+ .'|in_array\(\'(?:[^\']*)\', *array\( *(?:\'(?:[^\']+)\') *(?: *, *\'(?:[^\']+)\')* *\) *\)'
571
+ .'|\'[^\']*\'|[0-9,\'\.\-\(\)\*\/\?\:\+\<\>\=\&\|%! ])*$/',$formula)) {
572
+ $errors = array(
573
+ PREG_NO_ERROR => 'PREG_NO_ERROR',
574
+ PREG_INTERNAL_ERROR => 'PREG_INTERNAL_ERROR',
575
+ PREG_BACKTRACK_LIMIT_ERROR => 'PREG_BACKTRACK_LIMIT_ERROR',
576
+ PREG_RECURSION_LIMIT_ERROR => 'PREG_RECURSION_LIMIT_ERROR',
577
+ PREG_BAD_UTF8_ERROR => 'PREG_BAD_UTF8_ERROR',
578
+ PREG_BAD_UTF8_OFFSET_ERROR => 'PREG_BAD_UTF8_OFFSET_ERROR',
579
+ );
580
+ $error = preg_last_error();
581
+ if (isset($errors[$error])) $error = $errors[$error];
582
+ self::debug(' doesn\'t match ('.$error.')',10);
583
+ return null;
584
+ }
585
+ $formula = str_replace(
586
+ array('min','max'),
587
+ array('$this->_min','$this->_max'),
588
+ $formula
589
+ );
590
+ $eval_result = null;
591
+ @eval('$eval_result = ('.$formula.');');
592
+ return $eval_result;
593
+ }
594
+
595
+ protected function _getOptionsAndData($string) {
596
+ if (preg_match('/^(\\s*\(\\s*([^\] ]*)\\s*\)\\s*)/',$string,$result)) {
597
+ $options = $result[2];
598
+ $data = str_replace($result[1],'',$string);
599
+ } else {
600
+ $options = '';
601
+ $data = $string;
602
+ }
603
+ return array(
604
+ 'options' => $options,
605
+ 'data' => $data,
606
+ );
607
+ }
608
+
609
+ public function compress($input) {
610
+ if (preg_match_all("/{table (.*) in (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}/imsU",$input,$result,PREG_SET_ORDER)) {
611
+ foreach ($result as $result_i) {
612
+ $fees_table = explode(',',$result_i[2]);
613
+ $value = null;
614
+ foreach ($fees_table as $index => $item) {
615
+ list($max_value,$fee) = explode(':',$item);
616
+ $last_char = $max_value{strlen($max_value)-1};
617
+ if (in_array($last_char,array('[',']'))) {
618
+ $including_char = $last_char;
619
+ $max_value = str_replace(array('[',']'),'',$max_value);
620
+ } else $including_char = '';
621
+ $fees_table[$index] = ((float)$max_value).$including_char.':'.((float)$fee);
622
+ }
623
+ $input = str_replace($result_i[2],implode(',',$fees_table),$input);
624
+ $input = str_replace($result_i[1],trim($result_i[1]),$input);
625
+ }
626
+ }
627
+ if (preg_match_all("#{foreach ([^}]*)}(.*){/foreach}#imsU",$input,$result,PREG_SET_ORDER)) {
628
+ foreach ($result as $result_i) {
629
+ $input = str_replace($result_i[1],trim($result_i[1]),$input);
630
+ $input = str_replace($result_i[2],trim($result_i[2]),$input);
631
+ }
632
+ }
633
+ return '$$'.str_replace(
634
+ self::$UNCOMPRESSED_STRINGS,
635
+ self::$COMPRESSED_STRINGS,
636
+ $input
637
+ );
638
+ }
639
+
640
+ public function uncompress($input) {
641
+ if (preg_match_all("/{table (.*) in (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}/iU",$input,$result,PREG_SET_ORDER)) {
642
+ foreach ($result as $result_i) {
643
+ $fees_table = explode(',',$result_i[2]);
644
+ $value = null;
645
+ foreach ($fees_table as $index => $item) {
646
+ list($max_value,$fee) = explode(':',$item);
647
+ $last_char = $max_value{strlen($max_value)-1};
648
+ if (in_array($last_char,array('[',']'))) {
649
+ $including_char = $last_char;
650
+ $max_value = str_replace(array('[',']'),'',$max_value);
651
+ } else $including_char = '';
652
+ $max_value = (float)$max_value;
653
+ $fee = (float)$fee;
654
+ $new_max_value = number_format($max_value,2,'.','');
655
+ $new_fee = number_format($fee,2,'.','');
656
+ $fees_table[$index] = (((float)$new_max_value)==$max_value ? $new_max_value : $max_value).$including_char.':'
657
+ .(((float)$new_fee)==$fee ? $new_fee : $fee);
658
+ }
659
+ $input = str_replace($result_i[2],implode(', ',$fees_table),$input);
660
+ $input = str_replace($result_i[1],trim($result_i[1]),$input);
661
+ }
662
+ }
663
+ if (preg_match_all("#{foreach ([^}]*)}(.*){/foreach}#iU",$input,$result,PREG_SET_ORDER)) {
664
+ foreach ($result as $result_i) {
665
+ $input = str_replace($result_i[1],trim($result_i[1]),$input);
666
+ $input = str_replace($result_i[2],trim($result_i[2]),$input);
667
+ }
668
+ }
669
+ return str_replace(
670
+ self::$COMPRESSED_STRINGS,
671
+ self::$UNCOMPRESSED_STRINGS,
672
+ $input
673
+ );
674
+ }
675
+
676
+ public function parseProperty($input) {
677
+ $value = $input==='false' || $input==='true' ? $input=='true' : str_replace('\"','"',preg_replace('/^(?:"|\')(.*)(?:"|\')$/s','$1',$input));
678
+ return $value==='' ? null : $value;
679
+ }
680
+
681
+ public function cleanProperty(&$row, $key) {
682
+ $input = $row[$key]['value'];
683
+ if (is_string($input)) {
684
+ $input = str_replace(array("\n"),array(''),$input);
685
+ while (preg_match('/({TABLE |{SUM |{COUNT | DISTINCT | IN )/',$input,$resi)) {
686
+ $input = str_replace($resi[0],strtolower($resi[0]),$input);
687
+ }
688
+
689
+ while (preg_match('/{{customVar code=([a-zA-Z0-9_-]+)}}/',$input,$resi)) {
690
+ $input = str_replace($resi[0],'{customvar.'.$resi[1].'}',$input);
691
+ }
692
+
693
+ $regex = "{(weight|products_quantity|price_including_tax|price_excluding_tax|country)}";
694
+ if (preg_match('/'.$regex.'/',$input,$resi)) {
695
+ $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
696
+ while (preg_match('/'.$regex.'/',$input,$resi)) {
697
+ switch ($resi[1]) {
698
+ case 'price_including_tax':
699
+ case 'price_excluding_tax':
700
+ case 'weight':
701
+ $input = str_replace($resi[0],"{cart.".$resi[1]."}",$input);
702
+ break;
703
+ case 'products_quantity': $input = str_replace($resi[0],"{cart.quantity}",$input); break;
704
+ case 'country': $input = str_replace($resi[0],"{destination.country.name}",$input); break;
705
+ }
706
+ }
707
+ }
708
+
709
+ $regex1 = "{copy '([a-zA-Z0-9_]+)'\.'([a-zA-Z0-9_]+)'}";
710
+ if (preg_match('/'.$regex1.'/',$input,$resi)) {
711
+ $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
712
+ while (preg_match('/'.$regex1.'/',$input,$resi)) $input = str_replace($resi[0],'{'.$resi[1].'.'.$resi[2].'}',$input);
713
+ }
714
+
715
+ $regex1 = "{(count|all|any) (attribute|option) '([^'\)]+)' ?((?:==|<=|>=|<|>|!=) ?(?:".self::$FLOAT_REGEX."|true|false|'[^'\)]*'))}";
716
+ $regex2 = "{(sum) (attribute|option) '([^'\)]+)'}";
717
+ if (preg_match('/'.$regex1.'/',$input,$resi) || preg_match('/'.$regex2.'/',$input,$resi)) {
718
+ $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
719
+ while (preg_match('/'.$regex1.'/',$input,$resi) || preg_match('/'.$regex2.'/',$input,$resi)) {
720
+ switch ($resi[1]) {
721
+ case 'count': $input = str_replace($resi[0],"{count products where product.".$resi[2]."s.".$resi[3].$resi[4]."}",$input); break;
722
+ case 'all': $input = str_replace($resi[0],"{count products where product.".$resi[2]."s.".$resi[3].$resi[4]."}=={products_quantity}",$input); break;
723
+ case 'any': $input = str_replace($resi[0],"{count products where product.".$resi[2]."s.".$resi[3].$resi[4]."}>0",$input); break;
724
+ case 'sum': $input = str_replace($resi[0],"{sum product.".$resi[2].".".$resi[3]."}",$input); break;
725
+ }
726
+ }
727
+ }
728
+
729
+ $regex = "((?:{| )product.(?:attribute|option))s.";
730
+ if (preg_match('/'.$regex.'/',$input,$resi)) {
731
+ $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
732
+ while (preg_match('/'.$regex.'/',$input,$resi)) {
733
+ $input = str_replace($resi[0],$resi[1].'.',$input);
734
+ }
735
+ }
736
+
737
+ $regex = "{table '([^']+)' (".self::$COUPLE_REGEX."(?:, *".self::$COUPLE_REGEX.")*)}";
738
+ if (preg_match('/'.$regex.'/',$input,$resi)) {
739
+ $this->addMessage('warning',$row,$key,'Usage of deprecated syntax %s','<span class="osh-formula">'.$resi[0].'</span>');
740
+ while (preg_match('/'.$regex.'/',$input,$resi)) {
741
+ switch ($resi[1]) {
742
+ case 'products_quantity':
743
+ $input = str_replace($resi[0],"{table {cart.weight} in ".$resi[2]."}*{cart.quantity}",$input);
744
+ break;
745
+ default:
746
+ $input = str_replace($resi[0],"{table {cart.".$resi[1]."} in ".$resi[2]."}",$input);
747
+ break;
748
+ }
749
+ }
750
+ }
751
+ }
752
+ $row[$key]['value'] = $input;
753
+ }
754
+
755
+ protected function _parseInput() {
756
+ $config_string = str_replace(
757
+ array('&gt;','&lt;','“','”',utf8_encode(chr(147)),utf8_encode(chr(148)),'&laquo;','&raquo;',"\r\n","\t"),
758
+ array('>','<','"','"','"','"','"','"',"\n",' '),
759
+ $this->_input
760
+ );
761
+
762
+ if (substr($config_string,0,2)=='$$') $config_string = $this->uncompress(substr($config_string,2,strlen($config_string)));
763
+
764
+ //echo ini_get('pcre.backtrack_limit');
765
+ //exit;
766
+
767
+ $row_regex = ' *([a-z0-9_]+)\\s*:\\s*("(?:(?:[^"]|\\\\")*[^\\\\])?"|'.self::$FLOAT_REGEX.'|false|true)\\s*(,)? *(?:\\n)?';
768
+ if (!preg_match_all('/((?:#+[^{\\n]*\\s+)*)\\s*(#)?{\\s*('.$row_regex.')+\\s*}/i',$config_string,$result,PREG_SET_ORDER)) {
769
+ $errors = array(
770
+ PREG_NO_ERROR => 'PREG_NO_ERROR',
771
+ PREG_INTERNAL_ERROR => 'PREG_INTERNAL_ERROR',
772
+ PREG_BACKTRACK_LIMIT_ERROR => 'PREG_BACKTRACK_LIMIT_ERROR',
773
+ PREG_RECURSION_LIMIT_ERROR => 'PREG_RECURSION_LIMIT_ERROR',
774
+ PREG_BAD_UTF8_ERROR => 'PREG_BAD_UTF8_ERROR',
775
+ PREG_BAD_UTF8_OFFSET_ERROR => 'PREG_BAD_UTF8_OFFSET_ERROR',
776
+ );
777
+ $error = preg_last_error();
778
+ if (isset($errors[$error])) $error = $errors[$error];
779
+ self::debug(' preg_match_all error ('.$error.')',10);
780
+ }
781
+
782
+ $this->_config = array();
783
+ $available_keys = array(
784
+ 'code','label','enabled','description','fees','conditions','destination','origin','customer_groups','tracking_url',
785
+ 'fees_table','fees_formula','fixed_fees','reference_value',
786
+ 'prices_range','weights_range','product_properties',
787
+ 'free_shipping__fees_table','free_shipping__fees_formula','free_shipping__fixed_fees','free_shipping__label',
788
+ );
789
+
790
+ foreach ($result as $block) {
791
+ $deprecated_properties = array();
792
+ $unknown_properties = array();
793
+ $missing_semicolon = array();
794
+ $obsolete_disabling_method = array();
795
+
796
+ //$before = strstr($config_string,$block[0],true); // Seulement compatible avec PHP 5.3.0
797
+ list($before) = explode($block[0],$config_string,2);
798
+ if ($before!==false && trim($before)!='') {
799
+ $config_string = substr($config_string,strlen($before));
800
+ $this->_addIgnoredLines(trim($before));
801
+ $this->addMessage('info',$row=null,null,'Ignored lines %s','<div class="code">'.trim($before).'</div>');
802
+ }
803
+
804
+ $config_string = str_replace($block[0], '', $config_string);
805
+ preg_match_all('/'.$row_regex.'/i',$block[0],$result2,PREG_SET_ORDER);
806
+ $block_string = $block[0];
807
+
808
+ $row = array();
809
+ $i = 1;
810
+ foreach ($result2 as $data) {
811
+ $key = $data[1];
812
+ if (in_array($key,$available_keys) || substr($key,0,1)=='_') {
813
+ $property = $this->parseProperty($data[2]);
814
+ if (isset($property)) {
815
+ $row[$key] = array('value' => $property, 'original_value' => $property);
816
+ $this->cleanProperty($row,$key);
817
+ }
818
+ if ($i>2) {
819
+ $block_string = str_replace($data[0],$i==3 ? "...\n" : '',$block_string);
820
+ }
821
+ if ($i!=count($result2) && !isset($data[3]) || isset($data[3]) && $data[3]!=',') {
822
+ if (preg_match('/^("|\')(.{40})(.*)("|\')$/s',$data[2],$resultx))
823
+ $missing_semicolon[] = trim(str_replace($data[2],$resultx[1].$resultx[2].' ...'.$resultx[4],$data[0]));
824
+ else $missing_semicolon[] = trim($data[0]);
825
+ }
826
+ } else {
827
+ if (!in_array($key,$unknown_properties)) $unknown_properties[] = $key;
828
+ }
829
+ $i++;
830
+ }
831
+ if ($block[1]!='') $row['*comment']['value'] = $block[1];
832
+ if ($block[2]=='#' && !isset($row['enabled'])) {
833
+ $row['enabled'] = array('value' => false);
834
+ $obsolete_disabling_method[] = $block_string;
835
+ }
836
+
837
+ $formula_fields_to_check = array();
838
+ if (isset($row['conditions'])) $formula_fields_to_check[] = 'conditions';
839
+ if (isset($row['fees'])) $formula_fields_to_check[] = 'fees';
840
+
841
+ if (count($formula_fields_to_check)>0) {
842
+ foreach ($formula_fields_to_check as $property) {
843
+ $property_value = $row[$property]['value'];
844
+ if (preg_match('/{ +/',$property_value)) {
845
+ $this->addMessage('warning',$row,$property,'There are unwanted spaces after char `%s`','{');
846
+ $property_value = preg_replace('/{ +/','{',$property_value);
847
+ }
848
+ if (preg_match('/ +}/',$property_value)) {
849
+ $this->addMessage('warning',$row,$property,'There are unwanted spaces before char `%s`','}');
850
+ $property_value = preg_replace('/ +}/','}',$property_value);
851
+ }
852
+ if (preg_match('/ +/',$property_value)) {
853
+ $this->addMessage('warning',$row,$property,'There are unwanted multiples spaces `%s`',preg_replace('/( +)/','<span class="osh-formula">*$1*</span>',$property_value));
854
+ $property_value = preg_replace('/ +/',' ',$property_value);
855
+ }
856
+ $row[$property]['value'] = trim($property_value);
857
+ }
858
+ }
859
+
860
+ $float_value_regex = '\\s*('.self::$POSITIVE_FLOAT_REGEX.'|\*)\\s*';
861
+ $conditions = array();
862
+ if (isset($row['prices_range'])) {
863
+ if (!in_array('prices_range',$deprecated_properties)) $deprecated_properties[] = 'prices_range';
864
+
865
+ $result = $this->_getOptionsAndData($row['prices_range']['value']);
866
+ $options = $result['options'];
867
+ $prices_range = $result['data'];
868
+
869
+ if (($options=='' || in_array($options,array('incl.tax','ttc')))
870
+ && preg_match('/^\\s*(\[|\])?'.$float_value_regex.'=>'.$float_value_regex.'(\[|\])?\\s*$/',$prices_range,$result)) {
871
+ $min_price_included = $result[1]=='[';
872
+ $min_price = $result[2]=='*' ? -1 : (float)$result[2];
873
+ $max_price = $result[3]=='*' ? -1 : (float)$result[3];
874
+ $max_price_included = !isset($result[4]) || $result[4]==']' || $result[4]=='';
875
+
876
+ $tax_included = $options!='' && in_array($options,array('incl.tax','ttc')) || isset($row['reference_value']) && $row['reference_value']['value']=='price_including_tax';
877
+ $price = $tax_included ? '{cart.price_including_tax}' : '{cart.price_excluding_tax}';
878
+
879
+ if ($min_price!=-1) $conditions[] = $price.'>'.($min_price_included ? '=' : '').$min_price;
880
+ if ($max_price!=-1) $conditions[] = $price.'<'.($max_price_included ? '=' : '').$max_price;
881
+ }
882
+ else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">prices_range</span>','<span class="osh-formula">'.$row['prices_range']['value'].'</span>');
883
+ unset($row['prices_range']);
884
+ }
885
+ if (isset($row['weights_range'])) {
886
+ if (!in_array('weights_range',$deprecated_properties)) $deprecated_properties[] = 'weights_range';
887
+ if (preg_match('/^\\s*(\[|\])?'.$float_value_regex.'=>'.$float_value_regex.'(\[|\])?\\s*$/',$row['weights_range']['value'],$result)) {
888
+ $min_weight_included = $result[1]=='[';
889
+ $min_weight = $result[2]=='*' ? -1 : (float)$result[2];
890
+ $max_weight = $result[3]=='*' ? -1 : (float)$result[3];
891
+ $max_weight_included = !isset($result[4]) || $result[4]==']' || $result[4]=='';
892
+
893
+ if ($min_weight!=-1) $conditions[] = '{cart.weight}>'.($min_weight_included ? '=' : '').$min_weight;
894
+ if ($max_weight!=-1) $conditions[] = '{cart.weight}<'.($max_weight_included ? '=' : '').$max_weight;
895
+ }
896
+ else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">weights_range</span>','<span class="osh-formula">'.$row['weights_range']['value'].'</span>');
897
+ unset($row['weights_range']);
898
+ }
899
+ if (isset($row['product_properties'])) {
900
+ if (!in_array('product_properties',$deprecated_properties)) $deprecated_properties[] = 'product_properties';
901
+ $product_property_regex = "\\s*(and|or)? *\((?:(all|any|sum) )?(attribute|option) '([^'\)]+)' ?(==|=|<=|>=|<|>|!=) ?(".self::$FLOAT_REGEX."|true|false|'[^'\)]*')\)\\s*";
902
+ if (preg_match('/^('.$product_property_regex.')+$/',$row['product_properties']['value'],$result)) {
903
+ preg_match_all('/'.$product_property_regex.'/',$row['product_properties']['value'],$results,PREG_SET_ORDER);
904
+ $product_properties_condition = '';
905
+ foreach ($results as $result) {
906
+ $and_or = $result[1];
907
+ if ($and_or=='') $and_or = 'and';
908
+ $any_all_sum = $result[2];
909
+ if ($any_all_sum=='') $any_all_sum = 'any';
910
+ $property_type = $result[3];
911
+ $property_name = $result[4];
912
+ $cmp_symbol = $result[5];
913
+ if ($cmp_symbol=='=') $cmp_symbol = '==';
914
+ $cmp_value = $result[6];
915
+
916
+ $product_properties_condition .= $product_properties_condition=='' ? '' : ' '.$and_or.' ';
917
+ switch ($any_all_sum) {
918
+ case 'sum':
919
+ $product_properties_condition .= "{sum product.".$property_type.".".$property_name."}".$cmp_symbol.$cmp_value;
920
+ break;
921
+ case 'all':
922
+ $product_properties_condition .= "{count products where product.".$property_type.".".$property_name.$cmp_symbol.$cmp_value."}=={products_quantity}";
923
+ break;
924
+ case 'any':
925
+ $product_properties_condition .= "{count products where product.".$property_type.".".$property_name.$cmp_symbol.$cmp_value."}>0";
926
+ break;
927
+ }
928
+ }
929
+ if ($product_properties_condition!='') $conditions[] = $product_properties_condition;
930
+ }
931
+ else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">product_properties</span>','<span class="osh-formula">'.$row['product_properties']['value'].'</span>');
932
+ unset($row['product_properties']);
933
+ }
934
+ if (count($conditions)>0) $row['conditions'] = array('value' => count($conditions)==1 ? $conditions[0] : '('.implode(') && (',$conditions).')');
935
+
936
+ $fees = array();
937
+ if (isset($row['fees_table'])) {
938
+ if (!in_array('fees_table',$deprecated_properties)) $deprecated_properties[] = 'fees_table';
939
+ $options_and_data = $this->_getOptionsAndData($row['fees_table']['value']);
940
+ $options = $options_and_data['options'];
941
+ $fees_table_string = $options_and_data['data'];
942
+
943
+ $var = null;
944
+ if ($options=='') $var = (isset($row['reference_value']) ? $row['reference_value']['value'] : 'weight');
945
+ else if (in_array($options,array('incl.tax','ttc'))) $var = 'price_including_tax';
946
+ else if (in_array($options,array('excl.tax','ht'))) $var = 'price_excluding_tax';
947
+
948
+ if (isset($var)) {
949
+ if ($var=='price') $var = 'price_excluding_tax';
950
+ if ($var=='products_quantity') $var = 'quantity';
951
+ if (preg_match('/^[[:space:]]*\*[[:space:]]*:[[:space:]]*('.$float_value_regex.')[[:space:]]*$/s',$fees_table_string,$result)) $fees[] = $result[1];
952
+ else $fees[] = "{table {cart.".$var."} in ".str_replace(' ','',$fees_table_string)."}".($var=='quantity' ? '*{cart.quantity}' : '');
953
+ }
954
+ else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">fees_table</span>','<span class="osh-formula">'.$row['fees_table']['value'].'</span>');
955
+ unset($row['fees_table']);
956
+ }
957
+ if (isset($row['fees_formula'])) {
958
+ if (!in_array('fees_formula',$deprecated_properties)) $deprecated_properties[] = 'fees_formula';
959
+ $fees[] = str_replace(' ','',$row['fees_formula']['value']);
960
+ unset($row['fees_formula']);
961
+ }
962
+ if (isset($row['fixed_fees'])) {
963
+ if (!in_array('fixed_fees',$deprecated_properties)) $deprecated_properties[] = 'fixed_fees';
964
+ if ($row['fixed_fees']['value']!=0 || count($fees)==0) $fees[] = str_replace(' ','',$row['fixed_fees']['value']);
965
+ unset($row['fixed_fees']);
966
+ }
967
+ if (!isset($row['fees']) && count($fees)>0) $row['fees'] = array('value' => implode('+',$fees));
968
+
969
+ $fs_fees = array();
970
+ if (isset($row['free_shipping__fees_table'])) {
971
+ if (!in_array('free_shipping__fees_table',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__fees_table';
972
+ $options_and_data = $this->_getOptionsAndData($row['free_shipping__fees_table']['value']);
973
+ $options = $options_and_data['options'];
974
+ $fees_table_string = $options_and_data['data'];
975
+
976
+ $var = null;
977
+ if ($options=='') $var = isset($row['reference_value']) ? $row['reference_value']['value'] : 'weight';
978
+ else if (in_array($options,array('incl.tax','ttc'))) $var = 'price_including_tax';
979
+ else if (in_array($options,array('excl.tax','ht'))) $var = 'price_excluding_tax';
980
+ if ($var=='price') $var = 'price_excluding_tax';
981
+
982
+ if (isset($var)) {
983
+ if ($var=='price') $var = 'price_excluding_tax';
984
+ if ($var=='products_quantity') $var = 'quantity';
985
+ if (preg_match('/^[[:space:]]*\*[[:space:]]*:[[:space:]]*('.$float_value_regex.')[[:space:]]*$/s',$fees_table_string,$result)) $fs_fees[] = $result[1];
986
+ else $fs_fees[] = "{table {cart.".$var."} in ".str_replace(' ','',$fees_table_string)."}".($var=='quantity' ? '*{cart.quantity}' : '');
987
+ }
988
+ else $this->addMessage('error',$row,null,'Unrecognized value of deprecated property %s %s','<span class="osh-key">free_shipping__fees_table</span>','<span class="osh-formula">'.$row['free_shipping__fees_table']['value'].'</span>');
989
+ unset($row['free_shipping__fees_table']);
990
+ }
991
+ if (isset($row['free_shipping__fees_formula'])) {
992
+ if (!in_array('free_shipping__fees_formula',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__fees_formula';
993
+ $fs_fees[] = str_replace(' ','',$row['free_shipping__fees_formula']['value']);
994
+ unset($row['free_shipping__fees_formula']);
995
+ }
996
+ if (isset($row['free_shipping__fixed_fees'])) {
997
+ if (!in_array('free_shipping__fixed_fees',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__fixed_fees';
998
+ if ($row['free_shipping__fixed_fees']['value']!=0 || count($fees)==0) $fs_fees[] = str_replace(' ','',$row['free_shipping__fixed_fees']['value']);
999
+ unset($row['free_shipping__fixed_fees']);
1000
+ }
1001
+
1002
+ if (isset($row['reference_value'])) {
1003
+ if (!in_array('reference_value',$deprecated_properties)) $deprecated_properties[] = 'reference_value';
1004
+ unset($row['reference_value']);
1005
+ }
1006
+
1007
+ if (count($fs_fees)>0) {
1008
+ $row2 = $row;
1009
+ if (isset($row['code'])) $row2['code']['value'] = $row['code']['value'].'__free_shipping';
1010
+ $row2['fees']['value'] = implode('+',$fs_fees);
1011
+ $row2['conditions']['value'] = isset($row2['conditions']) ? '('.$row2['conditions']+') and {free_shipping}' : '{free_shipping}';
1012
+ $row['conditions']['value'] = isset($row['conditions']) ? '('.$row['conditions']+') and !{free_shipping}' : '!{free_shipping}';
1013
+ if (isset($row['free_shipping__label'])) {
1014
+ if (!in_array('free_shipping__label',$deprecated_properties)) $deprecated_properties[] = 'free_shipping__label';
1015
+ $row2['label']['value'] = $row['free_shipping__label']['value'];
1016
+ unset($row['free_shipping__label']);
1017
+ unset($row2['free_shipping__label']);
1018
+ }
1019
+ $this->_addRow($row2);
1020
+ }
1021
+ if (count($unknown_properties)>0) $this->addMessage('error',$row,null,'Usage of unknown properties %s',': <span class="osh-key">'.implode('</span>, <span class="osh-key">',$unknown_properties).'</span>');
1022
+ if (count($deprecated_properties)>0) $this->addMessage('warning',$row,null,'Usage of deprecated properties %s',': <span class="osh-key">'.implode('</span>, <span class="osh-key">',$deprecated_properties).'</span>');
1023
+ if (count($obsolete_disabling_method)>0) $this->addMessage('warning',$row,null,'Usage of obsolete method to disabling a shipping method (`#` before `{`)%s','<div class="code">'.implode('<br />',$obsolete_disabling_method).'</div>');
1024
+ if (count($missing_semicolon)>0) $this->addMessage('warning',$row,null,'A semicolon is missing at the end of following lines %s','<div class="code">'.implode('<br />',$missing_semicolon).'</div>');
1025
+ $this->_addRow($row);
1026
+ }
1027
+ if (trim($config_string)!='') {
1028
+ $this->_addIgnoredLines(trim($config_string));
1029
+ $this->addMessage('info',$row=null,null,'Ignored lines %s','<div class="code">'.trim($config_string).'</div>');
1030
+ }
1031
+ }
1032
+
1033
+ public function addMessage($type, &$row, $property) {
1034
+ $args = func_get_args();
1035
+ array_shift($args);
1036
+ array_shift($args);
1037
+ array_shift($args);
1038
+ $message = new OCS_Message($type,$args);
1039
+ if (isset($row)) {
1040
+ if (isset($property)) {
1041
+ $row[$property]['messages'][] = $message;
1042
+ } else {
1043
+ $row['*messages'][] = $message;
1044
+ }
1045
+ }
1046
+ $this->_messages[] = $message;
1047
+ self::debug(' => <span class="osh-'.$message->type.'">'.$message->toString().'</span>',1);
1048
+ }
1049
+
1050
+ protected function _addRow(&$row) {
1051
+ if (isset($row['code'])) {
1052
+ $key = $row['code']['value'];
1053
+ if (isset($this->_config[$key])) $this->addMessage('error',$row,'code','The property `code` must be unique, `%s` has been found twice',$key);
1054
+ while (isset($this->_config[$key])) $key .= rand(0,9);
1055
+ //$row['code'] = $key;
1056
+ } else {
1057
+ $i = 1;
1058
+ do {
1059
+ $key = 'code_auto'.sprintf('%03d',$i);
1060
+ $i++;
1061
+ } while (isset($this->_config[$key]));
1062
+ }
1063
+ $row['*code'] = $key;
1064
+ $this->_config[$key] = $row;
1065
+ }
1066
+
1067
+ protected function _addIgnoredLines($lines) {
1068
+ $this->_config[] = array('lines' => $lines);
1069
+ }
1070
+
1071
+ protected function _addressMatch($address_filter, $address) {
1072
+ $excluding = false;
1073
+ if (preg_match('# *\* *- *\((.*)\) *#s',$address_filter,$result)) {
1074
+ $address_filter = $result[1];
1075
+ $excluding = true;
1076
+ }
1077
+
1078
+ $tmp_address_filter_array = explode(',',trim($address_filter));
1079
+
1080
+ $concat = false;
1081
+ $concatened = '';
1082
+ $address_filter_array = array();
1083
+ $i = 0;
1084
+
1085
+ foreach ($tmp_address_filter_array as $address_filter) {
1086
+ if ($concat) $concatened .= ','.$address_filter;
1087
+ else {
1088
+ if ($i<count($tmp_address_filter_array)-1 && preg_match('#\(#',$address_filter)) {
1089
+ $concat = true;
1090
+ $concatened .= $address_filter;
1091
+ } else $address_filter_array[] = $address_filter;
1092
+ }
1093
+ if (preg_match('#\)#',$address_filter)) {
1094
+ $address_filter_array[] = $concatened;
1095
+ $concatened = '';
1096
+ $concat = false;
1097
+ }
1098
+ $i++;
1099
+ }
1100
+
1101
+ foreach ($address_filter_array as $address_filter) {
1102
+ if (preg_match('# *([A-Z]{2}) *(-)? *(?:\( *(-)? *(.*)\))? *#s',$address_filter,$result)) {
1103
+ $country_code = $result[1];
1104
+ if ($address['country_code']==$country_code) {
1105
+ self::debug(' country code <span class="osh-replacement">'.$address['country_code'].'</span> matches',5);
1106
+ if (!isset($result[4]) || $result[4]=='') return !$excluding;
1107
+ else {
1108
+ $region_codes = explode(',',$result[4]);
1109
+ $in_array = false;
1110
+ for ($i=count($region_codes); --$i>=0;) {
1111
+ $code = trim($region_codes[$i]);
1112
+ $region_codes[$i] = $code;
1113
+ if ($address['region_code']===$code) {
1114
+ self::debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> matches',5);
1115
+ $in_array = true;
1116
+ } else if ($address['postcode']===$code) {
1117
+ self::debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches',5);
1118
+ $in_array = true;
1119
+ } else if (strpos($code,'*')!==false && preg_match('/^'.str_replace('*','(?:.*)',$code).'$/',$address['postcode'])) {
1120
+ self::debug(' postcode <span class="osh-replacement">'.$address['postcode'].'</span> matches <span class="osh-formula">'.$code.'</span>',5);
1121
+ $in_array = true;
1122
+ }
1123
+ if ($in_array) break;
1124
+ }
1125
+ if (!$in_array) {
1126
+ self::debug(' region code <span class="osh-replacement">'.$address['region_code'].'</span> and postcode <span class="osh-replacement">'.$address['postcode'].'</span> don\'t match',5);
1127
+ }
1128
+ // Vérification stricte
1129
+ /*$in_array = in_array($address['region_code'],$region_codes,true) || in_array($address['postcode'],$region_codes,true);*/
1130
+ $excluding_region = $result[2]=='-' || $result[3]=='-';
1131
+ if ($excluding_region && !$in_array || !$excluding_region && $in_array) return !$excluding;
1132
+ }
1133
+ }
1134
+ }
1135
+ }
1136
+ return $excluding;
1137
+ }
1138
+
1139
+ protected function _getProductProperty($product, $property_type, $property_name, $get_by_id=false) {
1140
+ switch ($property_type) {
1141
+ case 'attribute':
1142
+ case 'attributes': return $product->getAttribute($property_name,$get_by_id);
1143
+ case 'option':
1144
+ case 'options': return $product->getOption($property_name,$get_by_id);
1145
+ case 'stock': return $product->getStockData($property_name);
1146
+ }
1147
+ return null;
1148
+ }
1149
+
1150
+ protected function _processProductProperty($products, $regex_result) {
1151
+ // COUNT, SUM or COUNT DISTINCT
1152
+ $operation = strtolower($regex_result[1]);
1153
+ switch ($operation) {
1154
+ case 'sum':
1155
+ case 'count distinct':
1156
+ $property_type = $regex_result[2];
1157
+ $property_name = $regex_result[3];
1158
+ $conditions = isset($regex_result[4]) ? $regex_result[4] : null;
1159
+ break;
1160
+ case 'count':
1161
+ $conditions = isset($regex_result[2]) ? $regex_result[2] : null;
1162
+ break;
1163
+ }
1164
+
1165
+ self::debug(' :: start <span class="osh-replacement">'.$regex_result[0].'</span>',10);
1166
+
1167
+ $return_value = 0;
1168
+
1169
+ preg_match_all('/product\.(attribute(?:s)?|option(?:s)?|stock)\.([a-z0-9_]+)(?:\.(id))?/i',$conditions,$properties_regex_result,PREG_SET_ORDER);
1170
+ $properties = array();
1171
+ foreach ($properties_regex_result as $property_regex_result) {
1172
+ $key = $property_regex_result[0];
1173
+ if (!isset($properties[$key])) $properties[$key] = $property_regex_result;
1174
+ }
1175
+
1176
+ foreach ($products as $product) {
1177
+ if (isset($conditions) && $conditions!='') {
1178
+ $formula = $conditions;
1179
+ foreach ($properties as $property) {
1180
+ $value = $this->_getProductProperty(
1181
+ $product,
1182
+ $tmp_property_type = $property[1],
1183
+ $tmp_property_name = $property[2],
1184
+ $get_by_id = isset($property[3]) && $property[3]=='id'
1185
+ );
1186
+ //$formula = $this->replace($property[0],$value,$formula);
1187
+ $from = $property[0];
1188
+ $to = is_string($value) || empty($value) ? "'".$value."'" : $value;
1189
+ $formula = str_replace($from,$to,$formula);
1190
+ 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>',5);
1191
+ }
1192
+ $eval_result = $this->_evalFormula($formula);
1193
+ if (!isset($eval_result)) return 'null';
1194
+ }
1195
+ else $eval_result = true;
1196
+
1197
+ if ($eval_result==true) {
1198
+ switch ($operation) {
1199
+ case 'sum':
1200
+ $value = $this->_getProductProperty($product,$property_type,$property_name);
1201
+ //self::debug($product->getSku().'.'.$property_type.'.'.$property_name.' = "'.$value.'" x '.$product->getQuantity(),10);
1202
+ $return_value += $value*$product->getQuantity();
1203
+ break;
1204
+ case 'count distinct':
1205
+ if (!isset($distinct_values)) $distinct_values = array();
1206
+ $value = $this->_getProductProperty($product,$property_type,$property_name);
1207
+ if (!in_array($value,$distinct_values)) {
1208
+ $distinct_values[] = $value;
1209
+ $return_value++;
1210
+ }
1211
+ break;
1212
+ case 'count':
1213
+ $return_value += $product->getQuantity();
1214
+ break;
1215
+ }
1216
+ }
1217
+ }
1218
+
1219
+ self::debug(' :: end <span class="osh-replacement">'.$regex_result[0].'</span>',10);
1220
+
1221
+ return $return_value;
1222
+ }
1223
+
1224
+ }
1225
+
1226
+ interface OCS_Product {
1227
+ public function getOption($option);
1228
+ public function getAttribute($attribute);
1229
+ public function getName();
1230
+ public function getSku();
1231
+ public function getQuantity();
1232
+ public function getStockData($key);
1233
+ }
1234
+
1235
+ class OCS_Message {
1236
+ public $type;
1237
+ public $message;
1238
+ public $args;
1239
+
1240
+ public function OCS_Message($type, $args) {
1241
+ $this->type = $type;
1242
+ $this->message = array_shift($args);
1243
+ $this->args = $args;
1244
+ }
1245
+
1246
+ public function toString() {
1247
+ return vsprintf($this->message,$this->args);
1248
+ }
1249
+ }
1250
+
1251
+ class OCS_Result {
1252
+ public $success;
1253
+ public $result;
1254
+
1255
+ public function OCS_Result($success, $result=null) {
1256
+ $this->success = $success;
1257
+ $this->result = $result;
1258
+ }
1259
+
1260
+ public function __toString() {
1261
+ return is_bool($this->result) ? ($this->result ? 'true' : 'false') : (string)$this->result;
1262
+ }
1263
+ }
1264
+
1265
+
1266
  ?>
app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-install-0.1.0.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
-
3
- $installer = $this;
4
-
5
- $installer->startSetup();
6
-
7
- $installer->addAttribute('order', 'w_relay_point_code', array(
8
- 'type' => 'varchar',
9
- 'input' => 'text',
10
- 'default' => 0,
11
- 'label' => 'Relay point',
12
- 'required' => 0
13
- ));
14
-
15
  $installer->endSetup();
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->addAttribute('order', 'w_relay_point_code', array(
8
+ 'type' => 'varchar',
9
+ 'input' => 'text',
10
+ 'default' => 0,
11
+ 'label' => 'Relay point',
12
+ 'required' => 0
13
+ ));
14
+
15
  $installer->endSetup();
app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.0-0.1.1.php CHANGED
@@ -1,8 +1,8 @@
1
- <?php
2
- $installer = $this;
3
- $installer->startSetup();
4
-
5
- $this->run("
6
- ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD `w_relay_point_code` varchar(255);
7
- ");
8
- $this->endSetup();
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $this->run("
6
+ ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD `w_relay_point_code` varchar(255);
7
+ ");
8
+ $this->endSetup();
app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.1-0.1.2.php CHANGED
@@ -1,8 +1,8 @@
1
- <?php
2
- $installer = $this;
3
- $installer->startSetup();
4
-
5
- $this->run("
6
- ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD `w_relay_point_code` varchar(255);
7
- ");
8
- $this->endSetup();
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $this->run("
6
+ ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD `w_relay_point_code` varchar(255);
7
+ ");
8
+ $this->endSetup();
app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.2-0.1.3.php CHANGED
@@ -1,8 +1,8 @@
1
- <?php
2
- $installer = $this;
3
- $installer->startSetup();
4
-
5
- $this->run("
6
- ALTER TABLE {$this->getTable('sales_flat_shipment_track')} ADD `chrono_reservation_number` varchar(255);
7
- ");
8
- $this->endSetup();
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $this->run("
6
+ ALTER TABLE {$this->getTable('sales_flat_shipment_track')} ADD `chrono_reservation_number` varchar(255);
7
+ ");
8
+ $this->endSetup();
app/code/community/Chronopost/Chronorelais/sql/chronorelais_setup/mysql4-upgrade-0.1.3-0.1.4.php CHANGED
@@ -1,14 +1,14 @@
1
- <?php
2
- $installer = $this;
3
- $installer->startSetup();
4
-
5
- $installer->run("
6
- -- DROP TABLE IF EXISTS {$this->getTable('sales_chronopost_order_export_status')};
7
- CREATE TABLE {$this->getTable('sales_chronopost_order_export_status')} (
8
- `order_id` int(10) unsigned NOT NULL,
9
- `livraison_le_samedi` varchar(10) NOT NULL DEFAULT 'Yes',
10
- UNIQUE KEY `order_id` (`order_id`)
11
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
12
- ");
13
-
14
  $installer->endSetup();
1
+ <?php
2
+ $installer = $this;
3
+ $installer->startSetup();
4
+
5
+ $installer->run("
6
+ -- DROP TABLE IF EXISTS {$this->getTable('sales_chronopost_order_export_status')};
7
+ CREATE TABLE {$this->getTable('sales_chronopost_order_export_status')} (
8
+ `order_id` int(10) unsigned NOT NULL,
9
+ `livraison_le_samedi` varchar(10) NOT NULL DEFAULT 'Yes',
10
+ UNIQUE KEY `order_id` (`order_id`)
11
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
12
+ ");
13
+
14
  $installer->endSetup();
app/design/adminhtml/default/default/template/chronorelais/import/form.phtml CHANGED
@@ -1,65 +1,65 @@
1
- <div class="content-header">
2
- <table cellspacing="0">
3
- <tr>
4
- <td><h3 class="icon-head head-tax-rate-importExport"><?php echo Mage::helper('chronorelais')->__('Importer une liste de num&eacute;ros de colis') ?></h3></td>
5
- </tr>
6
- </table>
7
- </div>
8
- <div class="entry-edit">
9
- <div class="box-left">
10
- <form id="import_form" action="<?php echo $this->getUrl('*/*/import') ?>" method="post" enctype="multipart/form-data">
11
- <?php echo $this->getBlockHtml('formkey')?>
12
- <div class="entry-edit-head">
13
- <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('chronorelais')->__('Importer une liste de num&eacute;ros de colis') ?></h4>
14
- </div>
15
-
16
- <fieldset>
17
- <table class="form-list" cellspacing="0">
18
- <colgroup class="label"/>
19
- <colgroup class="value"/>
20
- <tbody>
21
- <tr>
22
- <td class="label">
23
- <label><?php echo Mage::helper('chronorelais')->__('Tracking Title') ?></label>
24
- </td>
25
- <td class="value">
26
- <input type="text" name="import_chronorelais_tracking_title" class="input-file" value="<?php echo Mage::helper('chronorelais')->getConfigurationDefaultTrackingTitle() ?>"/>
27
- </td>
28
- </tr>
29
- <tr>
30
- <td class="label">
31
- <label><?php echo Mage::helper('chronorelais')->__('Import File') ?></label>
32
- </td>
33
- <td class="value">
34
- <input type="file" name="import_chronorelais_file" class="input-file required-entry"/>
35
- <p class="nm">
36
- <small><?php echo Mage::helper('chronorelais')->__('Line format:'). ' "'.Mage::helper('chronorelais')->__('order id').'","'.Mage::helper('chronorelais')->__('tracking number').'"'; ?></small>
37
- </p>
38
- </td>
39
- </tr>
40
- <tr>
41
- <td>&nbsp;</td>
42
- <td class="value">
43
- <?php $button_label = Mage::helper('chronorelais')->__('Import'); ?>
44
- <?php echo $this->getButtonHtml($button_label, "this.form.submit();displayLoadingMask();") ?>
45
- </td>
46
- </tr>
47
- </tbody>
48
- </table>
49
- </fieldset>
50
-
51
- </form>
52
- <script type="text/javascript">
53
- var importForm = new varienForm('import_form');
54
-
55
- function displayLoadingMask()
56
- {
57
- var loaderArea = $$('#html-body .wrapper')[0]; // Blocks all page
58
- Position.clone($(loaderArea), $('loading-mask'), {offsetLeft:-2});
59
- toggleSelectsUnderBlock($('loading-mask'), false);
60
- Element.show('loading-mask');
61
- }
62
- </script>
63
- </div>
64
- <div class="clear"></div>
65
- </div>
1
+ <div class="content-header">
2
+ <table cellspacing="0">
3
+ <tr>
4
+ <td><h3 class="icon-head head-tax-rate-importExport"><?php echo Mage::helper('chronorelais')->__('Importer une liste de num&eacute;ros de colis') ?></h3></td>
5
+ </tr>
6
+ </table>
7
+ </div>
8
+ <div class="entry-edit">
9
+ <div class="box-left">
10
+ <form id="import_form" action="<?php echo $this->getUrl('*/*/import') ?>" method="post" enctype="multipart/form-data">
11
+ <?php echo $this->getBlockHtml('formkey')?>
12
+ <div class="entry-edit-head">
13
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('chronorelais')->__('Importer une liste de num&eacute;ros de colis') ?></h4>
14
+ </div>
15
+
16
+ <fieldset>
17
+ <table class="form-list" cellspacing="0">
18
+ <colgroup class="label"/>
19
+ <colgroup class="value"/>
20
+ <tbody>
21
+ <tr>
22
+ <td class="label">
23
+ <label><?php echo Mage::helper('chronorelais')->__('Tracking Title') ?></label>
24
+ </td>
25
+ <td class="value">
26
+ <input type="text" name="import_chronorelais_tracking_title" class="input-file" value="<?php echo Mage::helper('chronorelais')->getConfigurationDefaultTrackingTitle() ?>"/>
27
+ </td>
28
+ </tr>
29
+ <tr>
30
+ <td class="label">
31
+ <label><?php echo Mage::helper('chronorelais')->__('Import File') ?></label>
32
+ </td>
33
+ <td class="value">
34
+ <input type="file" name="import_chronorelais_file" class="input-file required-entry"/>
35
+ <p class="nm">
36
+ <small><?php echo Mage::helper('chronorelais')->__('Line format:'). ' "'.Mage::helper('chronorelais')->__('order id').'","'.Mage::helper('chronorelais')->__('tracking number').'"'; ?></small>
37
+ </p>
38
+ </td>
39
+ </tr>
40
+ <tr>
41
+ <td>&nbsp;</td>
42
+ <td class="value">
43
+ <?php $button_label = Mage::helper('chronorelais')->__('Import'); ?>
44
+ <?php echo $this->getButtonHtml($button_label, "this.form.submit();displayLoadingMask();") ?>
45
+ </td>
46
+ </tr>
47
+ </tbody>
48
+ </table>
49
+ </fieldset>
50
+
51
+ </form>
52
+ <script type="text/javascript">
53
+ var importForm = new varienForm('import_form');
54
+
55
+ function displayLoadingMask()
56
+ {
57
+ var loaderArea = $$('#html-body .wrapper')[0]; // Blocks all page
58
+ Position.clone($(loaderArea), $('loading-mask'), {offsetLeft:-2});
59
+ toggleSelectsUnderBlock($('loading-mask'), false);
60
+ Element.show('loading-mask');
61
+ }
62
+ </script>
63
+ </div>
64
+ <div class="clear"></div>
65
+ </div>
app/design/frontend/default/default/template/chronorelais/checkout/multishipping/shipping.phtml CHANGED
@@ -131,7 +131,7 @@
131
  <span style="display: none;" class="please-wait" id="loading-process"><img class="v-middle" title="<?php echo $this->__('Loading...')?>" alt="<?php echo $this->__('Loading...')?>" src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>"> <?php echo $this->__('Loading...')?></span>
132
  <div id="checkout-shipping-method-chronorelais-load_<?php echo $_address->getId() ?>" class="chronorelais-list" style="clear: both;">
133
  <?php if($this->getAddressShippingMethod($_address)=="chronorelais_chronorelais"): ?>
134
- <?php Mage::getSingleton('core/session')->setMultiPostcode($_address->getPostcode()); ?>
135
  <?php echo $this->getChildHtml('relaislist') ?>
136
  <?php endif; ?>
137
  </div>
131
  <span style="display: none;" class="please-wait" id="loading-process"><img class="v-middle" title="<?php echo $this->__('Loading...')?>" alt="<?php echo $this->__('Loading...')?>" src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>"> <?php echo $this->__('Loading...')?></span>
132
  <div id="checkout-shipping-method-chronorelais-load_<?php echo $_address->getId() ?>" class="chronorelais-list" style="clear: both;">
133
  <?php if($this->getAddressShippingMethod($_address)=="chronorelais_chronorelais"): ?>
134
+ <?php Mage::getSingleton('core/session')->setMultiAddress($_address); ?>
135
  <?php echo $this->getChildHtml('relaislist') ?>
136
  <?php endif; ?>
137
  </div>
app/design/frontend/default/default/template/chronorelais/checkout/multishipping/shipping_method/chronorelais.phtml CHANGED
@@ -1,6 +1,9 @@
1
  <?php if(count($this->getChronorelais())>0): ?>
2
  <?php
3
- $postcode = Mage::getSingleton('core/session')->getMultiPostcode();
 
 
 
4
  ?>
5
  <div class="chronorelaismap">
6
  <div class="mappostalcode">
1
  <?php if(count($this->getChronorelais())>0): ?>
2
  <?php
3
+ //$quote = Mage::getSingleton('checkout/cart')->init()->getQuote();
4
+ //$address = $quote->getShippingAddress();
5
+ $address = Mage::getSingleton('core/session')->getMultiAddress();
6
+ $postcode = $address->getPostcode();
7
  ?>
8
  <div class="chronorelaismap">
9
  <div class="mappostalcode">
app/design/frontend/default/default/template/chronorelais/checkout/onepage/shipping_method.phtml CHANGED
@@ -1,93 +1,93 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
- */
26
- ?>
27
- <?php $isSoColissimoSimplicite = Mage::getConfig()->getModuleConfig('LaPoste_SoColissimoSimplicite')->is('active'); ?>
28
-
29
- <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=<?php echo Mage::helper('chronorelais')->getConfigurationGoogleMapAPIKey()?>" type="text/javascript"></script>
30
- <script type="text/javascript" src="<?php echo $this->getSkinUrl('chronorelais/chronorelaismap.js') ?>"></script>
31
- <script type="text/javascript">
32
- //<![CDATA[
33
- var Picto_Chrono_Relais = '<?php echo $this->getSkinUrl('chronorelais/Picto_Chrono_Relais.png')?>';
34
- var Home_Chrono_Icon = '<?php echo $this->getSkinUrl('chronorelais/home.png')?>';
35
- //]]>
36
- </script>
37
- <form id="co-shipping-method-form" action="">
38
- <div id="checkout-shipping-method-load">
39
- <?php echo $this->getChildHtml('available') ?>
40
- </div>
41
- <?php if(!empty($isSoColissimoSimplicite)) : ?>
42
- <?php $_helper = Mage::helper('socolissimosimplicite'); ?>
43
- <script type="text/javascript">
44
- //<![CDATA[
45
- // update method save to redirect onSuccess to method which deals with colissimo choice
46
- ShippingMethod.prototype.saveWithColissimo = function(){
47
- if (checkout.loadWaiting!=false) return;
48
- if (this.validate()) {
49
- checkout.setLoadWaiting('shipping-method');
50
- var request = new Ajax.Request(
51
- this.saveUrl,
52
- {
53
- method:'post',
54
- onComplete: this.onComplete,
55
- onSuccess: this.redirectToColissimo,
56
- onFailure: checkout.ajaxFailure.bind(checkout),
57
- parameters: Form.serialize(this.form)
58
- }
59
- );
60
- }
61
- };
62
- // check if colissimo is selected, then redirect on form which post data on this platform
63
- ShippingMethod.prototype.redirectToColissimo = function(transport){
64
- var rateCodeSoColissimoSimplicite = '<?php echo $_helper->getRateCode()?>';
65
- var urlFormSoColissimoSimplicite = '<?php echo $_helper->getFormUrl()?>';
66
- var methods = document.getElementsByName('shipping_method');
67
- for (var i=0; i<methods.length; i++) {
68
- if (methods[i].value == rateCodeSoColissimoSimplicite && methods[i].checked) {
69
- window.location = urlFormSoColissimoSimplicite;
70
- }
71
- }
72
- // pass to next step (= default onSave binding
73
- ShippingMethod.prototype.nextStep(transport);
74
- };
75
- //]]>
76
- </script>
77
- <?php endif; ?>
78
- <script type="text/javascript">
79
- //<![CDATA[
80
- var shippingMethod = new ShippingMethod('co-shipping-method-form', "<?php echo $this->getUrl('checkout/onepage/saveShippingMethod') ?>");
81
- //]]>
82
- </script>
83
- <div id="onepage-checkout-shipping-method-additional-load">
84
- <?php echo $this->getChildHtml('additional') ?>
85
- </div>
86
- <div class="buttons-set" id="shipping-method-buttons-container">
87
- <p class="back-link"><a href="#" onclick="checkout.back(); return false;"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
88
- <button type="button" class="button" onclick=" <?php if(!empty($isSoColissimoSimplicite)) : ?>shippingMethod.saveWithColissimo()<?php else: ?>shippingMethod.save()<?php endif;?>"><span><span><?php echo $this->__('Continue') ?></span></span></button>
89
- <span id="shipping-method-please-wait" class="please-wait" style="display:none;">
90
- <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading next step...') ?>" title="<?php echo $this->__('Loading next step...') ?>" class="v-middle" /> <?php echo $this->__('Loading next step...') ?>
91
- </span>
92
- </div>
93
  </form>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $isSoColissimoSimplicite = Mage::getConfig()->getModuleConfig('LaPoste_SoColissimoSimplicite')->is('active'); ?>
28
+
29
+ <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=<?php echo Mage::helper('chronorelais')->getConfigurationGoogleMapAPIKey()?>" type="text/javascript"></script>
30
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('chronorelais/chronorelaismap.js') ?>"></script>
31
+ <script type="text/javascript">
32
+ //<![CDATA[
33
+ var Picto_Chrono_Relais = '<?php echo $this->getSkinUrl('chronorelais/Picto_Chrono_Relais.png')?>';
34
+ var Home_Chrono_Icon = '<?php echo $this->getSkinUrl('chronorelais/home.png')?>';
35
+ //]]>
36
+ </script>
37
+ <form id="co-shipping-method-form" action="">
38
+ <div id="checkout-shipping-method-load">
39
+ <?php echo $this->getChildHtml('available') ?>
40
+ </div>
41
+ <?php if(!empty($isSoColissimoSimplicite)) : ?>
42
+ <?php $_helper = Mage::helper('socolissimosimplicite'); ?>
43
+ <script type="text/javascript">
44
+ //<![CDATA[
45
+ // update method save to redirect onSuccess to method which deals with colissimo choice
46
+ ShippingMethod.prototype.saveWithColissimo = function(){
47
+ if (checkout.loadWaiting!=false) return;
48
+ if (this.validate()) {
49
+ checkout.setLoadWaiting('shipping-method');
50
+ var request = new Ajax.Request(
51
+ this.saveUrl,
52
+ {
53
+ method:'post',
54
+ onComplete: this.onComplete,
55
+ onSuccess: this.redirectToColissimo,
56
+ onFailure: checkout.ajaxFailure.bind(checkout),
57
+ parameters: Form.serialize(this.form)
58
+ }
59
+ );
60
+ }
61
+ };
62
+ // check if colissimo is selected, then redirect on form which post data on this platform
63
+ ShippingMethod.prototype.redirectToColissimo = function(transport){
64
+ var rateCodeSoColissimoSimplicite = '<?php echo $_helper->getRateCode()?>';
65
+ var urlFormSoColissimoSimplicite = '<?php echo $_helper->getFormUrl()?>';
66
+ var methods = document.getElementsByName('shipping_method');
67
+ for (var i=0; i<methods.length; i++) {
68
+ if (methods[i].value == rateCodeSoColissimoSimplicite && methods[i].checked) {
69
+ window.location = urlFormSoColissimoSimplicite;
70
+ }
71
+ }
72
+ // pass to next step (= default onSave binding
73
+ ShippingMethod.prototype.nextStep(transport);
74
+ };
75
+ //]]>
76
+ </script>
77
+ <?php endif; ?>
78
+ <script type="text/javascript">
79
+ //<![CDATA[
80
+ var shippingMethod = new ShippingMethod('co-shipping-method-form', "<?php echo $this->getUrl('checkout/onepage/saveShippingMethod') ?>");
81
+ //]]>
82
+ </script>
83
+ <div id="onepage-checkout-shipping-method-additional-load">
84
+ <?php echo $this->getChildHtml('additional') ?>
85
+ </div>
86
+ <div class="buttons-set" id="shipping-method-buttons-container">
87
+ <p class="back-link"><a href="#" onclick="checkout.back(); return false;"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
88
+ <button type="button" class="button" onclick=" <?php if(!empty($isSoColissimoSimplicite)) : ?>shippingMethod.saveWithColissimo()<?php else: ?>shippingMethod.save()<?php endif;?>"><span><span><?php echo $this->__('Continue') ?></span></span></button>
89
+ <span id="shipping-method-please-wait" class="please-wait" style="display:none;">
90
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading next step...') ?>" title="<?php echo $this->__('Loading next step...') ?>" class="v-middle" /> <?php echo $this->__('Loading next step...') ?>
91
+ </span>
92
+ </div>
93
  </form>
app/design/frontend/default/default/template/chronorelais/checkout/onepage/shipping_method/available.phtml CHANGED
@@ -1,94 +1,94 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
- */
26
- ?>
27
- <?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
28
- <p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
29
- <?php else: ?>
30
- <dl class="sp-methods">
31
- <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
32
- <dt><?php echo $this->getCarrierName($code) ?></dt>
33
- <dd>
34
- <ul>
35
- <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
36
- <li>
37
- <?php if ($_rate->getErrorMessage()): ?>
38
- <ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
39
- <?php else: ?>
40
- <table>
41
- <tr><td class="method-radio">
42
- <?php /*if ($_sole) : ?>
43
- <span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" onclick="<?php if($code=="chronorelais"): ?>shippingMethod.getrelais('<?php echo $this->getUrl('checkout/onepage/getRelais')?>')<?php else: ?>shippingMethod.hiderelais()<?php endif; ?>" /></span>
44
- <?php else:*/ ?>
45
- <input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php /*if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"'*/ ?> class="radio" onclick="<?php if($code=="chronorelais"): ?>shippingMethod.getrelais('<?php echo $this->getUrl('checkout/onepage/getRelais')?>')<?php else: ?>shippingMethod.hiderelais()<?php endif; ?>" />
46
- <?php //endif; ?>
47
- </td>
48
- <?php if(Mage::getStoreConfig('carriers/'.$code.'/logo_url')): ?>
49
- <td class="method-image"><img src="<?php echo $this->getSkinUrl("chronorelais/".Mage::getStoreConfig('carriers/'.$code.'/logo_url')); ?>" alt="" /></td>
50
- <?php endif; ?>
51
- <td class="method-contents">
52
- <label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $_rate->getMethodTitle() ?>
53
- <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
54
- <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
55
- <?php echo $_excl; ?>
56
- <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
57
- (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
58
- <?php endif; ?>
59
- </label>
60
- <?php if($_rate->getMethodDescription()): ?>
61
- <div class="method-description">
62
- <?php echo $_rate->getMethodDescription()?>
63
- </div>
64
- <?php endif;?>
65
-
66
- <?php // disponibilit� de la plateforme soco ?>
67
- <?php if(Mage::getConfig()->getModuleConfig('LaPoste_SoColissimoSimplicite')->is('active')) : ?>
68
- <?php $helper = Mage::helper('socolissimosimplicite'); ?>
69
- <?php
70
- $serviceIsAvailable = true;
71
- if ($helper->getServiceIsAvailable() and $helper->getServiceIsAvailableUrl() != '') {
72
- $serviceIsAvailable = $helper->checkserviceAvailability();
73
- }
74
- ?>
75
- <?php if ($_rate->getCode() == 'socolissimosimplicite_socolissimosimplicite' and !$serviceIsAvailable): ?>
76
- <ul class="messages"><li class="error-msg"><ul><li><?php echo $helper->getServiceNotAvailableMessage(); ?></li></ul></li></ul>
77
- <?php endif ?>
78
- <?php endif; ?>
79
- </td>
80
- </tr>
81
- </table>
82
- <?php if($code=="chronorelais"): ?>
83
- <div id="checkout-shipping-method-chronorelais-load" class="chronorelais-list">
84
- <?php echo $this->getChildHtml('relaislist') ?>
85
- </div>
86
- <?php endif; ?>
87
- <?php endif ?>
88
- </li>
89
- <?php endforeach; ?>
90
- </ul>
91
- </dd>
92
- <?php endforeach; ?>
93
- </dl>
94
  <?php endif; ?>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
28
+ <p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
29
+ <?php else: ?>
30
+ <dl class="sp-methods">
31
+ <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
32
+ <dt><?php echo $this->getCarrierName($code) ?></dt>
33
+ <dd>
34
+ <ul>
35
+ <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
36
+ <li>
37
+ <?php if ($_rate->getErrorMessage()): ?>
38
+ <ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
39
+ <?php else: ?>
40
+ <table>
41
+ <tr><td class="method-radio">
42
+ <?php /*if ($_sole) : ?>
43
+ <span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" onclick="<?php if($code=="chronorelais"): ?>shippingMethod.getrelais('<?php echo $this->getUrl('checkout/onepage/getRelais')?>')<?php else: ?>shippingMethod.hiderelais()<?php endif; ?>" /></span>
44
+ <?php else:*/ ?>
45
+ <input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php /*if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"'*/ ?> class="radio" onclick="<?php if($code=="chronorelais"): ?>shippingMethod.getrelais('<?php echo $this->getUrl('checkout/onepage/getRelais')?>')<?php else: ?>shippingMethod.hiderelais()<?php endif; ?>" />
46
+ <?php //endif; ?>
47
+ </td>
48
+ <?php if(Mage::getStoreConfig('carriers/'.$code.'/logo_url')): ?>
49
+ <td class="method-image"><img src="<?php echo $this->getSkinUrl("chronorelais/".Mage::getStoreConfig('carriers/'.$code.'/logo_url')); ?>" alt="" /></td>
50
+ <?php endif; ?>
51
+ <td class="method-contents">
52
+ <label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $_rate->getMethodTitle() ?>
53
+ <?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
54
+ <?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
55
+ <?php echo $_excl; ?>
56
+ <?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
57
+ (<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
58
+ <?php endif; ?>
59
+ </label>
60
+ <?php if($_rate->getMethodDescription()): ?>
61
+ <div class="method-description">
62
+ <?php echo $_rate->getMethodDescription()?>
63
+ </div>
64
+ <?php endif;?>
65
+
66
+ <?php // disponibilit� de la plateforme soco ?>
67
+ <?php if(Mage::getConfig()->getModuleConfig('LaPoste_SoColissimoSimplicite')->is('active')) : ?>
68
+ <?php $helper = Mage::helper('socolissimosimplicite'); ?>
69
+ <?php
70
+ $serviceIsAvailable = true;
71
+ if ($helper->getServiceIsAvailable() and $helper->getServiceIsAvailableUrl() != '') {
72
+ $serviceIsAvailable = $helper->checkserviceAvailability();
73
+ }
74
+ ?>
75
+ <?php if ($_rate->getCode() == 'socolissimosimplicite_socolissimosimplicite' and !$serviceIsAvailable): ?>
76
+ <ul class="messages"><li class="error-msg"><ul><li><?php echo $helper->getServiceNotAvailableMessage(); ?></li></ul></li></ul>
77
+ <?php endif ?>
78
+ <?php endif; ?>
79
+ </td>
80
+ </tr>
81
+ </table>
82
+ <?php if($code=="chronorelais"): ?>
83
+ <div id="checkout-shipping-method-chronorelais-load" class="chronorelais-list">
84
+ <?php echo $this->getChildHtml('relaislist') ?>
85
+ </div>
86
+ <?php endif; ?>
87
+ <?php endif ?>
88
+ </li>
89
+ <?php endforeach; ?>
90
+ </ul>
91
+ </dd>
92
+ <?php endforeach; ?>
93
+ </dl>
94
  <?php endif; ?>
app/design/frontend/default/default/template/chronorelais/sales/order/history.phtml CHANGED
@@ -1,79 +1,79 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
- */
26
- ?>
27
- <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
28
- <?php $_orders = $this->getOrders(); ?>
29
- <div class="page-title">
30
- <h1><?php echo $this->__('My Orders') ?></h1>
31
- </div>
32
- <?php echo $this->getPagerHtml(); ?>
33
- <?php if($_orders->getSize()): ?>
34
- <table class="data-table" id="my-orders-table">
35
- <col width="1" />
36
- <col width="1" />
37
- <col />
38
- <col width="1" />
39
- <col width="1" />
40
- <col width="1" />
41
- <thead>
42
- <tr>
43
- <th><?php echo $this->__('Order #') ?></th>
44
- <th><?php echo $this->__('Date') ?></th>
45
- <th><?php echo $this->__('Ship To') ?></th>
46
- <th><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
47
- <th><span class="nobr"><?php echo $this->__('Order Status') ?></span></th>
48
- <th>&nbsp;</th>
49
- </tr>
50
- </thead>
51
- <tbody>
52
- <?php $_odd = ''; ?>
53
- <?php foreach ($_orders as $_order): ?>
54
- <tr>
55
- <td><?php echo $_order->getRealOrderId() ?></td>
56
- <td><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
57
- <td><?php echo $_order->getShippingAddress() ? $this->htmlEscape($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
58
- <td><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
59
- <td><em><?php echo $_order->getStatusLabel() ?></em></td>
60
- <td class="a-center">
61
- <span class="nobr"><a href="<?php echo $this->getViewUrl($_order) ?>"><?php echo $this->__('View Order') ?></a>
62
- <?php /*<span class="separator">|</span><a href="<?php echo $this->getTrackUrl($_order) ?>"><?php echo $this->__('Track Order') ?></a>&nbsp;*/ ?>
63
- <?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
64
- <span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
65
- <?php endif ?>
66
- </span>
67
- <?php if ($_order->getTracksCollection()->count()) : ?>
68
- <a href="#" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','top=50,left=50,width=800,height=600,resizable=yes,scrollbars=yes'); return false;" title="<?php echo $this->__('Track Your Order') ?>"><?php echo $this->__('Track Your Order') ?></a>
69
- <?php endif; ?>
70
- </td>
71
- </tr>
72
- <?php endforeach; ?>
73
- </tbody>
74
- </table>
75
- <script type="text/javascript">decorateTable('my-orders-table');</script>
76
- <?php echo $this->getPagerHtml(); ?>
77
- <?php else: ?>
78
- <p><?php echo $this->__('You have placed no orders.'); ?></p>
79
- <?php endif ?>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
28
+ <?php $_orders = $this->getOrders(); ?>
29
+ <div class="page-title">
30
+ <h1><?php echo $this->__('My Orders') ?></h1>
31
+ </div>
32
+ <?php echo $this->getPagerHtml(); ?>
33
+ <?php if($_orders->getSize()): ?>
34
+ <table class="data-table" id="my-orders-table">
35
+ <col width="1" />
36
+ <col width="1" />
37
+ <col />
38
+ <col width="1" />
39
+ <col width="1" />
40
+ <col width="1" />
41
+ <thead>
42
+ <tr>
43
+ <th><?php echo $this->__('Order #') ?></th>
44
+ <th><?php echo $this->__('Date') ?></th>
45
+ <th><?php echo $this->__('Ship To') ?></th>
46
+ <th><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
47
+ <th><span class="nobr"><?php echo $this->__('Order Status') ?></span></th>
48
+ <th>&nbsp;</th>
49
+ </tr>
50
+ </thead>
51
+ <tbody>
52
+ <?php $_odd = ''; ?>
53
+ <?php foreach ($_orders as $_order): ?>
54
+ <tr>
55
+ <td><?php echo $_order->getRealOrderId() ?></td>
56
+ <td><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
57
+ <td><?php echo $_order->getShippingAddress() ? $this->htmlEscape($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
58
+ <td><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
59
+ <td><em><?php echo $_order->getStatusLabel() ?></em></td>
60
+ <td class="a-center">
61
+ <span class="nobr"><a href="<?php echo $this->getViewUrl($_order) ?>"><?php echo $this->__('View Order') ?></a>
62
+ <?php /*<span class="separator">|</span><a href="<?php echo $this->getTrackUrl($_order) ?>"><?php echo $this->__('Track Order') ?></a>&nbsp;*/ ?>
63
+ <?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
64
+ <span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
65
+ <?php endif ?>
66
+ </span>
67
+ <?php if ($_order->getTracksCollection()->count()) : ?>
68
+ <a href="#" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','top=50,left=50,width=800,height=600,resizable=yes,scrollbars=yes'); return false;" title="<?php echo $this->__('Track Your Order') ?>"><?php echo $this->__('Track Your Order') ?></a>
69
+ <?php endif; ?>
70
+ </td>
71
+ </tr>
72
+ <?php endforeach; ?>
73
+ </tbody>
74
+ </table>
75
+ <script type="text/javascript">decorateTable('my-orders-table');</script>
76
+ <?php echo $this->getPagerHtml(); ?>
77
+ <?php else: ?>
78
+ <p><?php echo $this->__('You have placed no orders.'); ?></p>
79
+ <?php endif ?>
app/design/frontend/default/default/template/chronorelais/sales/order/recent.phtml CHANGED
@@ -1,78 +1,78 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
- */
26
- ?>
27
- <div class="box-account box-recent">
28
- <?php $_orders = $this->getOrders(); ?>
29
- <div class="box-head">
30
- <h2><?php echo $this->__('Recent Orders') ?></h2>
31
- <?php if( sizeof($_orders->getItems()) > 0 ): ?><a href="<?php echo $this->getUrl('sales/order/history') ?>"><?php echo $this->__('View All') ?></a><?php endif; ?>
32
- </div>
33
- <?php if( sizeof($_orders->getItems()) > 0 ): ?>
34
- <table class="data-table" id="my-orders-table">
35
- <col width="1" />
36
- <col width="1" />
37
- <col />
38
- <col width="1" />
39
- <col width="1" />
40
- <col width="1" />
41
- <thead>
42
- <tr>
43
- <th><?php echo $this->__('Order #') ?></th>
44
- <th><?php echo $this->__('Date') ?></th>
45
- <th><?php echo $this->__('Ship To') ?></th>
46
- <th><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
47
- <th><?php echo $this->__('Status') ?></th>
48
- <th>&nbsp;</th>
49
- </tr>
50
- </thead>
51
- <tbody>
52
- <?php foreach ($_orders as $_order): ?>
53
- <tr>
54
- <td><?php echo $_order->getRealOrderId() ?></td>
55
- <td><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
56
- <td><?php echo $_order->getShippingAddress() ? $this->htmlEscape($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
57
- <td><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
58
- <td><em><?php echo $_order->getStatusLabel() ?></em></td>
59
- <td class="a-center">
60
- <span class="nobr">
61
- <a href="<?php echo $this->getViewUrl($_order) ?>"><?php echo $this->__('View Order') ?></a>
62
- <?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
63
- <span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
64
- <?php endif ?>
65
- </span>
66
- <?php if ($_order->getTracksCollection()->count()) : ?>
67
- <a href="#" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','top=50,left=50,width=800,height=600,resizable=yes,scrollbars=yes'); return false;" title="<?php echo $this->__('Track Your Order') ?>"><?php echo $this->__('Track Your Order') ?></a>
68
- <?php endif; ?>
69
- </td>
70
- </tr>
71
- <?php endforeach; ?>
72
- </tbody>
73
- </table>
74
- <script type="text/javascript">decorateTable('my-orders-table')</script>
75
- <?php else: ?>
76
- <p><?php echo $this->__('You have placed no orders.'); ?></p>
77
- <?php endif; ?>
78
- </div>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div class="box-account box-recent">
28
+ <?php $_orders = $this->getOrders(); ?>
29
+ <div class="box-head">
30
+ <h2><?php echo $this->__('Recent Orders') ?></h2>
31
+ <?php if( sizeof($_orders->getItems()) > 0 ): ?><a href="<?php echo $this->getUrl('sales/order/history') ?>"><?php echo $this->__('View All') ?></a><?php endif; ?>
32
+ </div>
33
+ <?php if( sizeof($_orders->getItems()) > 0 ): ?>
34
+ <table class="data-table" id="my-orders-table">
35
+ <col width="1" />
36
+ <col width="1" />
37
+ <col />
38
+ <col width="1" />
39
+ <col width="1" />
40
+ <col width="1" />
41
+ <thead>
42
+ <tr>
43
+ <th><?php echo $this->__('Order #') ?></th>
44
+ <th><?php echo $this->__('Date') ?></th>
45
+ <th><?php echo $this->__('Ship To') ?></th>
46
+ <th><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
47
+ <th><?php echo $this->__('Status') ?></th>
48
+ <th>&nbsp;</th>
49
+ </tr>
50
+ </thead>
51
+ <tbody>
52
+ <?php foreach ($_orders as $_order): ?>
53
+ <tr>
54
+ <td><?php echo $_order->getRealOrderId() ?></td>
55
+ <td><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
56
+ <td><?php echo $_order->getShippingAddress() ? $this->htmlEscape($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
57
+ <td><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
58
+ <td><em><?php echo $_order->getStatusLabel() ?></em></td>
59
+ <td class="a-center">
60
+ <span class="nobr">
61
+ <a href="<?php echo $this->getViewUrl($_order) ?>"><?php echo $this->__('View Order') ?></a>
62
+ <?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
63
+ <span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
64
+ <?php endif ?>
65
+ </span>
66
+ <?php if ($_order->getTracksCollection()->count()) : ?>
67
+ <a href="#" onclick="popWin('<?php echo $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>','trackorder','top=50,left=50,width=800,height=600,resizable=yes,scrollbars=yes'); return false;" title="<?php echo $this->__('Track Your Order') ?>"><?php echo $this->__('Track Your Order') ?></a>
68
+ <?php endif; ?>
69
+ </td>
70
+ </tr>
71
+ <?php endforeach; ?>
72
+ </tbody>
73
+ </table>
74
+ <script type="text/javascript">decorateTable('my-orders-table')</script>
75
+ <?php else: ?>
76
+ <p><?php echo $this->__('You have placed no orders.'); ?></p>
77
+ <?php endif; ?>
78
+ </div>
app/etc/modules/WSChronopost_Chronorelais.xml CHANGED
@@ -1,28 +1,28 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /**
4
- * Magento Chronopost Chronorelais 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 Chronopost
17
- * @package Chronopost_Chronorelais
18
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
- */
20
- -->
21
- <config>
22
- <modules>
23
- <Chronopost_Chronorelais>
24
- <active>true</active>
25
- <codePool>community</codePool>
26
- </Chronopost_Chronorelais>
27
- </modules>
28
  </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento Chronopost Chronorelais 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 Chronopost
17
+ * @package Chronopost_Chronorelais
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+ -->
21
+ <config>
22
+ <modules>
23
+ <Chronopost_Chronorelais>
24
+ <active>true</active>
25
+ <codePool>community</codePool>
26
+ </Chronopost_Chronorelais>
27
+ </modules>
28
  </config>
js/chronopost/chronorelais/ocseditor.css CHANGED
@@ -1,465 +1,465 @@
1
- #ocs-editor #ocs-editor-config-loader {
2
- padding: 5px;
3
- border: solid 1px #6f8992;
4
- background: #e7efef;
5
- display: none;
6
- }
7
-
8
- #ocs-editor #ocs-editor-config-loader textarea {
9
- height: 100px;
10
- }
11
-
12
- #ocs-editor #os-config-helper {
13
- }
14
- #ocs-editor .buttons-set-label {
15
- padding: 2px 10px 2px 0;
16
- display: inline-block;
17
- font-weight: bold;
18
- }
19
- #ocs-editor div.buttons-set {
20
- padding: 0;
21
- margin: 2px 0;
22
- }
23
- #ocs-editor fieldset {
24
- display: block;
25
- border: solid 1px #6f8992;
26
- margin: 2px 0;
27
- padding: 0 8px 2px 8px;
28
- }
29
- #ocs-editor fieldset.buttons-set {
30
- margin: 2px 0;
31
- }
32
- #ocs-editor legend {
33
- display: inline;
34
- font-weight: bold;
35
- margin-left: 15px;
36
- padding: 0 5px;
37
- }
38
-
39
- #ocs-editor .config-container {
40
- border-top: solid 1px #6f8992;
41
- }
42
-
43
- #ocs-editor .properties-container {
44
- position: relative;
45
- display: none;
46
- }
47
-
48
- #ocs-editor .row-container.selected .properties-container {
49
- display: block;
50
- background: #d1dedf;
51
- }
52
-
53
- #ocs-editor .row-container.has-error .properties-container {
54
- background: #f3c6c6;
55
- }
56
-
57
- #ocs-editor .properties-list {
58
- position: relative;
59
- height: 350px;
60
- list-style: none;
61
- width: 20%;
62
- z-index: 2;
63
- padding: 5px 0;
64
- -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
65
- -khtml-box-sizing: border-box;
66
- -moz-box-sizing: border-box; /* Firefox, other Gecko */
67
- box-sizing: border-box; /* Opera/IE 8+ */
68
- }
69
-
70
- #ocs-editor .properties-list li {
71
- margin-left: 10px;
72
- padding: 5px 0;
73
- cursor: pointer;
74
- font-weight: bold;
75
- }
76
-
77
- #ocs-editor .properties-list li.selected {
78
- font-weight: bold;
79
- border-left: solid 1px #6f8992;
80
- border-top: solid 1px #6f8992;
81
- border-bottom: solid 1px #6f8992;
82
- background: #e7efef;
83
- padding: 7px 10px;
84
- position: relative;
85
- left: 1px;
86
- }
87
-
88
- #ocs-editor .row-container.has-error .properties-list li.selected {
89
- border-color: #af2c2c;
90
- background: #f7e8e8;
91
- }
92
-
93
- #ocs-editor .properties-list li.has-error {
94
- font-weight: bold;
95
- color: #d40707;
96
- }
97
-
98
- #ocs-editor .properties-list li.empty {
99
- font-weight: normal;
100
- -webkit-opacity: 0.8;
101
- -khtml-opacity: 0.8;
102
- -moz-opacity: 0.8;
103
- opacity: 0.8;
104
- }
105
-
106
- #ocs-editor .properties-list li.hide {
107
- display: none;
108
- }
109
-
110
- #ocs-editor .property-container {
111
- position: absolute;
112
- top: 0;
113
- right: 0;
114
- height: 350px;
115
- overflow: auto;
116
- width: 80%;
117
- padding: 8px;
118
- -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
119
- -khtml-box-sizing: border-box;
120
- -moz-box-sizing: border-box; /* Firefox, other Gecko */
121
- box-sizing: border-box; /* Opera/IE 8+ */
122
- display: none;
123
- border-left: solid 1px #6f8992;
124
- background: #e7efef;
125
- z-index: 1;
126
- }
127
-
128
- #ocs-editor .property-container.selected {
129
- display: block;
130
- }
131
-
132
- #ocs-editor .row-container.has-error .property-container {
133
- border-color: #af2c2c;
134
- background: #f7e8e8;
135
- }
136
-
137
- #ocs-editor .row-header {
138
- padding: 3px;
139
- background: #d1dedf;
140
- color: #6f8992;
141
- }
142
-
143
- #ocs-editor .row-header .error {
144
- padding: 0 10px;
145
- }
146
-
147
- #ocs-editor .row-container.selected .row-header .error {
148
- color: #fff !important;
149
- }
150
-
151
- #ocs-editor .row-title {
152
- padding: 2px 9px;
153
- cursor: pointer;
154
- font-weight: bold;
155
- font-size: 1.3em;
156
- }
157
-
158
- #ocs-editor .row-actions {
159
- float: right;
160
- opacity: 0.7;
161
- -moz-opacity: 0.7;
162
- -webkit-opacity: 0.7;
163
- -khtml-opacity: 0.7;
164
- }
165
- #ocs-editor .row-actions button {
166
- margin-left: 5px;
167
- }
168
-
169
- #ocs-editor .row-container {
170
- border: solid 1px #6f8992;
171
- border-top: 0;
172
- }
173
-
174
- #ocs-editor .row-container.selected .row-header {
175
- background: #6f8992;
176
- color: #fff;
177
- }
178
-
179
- #ocs-editor .row-container.selected .row-actions {
180
- opacity: 1;
181
- -moz-opacity: 1;
182
- -webkit-opacity: 1;
183
- -khtml-opacity: 1;
184
- }
185
-
186
- #ocs-editor .row-container.has-error {
187
- border: solid 1px #af2c2c;
188
- }
189
-
190
- #ocs-editor .row-container.has-error .row-header {
191
- background: #f3c6c6;
192
- color: #af2c2c;
193
- }
194
-
195
- #ocs-editor .row-container.selected.has-error .row-header {
196
- background: #af2c2c;
197
- color: #fff;
198
- }
199
-
200
- #ocs-editor textarea {
201
- border: 0;
202
- background: #fff;
203
- display: block;
204
- overflow: visible;
205
- width: 100%;
206
- height: auto;
207
- -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
208
- -moz-box-sizing: border-box; /* Firefox, other Gecko */
209
- -khtml-box-sizing: border-box;
210
- box-sizing: border-box; /* Opera/IE 8+ */
211
- padding: 2px 0 2px 5px;
212
- }
213
-
214
- #ocs-editor .row-container textarea {
215
- height: 100px;
216
- }
217
-
218
- #ocs-editor .field-container{
219
- background: #666;
220
- padding: 2px;
221
- }
222
-
223
- #ocs-editor .address-filter-list {
224
- font-size: 0.9em;
225
- padding: 2px 0 5px 0;
226
- line-height: normal;
227
- }
228
-
229
- #ocs-editor .address-filter {
230
- display: inline-block;
231
- padding: 2px 7px;
232
- margin: 1px;
233
- cursor: pointer;
234
- -webkit-border-radius: 5px;
235
- -khtml-border-radius: 5px;
236
- -moz-border-radius: 5px;
237
- border-radius: 5px;
238
- }
239
-
240
- #ocs-editor .address-filter-group-label {
241
- padding: 2px 7px;
242
- margin: 1px;
243
- cursor: pointer;
244
- border: solid 1px #6f8992;
245
- background: #6f8992;
246
- display: inline-block;
247
- }
248
-
249
- #ocs-editor .address-filter-group {
250
- padding: 2px;
251
- color: #fff;
252
- border: 0;
253
- background: #6f8992;
254
- display: block;
255
- }
256
-
257
- #ocs-editor .address-filter.known {
258
- color: #000;
259
- border: solid 1px #000;
260
- background: #7f0;
261
- }
262
-
263
- #ocs-editor .address-filter.soft-cleaned {
264
- /*color: #000;
265
- border: solid 1px #000;
266
- background: #f90;*/
267
- }
268
-
269
- #ocs-editor .address-filter.hard-cleaned {
270
- color: #000;
271
- border: solid 1px #000;
272
- background: #f90;
273
- }
274
-
275
- #ocs-editor .address-filter.replaced {
276
- color: #000;
277
- border: solid 1px #000;
278
- background: #f90;
279
- }
280
-
281
- #ocs-editor .address-filter.warning {
282
- color: #000;
283
- border: solid 1px #000;
284
- background: #f90;
285
- }
286
-
287
- #ocs-editor .address-filter.unknown {
288
- color: #000;
289
- border: solid 1px #000;
290
- background: #f00;
291
- font-weight: bold;
292
- }
293
- #ocs-editor .address-filter.error {
294
- color: #f00;
295
- border: solid 1px #f00;
296
- background: #dcc;
297
- font-weight: bold;
298
- }
299
-
300
- #ocs-editor .bad {
301
- text-decoration: line-through;
302
- }
303
-
304
- #ocs-editor .donate-container {
305
- position: absolute;
306
- bottom: 0;
307
- border-top: solid 4px #dfdfdf;
308
- padding: 0.25em 0 0 0;
309
- width: 100%;
310
- color: #eb5e00;
311
- font-size: 1.25em;
312
- font-weight: bold;
313
- background: #fff;
314
- }
315
- #ocs-editor .donate-container table {
316
- width: 100%;
317
- }
318
-
319
- #ocs-editor .donate-container .form-buttons {
320
- text-align: right;
321
- margin-bottom: 0;
322
- white-space: nowrap;
323
- }
324
-
325
- #ocs-editor .ocseditor-page {
326
- position: absolute;
327
- top: 0;
328
- left: 0;
329
- width: 100%;
330
- height: 100%;
331
- z-index: 300;
332
- display: none;
333
- background: #fff;
334
- }
335
-
336
- #ocs-editor .owebia-address {
337
- padding-left: 50px;
338
- font-family: monospace;
339
- }
340
-
341
- #ocs-contextual-menu {
342
- -webkit-box-shadow: 2px 2px 5px #000;
343
- -khtml-box-shadow: 2px 2px 5px #000;
344
- -moz-box-shadow: 2px 2px 5px #000;
345
- box-shadow: 2px 2px 5px #000;
346
- background: #d1dedf;
347
- list-style: none;
348
- margin: 0;
349
- display: none;
350
- border: solid 1px #6f8992;
351
- padding-bottom: 1px;
352
- }
353
- #ocs-contextual-menu li {
354
- font-size: 0.9em;
355
- }
356
-
357
- #ocs-contextual-menu a {
358
- padding: 3px 7px;
359
- display: block;
360
- color: #000;
361
- text-decoration: none;
362
- }
363
-
364
- #ocs-contextual-menu a:hover {
365
- background: #6f8992;
366
- color: #fff;
367
- }
368
-
369
- #ocs-contextual-menu span {
370
- padding: 2px 7px;
371
- display: block;
372
- color: #000;
373
- border-bottom: solid 1px #6f8992;
374
- font-weight: bold;
375
- margin-bottom: 1px;
376
- }
377
-
378
- #ocs-editor .ocseditor-page .code {
379
- font-family: monospace;
380
- word-wrap: break-word;
381
- }
382
- #ocs-editor .ocseditor-page div.code {
383
- background-color: #efe8de;
384
- border: solid 1px #5c5248;
385
- border-left: solid 3px #5c5248;
386
- padding: 10px 5px;
387
- overflow: auto;
388
- }
389
- #ocs-editor .ocseditor-page span.code {
390
- padding: 0 3px;
391
- color: #522;
392
- font-weight: bold;
393
- }
394
- #ocs-editor .ocseditor-page .code .comment {
395
- color: #666;
396
- }
397
- #ocs-editor .ocseditor-page .code .string {
398
- color: #009f00;
399
- }
400
- #ocs-editor .ocseditor-page p {
401
- margin: 7px 0;
402
- }
403
-
404
- #ocs-editor .ocseditor-page ul {
405
- margin: 0 0 15px 20px;
406
- list-style: disc;
407
- }
408
-
409
- #ocs-editor .ocseditor-page h4 {
410
- padding: 0 0 2px 0;
411
- margin: 0;
412
- border-bottom: solid 1px #dfdfdf;
413
- }
414
- #ocs-editor .tips {
415
- background: #ffdb6f;
416
- padding: 3px 10px;
417
- margin: 10px 0;
418
- }
419
- #ocs-editor .tips p {
420
- margin: 4px 0;
421
- }
422
- #ocs-editor .help-header, #ocs-editor .help-footer {
423
- background: #d1dedf;
424
- padding: 3px 10px;
425
- margin: 0 0 10px 0;
426
- }
427
- #ocs-editor .help-footer {
428
- margin: 10px 0 0 0;
429
- }
430
- #ocs-editor .help-header p, #ocs-editor .help-footer p {
431
- margin: 4px 0;
432
- }
433
- #ocs-editor .help-header a, #ocs-editor .help-footer a {
434
- color: #444;
435
- }
436
- #ocs-editor .ocseditor-page .new {
437
- color: #0221a9;
438
- }
439
- #ocs-editor .table-of-contents {
440
- margin: 15px 0;
441
- padding: 15px;
442
- background-color: #d1dedf;
443
- }
444
- #ocs-editor .table-of-contents ul {
445
- padding: 0;
446
- margin: 0;
447
- list-style: none;
448
- }
449
- #ocs-editor .table-of-contents ul ul {
450
- margin: 3px 0 5px 15px;
451
- }
452
- #ocs-editor .table-of-contents li {
453
- padding: 2px 0;
454
- margin: 0;
455
- }
456
- #ocs-editor .table-of-contents a {
457
- color: #444;
458
- }
459
- #ocs-editor .table-of-contents li.new a {
460
- color: #0221a9;
461
- font-weight: bold;
462
- }
463
- #ocs-editor .table-of-contents a.deprecated {
464
- color: #8f6e47;
465
- }
1
+ #ocs-editor #ocs-editor-config-loader {
2
+ padding: 5px;
3
+ border: solid 1px #6f8992;
4
+ background: #e7efef;
5
+ display: none;
6
+ }
7
+
8
+ #ocs-editor #ocs-editor-config-loader textarea {
9
+ height: 100px;
10
+ }
11
+
12
+ #ocs-editor #os-config-helper {
13
+ }
14
+ #ocs-editor .buttons-set-label {
15
+ padding: 2px 10px 2px 0;
16
+ display: inline-block;
17
+ font-weight: bold;
18
+ }
19
+ #ocs-editor div.buttons-set {
20
+ padding: 0;
21
+ margin: 2px 0;
22
+ }
23
+ #ocs-editor fieldset {
24
+ display: block;
25
+ border: solid 1px #6f8992;
26
+ margin: 2px 0;
27
+ padding: 0 8px 2px 8px;
28
+ }
29
+ #ocs-editor fieldset.buttons-set {
30
+ margin: 2px 0;
31
+ }
32
+ #ocs-editor legend {
33
+ display: inline;
34
+ font-weight: bold;
35
+ margin-left: 15px;
36
+ padding: 0 5px;
37
+ }
38
+
39
+ #ocs-editor .config-container {
40
+ border-top: solid 1px #6f8992;
41
+ }
42
+
43
+ #ocs-editor .properties-container {
44
+ position: relative;
45
+ display: none;
46
+ }
47
+
48
+ #ocs-editor .row-container.selected .properties-container {
49
+ display: block;
50
+ background: #d1dedf;
51
+ }
52
+
53
+ #ocs-editor .row-container.has-error .properties-container {
54
+ background: #f3c6c6;
55
+ }
56
+
57
+ #ocs-editor .properties-list {
58
+ position: relative;
59
+ height: 350px;
60
+ list-style: none;
61
+ width: 20%;
62
+ z-index: 2;
63
+ padding: 5px 0;
64
+ -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
65
+ -khtml-box-sizing: border-box;
66
+ -moz-box-sizing: border-box; /* Firefox, other Gecko */
67
+ box-sizing: border-box; /* Opera/IE 8+ */
68
+ }
69
+
70
+ #ocs-editor .properties-list li {
71
+ margin-left: 10px;
72
+ padding: 5px 0;
73
+ cursor: pointer;
74
+ font-weight: bold;
75
+ }
76
+
77
+ #ocs-editor .properties-list li.selected {
78
+ font-weight: bold;
79
+ border-left: solid 1px #6f8992;
80
+ border-top: solid 1px #6f8992;
81
+ border-bottom: solid 1px #6f8992;
82
+ background: #e7efef;
83
+ padding: 7px 10px;
84
+ position: relative;
85
+ left: 1px;
86
+ }
87
+
88
+ #ocs-editor .row-container.has-error .properties-list li.selected {
89
+ border-color: #af2c2c;
90
+ background: #f7e8e8;
91
+ }
92
+
93
+ #ocs-editor .properties-list li.has-error {
94
+ font-weight: bold;
95
+ color: #d40707;
96
+ }
97
+
98
+ #ocs-editor .properties-list li.empty {
99
+ font-weight: normal;
100
+ -webkit-opacity: 0.8;
101
+ -khtml-opacity: 0.8;
102
+ -moz-opacity: 0.8;
103
+ opacity: 0.8;
104
+ }
105
+
106
+ #ocs-editor .properties-list li.hide {
107
+ display: none;
108
+ }
109
+
110
+ #ocs-editor .property-container {
111
+ position: absolute;
112
+ top: 0;
113
+ right: 0;
114
+ height: 350px;
115
+ overflow: auto;
116
+ width: 80%;
117
+ padding: 8px;
118
+ -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
119
+ -khtml-box-sizing: border-box;
120
+ -moz-box-sizing: border-box; /* Firefox, other Gecko */
121
+ box-sizing: border-box; /* Opera/IE 8+ */
122
+ display: none;
123
+ border-left: solid 1px #6f8992;
124
+ background: #e7efef;
125
+ z-index: 1;
126
+ }
127
+
128
+ #ocs-editor .property-container.selected {
129
+ display: block;
130
+ }
131
+
132
+ #ocs-editor .row-container.has-error .property-container {
133
+ border-color: #af2c2c;
134
+ background: #f7e8e8;
135
+ }
136
+
137
+ #ocs-editor .row-header {
138
+ padding: 3px;
139
+ background: #d1dedf;
140
+ color: #6f8992;
141
+ }
142
+
143
+ #ocs-editor .row-header .error {
144
+ padding: 0 10px;
145
+ }
146
+
147
+ #ocs-editor .row-container.selected .row-header .error {
148
+ color: #fff !important;
149
+ }
150
+
151
+ #ocs-editor .row-title {
152
+ padding: 2px 9px;
153
+ cursor: pointer;
154
+ font-weight: bold;
155
+ font-size: 1.3em;
156
+ }
157
+
158
+ #ocs-editor .row-actions {
159
+ float: right;
160
+ opacity: 0.7;
161
+ -moz-opacity: 0.7;
162
+ -webkit-opacity: 0.7;
163
+ -khtml-opacity: 0.7;
164
+ }
165
+ #ocs-editor .row-actions button {
166
+ margin-left: 5px;
167
+ }
168
+
169
+ #ocs-editor .row-container {
170
+ border: solid 1px #6f8992;
171
+ border-top: 0;
172
+ }
173
+
174
+ #ocs-editor .row-container.selected .row-header {
175
+ background: #6f8992;
176
+ color: #fff;
177
+ }
178
+
179
+ #ocs-editor .row-container.selected .row-actions {
180
+ opacity: 1;
181
+ -moz-opacity: 1;
182
+ -webkit-opacity: 1;
183
+ -khtml-opacity: 1;
184
+ }
185
+
186
+ #ocs-editor .row-container.has-error {
187
+ border: solid 1px #af2c2c;
188
+ }
189
+
190
+ #ocs-editor .row-container.has-error .row-header {
191
+ background: #f3c6c6;
192
+ color: #af2c2c;
193
+ }
194
+
195
+ #ocs-editor .row-container.selected.has-error .row-header {
196
+ background: #af2c2c;
197
+ color: #fff;
198
+ }
199
+
200
+ #ocs-editor textarea {
201
+ border: 0;
202
+ background: #fff;
203
+ display: block;
204
+ overflow: visible;
205
+ width: 100%;
206
+ height: auto;
207
+ -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
208
+ -moz-box-sizing: border-box; /* Firefox, other Gecko */
209
+ -khtml-box-sizing: border-box;
210
+ box-sizing: border-box; /* Opera/IE 8+ */
211
+ padding: 2px 0 2px 5px;
212
+ }
213
+
214
+ #ocs-editor .row-container textarea {
215
+ height: 100px;
216
+ }
217
+
218
+ #ocs-editor .field-container{
219
+ background: #666;
220
+ padding: 2px;
221
+ }
222
+
223
+ #ocs-editor .address-filter-list {
224
+ font-size: 0.9em;
225
+ padding: 2px 0 5px 0;
226
+ line-height: normal;
227
+ }
228
+
229
+ #ocs-editor .address-filter {
230
+ display: inline-block;
231
+ padding: 2px 7px;
232
+ margin: 1px;
233
+ cursor: pointer;
234
+ -webkit-border-radius: 5px;
235
+ -khtml-border-radius: 5px;
236
+ -moz-border-radius: 5px;
237
+ border-radius: 5px;
238
+ }
239
+
240
+ #ocs-editor .address-filter-group-label {
241
+ padding: 2px 7px;
242
+ margin: 1px;
243
+ cursor: pointer;
244
+ border: solid 1px #6f8992;
245
+ background: #6f8992;
246
+ display: inline-block;
247
+ }
248
+
249
+ #ocs-editor .address-filter-group {
250
+ padding: 2px;
251
+ color: #fff;
252
+ border: 0;
253
+ background: #6f8992;
254
+ display: block;
255
+ }
256
+
257
+ #ocs-editor .address-filter.known {
258
+ color: #000;
259
+ border: solid 1px #000;
260
+ background: #7f0;
261
+ }
262
+
263
+ #ocs-editor .address-filter.soft-cleaned {
264
+ /*color: #000;
265
+ border: solid 1px #000;
266
+ background: #f90;*/
267
+ }
268
+
269
+ #ocs-editor .address-filter.hard-cleaned {
270
+ color: #000;
271
+ border: solid 1px #000;
272
+ background: #f90;
273
+ }
274
+
275
+ #ocs-editor .address-filter.replaced {
276
+ color: #000;
277
+ border: solid 1px #000;
278
+ background: #f90;
279
+ }
280
+
281
+ #ocs-editor .address-filter.warning {
282
+ color: #000;
283
+ border: solid 1px #000;
284
+ background: #f90;
285
+ }
286
+
287
+ #ocs-editor .address-filter.unknown {
288
+ color: #000;
289
+ border: solid 1px #000;
290
+ background: #f00;
291
+ font-weight: bold;
292
+ }
293
+ #ocs-editor .address-filter.error {
294
+ color: #f00;
295
+ border: solid 1px #f00;
296
+ background: #dcc;
297
+ font-weight: bold;
298
+ }
299
+
300
+ #ocs-editor .bad {
301
+ text-decoration: line-through;
302
+ }
303
+
304
+ #ocs-editor .donate-container {
305
+ position: absolute;
306
+ bottom: 0;
307
+ border-top: solid 4px #dfdfdf;
308
+ padding: 0.25em 0 0 0;
309
+ width: 100%;
310
+ color: #eb5e00;
311
+ font-size: 1.25em;
312
+ font-weight: bold;
313
+ background: #fff;
314
+ }
315
+ #ocs-editor .donate-container table {
316
+ width: 100%;
317
+ }
318
+
319
+ #ocs-editor .donate-container .form-buttons {
320
+ text-align: right;
321
+ margin-bottom: 0;
322
+ white-space: nowrap;
323
+ }
324
+
325
+ #ocs-editor .ocseditor-page {
326
+ position: absolute;
327
+ top: 0;
328
+ left: 0;
329
+ width: 100%;
330
+ height: 100%;
331
+ z-index: 300;
332
+ display: none;
333
+ background: #fff;
334
+ }
335
+
336
+ #ocs-editor .owebia-address {
337
+ padding-left: 50px;
338
+ font-family: monospace;
339
+ }
340
+
341
+ #ocs-contextual-menu {
342
+ -webkit-box-shadow: 2px 2px 5px #000;
343
+ -khtml-box-shadow: 2px 2px 5px #000;
344
+ -moz-box-shadow: 2px 2px 5px #000;
345
+ box-shadow: 2px 2px 5px #000;
346
+ background: #d1dedf;
347
+ list-style: none;
348
+ margin: 0;
349
+ display: none;
350
+ border: solid 1px #6f8992;
351
+ padding-bottom: 1px;
352
+ }
353
+ #ocs-contextual-menu li {
354
+ font-size: 0.9em;
355
+ }
356
+
357
+ #ocs-contextual-menu a {
358
+ padding: 3px 7px;
359
+ display: block;
360
+ color: #000;
361
+ text-decoration: none;
362
+ }
363
+
364
+ #ocs-contextual-menu a:hover {
365
+ background: #6f8992;
366
+ color: #fff;
367
+ }
368
+
369
+ #ocs-contextual-menu span {
370
+ padding: 2px 7px;
371
+ display: block;
372
+ color: #000;
373
+ border-bottom: solid 1px #6f8992;
374
+ font-weight: bold;
375
+ margin-bottom: 1px;
376
+ }
377
+
378
+ #ocs-editor .ocseditor-page .code {
379
+ font-family: monospace;
380
+ word-wrap: break-word;
381
+ }
382
+ #ocs-editor .ocseditor-page div.code {
383
+ background-color: #efe8de;
384
+ border: solid 1px #5c5248;
385
+ border-left: solid 3px #5c5248;
386
+ padding: 10px 5px;
387
+ overflow: auto;
388
+ }
389
+ #ocs-editor .ocseditor-page span.code {
390
+ padding: 0 3px;
391
+ color: #522;
392
+ font-weight: bold;
393
+ }
394
+ #ocs-editor .ocseditor-page .code .comment {
395
+ color: #666;
396
+ }
397
+ #ocs-editor .ocseditor-page .code .string {
398
+ color: #009f00;
399
+ }
400
+ #ocs-editor .ocseditor-page p {
401
+ margin: 7px 0;
402
+ }
403
+
404
+ #ocs-editor .ocseditor-page ul {
405
+ margin: 0 0 15px 20px;
406
+ list-style: disc;
407
+ }
408
+
409
+ #ocs-editor .ocseditor-page h4 {
410
+ padding: 0 0 2px 0;
411
+ margin: 0;
412
+ border-bottom: solid 1px #dfdfdf;
413
+ }
414
+ #ocs-editor .tips {
415
+ background: #ffdb6f;
416
+ padding: 3px 10px;
417
+ margin: 10px 0;
418
+ }
419
+ #ocs-editor .tips p {
420
+ margin: 4px 0;
421
+ }
422
+ #ocs-editor .help-header, #ocs-editor .help-footer {
423
+ background: #d1dedf;
424
+ padding: 3px 10px;
425
+ margin: 0 0 10px 0;
426
+ }
427
+ #ocs-editor .help-footer {
428
+ margin: 10px 0 0 0;
429
+ }
430
+ #ocs-editor .help-header p, #ocs-editor .help-footer p {
431
+ margin: 4px 0;
432
+ }
433
+ #ocs-editor .help-header a, #ocs-editor .help-footer a {
434
+ color: #444;
435
+ }
436
+ #ocs-editor .ocseditor-page .new {
437
+ color: #0221a9;
438
+ }
439
+ #ocs-editor .table-of-contents {
440
+ margin: 15px 0;
441
+ padding: 15px;
442
+ background-color: #d1dedf;
443
+ }
444
+ #ocs-editor .table-of-contents ul {
445
+ padding: 0;
446
+ margin: 0;
447
+ list-style: none;
448
+ }
449
+ #ocs-editor .table-of-contents ul ul {
450
+ margin: 3px 0 5px 15px;
451
+ }
452
+ #ocs-editor .table-of-contents li {
453
+ padding: 2px 0;
454
+ margin: 0;
455
+ }
456
+ #ocs-editor .table-of-contents a {
457
+ color: #444;
458
+ }
459
+ #ocs-editor .table-of-contents li.new a {
460
+ color: #0221a9;
461
+ font-weight: bold;
462
+ }
463
+ #ocs-editor .table-of-contents a.deprecated {
464
+ color: #8f6e47;
465
+ }
js/chronopost/chronorelais/ocseditor.js CHANGED
@@ -1,676 +1,676 @@
1
- /**
2
- * Magento Chronopost Chronorelais Module
3
- *
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the Open Software License (OSL 3.0)
7
- * that is bundled with this package in the file LICENSE.txt.
8
- * It is also available through the world-wide-web at this URL:
9
- * http://opensource.org/licenses/osl-3.0.php
10
- * If you did not receive a copy of the license and are unable to
11
- * obtain it through the world-wide-web, please send an email
12
- * to license@magentocommerce.com so we can send you a copy immediately.
13
- *
14
- * @category Chronopost
15
- * @package Chronopost_Chronorelais
16
- * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
17
- * @author Antoine Lemoine
18
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
- */
20
-
21
- /**
22
- * @constructor
23
- */
24
- OCSEditor = function (options) {
25
- this.options = options;
26
-
27
- this.jwindow = jQuery(window);
28
- this.jeditor = null;
29
- this.jeditor_content = null;
30
- this.jtextarea = null;
31
- this.jcontextualmenu = null;
32
- this.mouse_event_owner = null;
33
- this.dialog_v_padding = 10;
34
- this.dialog_h_padding = 15;
35
- }
36
-
37
- OCSEditor.prototype = {
38
- /**
39
- * @private
40
- */
41
- _init: function () {
42
- var jeditor = this._dialog('ocs-editor',"<div style=\"width:100%;height:100%;position:relative;\" id=\"ocs-editor-content\"></div>");
43
- this.jeditor = jeditor;
44
- var jdialogbox = jeditor.find('.dialog-box');
45
- this.jeditor_content = jeditor.find('#ocs-editor-content');
46
- this.jeditor_content.css({width: jdialogbox.innerWidth()-this.dialog_h_padding*2, height: jdialogbox.innerHeight()-this.dialog_v_padding*2, border: '0'});
47
-
48
- var self = this;
49
- jQuery('#ocs-editor .address-filter-list > .address-filter').live('click',function (event) {
50
- var caller = jQuery(this);
51
- self._contextualMenu('address-filter',caller);
52
- jQuery('#ocs-contextual-menu').css({position: 'absolute', 'z-index': 100, left: event.pageX-7, top: event.pageY}).show();
53
- event.preventDefault();
54
- event.stopPropagation();
55
- });
56
- jQuery('#ocs-editor .property-container .field').live('blur',function (event) {
57
- self._updateProperty(this);
58
- event.preventDefault();
59
- event.stopPropagation();
60
- });
61
- /*jQuery('#ocs-editor .property-container textarea').live('change',function (event) {
62
- self._updateProperty(this);
63
- event.preventDefault();
64
- event.stopPropagation();
65
- });*/
66
- },
67
-
68
- /**
69
- * @private
70
- */
71
- _dialog: function (id, content) {
72
- var w = this.jwindow.width();
73
- var h = this.jwindow.height();
74
- var margin = 50;
75
- var v_padding = this.dialog_v_padding;
76
- var h_padding = this.dialog_h_padding;
77
- var width = w-2*margin;
78
- var height = h-2*margin;
79
- var dialog_w = Math.max(width+2*h_padding,350);
80
- var dialog_h = Math.max(height+2*v_padding,250);
81
- var top = (h-dialog_h)/2;
82
- var left = (w-dialog_w)/2;
83
- var margin_top = (dialog_h-height)/2-v_padding;
84
- var margin_left = (dialog_w-width)/2-h_padding;
85
- var jdialog = jQuery("<div style=\"position:fixed;top:0;left:0;width:100%;height:100%;z-index:100;\" id=\""+id+"\">"
86
- +"<div class=\"dialog-bg\" style=\"position:fixed;top:0;left:0;z-index:100;width:100%;height:100%;background:#000;\"></div>"
87
- +"<div class=\"dialog-box\" style=\"position:fixed;background:#fff;-moz-box-shadow: #000 0 0 10px;top:"+top+"px;left:"+left+"px;width:"+dialog_w+"px;"
88
- +"height:"+dialog_h+"px;z-index:200;\"><div style=\"padding:"+v_padding+"px "+h_padding+"px;margin:"+margin_top+"px 0 0 "+margin_left+"px;\">"
89
- +content+'</div></div></div>');
90
- jdialog.find('.dialog-bg').click(function(event){
91
- jdialog.fadeOut(function(){jdialog.hide();});
92
- })
93
- .css({
94
- opacity: '0.7'
95
- })
96
- ;
97
- jQuery('body').append(jdialog);
98
- return jdialog;
99
- },
100
-
101
- /**
102
- * @private
103
- */
104
- _contextualMenu: function (which, caller) {
105
- var self = this;
106
- this.mouse_event_owner = caller;
107
-
108
- if (this.jcontextualmenu==null) {
109
- var jcontextualmenu = jQuery('<ul id="ocs-contextual-menu" style="display:none;"></ul>');
110
- jcontextualmenu.click(function (event) {
111
- jcontextualmenu.hide();
112
- event.preventDefault();
113
- event.stopPropagation();
114
- });
115
- jQuery('body').append(jcontextualmenu);
116
- jQuery(document).mouseup(function (event) {
117
- if (self.mouse_event_owner!=null && self.mouse_event_owner.hasClass('files-container')) {
118
- self.mouse_event_owner.trigger(event);
119
- }
120
- jcontextualmenu.hide();
121
- });
122
- this.jcontextualmenu = jcontextualmenu;
123
- }
124
-
125
- switch (which) {
126
- case 'address-filter':
127
- this.jcontextualmenu.html(
128
- "<li><span>"+caller.attr('full-value')+"</span></li>"
129
- +(caller.hasClass('address-filter-group') ?
130
- "<li><a id=\"ungroup-link\" href=\"#\">"+this.options.menu_item_dissociate_label+"</a></li>"
131
- :
132
- ''
133
- )
134
- +"<li><a id=\"edit-link\" href=\"#\">"+this.options.menu_item_edit_label+"</a></li>"
135
- +"<li><a id=\"remove-link\" href=\"#\" onclick=\"\">"+this.options.menu_item_remove_label+"</a></li>"
136
- );
137
- var parent = caller.parents('.property-container');
138
- jQuery('#remove-link').click(function (event) {
139
- caller.fadeOut(null,function(){
140
- caller.remove();
141
- self.updateCountries(parent);
142
- });
143
- event.preventDefault();
144
- });
145
- jQuery('#edit-link').click(function (event) {
146
- var new_value = prompt(this.options.prompt_new_value_label,caller.attr('original-value'));
147
- self._ajax({
148
- data: {
149
- what: 'get-address-filters',
150
- input: new_value
151
- },
152
- success: function (msg) {
153
- caller.replaceWith(msg);
154
- self.updateCountries(parent);
155
- }
156
- });
157
- event.preventDefault();
158
- });
159
- jQuery('#ungroup-link').click(function (event) {
160
- self._dissociateAddressFiltersGroup(caller,100);
161
- event.preventDefault();
162
- });
163
- break;
164
- }
165
- },
166
-
167
- /**
168
- * @private
169
- */
170
- _ajax: function (args) {
171
- args.data.form_key = this.options.form_key;
172
- jQuery.ajax({
173
- type: 'POST',
174
- url: this.options.ajax_url,
175
- data: args.data,
176
- success: args.success
177
- });
178
- },
179
-
180
- /**
181
- * @private
182
- */
183
- _download: function (data) {
184
- data.form_key = this.options.form_key;
185
- data = jQuery.param(data);
186
- var inputs = '';
187
- jQuery.each(data.split('&'),function(){
188
- var tmp = this.split('=');
189
- inputs += '<input type="hidden" name="'+tmp[0]+'" value="'+tmp[1]+'"/>';
190
- });
191
- jQuery('<form action="'+this.options.ajax_url+'" method="post">'+inputs+'</form>').appendTo('body').submit().remove();
192
- },
193
-
194
- /**
195
- * @private
196
- */
197
- _checkCountries: function (parent) {
198
- var output = '';
199
- parent.find('.address-filter').each(function () {
200
- var country_code = jQuery(this).attr('country-code');
201
- output += country_code+',';
202
- if (country_code!='') {
203
- var tmp = parent.find('.country-'+country_code);
204
- if (tmp.size()>1) {
205
- tmp.addClass('warning');
206
- } else {
207
- tmp.removeClass('warning');
208
- }
209
- }
210
- });
211
- },
212
-
213
- /**
214
- * @private
215
- */
216
- _getConfig: function () {
217
- var self = this;
218
- var config = '';
219
- this.jeditor_content.find('.row-container').each(function(){
220
- var jrowcontainer = jQuery(this);
221
- if (jrowcontainer.hasClass('ignored-lines')) {
222
- config += jrowcontainer.find('.field').val()+"\n";
223
- } else {
224
- var comment = jrowcontainer.find('.property-container[property-name="*comment"] .field').val();
225
- if (comment!='') {
226
- var lines = comment.replace(/(?:\r\n|\n|\r)/,"\n").split("\n");
227
- for (var i=0; i<lines.length; i++) {
228
- if (lines[i].substr(0,1)!='#') lines[i] = '# '+lines[i];
229
- else lines[i] = '#'+lines[i];
230
- }
231
- config += lines.join("\n")+"\n";
232
- }
233
- config += "{\n";
234
- jrowcontainer.find('.property-container').each(function(){
235
- var jpropertycontainer = jQuery(this);
236
- var property = jpropertycontainer.attr('property-name');
237
- if (property!='*comment') {
238
- var value = null;
239
- if (property=='destination' || property=='origin') {
240
- value = self._getAddressFilter('compact-value',this,true,true);
241
- }
242
- else value = jpropertycontainer.find('.field').val();
243
- var property = jpropertycontainer.attr('property-name');
244
-
245
- switch (property) {
246
- case 'enabled':
247
- if (value!='1') config += "\t"+property+': false,'+"\n";
248
- break;
249
- default:
250
- if (value!='') config += "\t"+property+': "'+value+'",'+"\n";
251
- break;
252
- }
253
-
254
- }
255
- });
256
- config += "}\n";
257
- }
258
- });
259
- return config;
260
- },
261
-
262
- /**
263
- * @private
264
- */
265
- _dissociateAddressFiltersGroup: function (caller, delay) {
266
- var self = this;
267
- var childs = caller.children('.address-filter');
268
- if (delay>0) {
269
- childs.each(function (i) {
270
- var child = jQuery(this);
271
- child.delay(i*delay).fadeOut(null,function(){
272
- child.insertBefore(caller);
273
- child.fadeIn();
274
- if (i==childs.size()-1) {
275
- caller.fadeOut(null,function(){
276
- caller.remove();
277
- self.updateCountries(parent);
278
- });
279
- }
280
- });
281
- });
282
- } else {
283
- childs.insertBefore(caller);
284
- caller.remove();
285
- self.updateCountries(parent);
286
- }
287
- },
288
-
289
- /**
290
- * @private
291
- */
292
- _updateAddressFilters: function (object) {
293
- if (!(object instanceof jQuery)) object = jQuery(object);
294
- if (!object.hasClass('property-container')) object = object.parents('.property-container');
295
-
296
- var self = this;
297
- this._ajax({
298
- data: {
299
- what: 'get-address-filters',
300
- input: object.find('textarea').val()
301
- },
302
- success: function (msg) {
303
- object.find('.address-filter-list').html(msg);
304
- //self._checkCountries(object);
305
- }
306
- });
307
- },
308
-
309
- /**
310
- * @private
311
- */
312
- _updateProperty: function (object) {
313
- if (!(object instanceof jQuery)) object = jQuery(object);
314
-
315
- var property_container = object.parents('.property-container');
316
- var property_name = property_container.attr('property-name');
317
- switch (property_name) {
318
- case 'destination':
319
- case 'origin':
320
- this._updateAddressFilters(object);
321
- break;
322
- case 'label':
323
- this._updateRowTitle(object,property_container);
324
- break;
325
- }
326
- this._ajax({
327
- data: {
328
- what: 'check-config',
329
- config: encodeURIComponent(this._getConfig()),
330
- },
331
- success: function (msg) {
332
- jQuery('body').append(msg);
333
- }
334
- });
335
- var id = object.attr('id')+'-item';
336
- if (object.val().trim()=='') jQuery('#'+id).addClass('empty');
337
- else jQuery('#'+id).removeClass('empty');
338
- },
339
-
340
- /**
341
- * @private
342
- */
343
- _updateRowTitle: function (jtextarea) {
344
- var title = jtextarea.val().trim();
345
- if (title=='') title = this.options.default_row_label;
346
- jtextarea.parents('.row-container').find('.row-title').html(title);
347
- },
348
-
349
- /**
350
- * @private
351
- */
352
- _updateRowsUI: function () {
353
- var jrows = this.jeditor.find('.row-container');
354
- if (jrows.filter('.selected').size()==0) {
355
- jrows.eq(0).addClass('selected');
356
- }
357
- if (jrows.size()<=1) {
358
- jrows.find('.row-actions .delete').hide();
359
- } else {
360
- jrows.find('.row-actions .delete').show();
361
- }
362
- },
363
-
364
- /**
365
- * @private
366
- */
367
- /*_linearizeAddressFilters: function (object) {
368
- if (!(object instanceof jQuery)) object = jQuery(object);
369
- if (!object.hasClass('property-container')) object = object.parents('.property-container');
370
-
371
- var self = this;
372
- object.find('.address-filter-list .address-filter-group').each(function () {
373
- self._dissociateAddressFiltersGroup(jQuery(this),0);
374
- });
375
- },*/
376
-
377
- /**
378
- * @public
379
- */
380
- insertAtCaret: function (object, text_to_insert) {
381
- if (!(object instanceof jQuery)) {
382
- object = jQuery(object);
383
- if (object[0].nodeName!='textarea') object = object.parents('.property-container');
384
- }
385
- if (object.hasClass('property-container')) object = object.find('textarea');
386
-
387
- object.each(function (i) {
388
- if (document.selection) {
389
- this.focus();
390
- var sel = document.selection.createRange();
391
- sel.text = text_to_insert;
392
- this.focus();
393
- } else if (this.selectionStart || this.selectionStart=='0') {
394
- var start_index = this.selectionStart;
395
- var end_index = this.selectionEnd;
396
- var scroll_top = this.scrollTop;
397
- this.value = this.value.substring(0,start_index)+text_to_insert+this.value.substring(end_index,this.value.length);
398
- this.focus();
399
- this.selectionStart = start_index + text_to_insert.length;
400
- this.selectionEnd = start_index + text_to_insert.length;
401
- this.scrollTop = scroll_top;
402
- } else {
403
- this.value += text_to_insert;
404
- this.focus();
405
- }
406
- });
407
- },
408
-
409
- /**
410
- * @public
411
- */
412
- updateCountries: function (object) {
413
- if (!(object instanceof jQuery)) object = jQuery(object);
414
- if (!object.hasClass('property-container')) object = object.parents('.property-container');
415
-
416
- var list = object.find('.address-filter-list');
417
- var displayed_field = list.attr('displayed-field');
418
- if (displayed_field==null) displayed_field = 'original-value';
419
- var compact = list.attr('compact');
420
- if (compact==null) compact = false;
421
- else compact = compact=='1';
422
- this.displayCountry(displayed_field,object,compact);
423
- this._checkCountries(object);
424
- },
425
-
426
- /**
427
- * @private
428
- */
429
- _getAddressFilter: function (field, object, compact, linearize_groups) {
430
- if (!(object instanceof jQuery)) object = jQuery(object);
431
- if (!object.hasClass('property-container')) object = object.parents('.property-container');
432
-
433
- var values = [];
434
- object.find('.address-filter-list').attr('displayed-field',field).attr('compact',compact?'1':'0');
435
-
436
- if (linearize_groups) {
437
- object.find('.address-filter-list .address-filter').each(function () {
438
- var jfilter = jQuery(this);
439
- if (!jfilter.hasClass('address-filter-group')) values.push(jfilter.attr(field));
440
- });
441
- } else {
442
- object.find('.address-filter-list > .address-filter').each(function () {
443
- values.push(jQuery(this).attr(field));
444
- });
445
- }
446
- var excluding = object.find('.excluding:checked').val()=='1';
447
- return (excluding ? '* - (' : '')+values.join(','+(compact ? '' : ' '))+(excluding ? ')' : '');
448
- },
449
-
450
- /**
451
- * @public
452
- */
453
- displayCountry: function (field, object, compact) {
454
- if (!(object instanceof jQuery)) object = jQuery(object);
455
- if (!object.hasClass('property-container')) object = object.parents('.property-container');
456
-
457
- object.find('.field').val(this._getAddressFilter(field,object,compact,false));
458
- this._checkCountries(object);
459
- },
460
-
461
- /**
462
- * @public
463
- */
464
- selectProperty: function (code, property) {
465
- jQuery('#r-'+code+'-container .property-item, #r-'+code+'-container .property-container').removeClass('selected');
466
- jQuery('#r-'+code+'-p-'+property+'-item, #r-'+code+'-p-'+property+'-container').addClass('selected');
467
- },
468
-
469
- /**
470
- * @public
471
- */
472
- selectRow: function (code) {
473
- jQuery('#ocs-editor .row-container').removeClass('selected');
474
- jQuery('#r-'+code+'-container').addClass('selected');
475
- },
476
-
477
- /**
478
- * @public
479
- */
480
- resetErrors: function (code, property, error) {
481
- this.jeditor.find('.has-error').not('.ignored-lines').removeClass('has-error');
482
- this.jeditor.find('div.error').remove();
483
- },
484
-
485
- /**
486
- * @public
487
- */
488
- setError: function (code, property, error) {
489
- if (property=='') {
490
- jQuery('#r-'+code+'-container .row-header').append("<div class=\"error\">"+error+"</div>");
491
- } else {
492
- jQuery('#r-'+code+'-container').addClass('has-error');
493
- jQuery('#r-'+code+'-p-'+property+'-item').addClass('has-error');
494
- jQuery('#r-'+code+'-p-'+property+'-container').prepend("<div class=\"error\">"+error+"</div>");
495
- }
496
- },
497
-
498
- /**
499
- * @public
500
- */
501
- correct: function (code, property, value) {
502
- var jfield = jQuery('#r-'+code+'-p-'+property);
503
- jfield.val(value);
504
- this._updateProperty(jfield);
505
- },
506
-
507
- /**
508
- * @public
509
- */
510
- removeRow: function (object) {
511
- var self = this;
512
- var jrow = jQuery(object).parents('.row-container');
513
- jrow.fadeOut(null,function(){
514
- jrow.remove();
515
- self._updateRowsUI();
516
- });
517
- },
518
-
519
- /**
520
- * @public
521
- */
522
- addRow: function () {
523
- var self = this;
524
- this._ajax({
525
- data: {
526
- what: 'add-row'
527
- },
528
- success: function (msg) {
529
- var jcontainer = self.jeditor.find('.config-container');
530
- jcontainer.find('.row-container.selected').removeClass('selected');
531
- jcontainer.append(msg);
532
- self._updateRowsUI();
533
- }
534
- });
535
- },
536
-
537
- /**
538
- * @public
539
- */
540
- saveToFile: function () {
541
- this._download({
542
- what: 'save-to-file',
543
- config: this._getConfig(),
544
- });
545
- },
546
-
547
- /**
548
- * @public
549
- */
550
- save: function () {
551
- this.jtextarea.val(this._getConfig());
552
- this.close();
553
- },
554
-
555
- /**
556
- * @public
557
- */
558
- applyChanges: function () {
559
- this.loadConfig(this._getConfig());
560
- },
561
-
562
- /**
563
- * @public
564
- */
565
- loadConfig: function (config) {
566
- if (typeof config=='undefined') {
567
- config = jQuery('#ocs-editor-config-loader textarea').val()
568
- }
569
- var self = this;
570
- this._ajax({
571
- data: {
572
- what: 'load-config',
573
- config: config
574
- },
575
- success: function (msg) {
576
- jQuery('#ocs-editor-config-container').html(msg);
577
- self.jeditor.find('.address-filter-list').each(function(){
578
- self._checkCountries(jQuery(this));
579
- });
580
- self._updateRowsUI();
581
- jQuery('#ocs-editor-config-loader').slideUp().find('textarea').val('');
582
- }
583
- });
584
- },
585
-
586
- /**
587
- * @public
588
- */
589
- showConfigLoader: function () {
590
- jQuery('#ocs-editor-config-loader').slideDown();
591
- },
592
-
593
- /**
594
- * @public
595
- */
596
- hideConfigLoader: function () {
597
- jQuery('#ocs-editor-config-loader').slideUp().find('textarea').val('');
598
- },
599
-
600
- /**
601
- * @public
602
- */
603
- open: function (object) {
604
- if (this.jeditor==null) this._init();
605
-
606
- var jcell = jQuery(object).parents('td.value');
607
- this.jtextarea = jcell.find('textarea');
608
-
609
- this.jeditor_content.html('<div class=\"loading rule-param-wait\">'+this.options.loading_label+'</div>');
610
- this.jeditor.fadeIn();
611
-
612
- var self = this;
613
- this._ajax({
614
- data: {
615
- what: 'open',
616
- input: this.jtextarea.val()
617
- },
618
- success: function (msg) {
619
- self.jeditor_content.html(msg);
620
- var jconfig_container = self.jeditor.find('#ocs-editor-config-container');
621
- var height = self.jeditor_content.height() - jconfig_container.position().top - self.jeditor.find('.donate-container').height() - 15;
622
- jconfig_container.css({
623
- overflow: 'auto',
624
- height: height
625
- });
626
- self._updateRowsUI();
627
- }
628
- });
629
- },
630
-
631
- /**
632
- * @public
633
- */
634
- close: function () {
635
- this.jeditor.fadeOut();
636
- },
637
-
638
- /**
639
- * @public
640
- */
641
- openPage: function (page) {
642
- jQuery('#ocseditor-'+page+'-page').fadeIn();
643
- },
644
-
645
- /**
646
- * @public
647
- */
648
- closePage: function (object) {
649
- jQuery(object).parents('.ocseditor-page').fadeOut();
650
- },
651
-
652
- /**
653
- * @public
654
- */
655
- help: function (help_section) {
656
- this._ajax({
657
- data: {
658
- what: 'help',
659
- input: help_section
660
- },
661
- success: function (msg) {
662
- var jhelp_page = jQuery('#ocseditor-help-page');
663
- var jpage_content = jhelp_page.find('.page-content');
664
- var height = jhelp_page.height() - jpage_content.position().top - 15;
665
- jpage_content.css({
666
- overflow: 'auto',
667
- height: height
668
- });
669
- jpage_content.html(msg);
670
- }
671
- });
672
- jQuery('#ocseditor-help-page .page-content').html('<div class=\"loading rule-param-wait\">'+this.options.loading_label+'</div>');
673
- this.openPage('help');
674
- }
675
- }
676
-
1
+ /**
2
+ * Magento Chronopost Chronorelais Module
3
+ *
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL 3.0)
7
+ * that is bundled with this package in the file LICENSE.txt.
8
+ * It is also available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ * If you did not receive a copy of the license and are unable to
11
+ * obtain it through the world-wide-web, please send an email
12
+ * to license@magentocommerce.com so we can send you a copy immediately.
13
+ *
14
+ * @category Chronopost
15
+ * @package Chronopost_Chronorelais
16
+ * @copyright Copyright (c) 2008-10 Owebia (http://www.owebia.com/)
17
+ * @author Antoine Lemoine
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * @constructor
23
+ */
24
+ OCSEditor = function (options) {
25
+ this.options = options;
26
+
27
+ this.jwindow = jQuery(window);
28
+ this.jeditor = null;
29
+ this.jeditor_content = null;
30
+ this.jtextarea = null;
31
+ this.jcontextualmenu = null;
32
+ this.mouse_event_owner = null;
33
+ this.dialog_v_padding = 10;
34
+ this.dialog_h_padding = 15;
35
+ }
36
+
37
+ OCSEditor.prototype = {
38
+ /**
39
+ * @private
40
+ */
41
+ _init: function () {
42
+ var jeditor = this._dialog('ocs-editor',"<div style=\"width:100%;height:100%;position:relative;\" id=\"ocs-editor-content\"></div>");
43
+ this.jeditor = jeditor;
44
+ var jdialogbox = jeditor.find('.dialog-box');
45
+ this.jeditor_content = jeditor.find('#ocs-editor-content');
46
+ this.jeditor_content.css({width: jdialogbox.innerWidth()-this.dialog_h_padding*2, height: jdialogbox.innerHeight()-this.dialog_v_padding*2, border: '0'});
47
+
48
+ var self = this;
49
+ jQuery('#ocs-editor .address-filter-list > .address-filter').live('click',function (event) {
50
+ var caller = jQuery(this);
51
+ self._contextualMenu('address-filter',caller);
52
+ jQuery('#ocs-contextual-menu').css({position: 'absolute', 'z-index': 100, left: event.pageX-7, top: event.pageY}).show();
53
+ event.preventDefault();
54
+ event.stopPropagation();
55
+ });
56
+ jQuery('#ocs-editor .property-container .field').live('blur',function (event) {
57
+ self._updateProperty(this);
58
+ event.preventDefault();
59
+ event.stopPropagation();
60
+ });
61
+ /*jQuery('#ocs-editor .property-container textarea').live('change',function (event) {
62
+ self._updateProperty(this);
63
+ event.preventDefault();
64
+ event.stopPropagation();
65
+ });*/
66
+ },
67
+
68
+ /**
69
+ * @private
70
+ */
71
+ _dialog: function (id, content) {
72
+ var w = this.jwindow.width();
73
+ var h = this.jwindow.height();
74
+ var margin = 50;
75
+ var v_padding = this.dialog_v_padding;
76
+ var h_padding = this.dialog_h_padding;
77
+ var width = w-2*margin;
78
+ var height = h-2*margin;
79
+ var dialog_w = Math.max(width+2*h_padding,350);
80
+ var dialog_h = Math.max(height+2*v_padding,250);
81
+ var top = (h-dialog_h)/2;
82
+ var left = (w-dialog_w)/2;
83
+ var margin_top = (dialog_h-height)/2-v_padding;
84
+ var margin_left = (dialog_w-width)/2-h_padding;
85
+ var jdialog = jQuery("<div style=\"position:fixed;top:0;left:0;width:100%;height:100%;z-index:100;\" id=\""+id+"\">"
86
+ +"<div class=\"dialog-bg\" style=\"position:fixed;top:0;left:0;z-index:100;width:100%;height:100%;background:#000;\"></div>"
87
+ +"<div class=\"dialog-box\" style=\"position:fixed;background:#fff;-moz-box-shadow: #000 0 0 10px;top:"+top+"px;left:"+left+"px;width:"+dialog_w+"px;"
88
+ +"height:"+dialog_h+"px;z-index:200;\"><div style=\"padding:"+v_padding+"px "+h_padding+"px;margin:"+margin_top+"px 0 0 "+margin_left+"px;\">"
89
+ +content+'</div></div></div>');
90
+ jdialog.find('.dialog-bg').click(function(event){
91
+ jdialog.fadeOut(function(){jdialog.hide();});
92
+ })
93
+ .css({
94
+ opacity: '0.7'
95
+ })
96
+ ;
97
+ jQuery('body').append(jdialog);
98
+ return jdialog;
99
+ },
100
+
101
+ /**
102
+ * @private
103
+ */
104
+ _contextualMenu: function (which, caller) {
105
+ var self = this;
106
+ this.mouse_event_owner = caller;
107
+
108
+ if (this.jcontextualmenu==null) {
109
+ var jcontextualmenu = jQuery('<ul id="ocs-contextual-menu" style="display:none;"></ul>');
110
+ jcontextualmenu.click(function (event) {
111
+ jcontextualmenu.hide();
112
+ event.preventDefault();
113
+ event.stopPropagation();
114
+ });
115
+ jQuery('body').append(jcontextualmenu);
116
+ jQuery(document).mouseup(function (event) {
117
+ if (self.mouse_event_owner!=null && self.mouse_event_owner.hasClass('files-container')) {
118
+ self.mouse_event_owner.trigger(event);
119
+ }
120
+ jcontextualmenu.hide();
121
+ });
122
+ this.jcontextualmenu = jcontextualmenu;
123
+ }
124
+
125
+ switch (which) {
126
+ case 'address-filter':
127
+ this.jcontextualmenu.html(
128
+ "<li><span>"+caller.attr('full-value')+"</span></li>"
129
+ +(caller.hasClass('address-filter-group') ?
130
+ "<li><a id=\"ungroup-link\" href=\"#\">"+this.options.menu_item_dissociate_label+"</a></li>"
131
+ :
132
+ ''
133
+ )
134
+ +"<li><a id=\"edit-link\" href=\"#\">"+this.options.menu_item_edit_label+"</a></li>"
135
+ +"<li><a id=\"remove-link\" href=\"#\" onclick=\"\">"+this.options.menu_item_remove_label+"</a></li>"
136
+ );
137
+ var parent = caller.parents('.property-container');
138
+ jQuery('#remove-link').click(function (event) {
139
+ caller.fadeOut(null,function(){
140
+ caller.remove();
141
+ self.updateCountries(parent);
142
+ });
143
+ event.preventDefault();
144
+ });
145
+ jQuery('#edit-link').click(function (event) {
146
+ var new_value = prompt(this.options.prompt_new_value_label,caller.attr('original-value'));
147
+ self._ajax({
148
+ data: {
149
+ what: 'get-address-filters',
150
+ input: new_value
151
+ },
152
+ success: function (msg) {
153
+ caller.replaceWith(msg);
154
+ self.updateCountries(parent);
155
+ }
156
+ });
157
+ event.preventDefault();
158
+ });
159
+ jQuery('#ungroup-link').click(function (event) {
160
+ self._dissociateAddressFiltersGroup(caller,100);
161
+ event.preventDefault();
162
+ });
163
+ break;
164
+ }
165
+ },
166
+
167
+ /**
168
+ * @private
169
+ */
170
+ _ajax: function (args) {
171
+ args.data.form_key = this.options.form_key;
172
+ jQuery.ajax({
173
+ type: 'POST',
174
+ url: this.options.ajax_url,
175
+ data: args.data,
176
+ success: args.success
177
+ });
178
+ },
179
+
180
+ /**
181
+ * @private
182
+ */
183
+ _download: function (data) {
184
+ data.form_key = this.options.form_key;
185
+ data = jQuery.param(data);
186
+ var inputs = '';
187
+ jQuery.each(data.split('&'),function(){
188
+ var tmp = this.split('=');
189
+ inputs += '<input type="hidden" name="'+tmp[0]+'" value="'+tmp[1]+'"/>';
190
+ });
191
+ jQuery('<form action="'+this.options.ajax_url+'" method="post">'+inputs+'</form>').appendTo('body').submit().remove();
192
+ },
193
+
194
+ /**
195
+ * @private
196
+ */
197
+ _checkCountries: function (parent) {
198
+ var output = '';
199
+ parent.find('.address-filter').each(function () {
200
+ var country_code = jQuery(this).attr('country-code');
201
+ output += country_code+',';
202
+ if (country_code!='') {
203
+ var tmp = parent.find('.country-'+country_code);
204
+ if (tmp.size()>1) {
205
+ tmp.addClass('warning');
206
+ } else {
207
+ tmp.removeClass('warning');
208
+ }
209
+ }
210
+ });
211
+ },
212
+
213
+ /**
214
+ * @private
215
+ */
216
+ _getConfig: function () {
217
+ var self = this;
218
+ var config = '';
219
+ this.jeditor_content.find('.row-container').each(function(){
220
+ var jrowcontainer = jQuery(this);
221
+ if (jrowcontainer.hasClass('ignored-lines')) {
222
+ config += jrowcontainer.find('.field').val()+"\n";
223
+ } else {
224
+ var comment = jrowcontainer.find('.property-container[property-name="*comment"] .field').val();
225
+ if (comment!='') {
226
+ var lines = comment.replace(/(?:\r\n|\n|\r)/,"\n").split("\n");
227
+ for (var i=0; i<lines.length; i++) {
228
+ if (lines[i].substr(0,1)!='#') lines[i] = '# '+lines[i];
229
+ else lines[i] = '#'+lines[i];
230
+ }
231
+ config += lines.join("\n")+"\n";
232
+ }
233
+ config += "{\n";
234
+ jrowcontainer.find('.property-container').each(function(){
235
+ var jpropertycontainer = jQuery(this);
236
+ var property = jpropertycontainer.attr('property-name');
237
+ if (property!='*comment') {
238
+ var value = null;
239
+ if (property=='destination' || property=='origin') {
240
+ value = self._getAddressFilter('compact-value',this,true,true);
241
+ }
242
+ else value = jpropertycontainer.find('.field').val();
243
+ var property = jpropertycontainer.attr('property-name');
244
+
245
+ switch (property) {
246
+ case 'enabled':
247
+ if (value!='1') config += "\t"+property+': false,'+"\n";
248
+ break;
249
+ default:
250
+ if (value!='') config += "\t"+property+': "'+value+'",'+"\n";
251
+ break;
252
+ }
253
+
254
+ }
255
+ });
256
+ config += "}\n";
257
+ }
258
+ });
259
+ return config;
260
+ },
261
+
262
+ /**
263
+ * @private
264
+ */
265
+ _dissociateAddressFiltersGroup: function (caller, delay) {
266
+ var self = this;
267
+ var childs = caller.children('.address-filter');
268
+ if (delay>0) {
269
+ childs.each(function (i) {
270
+ var child = jQuery(this);
271
+ child.delay(i*delay).fadeOut(null,function(){
272
+ child.insertBefore(caller);
273
+ child.fadeIn();
274
+ if (i==childs.size()-1) {
275
+ caller.fadeOut(null,function(){
276
+ caller.remove();
277
+ self.updateCountries(parent);
278
+ });
279
+ }
280
+ });
281
+ });
282
+ } else {
283
+ childs.insertBefore(caller);
284
+ caller.remove();
285
+ self.updateCountries(parent);
286
+ }
287
+ },
288
+
289
+ /**
290
+ * @private
291
+ */
292
+ _updateAddressFilters: function (object) {
293
+ if (!(object instanceof jQuery)) object = jQuery(object);
294
+ if (!object.hasClass('property-container')) object = object.parents('.property-container');
295
+
296
+ var self = this;
297
+ this._ajax({
298
+ data: {
299
+ what: 'get-address-filters',
300
+ input: object.find('textarea').val()
301
+ },
302
+ success: function (msg) {
303
+ object.find('.address-filter-list').html(msg);
304
+ //self._checkCountries(object);
305
+ }
306
+ });
307
+ },
308
+
309
+ /**
310
+ * @private
311
+ */
312
+ _updateProperty: function (object) {
313
+ if (!(object instanceof jQuery)) object = jQuery(object);
314
+
315
+ var property_container = object.parents('.property-container');
316
+ var property_name = property_container.attr('property-name');
317
+ switch (property_name) {
318
+ case 'destination':
319
+ case 'origin':
320
+ this._updateAddressFilters(object);
321
+ break;
322
+ case 'label':
323
+ this._updateRowTitle(object,property_container);
324
+ break;
325
+ }
326
+ this._ajax({
327
+ data: {
328
+ what: 'check-config',
329
+ config: encodeURIComponent(this._getConfig()),
330
+ },
331
+ success: function (msg) {
332
+ jQuery('body').append(msg);
333
+ }
334
+ });
335
+ var id = object.attr('id')+'-item';
336
+ if (object.val().trim()=='') jQuery('#'+id).addClass('empty');
337
+ else jQuery('#'+id).removeClass('empty');
338
+ },
339
+
340
+ /**
341
+ * @private
342
+ */
343
+ _updateRowTitle: function (jtextarea) {
344
+ var title = jtextarea.val().trim();
345
+ if (title=='') title = this.options.default_row_label;
346
+ jtextarea.parents('.row-container').find('.row-title').html(title);
347
+ },
348
+
349
+ /**
350
+ * @private
351
+ */
352
+ _updateRowsUI: function () {
353
+ var jrows = this.jeditor.find('.row-container');
354
+ if (jrows.filter('.selected').size()==0) {
355
+ jrows.eq(0).addClass('selected');
356
+ }
357
+ if (jrows.size()<=1) {
358
+ jrows.find('.row-actions .delete').hide();
359
+ } else {
360
+ jrows.find('.row-actions .delete').show();
361
+ }
362
+ },
363
+
364
+ /**
365
+ * @private
366
+ */
367
+ /*_linearizeAddressFilters: function (object) {
368
+ if (!(object instanceof jQuery)) object = jQuery(object);
369
+ if (!object.hasClass('property-container')) object = object.parents('.property-container');
370
+
371
+ var self = this;
372
+ object.find('.address-filter-list .address-filter-group').each(function () {
373
+ self._dissociateAddressFiltersGroup(jQuery(this),0);
374
+ });
375
+ },*/
376
+
377
+ /**
378
+ * @public
379
+ */
380
+ insertAtCaret: function (object, text_to_insert) {
381
+ if (!(object instanceof jQuery)) {
382
+ object = jQuery(object);
383
+ if (object[0].nodeName!='textarea') object = object.parents('.property-container');
384
+ }
385
+ if (object.hasClass('property-container')) object = object.find('textarea');
386
+
387
+ object.each(function (i) {
388
+ if (document.selection) {
389
+ this.focus();
390
+ var sel = document.selection.createRange();
391
+ sel.text = text_to_insert;
392
+ this.focus();
393
+ } else if (this.selectionStart || this.selectionStart=='0') {
394
+ var start_index = this.selectionStart;
395
+ var end_index = this.selectionEnd;
396
+ var scroll_top = this.scrollTop;
397
+ this.value = this.value.substring(0,start_index)+text_to_insert+this.value.substring(end_index,this.value.length);
398
+ this.focus();
399
+ this.selectionStart = start_index + text_to_insert.length;
400
+ this.selectionEnd = start_index + text_to_insert.length;
401
+ this.scrollTop = scroll_top;
402
+ } else {
403
+ this.value += text_to_insert;
404
+ this.focus();
405
+ }
406
+ });
407
+ },
408
+
409
+ /**
410
+ * @public
411
+ */
412
+ updateCountries: function (object) {
413
+ if (!(object instanceof jQuery)) object = jQuery(object);
414
+ if (!object.hasClass('property-container')) object = object.parents('.property-container');
415
+
416
+ var list = object.find('.address-filter-list');
417
+ var displayed_field = list.attr('displayed-field');
418
+ if (displayed_field==null) displayed_field = 'original-value';
419
+ var compact = list.attr('compact');
420
+ if (compact==null) compact = false;
421
+ else compact = compact=='1';
422
+ this.displayCountry(displayed_field,object,compact);
423
+ this._checkCountries(object);
424
+ },
425
+
426
+ /**
427
+ * @private
428
+ */
429
+ _getAddressFilter: function (field, object, compact, linearize_groups) {
430
+ if (!(object instanceof jQuery)) object = jQuery(object);
431
+ if (!object.hasClass('property-container')) object = object.parents('.property-container');
432
+
433
+ var values = [];
434
+ object.find('.address-filter-list').attr('displayed-field',field).attr('compact',compact?'1':'0');
435
+
436
+ if (linearize_groups) {
437
+ object.find('.address-filter-list .address-filter').each(function () {
438
+ var jfilter = jQuery(this);
439
+ if (!jfilter.hasClass('address-filter-group')) values.push(jfilter.attr(field));
440
+ });
441
+ } else {
442
+ object.find('.address-filter-list > .address-filter').each(function () {
443
+ values.push(jQuery(this).attr(field));
444
+ });
445
+ }
446
+ var excluding = object.find('.excluding:checked').val()=='1';
447
+ return (excluding ? '* - (' : '')+values.join(','+(compact ? '' : ' '))+(excluding ? ')' : '');
448
+ },
449
+
450
+ /**
451
+ * @public
452
+ */
453
+ displayCountry: function (field, object, compact) {
454
+ if (!(object instanceof jQuery)) object = jQuery(object);
455
+ if (!object.hasClass('property-container')) object = object.parents('.property-container');
456
+
457
+ object.find('.field').val(this._getAddressFilter(field,object,compact,false));
458
+ this._checkCountries(object);
459
+ },
460
+
461
+ /**
462
+ * @public
463
+ */
464
+ selectProperty: function (code, property) {
465
+ jQuery('#r-'+code+'-container .property-item, #r-'+code+'-container .property-container').removeClass('selected');
466
+ jQuery('#r-'+code+'-p-'+property+'-item, #r-'+code+'-p-'+property+'-container').addClass('selected');
467
+ },
468
+
469
+ /**
470
+ * @public
471
+ */
472
+ selectRow: function (code) {
473
+ jQuery('#ocs-editor .row-container').removeClass('selected');
474
+ jQuery('#r-'+code+'-container').addClass('selected');
475
+ },
476
+
477
+ /**
478
+ * @public
479
+ */
480
+ resetErrors: function (code, property, error) {
481
+ this.jeditor.find('.has-error').not('.ignored-lines').removeClass('has-error');
482
+ this.jeditor.find('div.error').remove();
483
+ },
484
+
485
+ /**
486
+ * @public
487
+ */
488
+ setError: function (code, property, error) {
489
+ if (property=='') {
490
+ jQuery('#r-'+code+'-container .row-header').append("<div class=\"error\">"+error+"</div>");
491
+ } else {
492
+ jQuery('#r-'+code+'-container').addClass('has-error');
493
+ jQuery('#r-'+code+'-p-'+property+'-item').addClass('has-error');
494
+ jQuery('#r-'+code+'-p-'+property+'-container').prepend("<div class=\"error\">"+error+"</div>");
495
+ }
496
+ },
497
+
498
+ /**
499
+ * @public
500
+ */
501
+ correct: function (code, property, value) {
502
+ var jfield = jQuery('#r-'+code+'-p-'+property);
503
+ jfield.val(value);
504
+ this._updateProperty(jfield);
505
+ },
506
+
507
+ /**
508
+ * @public
509
+ */
510
+ removeRow: function (object) {
511
+ var self = this;
512
+ var jrow = jQuery(object).parents('.row-container');
513
+ jrow.fadeOut(null,function(){
514
+ jrow.remove();
515
+ self._updateRowsUI();
516
+ });
517
+ },
518
+
519
+ /**
520
+ * @public
521
+ */
522
+ addRow: function () {
523
+ var self = this;
524
+ this._ajax({
525
+ data: {
526
+ what: 'add-row'
527
+ },
528
+ success: function (msg) {
529
+ var jcontainer = self.jeditor.find('.config-container');
530
+ jcontainer.find('.row-container.selected').removeClass('selected');
531
+ jcontainer.append(msg);
532
+ self._updateRowsUI();
533
+ }
534
+ });
535
+ },
536
+
537
+ /**
538
+ * @public
539
+ */
540
+ saveToFile: function () {
541
+ this._download({
542
+ what: 'save-to-file',
543
+ config: this._getConfig(),
544
+ });
545
+ },
546
+
547
+ /**
548
+ * @public
549
+ */
550
+ save: function () {
551
+ this.jtextarea.val(this._getConfig());
552
+ this.close();
553
+ },
554
+
555
+ /**
556
+ * @public
557
+ */
558
+ applyChanges: function () {
559
+ this.loadConfig(this._getConfig());
560
+ },
561
+
562
+ /**
563
+ * @public
564
+ */
565
+ loadConfig: function (config) {
566
+ if (typeof config=='undefined') {
567
+ config = jQuery('#ocs-editor-config-loader textarea').val()
568
+ }
569
+ var self = this;
570
+ this._ajax({
571
+ data: {
572
+ what: 'load-config',
573
+ config: config
574
+ },
575
+ success: function (msg) {
576
+ jQuery('#ocs-editor-config-container').html(msg);
577
+ self.jeditor.find('.address-filter-list').each(function(){
578
+ self._checkCountries(jQuery(this));
579
+ });
580
+ self._updateRowsUI();
581
+ jQuery('#ocs-editor-config-loader').slideUp().find('textarea').val('');
582
+ }
583
+ });
584
+ },
585
+
586
+ /**
587
+ * @public
588
+ */
589
+ showConfigLoader: function () {
590
+ jQuery('#ocs-editor-config-loader').slideDown();
591
+ },
592
+
593
+ /**
594
+ * @public
595
+ */
596
+ hideConfigLoader: function () {
597
+ jQuery('#ocs-editor-config-loader').slideUp().find('textarea').val('');
598
+ },
599
+
600
+ /**
601
+ * @public
602
+ */
603
+ open: function (object) {
604
+ if (this.jeditor==null) this._init();
605
+
606
+ var jcell = jQuery(object).parents('td.value');
607
+ this.jtextarea = jcell.find('textarea');
608
+
609
+ this.jeditor_content.html('<div class=\"loading rule-param-wait\">'+this.options.loading_label+'</div>');
610
+ this.jeditor.fadeIn();
611
+
612
+ var self = this;
613
+ this._ajax({
614
+ data: {
615
+ what: 'open',
616
+ input: this.jtextarea.val()
617
+ },
618
+ success: function (msg) {
619
+ self.jeditor_content.html(msg);
620
+ var jconfig_container = self.jeditor.find('#ocs-editor-config-container');
621
+ var height = self.jeditor_content.height() - jconfig_container.position().top - self.jeditor.find('.donate-container').height() - 15;
622
+ jconfig_container.css({
623
+ overflow: 'auto',
624
+ height: height
625
+ });
626
+ self._updateRowsUI();
627
+ }
628
+ });
629
+ },
630
+
631
+ /**
632
+ * @public
633
+ */
634
+ close: function () {
635
+ this.jeditor.fadeOut();
636
+ },
637
+
638
+ /**
639
+ * @public
640
+ */
641
+ openPage: function (page) {
642
+ jQuery('#ocseditor-'+page+'-page').fadeIn();
643
+ },
644
+
645
+ /**
646
+ * @public
647
+ */
648
+ closePage: function (object) {
649
+ jQuery(object).parents('.ocseditor-page').fadeOut();
650
+ },
651
+
652
+ /**
653
+ * @public
654
+ */
655
+ help: function (help_section) {
656
+ this._ajax({
657
+ data: {
658
+ what: 'help',
659
+ input: help_section
660
+ },
661
+ success: function (msg) {
662
+ var jhelp_page = jQuery('#ocseditor-help-page');
663
+ var jpage_content = jhelp_page.find('.page-content');
664
+ var height = jhelp_page.height() - jpage_content.position().top - 15;
665
+ jpage_content.css({
666
+ overflow: 'auto',
667
+ height: height
668
+ });
669
+ jpage_content.html(msg);
670
+ }
671
+ });
672
+ jQuery('#ocseditor-help-page .page-content').html('<div class=\"loading rule-param-wait\">'+this.options.loading_label+'</div>');
673
+ this.openPage('help');
674
+ }
675
+ }
676
+
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Chronopost</name>
4
- <version>0.2.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -9,8 +9,8 @@
9
  <summary>Cette extension officielle permet de proposer &#xE0; vos clients le mode de livraison Chronopost</summary>
10
  <description>Chronopost offre le choix parmi 2 solutions de livraison en France et 1 &#xE0; l'international pour toutes vos commandes en ligne :&#xD;
11
  &#xD;
12
- Chronopost livraison Express &#xE0; domicile. Colis livr&#xE9; le lendemain avant 13h &#xE0; l'adresse de votre choix&#xD;
13
- Chrono Relais, colis disponible le lendemain &#xE0; partir de 13h dans l'un de 3500 points Chrono Relais de votre choix&#xD;
14
  Chrono Express : livraison express partout dans le monde. L'Europe livr&#xE9;e en 1 &#xE0; 3 jours et le reste du monde en 3 &#xE0; 5 jours.&#xD;
15
  &#xD;
16
  Afin de vous accompagner dans le d&#xE9;veloppement des sites e-marchands sur la plateforme Magento, vous trouverez dans le module Chronopost un package de solutions :&#xD;
@@ -19,7 +19,7 @@ Afin de vous accompagner dans le d&#xE9;veloppement des sites e-marchands sur la
19
  Le calcul du co&#xFB;t du transport (via logiciel QuickCost)&#xD;
20
  Le suivi int&#xE9;gr&#xE9;&#xD;
21
  Le choix entre 3 solutions possibles d'&#xE9;tiquetage des envois selon les besoins de l'e-commer&#xE7;ant&#xD;
22
- Test&#xE9; et valid&#xE9; sur Magento 1.6.2&#xD;
23
  &#xD;
24
  --&gt; Un manuel d'installation est &#xE0; votre disposition dans la partie 'Docs' afin de vous guider dans l'installation du module. (A lire imp&#xE9;rativement)&#xD;
25
  &#xD;
@@ -28,7 +28,7 @@ ATTENTION : Pour toute mise en production du module Chronopost, un contrat avec
28
  R&#xE9;alisation Adexos&#xD;
29
  &#xD;
30
  Ce module est d&#xE9;vellop&#xE9; &#xE0; partir de l'extension Owebia Shipping 2</description>
31
- <notes>Version destin&#xE9;e &#xE0; Magento 1.6.X et sup&#xE9;rieures&#xD;
32
  ------------&#xD;
33
  Support du multi-shipping.&#xD;
34
  Correction sur le filtrage des commandes pour l'export.&#xD;
@@ -36,8 +36,8 @@ Correction du nom de point relais manquant dans les exports.&#xD;
36
  Modification de libell&#xE9; en admin pour explication du Quickcost.</notes>
37
  <authors><author><name>Benjamin GOSSELET</name><user>Chronopost</user><email>bgosselet@adexos.fr</email></author></authors>
38
  <date>2012-05-11</date>
39
- <time>14:22:43</time>
40
- <contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="chronorelais"><dir name="import"><file name="form.phtml" hash="356aadf2bb0182b23f7af38888a0cd38"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="chronorelais.xml" hash="a298640a9d7a9d5c9ad90b81801d0584"/></dir><dir name="template"><dir name="chronorelais"><dir name="checkout"><dir name="multishipping"><file name="shipping.phtml" hash="89ac65c42722975ec8b872a1e69b5ae9"/><dir name="shipping_method"><file name="chronorelais.phtml" hash="f184ce28e619c185434810545bc82d9f"/></dir></dir><dir name="onepage"><dir name="shipping_method"><file name="available.phtml" hash="7377a159a92db28c30f86ad52921a5b0"/><file name="chronorelais.phtml" hash="4d9d318e0add0ff4a70155541180654a"/></dir><file name="shipping_method.phtml" hash="4f084424b6dcdb187753f09357f46898"/></dir></dir><dir name="sales"><dir name="order"><file name="history.phtml" hash="f95a1860a4cf463f6fca48273cc45eaf"/><file name="recent.phtml" hash="8045fbbe75510efc55da31455d2cc47a"/></dir></dir></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir name="Chronopost"><dir name="Chronorelais"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Config.php" hash="b38741ddd97fcae5dd276239fb3c6b70"/></dir></dir></dir></dir></dir><dir name="Checkout"><dir name="Multishipping"><dir name="Shipping"><dir name="Method"><file name="Chronorelais.php" hash="a095d54809c9ad04453758635879127e"/></dir></dir></dir><dir name="Onepage"><dir name="Shipping"><dir name="Method"><file name="Chronorelais.php" hash="c4d908310310e4cd90833378df260599"/></dir></dir></dir></dir><file name="Detail.php" hash="005fa3b6e5918c6c9779402fab5713f2"/><dir name="Export"><dir name="Orders"><file name="Grid.php" hash="bec368bcf626b7c7665a3f042be17905"/></dir><file name="Orders.php" hash="9ada10bd85cb58122e722b3e82c71e37"/></dir><file name="Filter.php" hash="28f80e3ab34f6ff03b61f070ccbac697"/><dir name="Import"><file name="Form.php" hash="56c6e3787c05e58d57b48ec4b1421468"/></dir><dir name="Sales"><file name="Impression.php" hash="619599b136b9cc49f01dba5b08ee8428"/><dir name="Order"><dir name="Shipment"><file name="View.php" hash="f5407d7d14aa59acb844479da5046900"/></dir></dir><dir name="Shipment"><file name="Grid.php" hash="06928b811ee8d71e5e1fdcc0814ff9e0"/></dir></dir></dir><dir name="Controller"><file name="Abstract.php" hash="94680cd88c6af59764dedb613b08d5f6"/></dir><dir name="Helper"><file name="Data.php" hash="70531f8f903a63986c063f65553d643d"/></dir><dir name="Model"><dir name="Carrier"><file name="AbstractChronorelais.php" hash="f4957f6d660c4adb0328f9f2d73da1e2"/><file name="AbstractChronorelaisShipping.php" hash="1adab13f3659559803b338ad86205d43"/><file name="Chronoexpress.php" hash="bc867a6b98966ada549a0b81ec334b64"/><file name="Chronopost.php" hash="c4d4525447d2801d28d921eaedc35a9a"/><file name="Chronorelais.php" hash="5cfcb83c23d05585fdc50f8b2747fc40"/></dir><dir name="Config"><dir name="Source"><file name="Civility.php" hash="fe6ec6eebe6faffdd0bb65479d91cd5d"/><file name="EndOfLineCharacter.php" hash="3fe6b6069a9efdc29ad0d3f7d1cf4794"/><file name="FieldDelimiter.php" hash="3e023d40aeca50932e62ff97eed6317e"/><file name="FieldSeparator.php" hash="ce30c5974a893bd5467334d574dd578a"/><file name="FileCharset.php" hash="6cc4ebab95735bd121af16e0eedd90d6"/><file name="FileExtension.php" hash="597c3e78e7584bf7c4b7b2ebad6d2a65"/><file name="PrintMode.php" hash="67e8a6e98e12c7e72624ba5322076c00"/></dir></dir><dir name="Sales"><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Shipping.php" hash="2e69db363011f84ef2cdb5d0e9d4c4df"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="AjaxController.php" hash="1905b32a1366d3c27277836364737e98"/><dir name="Checkout"><file name="MultishippingController.php" hash="c44aa875ba9683e1d6311390c4e77080"/><file name="OnepageController.php" hash="6986dd92fff2085260d011234fc298f6"/></dir><file name="ExportController.php" hash="9a24df876d6d7c48df53d99ff5498d6b"/><file name="ImportController.php" hash="7cce42f41a838e1cb3e220742020eeff"/><file name="RelaisController.php" hash="5d48155ddb7cc2d4effbbfdeb4f3946d"/><dir name="Sales"><file name="ImpressionController.php" hash="7b040384c03fec329f66ec0afb2d4d44"/><dir name="Order"><file name="ShipmentController.php" hash="992c53ee433323ef9fb1c0f101c54ea3"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="8a9bc798220b1a454bef20bddcee2dd2"/><file name="system.xml" hash="1eb275cce36bcc0c8322f3f95fd5deb1"/></dir><dir name="includes"><file name="ChronorelaisShippingHelper.php" hash="9a3aa6bb5b3846102d78450d76c93fdf"/><file name="countries.inc.php" hash="d21cd393c7c0ebc83beccc99950d6ab1"/></dir><dir name="sql"><dir name="chronorelais_setup"><file name="mysql4-install-0.1.0.php" hash="c307802a7bd10c1ecce06799b04569c2"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="ea3358055a851a96b673c721202045be"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="961f41dc1012d0917504f9bb5f5d106c"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="b85470889421f652c3d01b96072f579c"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="def69d0ae26b0d130d2ce6e0838e5d7f"/></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="Chronopost_Chronorelais.csv" hash="76475aa4fa500c135a666e47bab62ddf"/></dir><dir name="fr_FR"><file name="Chronopost_Chronorelais.csv" hash="ebcbda74580c951df42e932aa434a33a"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="chronorelais"><file name="Picto_Chrono_Relais.png" hash="1ea0f0c410d237adf23d5905cd8431f5"/><file name="Thumbs.db" hash="2e16ed23c37d1aa29a6caf73f513a648"/><file name="ac.png" hash="0c04f70da35d43a2636cfbd6ad2b10d5"/><file name="chronopost.png" hash="93e5b22e2f280923df8d503f5c8e5b92"/><file name="chronorelais.css" hash="a1fef1934a1114be6c8f4eebde2b5263"/><file name="chronorelais.png" hash="87c42de75ddafe495dfc0248c2a688b4"/><file name="chronorelaismap.js" hash="60db33945bcaeeaf58e1a57cb3a3f23d"/><file name="home.png" hash="7904b495e94047eb3406e260bc660cce"/><file name="ico_ac_shaded.gif" hash="e55d9b2071fb976cf5331b6273a40731"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="WSChronopost_Chronorelais.xml" hash="e614759d6b46c0c25f6c26d6e9dff45a"/></dir></target><target name="mage"><dir name="js"><dir name="chronopost"><dir name="chronorelais"><file name="ocseditor.css" hash="1bfc847153768d6729cdad7cb1abe443"/><file name="ocseditor.js" hash="8b7f29ddf7faff2fd3a63af18ba666aa"/></dir></dir></dir></target></contents>
41
  <compatible/>
42
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
43
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Chronopost</name>
4
+ <version>0.1.8</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
9
  <summary>Cette extension officielle permet de proposer &#xE0; vos clients le mode de livraison Chronopost</summary>
10
  <description>Chronopost offre le choix parmi 2 solutions de livraison en France et 1 &#xE0; l'international pour toutes vos commandes en ligne :&#xD;
11
  &#xD;
12
+ Chronopost livraison Express &#xE0; domicile. Colis livr&#xE9; le lendemain avant 13h &#xE0; l'adresse de votre choix.&#xD;
13
+ Chrono Relais, colis livr&#xE9; en Chronopost le lendemain avant 13 h dans l'un des 3500 relais Pickup de votre choix.&#xD;
14
  Chrono Express : livraison express partout dans le monde. L'Europe livr&#xE9;e en 1 &#xE0; 3 jours et le reste du monde en 3 &#xE0; 5 jours.&#xD;
15
  &#xD;
16
  Afin de vous accompagner dans le d&#xE9;veloppement des sites e-marchands sur la plateforme Magento, vous trouverez dans le module Chronopost un package de solutions :&#xD;
19
  Le calcul du co&#xFB;t du transport (via logiciel QuickCost)&#xD;
20
  Le suivi int&#xE9;gr&#xE9;&#xD;
21
  Le choix entre 3 solutions possibles d'&#xE9;tiquetage des envois selon les besoins de l'e-commer&#xE7;ant&#xD;
22
+ Test&#xE9; et valid&#xE9; sur Magento 1.4.2 et 1.5.1&#xD;
23
  &#xD;
24
  --&gt; Un manuel d'installation est &#xE0; votre disposition dans la partie 'Docs' afin de vous guider dans l'installation du module. (A lire imp&#xE9;rativement)&#xD;
25
  &#xD;
28
  R&#xE9;alisation Adexos&#xD;
29
  &#xD;
30
  Ce module est d&#xE9;vellop&#xE9; &#xE0; partir de l'extension Owebia Shipping 2</description>
31
+ <notes>Version destin&#xE9;e &#xE0; Magento 1.5.X et ant&#xE9;rieures&#xD;
32
  ------------&#xD;
33
  Support du multi-shipping.&#xD;
34
  Correction sur le filtrage des commandes pour l'export.&#xD;
36
  Modification de libell&#xE9; en admin pour explication du Quickcost.</notes>
37
  <authors><author><name>Benjamin GOSSELET</name><user>Chronopost</user><email>bgosselet@adexos.fr</email></author></authors>
38
  <date>2012-05-11</date>
39
+ <time>15:05:41</time>
40
+ <contents><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="chronorelais"><dir name="import"><file name="form.phtml" hash="2bcee11adb6765d11f85d29fbdc36268"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="chronorelais.xml" hash="a298640a9d7a9d5c9ad90b81801d0584"/></dir><dir name="template"><dir name="chronorelais"><dir name="checkout"><dir name="multishipping"><file name="shipping.phtml" hash="97672f80aee38d7207fb30b142e88d6c"/><dir name="shipping_method"><file name="chronorelais.phtml" hash="c79a77477e490b09b87371f359b662cd"/></dir></dir><dir name="onepage"><dir name="shipping_method"><file name="available.phtml" hash="42513d95375d29d9fb3f010a8162ca97"/><file name="chronorelais.phtml" hash="4d9d318e0add0ff4a70155541180654a"/></dir><file name="shipping_method.phtml" hash="833af4005f6b97a286284b7e5e76307a"/></dir></dir><dir name="sales"><dir name="order"><file name="history.phtml" hash="9b78d023838eb24d651c4e57715ebf42"/><file name="recent.phtml" hash="959a6b73dfe078bc89005c41ada204d9"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir><dir name="Chronopost"><dir name="Chronorelais"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Config.php" hash="d2d76b40f2701c54066256fac1be3909"/></dir></dir></dir></dir></dir><dir name="Checkout"><dir name="Multishipping"><dir name="Shipping"><dir name="Method"><file name="Chronorelais.php" hash="e0098707ef18f1049572ede06a2211f2"/></dir></dir></dir><dir name="Onepage"><dir name="Shipping"><dir name="Method"><file name="Chronorelais.php" hash="0d2decd6669715fea0247f4ec60563da"/></dir></dir></dir></dir><file name="Detail.php" hash="77d61f06b9ae3672da44436f3d92b6c0"/><dir name="Export"><dir name="Orders"><file name="Grid.php" hash="6ab81964d8dc3cc28e39811843bd9b36"/></dir><file name="Orders.php" hash="696444f17e23e5705f327bd42613fc47"/></dir><file name="Filter.php" hash="d4d004eca8c3a30e3b817b44c6086cc4"/><dir name="Import"><file name="Form.php" hash="439debe57531bd3a10e6d8f4432888a2"/></dir><dir name="Sales"><file name="Impression.php" hash="8c39604219f83824de82046e438bb95f"/><dir name="Order"><dir name="Shipment"><file name="View.php" hash="14e7d3d466eb16dc5db8c8f6f03d1edb"/></dir></dir><dir name="Shipment"><file name="Copy of Grid.php" hash="f72d35dcf2b3be9d8d5f24342c0633f4"/><file name="Grid-bkp-03-02-11.php" hash="e3b798fa5259cca5e9d3a08a75fb3f76"/><file name="Grid.php" hash="eecff77b3df133e29145ce71c161a7f5"/></dir></dir></dir><dir name="Controller"><file name="Abstract.php" hash="98d3fe6e8efc0a6668de4906189908b4"/></dir><dir name="Helper"><file name="Data.php" hash="d07f138f5f59925c6828eea1ca83518c"/></dir><dir name="Model"><dir name="Carrier"><file name="AbstractChronorelais.php" hash="07b792fb62878de20d6ac123b3989b4a"/><file name="AbstractChronorelaisShipping.php" hash="4f0e97260a60a6c31e26d8299b15e559"/><file name="Chronoexpress.php" hash="1739a8e98b5dd942b6785645acd1b5a3"/><file name="Chronopost.php" hash="ecc97117ac7ac23b717408e00860d980"/><file name="Chronorelais.php" hash="1da97bed0cfaf406d85bcb918a958329"/></dir><dir name="Config"><dir name="Source"><file name="Civility.php" hash="a05123281a3a3740f1cf56755c1d8ef8"/><file name="EndOfLineCharacter.php" hash="6c45af21d32b0aec8726fe6b76d89746"/><file name="FieldDelimiter.php" hash="958cc3a7f87f68a262a37650d953b23a"/><file name="FieldSeparator.php" hash="28e5d99c612a05d8418563bb112e2733"/><file name="FileCharset.php" hash="8e4e9212d6c6d6a08edb63863c128188"/><file name="FileExtension.php" hash="155284e9305a4a5cd295009ffbba455a"/><file name="PrintMode.php" hash="916bfa01c473cbde28c22d1ee1fa8d90"/></dir></dir><dir name="Sales"><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Shipping.php" hash="fbc2d92286b2df2d2b8f35c018788f4a"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="AjaxController.php" hash="5c4ae938aa8ba38c93d3b2c74cbe172f"/><dir name="Checkout"><file name="MultishippingController.php" hash="691b6aa28ebc6fc046e13c12cb021291"/><file name="OnepageController.php" hash="86032a20d67f38ab96359df791bf8bb7"/></dir><file name="ExportController.php" hash="9a24df876d6d7c48df53d99ff5498d6b"/><file name="ImportController.php" hash="385f03f379f1322f7ba62e522a17eecd"/><file name="RelaisController.php" hash="9bb0c3e37a63780552321514507687a7"/><dir name="Sales"><file name="ImpressionController.php" hash="6c667125023b475d062af9db4d252dfb"/><dir name="Order"><file name="ShipmentController.php" hash="361e5ce78c3dc1685c35bad4d92b96e4"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="8a9bc798220b1a454bef20bddcee2dd2"/><file name="system.xml" hash="1eb275cce36bcc0c8322f3f95fd5deb1"/></dir><dir name="includes"><file name="ChronorelaisShippingHelper.php" hash="962c6245ae453be28f52183afdcaf564"/><file name="countries.inc.php" hash="d21cd393c7c0ebc83beccc99950d6ab1"/></dir><dir name="sql"><dir name="chronorelais_setup"><file name="mysql4-install-0.1.0.php" hash="ebffe564d680a631bd4978af3cbe2031"/><file name="mysql4-upgrade-0.1.0-0.1.1.php" hash="d6c42651e2271471e98ce50adce83be1"/><file name="mysql4-upgrade-0.1.1-0.1.2.php" hash="00d62f07389de34d0a934163bee5a7da"/><file name="mysql4-upgrade-0.1.2-0.1.3.php" hash="f96d485cb1f26069a16230becda65d28"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="a603da2c287896f85a39e912f014f8a7"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="en_US"><file name="Chronopost_Chronorelais.csv" hash="76475aa4fa500c135a666e47bab62ddf"/></dir><dir name="fr_FR"><file name="Chronopost_Chronorelais.csv" hash="ebcbda74580c951df42e932aa434a33a"/></dir></dir></target><target name="mageskin"><dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="chronorelais"><file name="Picto_Chrono_Relais.png" hash="1ea0f0c410d237adf23d5905cd8431f5"/><file name="Thumbs.db" hash="2e16ed23c37d1aa29a6caf73f513a648"/><file name="ac.png" hash="0c04f70da35d43a2636cfbd6ad2b10d5"/><file name="chronopost.png" hash="93e5b22e2f280923df8d503f5c8e5b92"/><file name="chronorelais.css" hash="a1fef1934a1114be6c8f4eebde2b5263"/><file name="chronorelais.png" hash="87c42de75ddafe495dfc0248c2a688b4"/><file name="chronorelaismap.js" hash="60db33945bcaeeaf58e1a57cb3a3f23d"/><file name="home.png" hash="7904b495e94047eb3406e260bc660cce"/><file name="ico_ac_shaded.gif" hash="e55d9b2071fb976cf5331b6273a40731"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="WSChronopost_Chronorelais.xml" hash="a432624b16f2f25dff3c66937e1d8f5d"/></dir></dir></target><target name="mage"><dir name="js"><dir name="chronopost"><dir name="chronorelais"><file name="ocseditor.css" hash="3c8847aafc00b562d38085ef1a5143a9"/><file name="ocseditor.js" hash="33b7333d5115c7ca18c5be78cdb9f38b"/></dir></dir></dir></target></contents>
41
  <compatible/>
42
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
43
  </package>