Lengow_Export - Version 2.2.4

Version Notes

New version of Lengow's Connector

Download this release

Release Info

Developer Lengow
Extension Lengow_Export
Version 2.2.4
Comparing to
See all releases


Code changes from version 2.1.2 to 2.2.4

Files changed (132) hide show
  1. app/code/community/Lengow/Dashboard/Block/Adminhtml/Dashboard/Charts.php +0 -28
  2. app/code/community/Lengow/Dashboard/Block/Adminhtml/Dashboard/Diagrams.php +0 -29
  3. app/code/community/Lengow/Dashboard/Helper/Data.php +0 -10
  4. app/code/community/Lengow/Dashboard/Model/Config.php +0 -22
  5. app/code/community/Lengow/Dashboard/etc/config.xml +0 -78
  6. app/code/community/Lengow/Export/Block/Adminhtml/Product.php +18 -12
  7. app/code/community/Lengow/Export/Block/Adminhtml/Product/Grid.php +94 -78
  8. app/code/community/Lengow/Export/Helper/Data.php +38 -25
  9. app/code/community/Lengow/Export/Helper/Security.php +50 -29
  10. app/code/community/Lengow/Export/Model/Catalog/Product.php +143 -121
  11. app/code/community/Lengow/Export/Model/Config.php +238 -236
  12. app/code/community/Lengow/Export/Model/Convert/Parser/Product.php +15 -12
  13. app/code/community/Lengow/Export/Model/Export/Rewrite/Catalog/Config.php +16 -32
  14. app/code/community/Lengow/Export/Model/Feed/Abstract.php +17 -10
  15. app/code/community/Lengow/Export/Model/Feed/Csv.php +62 -23
  16. app/code/community/Lengow/Export/Model/Feed/Json.php +17 -12
  17. app/code/community/Lengow/Export/Model/Feed/Xml.php +16 -11
  18. app/code/community/Lengow/Export/Model/Feed/Yaml.php +22 -15
  19. app/code/community/Lengow/Export/Model/Generate.php +232 -176
  20. app/code/community/Lengow/Export/Model/Generateoptimize.php +464 -421
  21. app/code/community/Lengow/Export/Model/Observer.php +35 -32
  22. app/code/community/Lengow/Export/Model/Product/Collection.php +13 -4
  23. app/code/community/Lengow/Export/Model/Resource/Catalog/Product.php +10 -3
  24. app/code/community/Lengow/Export/Model/Shipping/Carrier/Lengow.php +36 -29
  25. app/code/community/Lengow/Export/Model/Source/Attributes.php +14 -10
  26. app/code/community/Lengow/Export/Model/Source/Types.php +13 -9
  27. app/code/community/Lengow/Export/Model/System/Config/Backend/Apikey.php +24 -20
  28. app/code/community/Lengow/Export/Model/System/Config/Source/Category/Level.php +9 -8
  29. app/code/community/Lengow/Export/Model/System/Config/Source/Format.php +29 -18
  30. app/code/community/Lengow/Export/Model/System/Config/Source/Getattributes.php +16 -13
  31. app/code/community/Lengow/Export/Model/System/Config/Source/Images.php +17 -13
  32. app/code/community/Lengow/Export/Model/System/Config/Source/Status.php +24 -16
  33. app/code/community/Lengow/Export/Model/System/Config/Source/Types.php +31 -19
  34. app/code/community/Lengow/Export/controllers/Adminhtml/Lengow/{ExportController.php → ProductController.php} +27 -27
  35. app/code/community/Lengow/Export/controllers/FeedController.php +22 -16
  36. app/code/community/Lengow/Export/etc/config.xml +2 -2
  37. app/code/community/Lengow/Export/etc/system.xml +0 -10
  38. app/code/community/Lengow/Feed/Block/Adminhtml/Feed.php +0 -57
  39. app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Grid.php +0 -216
  40. app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Renderer/Migrate.php +0 -26
  41. app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Renderer/Select.php +0 -54
  42. app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Renderer/Url.php +0 -25
  43. app/code/community/Lengow/Feed/Helper/Data.php +0 -51
  44. app/code/community/Lengow/Feed/Model/Config.php +0 -26
  45. app/code/community/Lengow/Feed/Model/Feed.php +0 -136
  46. app/code/community/Lengow/Feed/controllers/Adminhtml/Lengow/FeedController.php +0 -105
  47. app/code/community/Lengow/Feed/etc/config.xml +0 -112
  48. app/code/community/Lengow/Feed/etc/system.xml +0 -40
  49. app/code/community/Lengow/Sync/Block/Adminhtml/Cron.php +7 -5
  50. app/code/community/Lengow/Sync/Block/Adminhtml/Cron/Grid.php +14 -15
  51. app/code/community/Lengow/Sync/Block/Adminhtml/Import.php +16 -5
  52. app/code/community/Lengow/Sync/Block/Adminhtml/Log.php +20 -17
  53. app/code/community/Lengow/Sync/Block/Adminhtml/Log/Grid.php +18 -13
  54. app/code/community/Lengow/Sync/Block/Adminhtml/Order.php +19 -15
  55. app/code/community/Lengow/Sync/Block/Adminhtml/Order/Grid.php +80 -73
  56. app/code/community/Lengow/Sync/Block/Adminhtml/Order/Tab.php +24 -13
  57. app/code/community/Lengow/Sync/Block/Payment/Info/Purchaseorder.php +7 -5
  58. app/code/community/Lengow/Sync/Block/System/Config/Form/Hidden.php +24 -0
  59. app/code/community/Lengow/Sync/Helper/Api.php +10 -8
  60. app/code/community/Lengow/Sync/Helper/Cron.php +5 -5
  61. app/code/community/Lengow/Sync/Helper/Data.php +78 -44
  62. app/code/community/Lengow/Sync/Model/Config.php +86 -76
  63. app/code/community/Lengow/Sync/Model/Connector.php +177 -228
  64. app/code/community/Lengow/Sync/Model/Connector/Exception.php +62 -49
  65. app/code/community/Lengow/Sync/Model/Connectorv2.php +323 -0
  66. app/code/community/Lengow/Sync/Model/Customer/Customer.php +91 -67
  67. app/code/community/Lengow/Sync/Model/Customer/Customerv2.php +205 -0
  68. app/code/community/Lengow/Sync/Model/File.php +13 -5
  69. app/code/community/Lengow/Sync/Model/Import.php +512 -261
  70. app/code/community/Lengow/Sync/Model/Importv2.php +541 -0
  71. app/code/community/Lengow/Sync/Model/Log.php +47 -25
  72. app/code/community/Lengow/Sync/Model/Marketplace.php +410 -285
  73. app/code/community/Lengow/Sync/Model/Marketplace/Exception.php +26 -14
  74. app/code/community/Lengow/Sync/Model/Marketplacev2.php +416 -0
  75. app/code/community/Lengow/Sync/Model/Mysql4/Log.php +10 -7
  76. app/code/community/Lengow/Sync/Model/Mysql4/Log/Collection.php +10 -7
  77. app/code/community/Lengow/Sync/Model/Mysql4/Orderline.php +19 -0
  78. app/code/community/Lengow/Sync/Model/Mysql4/Orderline/Collection.php +20 -0
  79. app/code/community/Lengow/Sync/Model/Observer.php +305 -113
  80. app/code/community/Lengow/Sync/Model/Order.php +200 -83
  81. app/code/community/Lengow/Sync/Model/Orderline.php +37 -0
  82. app/code/community/Lengow/Sync/Model/Orderv2.php +305 -0
  83. app/code/community/Lengow/Sync/Model/Payment/Method/Lengow.php +14 -10
  84. app/code/community/Lengow/Sync/Model/Quote.php +108 -69
  85. app/code/community/Lengow/Sync/Model/Quote/Item.php +6 -4
  86. app/code/community/Lengow/Sync/Model/Quotev2.php +168 -0
  87. app/code/community/Lengow/Sync/Model/Shipping/Carrier/Lengow.php +23 -16
  88. app/code/community/Lengow/Sync/Model/System/Config/Source/Customer/Group.php +13 -11
  89. app/code/community/Lengow/Sync/Model/System/Config/Source/Shipping/Carrier.php +18 -7
  90. app/code/community/Lengow/Sync/Model/System/Config/Source/Shipping/Method.php +31 -16
  91. app/code/community/Lengow/Sync/controllers/Adminhtml/Lengow/DebugController.php +10 -7
  92. app/code/community/Lengow/Sync/controllers/Adminhtml/Lengow/LogController.php +20 -17
  93. app/code/community/Lengow/Sync/controllers/Adminhtml/Lengow/OrderController.php +139 -79
  94. app/code/community/Lengow/Sync/controllers/ApiController.php +16 -11
  95. app/code/community/Lengow/Sync/etc/config.xml +56 -13
  96. app/code/community/Lengow/Sync/etc/marketplaces.xml +2169 -387
  97. app/code/community/Lengow/Sync/etc/system.xml +0 -10
  98. app/code/community/Lengow/Sync/etc/wsdl.xml +0 -34
  99. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-install-2.0.0.0.php +2 -2
  100. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.0.0.0-2.0.0.1.php +2 -3
  101. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.0.2-2.1.0.php +2 -2
  102. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.1.2-2.2.0.php +72 -0
  103. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.0-2.2.1.php +8 -0
  104. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.1-2.2.2.php +8 -0
  105. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.2-2.2.3.php +8 -0
  106. app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.3-2.2.4.php +8 -0
  107. app/code/community/Lengow/Tracker/Block/Adminhtml/System/Config/Check.php +13 -25
  108. app/code/community/Lengow/Tracker/Block/Tag/Capsule.php +147 -113
  109. app/code/community/Lengow/Tracker/Block/Tag/Simple.php +48 -22
  110. app/code/community/Lengow/Tracker/Block/Tracker.php +30 -28
  111. app/code/community/Lengow/Tracker/Helper/Check.php +19 -15
  112. app/code/community/Lengow/Tracker/Helper/Data.php +6 -5
  113. app/code/community/Lengow/Tracker/Model/Capsule.php +16 -14
  114. app/code/community/Lengow/Tracker/Model/Config.php +13 -10
  115. app/code/community/Lengow/Tracker/Model/System/Config/Source/Identifiant.php +12 -3
  116. app/code/community/Lengow/Tracker/Model/System/Config/Source/Tracker.php +24 -8
  117. app/code/community/Lengow/Tracker/Model/Tracker.php +47 -15
  118. app/code/community/Lengow/Tracker/etc/config.xml +5 -1
  119. app/code/community/Lengow/Tracker/etc/plugins.xml +4 -4
  120. app/code/community/Lengow/Tracker/etc/system.xml +59 -6
  121. app/design/adminhtml/default/default/layout/lengow.xml +4 -27
  122. app/design/adminhtml/default/default/template/lengow/dashboard/charts.phtml +0 -86
  123. app/design/adminhtml/default/default/template/lengow/debug/index.phtml +109 -79
  124. app/design/adminhtml/default/default/template/lengow/feed/grid.phtml +0 -61
  125. app/design/frontend/base/default/layout/lengow.xml +1 -6
  126. app/design/frontend/base/default/template/lengow/tracker/simpletag.phtml +17 -2
  127. app/design/frontend/base/default/template/lengow/tracker/tagcapsule.phtml +4 -3
  128. app/etc/modules/Lengow_Connector.xml +2 -16
  129. app/locale/fr_FR/Lengow_Connector.csv +23 -26
  130. package.xml +5 -5
  131. skin/adminhtml/default/default/lengow/css/admin.css +3 -0
  132. skin/frontend/base/default/lengow/js/tracker.js +26 -27
app/code/community/Lengow/Dashboard/Block/Adminhtml/Dashboard/Charts.php DELETED
@@ -1,28 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow_Tracker Tracking Block Capsule
5
- *
6
- * @category Lengow
7
- * @package Lengow_Tracker
8
- * @author Romain Le Polh <romain@lengow.com>
9
- */
10
- class Lengow_Dashboard_Block_Adminhtml_Dashboard_Charts extends Mage_Core_Block_Template {
11
-
12
- protected $_data = array();
13
-
14
- public function __construct() {
15
- parent::__construct();
16
-
17
- $this->setData('config_model', Mage::getSingleton('lendashboard/config'));
18
- $this->setData('id_client', $this->getData('config_model')->get('general/login'));
19
- $this->setData('id_group', $this->getData('config_model')->get('general/group'));
20
- $this->setData('api_key', $this->getData('config_model')->get('general/api_key'));
21
- }
22
-
23
- protected function _prepareLayout() {
24
- parent::_prepareLayout();
25
- $this->setTemplate('lengow/dashboard/charts.phtml');
26
- return $this;
27
- }
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Dashboard/Block/Adminhtml/Dashboard/Diagrams.php DELETED
@@ -1,29 +0,0 @@
1
- <?php
2
- /**
3
- * Lengow dashboard Block Dashboard diagrams
4
- *
5
- * @category Lengow
6
- * @package Lengow_Dashboard
7
- * @author Romain Le Polh <romain@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
- */
11
-
12
- class Lengow_Dashboard_Block_Adminhtml_Dashboard_Diagrams extends Mage_Adminhtml_Block_Dashboard_Diagrams {
13
-
14
- protected $_data = array();
15
-
16
- public function __construct() {
17
- parent::__construct();
18
- }
19
-
20
- protected function _prepareLayout(){
21
- parent::_prepareLayout();
22
- $this->addTab('lengow', array(
23
- 'label' => Mage::helper('adminhtml')->__('Lengow'),
24
- 'content' => $this->getLayout()->createBlock('lendashboard/adminhtml_dashboard_charts')->toHtml(),
25
- 'active' => false
26
- ));
27
- }
28
-
29
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Dashboard/Helper/Data.php DELETED
@@ -1,10 +0,0 @@
1
- <?php
2
- /**
3
- * Lengow Dashboard Helper
4
- * @category Lengow
5
- * @package Lengow_Dashboard
6
- * @author Romain Le Polh
7
- */
8
- class Lengow_Dashboard_Helper_Data extends Mage_Core_Helper_Abstract {
9
-
10
- }
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Dashboard/Model/Config.php DELETED
@@ -1,22 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow dashboard model config
5
- *
6
- * @category Lengow
7
- * @package Lengow_Dashboard
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Dashboard_Model_Config extends Varien_Object {
13
-
14
- public function setStore($id_store) {
15
- $this->_id_store = $id_store;
16
- }
17
-
18
- public function get($key) {
19
- return Mage::getStoreConfig('lentracker/' . $key, $this->_id_store);
20
- }
21
-
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Dashboard/etc/config.xml DELETED
@@ -1,78 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Lengow_Dashboard>
5
- <version>2.1.2</version>
6
- </Lengow_Dashboard>
7
- </modules>
8
- <admin>
9
- <routers>
10
- <adminhtml>
11
- <args>
12
- <modules>
13
- <lendashboard before="Mage_Adminhtml">Lengow_Dashboard_Adminhtml</lendashboard>
14
- </modules>
15
- </args>
16
- </adminhtml>
17
- </routers>
18
- </admin>
19
- <global>
20
- <models>
21
- <lendashboard>
22
- <class>Lengow_Dashboard_Model</class>
23
- <resourceModel>dashboard_mysql4</resourceModel>
24
- </lendashboard>
25
- <dashboard_mysql4>
26
- <class>Lengow_Dashboard_Model_Mysql4</class>
27
- <entities>
28
- <manageorders_log>
29
- <table>lengow_log</table>
30
- </manageorders_log>
31
- </entities>
32
- </dashboard_mysql4>
33
- </models>
34
- <resources>
35
- <lendashboard_setup>
36
- <connection>
37
- <use>core_setup</use>
38
- </connection>
39
- </lendashboard_setup>
40
- <lendashboard_write>
41
- <connection>
42
- <use>core_write</use>
43
- </connection>
44
- </lendashboard_write>
45
- <lendashboard_read>
46
- <connection>
47
- <use>core_read</use>
48
- </connection>
49
- </lendashboard_read>
50
- </resources>
51
- <blocks>
52
- <adminhtml>
53
- <rewrite>
54
- <dashboard_diagrams>Lengow_Dashboard_Block_Adminhtml_Dashboard_Diagrams</dashboard_diagrams>
55
- </rewrite>
56
- </adminhtml>
57
- <lendashboard>
58
- <class>Lengow_Dashboard_Block</class>
59
- </lendashboard>
60
- </blocks>
61
- <helpers>
62
- <lendashboard>
63
- <class>Lengow_Dashboard_Helper</class>
64
- </lendashboard>
65
- </helpers>
66
- </global>
67
- <adminhtml>
68
- <translate>
69
- <modules>
70
- <Lengow_Dashboard>
71
- <files>
72
- <default>Lengow_Connector.csv</default>
73
- </files>
74
- </Lengow_Dashboard>
75
- </modules>
76
- </translate>
77
- </adminhtml>
78
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Export/Block/Adminhtml/Product.php CHANGED
@@ -1,19 +1,22 @@
1
  <?php
 
2
  /**
3
- * Lengow select products block
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Block_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_Container {
 
12
 
13
  /**
14
  * Set template
15
  */
16
- public function __construct() {
 
17
  parent::__construct();
18
  }
19
 
@@ -22,11 +25,12 @@ class Lengow_Export_Block_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_
22
  *
23
  * @return Mage_Adminhtml_Block_Catalog_Product
24
  */
25
- protected function _prepareLayout() {
 
26
  $this->_addButton('export', array(
27
- 'label' => Mage::helper('lenexport')->__('See the export feed'),
28
- 'onclick' => 'popWin(\''.$this->getUrl('lengow/feed', array('_current'=>true)).'\', \'_blank\')',
29
- 'class' => 'add'
30
  ));
31
  $this->setChild('grid', $this->getLayout()->createBlock('lenexport/adminhtml_product_grid', 'product.grid'));
32
  return parent::_prepareLayout();
@@ -37,7 +41,8 @@ class Lengow_Export_Block_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_
37
  *
38
  * @return string
39
  */
40
- public function getGridHtml() {
 
41
  return $this->getChildHtml('grid');
42
  }
43
 
@@ -46,9 +51,10 @@ class Lengow_Export_Block_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_
46
  *
47
  * @return bool
48
  */
49
- public function isSingleStoreMode() {
 
50
  if (!Mage::app()->isSingleStoreMode()) {
51
- return false;
52
  }
53
  return true;
54
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow export block adminhtml product
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Block_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_Container
13
+ {
14
 
15
  /**
16
  * Set template
17
  */
18
+ public function __construct()
19
+ {
20
  parent::__construct();
21
  }
22
 
25
  *
26
  * @return Mage_Adminhtml_Block_Catalog_Product
27
  */
28
+ protected function _prepareLayout()
29
+ {
30
  $this->_addButton('export', array(
31
+ 'label' => Mage::helper('lenexport')->__('See the export feed'),
32
+ 'onclick' => 'popWin(\'' . $this->getUrl('lengow/feed', array('_current' => true)) . '\', \'_blank\')',
33
+ 'class' => 'add'
34
  ));
35
  $this->setChild('grid', $this->getLayout()->createBlock('lenexport/adminhtml_product_grid', 'product.grid'));
36
  return parent::_prepareLayout();
41
  *
42
  * @return string
43
  */
44
+ public function getGridHtml()
45
+ {
46
  return $this->getChildHtml('grid');
47
  }
48
 
51
  *
52
  * @return bool
53
  */
54
+ public function isSingleStoreMode()
55
+ {
56
  if (!Mage::app()->isSingleStoreMode()) {
57
+ return false;
58
  }
59
  return true;
60
  }
app/code/community/Lengow/Export/Block/Adminhtml/Product/Grid.php CHANGED
@@ -1,16 +1,19 @@
1
  <?php
 
2
  /**
3
- * Lengow grid products block
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid {
 
12
 
13
- public function __construct() {
 
14
  parent::__construct();
15
  $this->setId('productGrid');
16
  $this->setDefaultSort('entity_id');
@@ -20,32 +23,36 @@ class Lengow_Export_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Wi
20
  $this->setVarNameFilter('product_filter');
21
  }
22
 
23
- protected function _getStore() {
24
- $storeId = (int) $this->getRequest()->getParam('store', 0);
 
25
  return Mage::app()->getStore($storeId);
26
  }
27
 
28
- protected function _prepareCollection() {
 
29
  $store = $this->_getStore();
30
  $collection = Mage::getModel('catalog/product')->getCollection()
31
- ->addAttributeToSelect('sku')
32
- ->addAttributeToSelect('name')
33
- ->addAttributeToSelect('lengow_product')
34
- ->addAttributeToSelect('attribute_set_id')
35
- ->addAttributeToSelect('type_id')
36
- ->joinField('qty',
37
- 'cataloginventory/stock_item',
38
- 'qty',
39
- 'product_id=entity_id',
40
- '{{table}}.stock_id=1',
41
- 'left');
42
 
43
  if ($store->getId()) {
44
  $collection->setStoreId($store->getId());
45
  $collection->addStoreFilter($store);
46
- $collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner', $store->getId());
 
47
  $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store->getId());
48
- $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store->getId());
 
49
  $collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store->getId());
50
  } else {
51
  $collection->addAttributeToSelect('price');
@@ -58,7 +65,8 @@ class Lengow_Export_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Wi
58
  return $this;
59
  }
60
 
61
- protected function _addColumnFilterToCollection($column) {
 
62
  if ($this->getCollection()) {
63
  if ($column->getId() == 'websites') {
64
  $this->getCollection()->joinField('websites',
@@ -72,134 +80,142 @@ class Lengow_Export_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Wi
72
  return parent::_addColumnFilterToCollection($column);
73
  }
74
 
75
- protected function _prepareColumns() {
 
76
  $this->addColumn('entity_id',
77
  array(
78
- 'header'=> Mage::helper('catalog')->__('ID'),
79
  'width' => '50px',
80
- 'type' => 'number',
81
  'index' => 'entity_id',
82
- ));
83
  $this->addColumn('name',
84
  array(
85
- 'header'=> Mage::helper('catalog')->__('Name'),
86
  'index' => 'name',
87
- ));
88
  $store = $this->_getStore();
89
  if ($store->getId()) {
90
  $this->addColumn('custom_name',
91
  array(
92
- 'header'=> Mage::helper('catalog')->__('Name In %s', $store->getName()),
93
  'index' => 'custom_name',
94
- ));
95
  }
96
  $this->addColumn('type',
97
  array(
98
- 'header'=> Mage::helper('catalog')->__('Type'),
99
  'width' => '60px',
100
  'index' => 'type_id',
101
- 'type' => 'options',
102
  'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
103
- ));
104
  $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
105
  ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
106
  ->load()
107
  ->toOptionHash();
108
  $this->addColumn('set_name',
109
  array(
110
- 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
111
  'width' => '100px',
112
  'index' => 'attribute_set_id',
113
- 'type' => 'options',
114
  'options' => $sets,
115
- ));
116
  $this->addColumn('sku',
117
  array(
118
- 'header'=> Mage::helper('catalog')->__('SKU'),
119
  'width' => '80px',
120
  'index' => 'sku',
121
- ));
122
  $store = $this->_getStore();
123
  $this->addColumn('price',
124
  array(
125
- 'header'=> Mage::helper('catalog')->__('Price'),
126
- 'type' => 'price',
127
  'currency_code' => $store->getBaseCurrency()->getCode(),
128
  'index' => 'price',
129
- ));
130
  $this->addColumn('qty',
131
  array(
132
- 'header'=> Mage::helper('catalog')->__('Qty'),
133
  'width' => '100px',
134
- 'type' => 'number',
135
  'index' => 'qty',
136
- ));
137
  $this->addColumn('visibility',
138
  array(
139
- 'header'=> Mage::helper('catalog')->__('Visibility'),
140
  'width' => '70px',
141
  'index' => 'visibility',
142
- 'type' => 'options',
143
  'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
144
- ));
145
  $this->addColumn('status',
146
  array(
147
- 'header'=> Mage::helper('catalog')->__('Status'),
148
  'width' => '70px',
149
  'index' => 'status',
150
- 'type' => 'options',
151
  'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
152
- ));
153
- $options = array(0 => Mage::helper('catalog')->__('No'),
154
- 1 => Mage::helper('catalog')->__('Yes'));
 
 
155
  $this->addColumn('lengow_product',
156
  array(
157
- 'header'=> Mage::helper('lenexport')->__('Publish on Lengow'),
158
  'width' => '70px',
159
  'index' => 'lengow_product',
160
- 'type' => 'options',
161
  'options' => $options,
162
- ));
163
  if (!Mage::app()->isSingleStoreMode()) {
164
  $this->addColumn('websites',
165
  array(
166
- 'header'=> Mage::helper('catalog')->__('Websites'),
167
  'width' => '100px',
168
- 'sortable' => false,
169
- 'index' => 'websites',
170
- 'type' => 'options',
171
- 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
172
- ));
173
  }
174
  return parent::_prepareColumns();
175
  }
176
 
177
- protected function _prepareMassaction() {
 
178
  $this->setMassactionIdField('entity_id');
179
  $this->getMassactionBlock()->setFormFieldName('product');
180
- $options = array(0 => Mage::helper('catalog')->__('No'),
181
- 1 => Mage::helper('catalog')->__('Yes'));
 
 
182
  $this->getMassactionBlock()->addItem('publish', array(
183
- 'label'=> Mage::helper('lenexport')->__('Change Lengow\'s publication'),
184
- 'url' => $this->getUrl('*/*/massPublish', array('_current'=>true)),
185
- 'additional' => array(
186
- 'visibility' => array(
187
- 'name' => 'publish',
188
- 'type' => 'select',
189
- 'class' => 'required-entry',
190
- 'label' => Mage::helper('catalog')->__('Publication'),
191
- 'values' => $options
192
- )
193
- )
194
  ));
195
  return $this;
196
  }
197
 
198
- public function getGridUrl() {
199
- return $this->getUrl('*/*/grid', array('_current'=>true));
 
200
  }
201
 
202
- public function getRowUrl($row) {
 
203
  return '';
204
  }
205
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow export block adminhtml product grid
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
13
+ {
14
 
15
+ public function __construct()
16
+ {
17
  parent::__construct();
18
  $this->setId('productGrid');
19
  $this->setDefaultSort('entity_id');
23
  $this->setVarNameFilter('product_filter');
24
  }
25
 
26
+ protected function _getStore()
27
+ {
28
+ $storeId = (int)$this->getRequest()->getParam('store', 0);
29
  return Mage::app()->getStore($storeId);
30
  }
31
 
32
+ protected function _prepareCollection()
33
+ {
34
  $store = $this->_getStore();
35
  $collection = Mage::getModel('catalog/product')->getCollection()
36
+ ->addAttributeToSelect('sku')
37
+ ->addAttributeToSelect('name')
38
+ ->addAttributeToSelect('lengow_product')
39
+ ->addAttributeToSelect('attribute_set_id')
40
+ ->addAttributeToSelect('type_id')
41
+ ->joinField('qty',
42
+ 'cataloginventory/stock_item',
43
+ 'qty',
44
+ 'product_id=entity_id',
45
+ '{{table}}.stock_id=1',
46
+ 'left');
47
 
48
  if ($store->getId()) {
49
  $collection->setStoreId($store->getId());
50
  $collection->addStoreFilter($store);
51
+ $collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner',
52
+ $store->getId());
53
  $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store->getId());
54
+ $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner',
55
+ $store->getId());
56
  $collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store->getId());
57
  } else {
58
  $collection->addAttributeToSelect('price');
65
  return $this;
66
  }
67
 
68
+ protected function _addColumnFilterToCollection($column)
69
+ {
70
  if ($this->getCollection()) {
71
  if ($column->getId() == 'websites') {
72
  $this->getCollection()->joinField('websites',
80
  return parent::_addColumnFilterToCollection($column);
81
  }
82
 
83
+ protected function _prepareColumns()
84
+ {
85
  $this->addColumn('entity_id',
86
  array(
87
+ 'header' => Mage::helper('catalog')->__('ID'),
88
  'width' => '50px',
89
+ 'type' => 'number',
90
  'index' => 'entity_id',
91
+ ));
92
  $this->addColumn('name',
93
  array(
94
+ 'header' => Mage::helper('catalog')->__('Name'),
95
  'index' => 'name',
96
+ ));
97
  $store = $this->_getStore();
98
  if ($store->getId()) {
99
  $this->addColumn('custom_name',
100
  array(
101
+ 'header' => Mage::helper('catalog')->__('Name In %s', $store->getName()),
102
  'index' => 'custom_name',
103
+ ));
104
  }
105
  $this->addColumn('type',
106
  array(
107
+ 'header' => Mage::helper('catalog')->__('Type'),
108
  'width' => '60px',
109
  'index' => 'type_id',
110
+ 'type' => 'options',
111
  'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
112
+ ));
113
  $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
114
  ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
115
  ->load()
116
  ->toOptionHash();
117
  $this->addColumn('set_name',
118
  array(
119
+ 'header' => Mage::helper('catalog')->__('Attrib. Set Name'),
120
  'width' => '100px',
121
  'index' => 'attribute_set_id',
122
+ 'type' => 'options',
123
  'options' => $sets,
124
+ ));
125
  $this->addColumn('sku',
126
  array(
127
+ 'header' => Mage::helper('catalog')->__('SKU'),
128
  'width' => '80px',
129
  'index' => 'sku',
130
+ ));
131
  $store = $this->_getStore();
132
  $this->addColumn('price',
133
  array(
134
+ 'header' => Mage::helper('catalog')->__('Price'),
135
+ 'type' => 'price',
136
  'currency_code' => $store->getBaseCurrency()->getCode(),
137
  'index' => 'price',
138
+ ));
139
  $this->addColumn('qty',
140
  array(
141
+ 'header' => Mage::helper('catalog')->__('Qty'),
142
  'width' => '100px',
143
+ 'type' => 'number',
144
  'index' => 'qty',
145
+ ));
146
  $this->addColumn('visibility',
147
  array(
148
+ 'header' => Mage::helper('catalog')->__('Visibility'),
149
  'width' => '70px',
150
  'index' => 'visibility',
151
+ 'type' => 'options',
152
  'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
153
+ ));
154
  $this->addColumn('status',
155
  array(
156
+ 'header' => Mage::helper('catalog')->__('Status'),
157
  'width' => '70px',
158
  'index' => 'status',
159
+ 'type' => 'options',
160
  'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
161
+ ));
162
+ $options = array(
163
+ 0 => Mage::helper('catalog')->__('No'),
164
+ 1 => Mage::helper('catalog')->__('Yes')
165
+ );
166
  $this->addColumn('lengow_product',
167
  array(
168
+ 'header' => Mage::helper('lenexport')->__('Publish on Lengow'),
169
  'width' => '70px',
170
  'index' => 'lengow_product',
171
+ 'type' => 'options',
172
  'options' => $options,
173
+ ));
174
  if (!Mage::app()->isSingleStoreMode()) {
175
  $this->addColumn('websites',
176
  array(
177
+ 'header' => Mage::helper('catalog')->__('Websites'),
178
  'width' => '100px',
179
+ 'sortable' => false,
180
+ 'index' => 'websites',
181
+ 'type' => 'options',
182
+ 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
183
+ ));
184
  }
185
  return parent::_prepareColumns();
186
  }
187
 
188
+ protected function _prepareMassaction()
189
+ {
190
  $this->setMassactionIdField('entity_id');
191
  $this->getMassactionBlock()->setFormFieldName('product');
192
+ $options = array(
193
+ 0 => Mage::helper('catalog')->__('No'),
194
+ 1 => Mage::helper('catalog')->__('Yes')
195
+ );
196
  $this->getMassactionBlock()->addItem('publish', array(
197
+ 'label' => Mage::helper('lenexport')->__('Change Lengow\'s publication'),
198
+ 'url' => $this->getUrl('*/*/massPublish', array('_current' => true)),
199
+ 'additional' => array(
200
+ 'visibility' => array(
201
+ 'name' => 'publish',
202
+ 'type' => 'select',
203
+ 'class' => 'required-entry',
204
+ 'label' => Mage::helper('catalog')->__('Publication'),
205
+ 'values' => $options
206
+ )
207
+ )
208
  ));
209
  return $this;
210
  }
211
 
212
+ public function getGridUrl()
213
+ {
214
+ return $this->getUrl('*/*/grid', array('_current' => true));
215
  }
216
 
217
+ public function getRowUrl($row)
218
+ {
219
  return '';
220
  }
221
  }
app/code/community/Lengow/Export/Helper/Data.php CHANGED
@@ -1,12 +1,16 @@
1
  <?php
2
 
3
  /**
4
- * Lengow Helper
5
- * @category Lengow
6
- * @package Lengow_Export
7
- * @author kassim belghait
 
 
 
8
  */
9
- class Lengow_Export_Helper_Data extends Mage_Core_Helper_Abstract {
 
10
 
11
  /**
12
  * Returns the node and children as an array
@@ -15,31 +19,33 @@ class Lengow_Export_Helper_Data extends Mage_Core_Helper_Abstract {
15
  * @param bool $isCanonical - whether to ignore attributes
16
  * @return array|string
17
  */
18
- public function asArray(SimpleXMLElement $xml, $isCanonical = true) {
 
19
  $result = array();
20
  if (!$isCanonical) {
21
  // add attributes
22
  foreach ($xml->attributes() as $attributeName => $attribute) {
23
  if ($attribute) {
24
- $result['@'][$attributeName] = trim((string) $attribute);
25
  }
26
  }
27
  }
28
  // add children values
29
  if ($xml->hasChildren()) {
30
  foreach ($xml->children() as $childName => $child) {
31
- if (!$child->hasChildren())
32
  $result[$childName] = $this->asArray($child, $isCanonical);
33
- else
34
  $result[$childName][] = $this->asArray($child, $isCanonical);
 
35
  }
36
  } else {
37
  if (empty($result)) {
38
  // return as string, if nothing was found
39
- $result = trim((string) $xml);
40
  } else {
41
  // value has zero key element
42
- $result[0] = trim((string) $xml);
43
  }
44
  }
45
  return $result;
@@ -54,23 +60,26 @@ class Lengow_Export_Helper_Data extends Mage_Core_Helper_Abstract {
54
  * @param boolean $html Keep html
55
  * @return string $value
56
  */
57
- public function cleanData($value, $convert = false, $html = false) {
58
- if ($convert && $html)
 
59
  $value = htmlentities($value);
60
- if(is_array($value))
 
61
  return $value;
 
62
  $value = nl2br($value);
63
  $value = Mage::helper('core/string')->cleanString($value);
64
  // Reject overly long 2 byte sequences, as well as characters above U+10000 and replace with blank
65
  $value = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' .
66
- '|[\x00-\x7F][\x80-\xBF]+' .
67
- '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' .
68
- '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' .
69
- '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S', '', $value);
70
  // Reject overly long 3 byte sequences and UTF-16 surrogates and replace with blank
71
  $value = preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]' .
72
- '|\xED[\xA0-\xBF][\x80-\xBF]/S', '', $value);
73
- if(!$html) {
74
  $pattern = '@<[\/\!]*?[^<>]*?>@si'; //nettoyage du code HTML
75
  $value = preg_replace($pattern, ' ', $value);
76
  }
@@ -113,15 +122,19 @@ class Lengow_Export_Helper_Data extends Mage_Core_Helper_Abstract {
113
  return $value;
114
  }
115
 
116
- public function convertHTML($html) {
 
117
  $html = str_replace(array('"', "\r", "\n"),
118
- array('"""', '', ''),
119
- trim(nl2br($html)));
120
  return $html;
121
  }
122
 
123
- protected function _convert($content) {
124
- if (!mb_check_encoding($content, 'UTF-8') OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))) {
 
 
 
125
  $content = mb_convert_encoding($content, 'UTF-8');
126
  }
127
  return $content;
1
  <?php
2
 
3
  /**
4
+ * Lengow export helper data
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Helper_Data extends Mage_Core_Helper_Abstract
13
+ {
14
 
15
  /**
16
  * Returns the node and children as an array
19
  * @param bool $isCanonical - whether to ignore attributes
20
  * @return array|string
21
  */
22
+ public function asArray(SimpleXMLElement $xml, $isCanonical = true)
23
+ {
24
  $result = array();
25
  if (!$isCanonical) {
26
  // add attributes
27
  foreach ($xml->attributes() as $attributeName => $attribute) {
28
  if ($attribute) {
29
+ $result['@'][$attributeName] = trim((string)$attribute);
30
  }
31
  }
32
  }
33
  // add children values
34
  if ($xml->hasChildren()) {
35
  foreach ($xml->children() as $childName => $child) {
36
+ if (!$child->hasChildren()) {
37
  $result[$childName] = $this->asArray($child, $isCanonical);
38
+ } else {
39
  $result[$childName][] = $this->asArray($child, $isCanonical);
40
+ }
41
  }
42
  } else {
43
  if (empty($result)) {
44
  // return as string, if nothing was found
45
+ $result = trim((string)$xml);
46
  } else {
47
  // value has zero key element
48
+ $result[0] = trim((string)$xml);
49
  }
50
  }
51
  return $result;
60
  * @param boolean $html Keep html
61
  * @return string $value
62
  */
63
+ public function cleanData($value, $convert = false, $html = false)
64
+ {
65
+ if ($convert && $html) {
66
  $value = htmlentities($value);
67
+ }
68
+ if (is_array($value)) {
69
  return $value;
70
+ }
71
  $value = nl2br($value);
72
  $value = Mage::helper('core/string')->cleanString($value);
73
  // Reject overly long 2 byte sequences, as well as characters above U+10000 and replace with blank
74
  $value = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' .
75
+ '|[\x00-\x7F][\x80-\xBF]+' .
76
+ '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' .
77
+ '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' .
78
+ '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S', '', $value);
79
  // Reject overly long 3 byte sequences and UTF-16 surrogates and replace with blank
80
  $value = preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]' .
81
+ '|\xED[\xA0-\xBF][\x80-\xBF]/S', '', $value);
82
+ if (!$html) {
83
  $pattern = '@<[\/\!]*?[^<>]*?>@si'; //nettoyage du code HTML
84
  $value = preg_replace($pattern, ' ', $value);
85
  }
122
  return $value;
123
  }
124
 
125
+ public function convertHTML($html)
126
+ {
127
  $html = str_replace(array('"', "\r", "\n"),
128
+ array('"""', '', ''),
129
+ trim(nl2br($html)));
130
  return $html;
131
  }
132
 
133
+ protected function _convert($content)
134
+ {
135
+ if (!mb_check_encoding($content, 'UTF-8') OR !($content === mb_convert_encoding(mb_convert_encoding($content,
136
+ 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))
137
+ ) {
138
  $content = mb_convert_encoding($content, 'UTF-8');
139
  }
140
  return $content;
app/code/community/Lengow/Export/Helper/Security.php CHANGED
@@ -1,35 +1,54 @@
1
  <?php
 
2
  /**
3
  * Lengow export helper security
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Helper_Security extends Mage_Core_Helper_Abstract {
 
12
 
13
  /**
14
  * Lengow IP.
15
  */
16
  public static $IPS_LENGOW = array(
17
- '127.0.0.1' ,
18
- '95.131.137.18' ,
19
- '95.131.137.19' ,
20
- '95.131.137.21' ,
21
- '95.131.137.26' ,
22
- '95.131.137.27' ,
23
- '88.164.17.227' ,
24
- '88.164.17.216' ,
25
- '109.190.78.5' ,
26
- '80.11.36.123' ,
27
- '95.131.141.169' ,
28
- '95.131.141.170' ,
29
- '95.131.141.171' ,
30
- '82.127.207.67' ,
31
- '80.14.226.127' ,
32
- '80.236.15.223' ,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  );
34
 
35
  /**
@@ -37,14 +56,16 @@ class Lengow_Export_Helper_Security extends Mage_Core_Helper_Abstract {
37
  *
38
  * @return boolean.
39
  */
40
- public function checkIP() {
 
41
  $ips = Mage::getStoreConfig('lenexport/performances/valid_ip');
42
  $ips = trim(str_replace(array("\r\n", ',', '-', '|', ' '), ';', $ips), ';');
43
  $ips = explode(';', $ips);
44
  $authorized_ips = array_merge($ips, self::$IPS_LENGOW);
45
  $hostname_ip = $_SERVER['REMOTE_ADDR'];
46
- if(in_array($hostname_ip, $authorized_ips))
47
  return true;
 
48
  return false;
49
  }
50
 
@@ -55,16 +76,16 @@ class Lengow_Export_Helper_Security extends Mage_Core_Helper_Abstract {
55
  */
56
  public function checkValidAuthorizedIP($authorizedIp)
57
  {
58
- $cleanIps = preg_replace('/\ /','',$authorizedIp);
59
- if (strlen($cleanIps)==0){ return false; }
60
- $ips = explode(',',$cleanIps);
61
- foreach($ips as $ip){
62
- if (!preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/',$ip)){
 
 
63
  return false;
64
  }
65
  }
66
  return true;
67
  }
68
-
69
-
70
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export helper security
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Helper_Security extends Mage_Core_Helper_Abstract
13
+ {
14
 
15
  /**
16
  * Lengow IP.
17
  */
18
  public static $IPS_LENGOW = array(
19
+ '127.0.0.1',
20
+ '46.19.183.204',
21
+ '46.19.183.218',
22
+ '46.19.183.222',
23
+ '89.107.175.172',
24
+ '89.107.175.186',
25
+ '185.61.176.129',
26
+ '185.61.176.130',
27
+ '185.61.176.131',
28
+ '185.61.176.132',
29
+ '185.61.176.133',
30
+ '185.61.176.134',
31
+ '185.61.176.137',
32
+ '185.61.176.138',
33
+ '185.61.176.139',
34
+ '185.61.176.140',
35
+ '185.61.176.141',
36
+ '185.61.176.142',
37
+ '95.131.137.18',
38
+ '95.131.137.19',
39
+ '95.131.137.21',
40
+ '95.131.137.26',
41
+ '95.131.137.27',
42
+ '88.164.17.227',
43
+ '88.164.17.216',
44
+ '109.190.78.5',
45
+ '80.11.36.123',
46
+ '95.131.141.169',
47
+ '95.131.141.170',
48
+ '95.131.141.171',
49
+ '82.127.207.67',
50
+ '80.14.226.127',
51
+ '80.236.15.223',
52
  );
53
 
54
  /**
56
  *
57
  * @return boolean.
58
  */
59
+ public function checkIP()
60
+ {
61
  $ips = Mage::getStoreConfig('lenexport/performances/valid_ip');
62
  $ips = trim(str_replace(array("\r\n", ',', '-', '|', ' '), ';', $ips), ';');
63
  $ips = explode(';', $ips);
64
  $authorized_ips = array_merge($ips, self::$IPS_LENGOW);
65
  $hostname_ip = $_SERVER['REMOTE_ADDR'];
66
+ if (in_array($hostname_ip, $authorized_ips)) {
67
  return true;
68
+ }
69
  return false;
70
  }
71
 
76
  */
77
  public function checkValidAuthorizedIP($authorizedIp)
78
  {
79
+ $cleanIps = preg_replace('/\ /', '', $authorizedIp);
80
+ if (strlen($cleanIps) == 0) {
81
+ return false;
82
+ }
83
+ $ips = explode(',', $cleanIps);
84
+ foreach ($ips as $ip) {
85
+ if (!preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $ip)) {
86
  return false;
87
  }
88
  }
89
  return true;
90
  }
91
+ }
 
 
app/code/community/Lengow/Export/Model/Catalog/Product.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
  * Lengow export model convert parser product
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
 
12
 
13
  /**
14
  * Config model export
@@ -30,24 +32,25 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
30
  * Get Shipping info
31
  *
32
  * @param Mage_Catalog_Model_Product $product_instance
33
- *
34
  * @return array
35
  */
36
- public function getShippingInfo($product_instance)
37
  {
38
  $data['shipping-name'] = '';
39
  $data['shipping-price'] = '';
40
  $data['shipping-delay'] = $this->_config_model->get('data/default_shipping_delay');
41
  $carrier = $this->_config_model->get('data/default_shipping_method');
42
- if(empty($carrier))
43
  return $data;
44
- $carrierTab = explode('_',$carrier);
45
- list($carrierCode,$methodCode) = $carrierTab;
 
46
  $data['shipping-name'] = ucfirst($methodCode);
47
  $shippingPrice = 0;
48
  $countryCode = $this->_config_model->get('data/shipping_price_based_on');
49
  $shippingPrice = $this->_getShippingPrice($product_instance, $carrier, $countryCode);
50
- if(!$shippingPrice) {
51
  $shippingPrice = $this->_config_model->get('data/default_shipping_price');
52
  }
53
  $data['shipping-price'] = $shippingPrice;
@@ -58,10 +61,10 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
58
  /**
59
  * Get shipping price
60
  *
61
- * @param Mage_Catalog_Model_Product $product_instance
62
- * @param string $carrierValue
63
- * @param string $countryCode
64
- *
65
  * @return mixed
66
  */
67
  public function _getShippingPrice($product_instance, $carrierValue, $countryCode = 'FR')
@@ -70,13 +73,14 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
70
  list($carrierCode, $methodCode) = $carrierTab;
71
  $shipping = Mage::getModel('shipping/shipping');
72
  $methodModel = $shipping->getCarrierByCode($carrierCode);
73
- if($methodModel) {
74
- $result = $methodModel->collectRates($this->_getShippingRateRequest($product_instance, $countryCode = 'FR'));
75
- if($result != NULL) {
76
- if($result->getError()) {
 
77
  Mage::logException(new Exception($result->getError()));
78
  } else {
79
- foreach($result->getAllRates() as $rate) {
80
  return $rate->getPrice();
81
  }
82
  }
@@ -90,9 +94,9 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
90
  /**
91
  * Get Shipping rate request
92
  *
93
- * @param Mage_Catalog_Model_Product $product_instance
94
- * @param string $countryCode
95
- *
96
  * @return Mage_Shipping_Model_Rate_Request
97
  */
98
  protected function _getShippingRateRequest($product_instance, $countryCode = 'FR')
@@ -102,14 +106,14 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
102
  $storeId = $request->getStoreId();
103
  if (!$request->getOrig()) {
104
  $request->setCountryId($countryCode)
105
- ->setRegionId('')
106
- ->setCity('')
107
- ->setPostcode('');
108
  }
109
  $item = Mage::getModel('sales/quote_item');
110
  $item->setStoreId($storeId);
111
  $item->setOptions($this->getCustomOptions())
112
- ->setProduct($this);
113
  $request->setAllItems(array($item));
114
  $request->setDestCountryId($countryCode);
115
  $request->setDestRegionId('');
@@ -130,10 +134,10 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
130
  /**
131
  * Get price
132
  *
133
- * @param Mage_Catalog_Model_Product $product_instance
134
- * @param Mage_Catalog_Model_Product $configurable_instance
135
- * @param integer $id_store
136
- *
137
  * @return array
138
  */
139
  public function getPrices($product_instance, $configurable_instance = null, $id_store)
@@ -152,16 +156,18 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
152
  $configurableOldPrice = 0;
153
  $attributes = $configurable_instance->getTypeInstance(true)->getConfigurableAttributes($configurable_instance);
154
  $attributes = Mage::helper('core')->decorateArray($attributes);
155
- if($attributes) {
156
- foreach($attributes as $attribute) {
157
- $productAttribute = $attribute->getProductAttribute();
158
  $productAttributeId = $productAttribute->getId();
159
- $attributeValue = $product_instance->getData($productAttribute->getAttributeCode());
160
- if(count($attribute->getPrices()) > 0) {
161
- foreach($attribute->getPrices() as $priceChange) {
162
- if (is_array($price) && array_key_exists('value_index', $price) && $price['value_index'] == $attributeValue) {
163
- $configurableOldPrice += (float) ( $priceChange['is_percent'] ? ( ( (float) $priceChange['pricing_value'] ) * $price / 100 ) : $priceChange['pricing_value'] );
164
- $configurablePrice += (float) ( $priceChange['is_percent'] ? ( ( (float) $priceChange['pricing_value'] ) * $finalPrice / 100 ) : $priceChange['pricing_value'] );
 
 
165
  }
166
  }
167
  }
@@ -176,31 +182,33 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
176
  $configurablePrice = $configurable_instance->getConfigurablePrice();
177
  $price = $product_instance->getPrice() + $configurableOldPrice;
178
  $final_price = $product_instance->getFinalPrice() + $configurablePrice;
179
- } else if($product_instance->getTypeId() == 'grouped') {
180
- $price = 0;
181
- $final_price = 0;
182
- $childs = Mage::getModel('catalog/product_type_grouped')->getChildrenIds($product_instance->getId());
183
- $childs = $childs[Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED];
184
- foreach ($childs as $value) {
185
- $product = Mage::getModel('lenexport/catalog_product')->load($value);
186
- $price += $product->getPrice();
187
- $final_price += $product->getFinalPrice();
188
- }
189
- $price_including_tax = Mage::helper('tax')->getPrice(
190
- $product_instance->setTaxPercent(null),
191
- $price,
192
- true
193
- );
194
- $final_price_including_tax = Mage::helper('tax')->getPrice(
195
- $product_instance->setTaxPercent(null),
196
- $final_price,
197
- true
198
- );
199
  } else {
200
- $price = $product_instance->getPrice();
201
- $final_price = $product_instance->getFinalPrice();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  }
203
- if(!$config) {
204
  $price_including_tax = $price + $calculator->calcTaxAmount($price, $taxPercent, false);
205
  $final_price_including_tax = $final_price + $calculator->calcTaxAmount($final_price, $taxPercent, false);
206
  } else {
@@ -208,42 +216,53 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
208
  $final_price_including_tax = $final_price;
209
  }
210
  // get currency for convert
211
- if (!$this->getCurrentCurrencyCode())
212
  $toCurrency = $store->getCurrentCurrency();
213
- else
214
  $toCurrency = Mage::getModel('directory/currency')->load($this->getCurrentCurrencyCode());
 
215
  // get prices with or without convertion
216
  if ($this->getOriginalCurrency() == $toCurrency->getCode()) {
217
  $discount_amount = $price_including_tax - $final_price_including_tax;
218
- $data['price-ttc'] = round($final_price_including_tax,2);
219
- $data['price-before-discount'] = round($price_including_tax,2);
220
  } else {
221
- $discount_amount = Mage::helper('directory')->currencyConvert($price_including_tax, $this->getOriginalCurrency(), $toCurrency) - Mage::helper('directory')->currencyConvert($final_price_including_tax, $this->getOriginalCurrency(), $this->getCurrentCurrencyCode());
222
- $data['price-ttc'] = round(Mage::helper('directory')->currencyConvert($final_price_including_tax, $this->getOriginalCurrency(), $this->getCurrentCurrencyCode()), 2);
223
- $data['price-before-discount'] = round(Mage::helper('directory')->currencyConvert($price_including_tax, $this->getOriginalCurrency(), $this->getCurrentCurrencyCode()), 2);
 
 
 
 
 
224
  }
225
  $data['discount-amount'] = $discount_amount > 0 ? round($discount_amount, 2) : '0';
226
- $data['discount-percent'] = $discount_amount > 0 ? round(($discount_amount * 100) / $price_including_tax, 0) : '0';
 
227
  $data['start-date-discount'] = $product_instance->getSpecialFromDate();
228
  $data['end-date-discount'] = $product_instance->getSpecialToDate();
229
  // retrieving promotions
230
  $dateTs = Mage::app()->getLocale()->storeTimeStamp($product_instance->getStoreId());
231
- if (method_exists(Mage::getResourceModel('catalogrule/rule'), 'getRulesFromProduct'))
232
- $promo = Mage::getResourceModel('catalogrule/rule')->getRulesFromProduct($dateTs, $product_instance->getStoreId(), 1, $product_instance->getId());
233
- elseif (method_exists(Mage::getResourceModel('catalogrule/rule'), 'getRulesForProduct'))
234
- $promo = Mage::getResourceModel('catalogrule/rule')->getRulesForProduct($dateTs, $product_instance->getStoreId(), $product_instance->getId());
235
- if (count($promo))
236
- {
 
 
237
  $promo = $promo[0];
238
- if (isset($promo['from_time']))
239
  $from = $promo['from_time'];
240
- else
241
  $from = $promo['from_date'];
 
242
 
243
- if (isset($promo['to_time']))
244
  $to = $promo['to_time'];
245
- else
246
  $to = $promo['to_date'];
 
247
  $data['start-date-discount'] = date('Y-m-d H:i:s', strtotime($from));
248
  $data['end-date-discount'] = is_null($to) ? '' : date('Y-m-d H:i:s', strtotime($to));
249
  }
@@ -253,25 +272,25 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
253
  /**
254
  * Get categories and breadcrumb
255
  *
256
- * @param Mage_Catalog_Model_Product $product_instance
257
- * @param Mage_Catalog_Model_Product $parent_instance
258
- * @param integer $id_store
259
- *
260
  * @return array
261
  */
262
  public function getCategories($product_instance, $parent_instance, $id_store, &$categoryCache = array())
263
  {
264
- $id_root_category = Mage::app()->getStore($id_store)->getRootCategoryId();
265
- if($product_instance->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($parent_instance)) {
266
  $categories = $parent_instance->getCategoryCollection()
267
- ->addPathsFilter('1/' . $id_root_category . '/')
268
- ->exportToArray();
269
  } else {
270
  $categories = $product_instance->getCategoryCollection()
271
- ->addPathsFilter('1/' . $id_root_category . '/')
272
- ->exportToArray();
273
  }
274
- if (isset($categoryCache[key($categories)])){
275
  return $categoryCache[key($categories)];
276
  }
277
 
@@ -279,50 +298,53 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
279
  $max_level = $this->_config_model->get('data/levelcategory');
280
  $current_level = 0;
281
  $category_buffer = false;
282
- foreach($categories as $category) {
283
- if($category['level'] > $current_level) {
284
  $current_level = $category['level'];
285
  $category_buffer = $category;
286
  }
287
- if($current_level > $max_level)
288
  break;
 
289
  }
290
- if(isset($category) && $category['path'] != '')
291
  $categories = explode('/', $category_buffer['path']);
292
- else
293
  $categories = array();
 
294
  $data['category'] = '';
295
  $data['category-url'] = '';
296
- for($i = 1; $i <= $max_level; $i++) {
297
- $data['category-sub-'.($i)] = '';
298
- $data['category-url-sub-'.($i)] = '';
299
  }
300
  $i = 0;
301
  $ariane = array();
302
- foreach($categories as $cid) {
303
  $c = Mage::getModel('catalog/category')
304
- ->setStoreId($id_store)
305
- ->load($cid);
306
- if($c->getId() != 1) {
307
  // No root category
308
- if($i == 0) {
309
  $data['category'] = $c->getName();
310
  $data['category-url'] = $c->getUrl();
311
  $ariane[] = $c->getName();
312
- } elseif($i <= $max_level) {
313
  $ariane[] = $c->getName();
314
- $data['category-sub-'.$i] = $c->getName();
315
- $data['category-url-sub-'.$i] = $c->getUrl();
316
  }
317
  $i++;
318
  }
319
- if(method_exists($c, 'clearInstance'))
320
  $c->clearInstance();
 
321
  }
322
  $data['category-breadcrumb'] = implode(' > ', $ariane);
323
- $maxDimension = count($categories)-1;
324
- if ($maxDimension>=0){
325
- $categoryCache[$categories[count($categories)-1]] = $data;
326
  }
327
  unset($categories, $category, $ariane);
328
 
@@ -332,19 +354,19 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
332
  /**
333
  * Merge images child with images' parents.
334
  *
335
- * @param array $images of child's product
336
- * @param array $parentimages of parent's product
337
- *
338
  * @return array images merged
339
  */
340
  public function getImages($images, $parentimages = false)
341
  {
342
- if($parentimages !== false) {
343
  $images = array_merge($parentimages, $images);
344
  $_images = array();
345
  $_ids = array();
346
- foreach($images['images'] as $image) {
347
- if(array_key_exists('value_id', $image) && !in_array($image['value_id'], $_ids)) {
348
  $_ids[] = $image['value_id'];
349
  $_images[]['file'] = $image['file'];
350
  }
@@ -354,17 +376,17 @@ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product {
354
  }
355
  $data = array();
356
  $max_image = $this->_config_model->getCountExportImages();
357
- for($i = 1; $i < $max_image + 1; $i++) {
358
- $data['image-url-'.$i] = '';
359
  }
360
  $c = 1;
361
- foreach($images as $i) {
362
  $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $i['file'];
363
  $data['image-url-' . $c++] = $url;
364
- if($i == $max_image + 1)
365
  break;
 
366
  }
367
  return $data;
368
  }
369
-
370
  }
1
  <?php
2
+
3
  /**
4
  * Lengow export model convert parser product
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Catalog_Product extends Mage_Catalog_Model_Product
13
+ {
14
 
15
  /**
16
  * Config model export
32
  * Get Shipping info
33
  *
34
  * @param Mage_Catalog_Model_Product $product_instance
35
+ *
36
  * @return array
37
  */
38
+ public function getShippingInfo($product_instance)
39
  {
40
  $data['shipping-name'] = '';
41
  $data['shipping-price'] = '';
42
  $data['shipping-delay'] = $this->_config_model->get('data/default_shipping_delay');
43
  $carrier = $this->_config_model->get('data/default_shipping_method');
44
+ if (empty($carrier)) {
45
  return $data;
46
+ }
47
+ $carrierTab = explode('_', $carrier);
48
+ list($carrierCode, $methodCode) = $carrierTab;
49
  $data['shipping-name'] = ucfirst($methodCode);
50
  $shippingPrice = 0;
51
  $countryCode = $this->_config_model->get('data/shipping_price_based_on');
52
  $shippingPrice = $this->_getShippingPrice($product_instance, $carrier, $countryCode);
53
+ if (!$shippingPrice) {
54
  $shippingPrice = $this->_config_model->get('data/default_shipping_price');
55
  }
56
  $data['shipping-price'] = $shippingPrice;
61
  /**
62
  * Get shipping price
63
  *
64
+ * @param Mage_Catalog_Model_Product $product_instance
65
+ * @param string $carrierValue
66
+ * @param string $countryCode
67
+ *
68
  * @return mixed
69
  */
70
  public function _getShippingPrice($product_instance, $carrierValue, $countryCode = 'FR')
73
  list($carrierCode, $methodCode) = $carrierTab;
74
  $shipping = Mage::getModel('shipping/shipping');
75
  $methodModel = $shipping->getCarrierByCode($carrierCode);
76
+ if ($methodModel) {
77
+ $result = $methodModel->collectRates($this->_getShippingRateRequest($product_instance,
78
+ $countryCode = 'FR'));
79
+ if ($result != null) {
80
+ if ($result->getError()) {
81
  Mage::logException(new Exception($result->getError()));
82
  } else {
83
+ foreach ($result->getAllRates() as $rate) {
84
  return $rate->getPrice();
85
  }
86
  }
94
  /**
95
  * Get Shipping rate request
96
  *
97
+ * @param Mage_Catalog_Model_Product $product_instance
98
+ * @param string $countryCode
99
+ *
100
  * @return Mage_Shipping_Model_Rate_Request
101
  */
102
  protected function _getShippingRateRequest($product_instance, $countryCode = 'FR')
106
  $storeId = $request->getStoreId();
107
  if (!$request->getOrig()) {
108
  $request->setCountryId($countryCode)
109
+ ->setRegionId('')
110
+ ->setCity('')
111
+ ->setPostcode('');
112
  }
113
  $item = Mage::getModel('sales/quote_item');
114
  $item->setStoreId($storeId);
115
  $item->setOptions($this->getCustomOptions())
116
+ ->setProduct($this);
117
  $request->setAllItems(array($item));
118
  $request->setDestCountryId($countryCode);
119
  $request->setDestRegionId('');
134
  /**
135
  * Get price
136
  *
137
+ * @param Mage_Catalog_Model_Product $product_instance
138
+ * @param Mage_Catalog_Model_Product $configurable_instance
139
+ * @param integer $id_store
140
+ *
141
  * @return array
142
  */
143
  public function getPrices($product_instance, $configurable_instance = null, $id_store)
156
  $configurableOldPrice = 0;
157
  $attributes = $configurable_instance->getTypeInstance(true)->getConfigurableAttributes($configurable_instance);
158
  $attributes = Mage::helper('core')->decorateArray($attributes);
159
+ if ($attributes) {
160
+ foreach ($attributes as $attribute) {
161
+ $productAttribute = $attribute->getProductAttribute();
162
  $productAttributeId = $productAttribute->getId();
163
+ $attributeValue = $product_instance->getData($productAttribute->getAttributeCode());
164
+ if (count($attribute->getPrices()) > 0) {
165
+ foreach ($attribute->getPrices() as $priceChange) {
166
+ if (is_array($price) && array_key_exists('value_index',
167
+ $price) && $price['value_index'] == $attributeValue
168
+ ) {
169
+ $configurableOldPrice += (float)($priceChange['is_percent'] ? (((float)$priceChange['pricing_value']) * $price / 100) : $priceChange['pricing_value']);
170
+ $configurablePrice += (float)($priceChange['is_percent'] ? (((float)$priceChange['pricing_value']) * $finalPrice / 100) : $priceChange['pricing_value']);
171
  }
172
  }
173
  }
182
  $configurablePrice = $configurable_instance->getConfigurablePrice();
183
  $price = $product_instance->getPrice() + $configurableOldPrice;
184
  $final_price = $product_instance->getFinalPrice() + $configurablePrice;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  } else {
186
+ if ($product_instance->getTypeId() == 'grouped') {
187
+ $price = 0;
188
+ $final_price = 0;
189
+ $childs = Mage::getModel('catalog/product_type_grouped')->getChildrenIds($product_instance->getId());
190
+ $childs = $childs[Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED];
191
+ foreach ($childs as $value) {
192
+ $product = Mage::getModel('lenexport/catalog_product')->load($value);
193
+ $price += $product->getPrice();
194
+ $final_price += $product->getFinalPrice();
195
+ }
196
+ $price_including_tax = Mage::helper('tax')->getPrice(
197
+ $product_instance->setTaxPercent(null),
198
+ $price,
199
+ true
200
+ );
201
+ $final_price_including_tax = Mage::helper('tax')->getPrice(
202
+ $product_instance->setTaxPercent(null),
203
+ $final_price,
204
+ true
205
+ );
206
+ } else {
207
+ $price = $product_instance->getPrice();
208
+ $final_price = $product_instance->getFinalPrice();
209
+ }
210
  }
211
+ if (!$config) {
212
  $price_including_tax = $price + $calculator->calcTaxAmount($price, $taxPercent, false);
213
  $final_price_including_tax = $final_price + $calculator->calcTaxAmount($final_price, $taxPercent, false);
214
  } else {
216
  $final_price_including_tax = $final_price;
217
  }
218
  // get currency for convert
219
+ if (!$this->getCurrentCurrencyCode()) {
220
  $toCurrency = $store->getCurrentCurrency();
221
+ } else {
222
  $toCurrency = Mage::getModel('directory/currency')->load($this->getCurrentCurrencyCode());
223
+ }
224
  // get prices with or without convertion
225
  if ($this->getOriginalCurrency() == $toCurrency->getCode()) {
226
  $discount_amount = $price_including_tax - $final_price_including_tax;
227
+ $data['price-ttc'] = round($final_price_including_tax, 2);
228
+ $data['price-before-discount'] = round($price_including_tax, 2);
229
  } else {
230
+ $discount_amount = Mage::helper('directory')->currencyConvert($price_including_tax,
231
+ $this->getOriginalCurrency(),
232
+ $toCurrency) - Mage::helper('directory')->currencyConvert($final_price_including_tax,
233
+ $this->getOriginalCurrency(), $this->getCurrentCurrencyCode());
234
+ $data['price-ttc'] = round(Mage::helper('directory')->currencyConvert($final_price_including_tax,
235
+ $this->getOriginalCurrency(), $this->getCurrentCurrencyCode()), 2);
236
+ $data['price-before-discount'] = round(Mage::helper('directory')->currencyConvert($price_including_tax,
237
+ $this->getOriginalCurrency(), $this->getCurrentCurrencyCode()), 2);
238
  }
239
  $data['discount-amount'] = $discount_amount > 0 ? round($discount_amount, 2) : '0';
240
+ $data['discount-percent'] = $discount_amount > 0 ? round(($discount_amount * 100) / $price_including_tax,
241
+ 0) : '0';
242
  $data['start-date-discount'] = $product_instance->getSpecialFromDate();
243
  $data['end-date-discount'] = $product_instance->getSpecialToDate();
244
  // retrieving promotions
245
  $dateTs = Mage::app()->getLocale()->storeTimeStamp($product_instance->getStoreId());
246
+ if (method_exists(Mage::getResourceModel('catalogrule/rule'), 'getRulesFromProduct')) {
247
+ $promo = Mage::getResourceModel('catalogrule/rule')->getRulesFromProduct($dateTs,
248
+ $product_instance->getStoreId(), 1, $product_instance->getId());
249
+ } elseif (method_exists(Mage::getResourceModel('catalogrule/rule'), 'getRulesForProduct')) {
250
+ $promo = Mage::getResourceModel('catalogrule/rule')->getRulesForProduct($dateTs,
251
+ $product_instance->getStoreId(), $product_instance->getId());
252
+ }
253
+ if (count($promo)) {
254
  $promo = $promo[0];
255
+ if (isset($promo['from_time'])) {
256
  $from = $promo['from_time'];
257
+ } else {
258
  $from = $promo['from_date'];
259
+ }
260
 
261
+ if (isset($promo['to_time'])) {
262
  $to = $promo['to_time'];
263
+ } else {
264
  $to = $promo['to_date'];
265
+ }
266
  $data['start-date-discount'] = date('Y-m-d H:i:s', strtotime($from));
267
  $data['end-date-discount'] = is_null($to) ? '' : date('Y-m-d H:i:s', strtotime($to));
268
  }
272
  /**
273
  * Get categories and breadcrumb
274
  *
275
+ * @param Mage_Catalog_Model_Product $product_instance
276
+ * @param Mage_Catalog_Model_Product $parent_instance
277
+ * @param integer $id_store
278
+ *
279
  * @return array
280
  */
281
  public function getCategories($product_instance, $parent_instance, $id_store, &$categoryCache = array())
282
  {
283
+ $id_root_category = Mage::app()->getStore($id_store)->getRootCategoryId();
284
+ if ($product_instance->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($parent_instance)) {
285
  $categories = $parent_instance->getCategoryCollection()
286
+ ->addPathsFilter('1/' . $id_root_category . '/')
287
+ ->exportToArray();
288
  } else {
289
  $categories = $product_instance->getCategoryCollection()
290
+ ->addPathsFilter('1/' . $id_root_category . '/')
291
+ ->exportToArray();
292
  }
293
+ if (isset($categoryCache[key($categories)])) {
294
  return $categoryCache[key($categories)];
295
  }
296
 
298
  $max_level = $this->_config_model->get('data/levelcategory');
299
  $current_level = 0;
300
  $category_buffer = false;
301
+ foreach ($categories as $category) {
302
+ if ($category['level'] > $current_level) {
303
  $current_level = $category['level'];
304
  $category_buffer = $category;
305
  }
306
+ if ($current_level > $max_level) {
307
  break;
308
+ }
309
  }
310
+ if (isset($category) && $category['path'] != '') {
311
  $categories = explode('/', $category_buffer['path']);
312
+ } else {
313
  $categories = array();
314
+ }
315
  $data['category'] = '';
316
  $data['category-url'] = '';
317
+ for ($i = 1; $i <= $max_level; $i++) {
318
+ $data['category-sub-' . ($i)] = '';
319
+ $data['category-url-sub-' . ($i)] = '';
320
  }
321
  $i = 0;
322
  $ariane = array();
323
+ foreach ($categories as $cid) {
324
  $c = Mage::getModel('catalog/category')
325
+ ->setStoreId($id_store)
326
+ ->load($cid);
327
+ if ($c->getId() != 1) {
328
  // No root category
329
+ if ($i == 0) {
330
  $data['category'] = $c->getName();
331
  $data['category-url'] = $c->getUrl();
332
  $ariane[] = $c->getName();
333
+ } elseif ($i <= $max_level) {
334
  $ariane[] = $c->getName();
335
+ $data['category-sub-' . $i] = $c->getName();
336
+ $data['category-url-sub-' . $i] = $c->getUrl();
337
  }
338
  $i++;
339
  }
340
+ if (method_exists($c, 'clearInstance')) {
341
  $c->clearInstance();
342
+ }
343
  }
344
  $data['category-breadcrumb'] = implode(' > ', $ariane);
345
+ $maxDimension = count($categories) - 1;
346
+ if ($maxDimension >= 0) {
347
+ $categoryCache[$categories[count($categories) - 1]] = $data;
348
  }
349
  unset($categories, $category, $ariane);
350
 
354
  /**
355
  * Merge images child with images' parents.
356
  *
357
+ * @param array $images of child's product
358
+ * @param array $parentimages of parent's product
359
+ *
360
  * @return array images merged
361
  */
362
  public function getImages($images, $parentimages = false)
363
  {
364
+ if ($parentimages !== false) {
365
  $images = array_merge($parentimages, $images);
366
  $_images = array();
367
  $_ids = array();
368
+ foreach ($images['images'] as $image) {
369
+ if (array_key_exists('value_id', $image) && !in_array($image['value_id'], $_ids)) {
370
  $_ids[] = $image['value_id'];
371
  $_images[]['file'] = $image['file'];
372
  }
376
  }
377
  $data = array();
378
  $max_image = $this->_config_model->getCountExportImages();
379
+ for ($i = 1; $i < $max_image + 1; $i++) {
380
+ $data['image-url-' . $i] = '';
381
  }
382
  $c = 1;
383
+ foreach ($images as $i) {
384
  $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $i['file'];
385
  $data['image-url-' . $c++] = $url;
386
+ if ($i == $max_image + 1) {
387
  break;
388
+ }
389
  }
390
  return $data;
391
  }
 
392
  }
app/code/community/Lengow/Export/Model/Config.php CHANGED
@@ -1,265 +1,267 @@
1
  <?php
 
2
  /**
3
  * Lengow export model config
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Config extends Varien_Object {
12
-
13
-
14
- /**
15
- * Config key "Enable manage orders"
16
- */
17
- const ENABLED = 'active';
18
-
19
- /**
20
- * Config key "Filter by attribute"
21
- */
22
- const EXPORT_ONLY_SELECTED = 'global/export_only_selected';
23
-
24
- /**
25
- * Config key "Export soldout"
26
- */
27
- const EXPORT_SOLDOUT = 'global/export_soldout';
28
-
29
- /**
30
- * Config key "Export count images"
31
- */
32
- const COUNT_IMAGES = 'data/count_images';
33
-
34
- /**
35
- * Config key "Filter by attribute"
36
- */
37
- const LIMIT_PRODUCT = 'limit_product';
38
-
39
- /**
40
- * Config key "Attributes kow"
41
- */
42
- const ATTRIBUTES_KNOW = 'attributes_know';
43
-
44
- /**
45
- * Config key "Attributes unkow"
46
- */
47
- const ATTRIBUTES_UNKNOW = 'attributes_unknow';
48
-
49
- /**
50
- * Config key "Auto export product"
51
- */
52
- const AUTOEXPORT_NEWPRODUCT = 'autoexport_newproduct';
53
-
54
- /*
55
- * @var array $_attributesKnow
56
- */
57
- protected $_attributesKnow = null;
58
-
59
- /**
60
- * @var array $_attributesUnKnow
61
- */
62
- protected $_attributesUnKnow = null;
63
-
64
- protected $_attributesSelected = null;
65
-
66
- protected $_attributesHtml = array();
67
-
68
- protected $_id_store;
69
-
70
- /**
71
- * Set Store
72
- *
73
- * @param int $id_store
74
- */
75
- public function setStore($id_store)
76
- {
77
- $this->_id_store = $id_store;
78
- }
79
-
80
- /**
81
- * Get any paramater for lenexport
82
- *
83
- * @param string $key
84
- *
85
- * @return mixed
86
- */
87
- public function get($key)
88
- {
 
89
  return Mage::getStoreConfig('lenexport/' . $key, $this->_id_store);
90
- }
91
 
92
- /**
93
  * Return config var
94
  *
95
- * @param string $key Var path key
96
- * @param int $id_store Store View Id
97
- *
98
- * @return mixed
99
  */
100
- public function getConfigData($key, $group = 'global', $id_store = null)
101
- {
102
- if (!$this->hasData($key)) {
103
  $value = Mage::getStoreConfig('lenexport/' . $group . '/' . $key, $id_store);
104
  $this->setData($key, $value);
105
  }
106
  return $this->getData($key);
107
- }
108
 
109
- /**
110
  * Return config var
111
  *
112
- * @param string $key Var path key
113
- * @param int $id_store Store View Id
114
- *
115
- * @return mixed
116
  */
117
- public function getConfigFlag($key, $group = 'global', $id_store = null)
118
- {
119
- if (!$this->hasData($key)) {
120
  $value = Mage::getStoreConfigFlag('lenexport/' . $group . '/' . $key, $id_store);
121
  $this->setData($key, $value);
122
  }
123
  return $this->getData($key);
124
- }
125
 
126
 
127
- public function getAny($group, $key, $id_store = null)
128
- {
129
  return Mage::getStoreConfig('lenexport/' . $group . '/' . $key, $id_store);
130
- }
131
-
132
- /**
133
- * Retrieve if export is active
134
- *
135
- * @return boolean
136
- */
137
- public function isEnabled()
138
- {
139
- return $this->getConfigFlag(self::ENABLED);
140
- }
141
-
142
- /**
143
- * Retrieve if export is active
144
- *
145
- * @return boolean
146
- */
147
- public function onlySelectedProducts()
148
- {
149
- return $this->get(self::EXPORT_ONLY_SELECTED);
150
- }
151
-
152
- /**
153
- * Retrieve if export sold out products
154
- *
155
- * @return boolean
156
- */
157
- public function isExportSoldout()
158
- {
159
- return $this->get(self::EXPORT_SOLDOUT);
160
- }
161
-
162
- /**
163
- * Retrieve limit of product in query
164
- *
165
- * @return int
166
- */
167
- public function getLimitProduct()
168
- {
169
- return (int) $this->getConfigData(self::LIMIT_PRODUCT);
170
- }
171
-
172
- /**
173
- * Retrieve limit of product in query
174
- *
175
- * @return int
176
- */
177
- public function getCountExportImages()
178
- {
179
- return (int) $this->get(self::COUNT_IMAGES);
180
- }
181
-
182
- /**
183
- * Auto export new product
184
- *
185
- * @return int
186
- */
187
- public function isAutoExportProduct()
188
- {
189
- return (int) $this->getConfigData(self::AUTOEXPORT_NEWPRODUCT);
190
- }
191
-
192
- /**
193
- * Return Attributes Unknowed in array with key=>value
194
- * key = node adn value = inner text
195
- * @param int $id_store
196
- *
197
- * @return array
198
- */
199
- public function getMappgingAttributesUnKnow($id_store = null)
200
- {
201
- //if(is_null($this->_attributesUnKnow))
202
- if($this->_attributesUnKnow === null || !isset($this->_attributesUnKnow) || empty($this->_attributesUnKnow)) {
203
- $this->_attributesUnKnow = Mage::getStoreConfig('lenexport/attributes_unknow', $id_store);
204
- }
205
-
206
- return $this->_attributesUnKnow;
207
- }
208
-
209
- /**
210
- * Get Selected attributes
211
- *
212
- * @param int $id_store
213
- *
214
- * @return array
215
- */
216
- public function getSelectedAttributes($id_store = null)
217
- {
218
- $tab = array();
219
- $this->_attributesSelected = array();
220
- if($this->_attributesSelected === null || !isset($this->_attributesSelected) || empty($this->_attributesSelected)) {
221
- $val = Mage::getStoreConfig('lenexport/attributelist/attributes', $id_store);
222
- if(!empty($val)) {
223
- $tab = explode(',',$val);
224
- $this->_attributesSelected = array_flip($tab);
225
- }
226
- }
227
- if(!empty($tab)) {
228
- foreach($this->_attributesSelected as $key => $value) {
229
- $this->_attributesSelected[$key] = $key;
230
- }
231
- }
232
- return $this->_attributesSelected;
233
- }
234
-
235
- /**
236
- * Return ALL Attributes Knowed and Unknowed in array with key=>value
237
- * key = node adn value = inner text
238
- *
239
- * @param int $id_store
240
- *
241
- * @return array
242
- */
243
- public function getMappingAllAttributes($id_store = null)
244
- {
245
  return $this->getSelectedAttributes($id_store);
246
- }
247
-
248
- /**
249
- * Get Html attributes
250
- *
251
- * @param int $id_store
252
- *
253
- * @return array
254
- */
255
- public function getHtmlAttributes($id_store = null)
256
- {
257
- if (count($this->_attributesHtml) == 0) {
258
- $attributes = Mage::getStoreConfig('lenexport/data/html_attributes', $id_store);
259
- if(!empty($attributes))
260
- $this->_attributesHtml = explode(',', $attributes);
261
- }
262
- return $this->_attributesHtml;
263
- }
264
-
265
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export model config
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Config extends Varien_Object
13
+ {
14
+
15
+
16
+ /**
17
+ * Config key "Enable manage orders"
18
+ */
19
+ const ENABLED = 'active';
20
+
21
+ /**
22
+ * Config key "Filter by attribute"
23
+ */
24
+ const EXPORT_ONLY_SELECTED = 'global/export_only_selected';
25
+
26
+ /**
27
+ * Config key "Export soldout"
28
+ */
29
+ const EXPORT_SOLDOUT = 'global/export_soldout';
30
+
31
+ /**
32
+ * Config key "Export count images"
33
+ */
34
+ const COUNT_IMAGES = 'data/count_images';
35
+
36
+ /**
37
+ * Config key "Filter by attribute"
38
+ */
39
+ const LIMIT_PRODUCT = 'limit_product';
40
+
41
+ /**
42
+ * Config key "Attributes kow"
43
+ */
44
+ const ATTRIBUTES_KNOW = 'attributes_know';
45
+
46
+ /**
47
+ * Config key "Attributes unkow"
48
+ */
49
+ const ATTRIBUTES_UNKNOW = 'attributes_unknow';
50
+
51
+ /**
52
+ * Config key "Auto export product"
53
+ */
54
+ const AUTOEXPORT_NEWPRODUCT = 'autoexport_newproduct';
55
+
56
+ /*
57
+ * @var array $_attributesKnow
58
+ */
59
+ protected $_attributesKnow = null;
60
+
61
+ /**
62
+ * @var array $_attributesUnKnow
63
+ */
64
+ protected $_attributesUnKnow = null;
65
+
66
+ protected $_attributesSelected = null;
67
+
68
+ protected $_attributesHtml = array();
69
+
70
+ protected $_id_store;
71
+
72
+ /**
73
+ * Set Store
74
+ *
75
+ * @param int $id_store
76
+ */
77
+ public function setStore($id_store)
78
+ {
79
+ $this->_id_store = $id_store;
80
+ }
81
+
82
+ /**
83
+ * Get any paramater for lenexport
84
+ *
85
+ * @param string $key
86
+ *
87
+ * @return mixed
88
+ */
89
+ public function get($key)
90
+ {
91
  return Mage::getStoreConfig('lenexport/' . $key, $this->_id_store);
92
+ }
93
 
94
+ /**
95
  * Return config var
96
  *
97
+ * @param string $key Var path key
98
+ * @param int $id_store Store View Id
99
+ *
100
+ * @return mixed
101
  */
102
+ public function getConfigData($key, $group = 'global', $id_store = null)
103
+ {
104
+ if (!$this->hasData($key)) {
105
  $value = Mage::getStoreConfig('lenexport/' . $group . '/' . $key, $id_store);
106
  $this->setData($key, $value);
107
  }
108
  return $this->getData($key);
109
+ }
110
 
111
+ /**
112
  * Return config var
113
  *
114
+ * @param string $key Var path key
115
+ * @param int $id_store Store View Id
116
+ *
117
+ * @return mixed
118
  */
119
+ public function getConfigFlag($key, $group = 'global', $id_store = null)
120
+ {
121
+ if (!$this->hasData($key)) {
122
  $value = Mage::getStoreConfigFlag('lenexport/' . $group . '/' . $key, $id_store);
123
  $this->setData($key, $value);
124
  }
125
  return $this->getData($key);
126
+ }
127
 
128
 
129
+ public function getAny($group, $key, $id_store = null)
130
+ {
131
  return Mage::getStoreConfig('lenexport/' . $group . '/' . $key, $id_store);
132
+ }
133
+
134
+ /**
135
+ * Retrieve if export is active
136
+ *
137
+ * @return boolean
138
+ */
139
+ public function isEnabled()
140
+ {
141
+ return $this->getConfigFlag(self::ENABLED);
142
+ }
143
+
144
+ /**
145
+ * Retrieve if export is active
146
+ *
147
+ * @return boolean
148
+ */
149
+ public function onlySelectedProducts()
150
+ {
151
+ return $this->get(self::EXPORT_ONLY_SELECTED);
152
+ }
153
+
154
+ /**
155
+ * Retrieve if export sold out products
156
+ *
157
+ * @return boolean
158
+ */
159
+ public function isExportSoldout()
160
+ {
161
+ return $this->get(self::EXPORT_SOLDOUT);
162
+ }
163
+
164
+ /**
165
+ * Retrieve limit of product in query
166
+ *
167
+ * @return int
168
+ */
169
+ public function getLimitProduct()
170
+ {
171
+ return (int)$this->getConfigData(self::LIMIT_PRODUCT);
172
+ }
173
+
174
+ /**
175
+ * Retrieve limit of product in query
176
+ *
177
+ * @return int
178
+ */
179
+ public function getCountExportImages()
180
+ {
181
+ return (int)$this->get(self::COUNT_IMAGES);
182
+ }
183
+
184
+ /**
185
+ * Auto export new product
186
+ *
187
+ * @return int
188
+ */
189
+ public function isAutoExportProduct()
190
+ {
191
+ return (int)$this->getConfigData(self::AUTOEXPORT_NEWPRODUCT);
192
+ }
193
+
194
+ /**
195
+ * Return Attributes Unknowed in array with key=>value
196
+ * key = node adn value = inner text
197
+ * @param int $id_store
198
+ *
199
+ * @return array
200
+ */
201
+ public function getMappgingAttributesUnKnow($id_store = null)
202
+ {
203
+ //if(is_null($this->_attributesUnKnow))
204
+ if ($this->_attributesUnKnow === null || !isset($this->_attributesUnKnow) || empty($this->_attributesUnKnow)) {
205
+ $this->_attributesUnKnow = Mage::getStoreConfig('lenexport/attributes_unknow', $id_store);
206
+ }
207
+
208
+ return $this->_attributesUnKnow;
209
+ }
210
+
211
+ /**
212
+ * Get Selected attributes
213
+ *
214
+ * @param int $id_store
215
+ *
216
+ * @return array
217
+ */
218
+ public function getSelectedAttributes($id_store = null)
219
+ {
220
+ $tab = array();
221
+ $this->_attributesSelected = array();
222
+ if ($this->_attributesSelected === null || !isset($this->_attributesSelected) || empty($this->_attributesSelected)) {
223
+ $val = Mage::getStoreConfig('lenexport/attributelist/attributes', $id_store);
224
+ if (!empty($val)) {
225
+ $tab = explode(',', $val);
226
+ $this->_attributesSelected = array_flip($tab);
227
+ }
228
+ }
229
+ if (!empty($tab)) {
230
+ foreach ($this->_attributesSelected as $key => $value) {
231
+ $this->_attributesSelected[$key] = $key;
232
+ }
233
+ }
234
+ return $this->_attributesSelected;
235
+ }
236
+
237
+ /**
238
+ * Return ALL Attributes Knowed and Unknowed in array with key=>value
239
+ * key = node adn value = inner text
240
+ *
241
+ * @param int $id_store
242
+ *
243
+ * @return array
244
+ */
245
+ public function getMappingAllAttributes($id_store = null)
246
+ {
247
  return $this->getSelectedAttributes($id_store);
248
+ }
249
+
250
+ /**
251
+ * Get Html attributes
252
+ *
253
+ * @param int $id_store
254
+ *
255
+ * @return array
256
+ */
257
+ public function getHtmlAttributes($id_store = null)
258
+ {
259
+ if (count($this->_attributesHtml) == 0) {
260
+ $attributes = Mage::getStoreConfig('lenexport/data/html_attributes', $id_store);
261
+ if (!empty($attributes)) {
262
+ $this->_attributesHtml = explode(',', $attributes);
263
+ }
264
+ }
265
+ return $this->_attributesHtml;
266
+ }
267
+ }
app/code/community/Lengow/Export/Model/Convert/Parser/Product.php CHANGED
@@ -1,29 +1,33 @@
1
  <?php
 
2
  /**
3
  * Lengow export model convert parser product
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Convert_Parser_Product extends Mage_Catalog_Model_Convert_Parser_Product {
 
12
 
13
  /**
14
  * Retrieve accessible external product attributes
15
  *
16
  * @return array
17
  */
18
- public function getExternalAttributes() {
19
- $productAttributes = array();
20
- if(file_exists(Mage::getModuleDir(null,'Mage_Catalog') . 'Model/Resource/Eav/Mysql4/Product/Attribute/Collection')) {
21
- $productAttributes = Mage::getResourceModel('catalog/product_attribute_collection')->load();
 
 
22
  } else {
23
- $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getId();
24
- $productAttributes = Mage::getResourceModel('eav/entity_attribute_collection')
25
- ->setEntityTypeFilter($entityTypeId)
26
- ->load();
27
  }
28
  $attributes = $this->_externalFields;
29
  foreach ($productAttributes as $attr) {
@@ -38,5 +42,4 @@ class Lengow_Export_Model_Convert_Parser_Product extends Mage_Catalog_Model_Conv
38
  }
39
  return $attributes;
40
  }
41
-
42
  }
1
  <?php
2
+
3
  /**
4
  * Lengow export model convert parser product
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Convert_Parser_Product extends Mage_Catalog_Model_Convert_Parser_Product
13
+ {
14
 
15
  /**
16
  * Retrieve accessible external product attributes
17
  *
18
  * @return array
19
  */
20
+ public function getExternalAttributes()
21
+ {
22
+ $productAttributes = array();
23
+ if (file_exists(Mage::getModuleDir(null,
24
+ 'Mage_Catalog') . 'Model/Resource/Eav/Mysql4/Product/Attribute/Collection')) {
25
+ $productAttributes = Mage::getResourceModel('catalog/product_attribute_collection')->load();
26
  } else {
27
+ $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getId();
28
+ $productAttributes = Mage::getResourceModel('eav/entity_attribute_collection')
29
+ ->setEntityTypeFilter($entityTypeId)
30
+ ->load();
31
  }
32
  $attributes = $this->_externalFields;
33
  foreach ($productAttributes as $attr) {
42
  }
43
  return $attributes;
44
  }
 
45
  }
app/code/community/Lengow/Export/Model/Export/Rewrite/Catalog/Config.php CHANGED
@@ -1,32 +1,17 @@
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_Catalog
23
- * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
  */
 
 
26
 
27
-
28
- class Lengow_Export_Model_Rewrite_Catalog_Config extends Mage_Catalog_Model_Config{
29
-
30
  /**
31
  * Get attribute by code for entity type
32
  *
@@ -34,13 +19,12 @@ class Lengow_Export_Model_Rewrite_Catalog_Config extends Mage_Catalog_Model_Conf
34
  * @param mixed $code
35
  * @return Mage_Eav_Model_Entity_Attribute_Abstract
36
  */
37
- public function getAttribute($entityType, $code) {
38
- $attribute = parent::getAttribute($entityType, $code);
39
- if(is_object($attribute) && $attribute->getAttributeCode() == '') {
40
- $attribute->setAttributeCode($code);
41
- }
42
- return $attribute;
 
43
  }
44
-
45
-
46
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model rewrite catalog config
 
 
 
 
 
 
 
 
 
 
 
 
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 
 
 
11
  */
12
+ class Lengow_Export_Model_Rewrite_Catalog_Config extends Mage_Catalog_Model_Config
13
+ {
14
 
 
 
 
15
  /**
16
  * Get attribute by code for entity type
17
  *
19
  * @param mixed $code
20
  * @return Mage_Eav_Model_Entity_Attribute_Abstract
21
  */
22
+ public function getAttribute($entityType, $code)
23
+ {
24
+ $attribute = parent::getAttribute($entityType, $code);
25
+ if (is_object($attribute) && $attribute->getAttributeCode() == '') {
26
+ $attribute->setAttributeCode($code);
27
+ }
28
+ return $attribute;
29
  }
 
 
30
  }
app/code/community/Lengow/Export/Model/Feed/Abstract.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
- * Lengow export feed abstract
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- abstract class Lengow_Export_Model_Feed_Abstract {
 
12
 
13
  /**
14
  * Version.
@@ -19,19 +21,24 @@ abstract class Lengow_Export_Model_Feed_Abstract {
19
 
20
  protected $_content_type;
21
 
22
- public function getContentType() {
 
23
  }
24
 
25
- public function setFields($array = array()) {
26
- $this->_fields = $array;
 
27
  }
28
 
29
- public function makeHeader() {
 
30
  }
31
 
32
- public function makeData($array, $args = array()) {
 
33
  }
34
 
35
- public function makeFooter() {
 
36
  }
37
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model feed abstract
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ abstract class Lengow_Export_Model_Feed_Abstract
13
+ {
14
 
15
  /**
16
  * Version.
21
 
22
  protected $_content_type;
23
 
24
+ public function getContentType()
25
+ {
26
  }
27
 
28
+ public function setFields($array = array())
29
+ {
30
+ $this->_fields = $array;
31
  }
32
 
33
+ public function makeHeader()
34
+ {
35
  }
36
 
37
+ public function makeData($array, $args = array())
38
+ {
39
  }
40
 
41
+ public function makeFooter()
42
+ {
43
  }
44
  }
app/code/community/Lengow/Export/Model/Feed/Csv.php CHANGED
@@ -1,25 +1,27 @@
1
  <?php
 
2
  /**
3
- * Lengow export feed csv
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Feed_Csv extends Lengow_Export_Model_Feed_Abstract {
 
12
 
13
  /**
14
  * CSV separator.
15
  */
16
  public static $CSV_SEPARATOR = '|';
17
-
18
  /**
19
  * CSV protection.
20
  */
21
  public static $CSV_PROTECTION = '"';
22
-
23
  /**
24
  * CSV End of line.
25
  */
@@ -27,27 +29,34 @@ class Lengow_Export_Model_Feed_Csv extends Lengow_Export_Model_Feed_Abstract {
27
 
28
  protected $_content_type = 'text/csv';
29
 
30
- public function getContentType() {
 
31
  return $this->_content_type;
32
  }
33
 
34
- public function makeHeader() {
 
35
  $head = '';
36
- foreach($this->_fields as $name) {
37
- $head .= self::$CSV_PROTECTION . $this->_clean(substr(str_replace('-', '_', $name), 0, 59)) . self::$CSV_PROTECTION . self::$CSV_SEPARATOR;
 
38
  }
39
- return rtrim($head, self::$CSV_SEPARATOR) . self::$CSV_EOL;
40
  }
41
 
42
- public function makeData($array, $args = array()) {
 
43
  $line = '';
44
- foreach($this->_fields as $name) {
45
- $line .= self::$CSV_PROTECTION . (array_key_exists($name, $array) ? (str_replace(array(self::$CSV_PROTECTION, '\\'), '', $array[$name])) : '') . self::$CSV_PROTECTION . self::$CSV_SEPARATOR;
 
 
46
  }
47
- return rtrim($line, self::$CSV_SEPARATOR) . self::$CSV_EOL;
48
  }
49
 
50
- public function makeFooter() {
 
51
  return '';
52
  }
53
 
@@ -57,7 +66,8 @@ class Lengow_Export_Model_Feed_Csv extends Lengow_Export_Model_Feed_Abstract {
57
  * @param string $str The fieldname
58
  * @return string The formated header.
59
  */
60
- private function _clean($str) {
 
61
  $patterns = array(
62
  /* Lowercase */
63
  '/[\x{0105}\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}]/u',
@@ -91,12 +101,41 @@ class Lengow_Export_Model_Feed_Csv extends Lengow_Export_Model_Feed_Abstract {
91
  '/[\x{00D9}\x{00DA}\x{00DB}\x{00DC}\x{016E}]/u',
92
  '/[\x{017B}\x{0179}\x{017D}]/u',
93
  '/[\x{00C6}]/u',
94
- '/[\x{0152}]/u');
 
95
  $replacements = array(
96
- 'a', 'c', 'd', 'e', 'i', 'l', 'n', 'o', 'r', 's', 'ss', 't', 'u', 'y', 'z', 'ae', 'oe',
97
- 'A', 'C', 'D', 'E', 'L', 'N', 'O', 'R', 'S', 'T', 'U', 'Z', 'AE', 'OE'
98
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  return preg_replace($patterns, $replacements, $str);
100
  }
101
-
102
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model feed csv
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Feed_Csv extends Lengow_Export_Model_Feed_Abstract
13
+ {
14
 
15
  /**
16
  * CSV separator.
17
  */
18
  public static $CSV_SEPARATOR = '|';
19
+
20
  /**
21
  * CSV protection.
22
  */
23
  public static $CSV_PROTECTION = '"';
24
+
25
  /**
26
  * CSV End of line.
27
  */
29
 
30
  protected $_content_type = 'text/csv';
31
 
32
+ public function getContentType()
33
+ {
34
  return $this->_content_type;
35
  }
36
 
37
+ public function makeHeader()
38
+ {
39
  $head = '';
40
+ foreach ($this->_fields as $name) {
41
+ $head .= self::$CSV_PROTECTION . $this->_clean(substr(str_replace('-', '_', $name), 0,
42
+ 59)) . self::$CSV_PROTECTION . self::$CSV_SEPARATOR;
43
  }
44
+ return rtrim($head, self::$CSV_SEPARATOR) . self::$CSV_EOL;
45
  }
46
 
47
+ public function makeData($array, $args = array())
48
+ {
49
  $line = '';
50
+ foreach ($this->_fields as $name) {
51
+ $line .= self::$CSV_PROTECTION . (array_key_exists($name,
52
+ $array) ? (str_replace(array(self::$CSV_PROTECTION, '\\'), '',
53
+ $array[$name])) : '') . self::$CSV_PROTECTION . self::$CSV_SEPARATOR;
54
  }
55
+ return rtrim($line, self::$CSV_SEPARATOR) . self::$CSV_EOL;
56
  }
57
 
58
+ public function makeFooter()
59
+ {
60
  return '';
61
  }
62
 
66
  * @param string $str The fieldname
67
  * @return string The formated header.
68
  */
69
+ private function _clean($str)
70
+ {
71
  $patterns = array(
72
  /* Lowercase */
73
  '/[\x{0105}\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}]/u',
101
  '/[\x{00D9}\x{00DA}\x{00DB}\x{00DC}\x{016E}]/u',
102
  '/[\x{017B}\x{0179}\x{017D}]/u',
103
  '/[\x{00C6}]/u',
104
+ '/[\x{0152}]/u'
105
+ );
106
  $replacements = array(
107
+ 'a',
108
+ 'c',
109
+ 'd',
110
+ 'e',
111
+ 'i',
112
+ 'l',
113
+ 'n',
114
+ 'o',
115
+ 'r',
116
+ 's',
117
+ 'ss',
118
+ 't',
119
+ 'u',
120
+ 'y',
121
+ 'z',
122
+ 'ae',
123
+ 'oe',
124
+ 'A',
125
+ 'C',
126
+ 'D',
127
+ 'E',
128
+ 'L',
129
+ 'N',
130
+ 'O',
131
+ 'R',
132
+ 'S',
133
+ 'T',
134
+ 'U',
135
+ 'Z',
136
+ 'AE',
137
+ 'OE'
138
+ );
139
  return preg_replace($patterns, $replacements, $str);
140
  }
141
+ }
 
app/code/community/Lengow/Export/Model/Feed/Json.php CHANGED
@@ -1,35 +1,40 @@
1
  <?php
 
2
  /**
3
- * Lengow export feed json
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Feed_Json extends Lengow_Export_Model_Feed_Abstract {
 
12
 
13
  protected $_content_type = 'application/json';
14
 
15
- public function getContentType() {
 
16
  return $this->_content_type;
17
  }
18
 
19
- public function makeHeader() {
 
20
  return '{"catalog":[';
21
  }
22
 
23
- public function makeData($array, $args = array()) {
24
- foreach($this->_fields as $name) {
 
25
  $json_array[$name] = array_key_exists($name, $array) ? $array[$name] : '';
26
  }
27
- $line = Mage::helper('core')->jsonEncode($json_array) . (!$args['last'] ? ',' : '') ;
28
  return $line;
29
  }
30
 
31
- public function makeFooter() {
 
32
  return ']}';
33
  }
34
-
35
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model feed json
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Feed_Json extends Lengow_Export_Model_Feed_Abstract
13
+ {
14
 
15
  protected $_content_type = 'application/json';
16
 
17
+ public function getContentType()
18
+ {
19
  return $this->_content_type;
20
  }
21
 
22
+ public function makeHeader()
23
+ {
24
  return '{"catalog":[';
25
  }
26
 
27
+ public function makeData($array, $args = array())
28
+ {
29
+ foreach ($this->_fields as $name) {
30
  $json_array[$name] = array_key_exists($name, $array) ? $array[$name] : '';
31
  }
32
+ $line = Mage::helper('core')->jsonEncode($json_array) . (!$args['last'] ? ',' : '');
33
  return $line;
34
  }
35
 
36
+ public function makeFooter()
37
+ {
38
  return ']}';
39
  }
40
+ }
 
app/code/community/Lengow/Export/Model/Feed/Xml.php CHANGED
@@ -1,37 +1,42 @@
1
  <?php
 
2
  /**
3
  * Lengow export feed xml
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Feed_Xml extends Lengow_Export_Model_Feed_Abstract {
 
12
 
13
  protected $_content_type = 'application/xml';
14
 
15
- public function getContentType() {
 
16
  return $this->_content_type;
17
  }
18
 
19
- public function makeHeader() {
 
20
  return '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
21
- . '<catalog>' . "\r\n";
22
  }
23
 
24
- public function makeData($array, $args = array()) {
 
25
  $line = '<product>' . "\r\n";
26
- foreach($this->_fields as $name) {
27
  $line .= '<' . $name . '><![CDATA[' . (isset($array[$name]) ? $array[$name] : '') . ']]></' . $name . '>' . "\r\n";
28
  }
29
  $line .= '</product>' . "\r\n";
30
  return $line;
31
  }
32
 
33
- public function makeFooter() {
 
34
  return '</catalog>';
35
  }
36
-
37
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export feed xml
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Feed_Xml extends Lengow_Export_Model_Feed_Abstract
13
+ {
14
 
15
  protected $_content_type = 'application/xml';
16
 
17
+ public function getContentType()
18
+ {
19
  return $this->_content_type;
20
  }
21
 
22
+ public function makeHeader()
23
+ {
24
  return '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
25
+ . '<catalog>' . "\r\n";
26
  }
27
 
28
+ public function makeData($array, $args = array())
29
+ {
30
  $line = '<product>' . "\r\n";
31
+ foreach ($this->_fields as $name) {
32
  $line .= '<' . $name . '><![CDATA[' . (isset($array[$name]) ? $array[$name] : '') . ']]></' . $name . '>' . "\r\n";
33
  }
34
  $line .= '</product>' . "\r\n";
35
  return $line;
36
  }
37
 
38
+ public function makeFooter()
39
+ {
40
  return '</catalog>';
41
  }
42
+ }
 
app/code/community/Lengow/Export/Model/Feed/Yaml.php CHANGED
@@ -1,34 +1,41 @@
1
  <?php
 
2
  /**
3
- * Lengow export feed yaml
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Feed_Yaml extends Lengow_Export_Model_Feed_Abstract {
 
12
 
13
  protected $_content_type = 'text/x-yaml';
14
 
15
- public function getContentType() {
 
16
  return $this->_content_type;
17
  }
18
 
19
- public function makeHeader() {
20
- return '"catalog":' . "\r\n";
 
21
  }
22
 
23
- public function makeData($array, $args = array()) {
 
24
  $line = ' ' . '"product":' . "\r\n";
25
- foreach($this->_fields as $name) {
26
- $line .= ' ' . '"' . $name . '":' . $this->_addSpaces($name , 22) . (isset($array[$name]) ? $array[$name] : '') . "\r\n";
 
27
  }
28
  return $line;
29
  }
30
 
31
- public function makeFooter() {
 
32
  return '';
33
  }
34
 
@@ -40,13 +47,13 @@ class Lengow_Export_Model_Feed_Yaml extends Lengow_Export_Model_Feed_Abstract {
40
  *
41
  * @return string Spaces.
42
  */
43
- private function _addSpaces($name, $size) {
 
44
  $strlen = strlen($name);
45
  $spaces = '';
46
- for($i = $strlen; $i < $size; $i++) {
47
  $spaces .= ' ';
48
  }
49
  return $spaces;
50
  }
51
-
52
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model feed yaml
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Feed_Yaml extends Lengow_Export_Model_Feed_Abstract
13
+ {
14
 
15
  protected $_content_type = 'text/x-yaml';
16
 
17
+ public function getContentType()
18
+ {
19
  return $this->_content_type;
20
  }
21
 
22
+ public function makeHeader()
23
+ {
24
+ return '"catalog":' . "\r\n";
25
  }
26
 
27
+ public function makeData($array, $args = array())
28
+ {
29
  $line = ' ' . '"product":' . "\r\n";
30
+ foreach ($this->_fields as $name) {
31
+ $line .= ' ' . '"' . $name . '":' . $this->_addSpaces($name,
32
+ 22) . (isset($array[$name]) ? $array[$name] : '') . "\r\n";
33
  }
34
  return $line;
35
  }
36
 
37
+ public function makeFooter()
38
+ {
39
  return '';
40
  }
41
 
47
  *
48
  * @return string Spaces.
49
  */
50
+ private function _addSpaces($name, $size)
51
+ {
52
  $strlen = strlen($name);
53
  $spaces = '';
54
+ for ($i = $strlen; $i < $size; $i++) {
55
  $spaces .= ' ';
56
  }
57
  return $spaces;
58
  }
59
+ }
 
app/code/community/Lengow/Export/Model/Generate.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
  * Lengow adminhtml export controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Generate extends Varien_Object {
 
12
 
13
  protected $_id_store;
14
 
@@ -38,26 +40,30 @@ class Lengow_Export_Model_Generate extends Varien_Object {
38
 
39
  var $storeParents = array();
40
 
41
- protected $_excludes = array('media_gallery',
 
42
  'tier_price',
43
  'short_description',
44
  'description',
45
- 'quantity');
46
-
 
47
  /**
48
  * Default fields.
49
  */
50
- public static $DEFAULT_FIELDS = array('sku' => 'sku' ,
51
- 'entity_id' => 'product-id' ,
52
- 'parent-id' => 'parent-id' ,
53
- 'qty' => 'qty' ,
54
- 'name' => 'name' ,
55
- 'description' => 'description' ,
56
- 'short_description' => 'short_description' ,
57
- 'price-ttc' => 'price-ttc' ,
58
- 'shipping-name' => 'shipping-name' ,
59
- 'image-url-1' => 'image-url-1' ,
60
- 'product-url' => 'product-url');
 
 
61
 
62
  /**
63
  * Construct generator
@@ -76,25 +82,26 @@ class Lengow_Export_Model_Generate extends Varien_Object {
76
  /**
77
  * Make the feed
78
  *
79
- * @param integer $id_store ID of store
80
- * @param varchar $mode The mode of export
81
  * size : display only count of products to export
82
  * full : export simple product + configured product
83
  * xxx,yyy : export xxx type product + yyy type product
84
- * @param varchar $format Format of export
85
- * @param varchar $types Type(s) of product
86
- * @param varchar $status Status of product to export
87
- * @param boolean $export_child Export child of product
88
- * @param boolean $out_of_stock Export product out of stock
89
- * @param boolean $selected_products Export selected product
90
- * @param boolean $stream Export in file or not
91
- * @param integer $limit The number of product to be exported
92
- * @param integer $offset From what product export
93
- * @param array $ids_product Ids product to export
94
  *
95
  * @return Mage_Catalog_Model_Product
96
  */
97
- public function exec($id_store,
 
98
  $mode = null,
99
  $format = null,
100
  $types = null,
@@ -105,8 +112,8 @@ class Lengow_Export_Model_Generate extends Varien_Object {
105
  $stream = null,
106
  $limit = null,
107
  $offset = null,
108
- $ids_product = null)
109
- {
110
 
111
  //store start time export
112
  $time_start = $this->microtime_float();
@@ -116,27 +123,31 @@ class Lengow_Export_Model_Generate extends Varien_Object {
116
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
117
  $this->_config['directory_path'] = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store_code . DS;
118
 
119
- if (!is_null($format))
120
  $this->_format = $format;
 
121
  $this->_fileFormat = $this->_format;
122
 
123
- if ($this->_isAlreadyLaunch()){
124
  Mage::helper('lensync/data')->log('Feed already launch');
125
 
126
- if(!$this->_stream) {
127
  echo date('Y-m-d h:i:s') . ' - FEED ALREADY LAUNCH<br />';
128
  }
129
  exit();
130
  }
131
 
132
  // Get products list to export
133
- $products = $this->_getProductsCollection($types, $status, $export_child, $out_of_stock, $selected_products, $limit, $offset, $ids_product);
 
134
  // Mode size, return count of products
135
- if($mode == 'size')
136
- die((string) sizeof($products));
137
- if(!is_null($stream))
 
138
  $this->_stream = $stream;
139
- if(!$this->_stream) {
 
140
  header('Content-Type: text/html; charset=utf-8');
141
  echo date('Y-m-d h:i:s') . ' - Start export in store ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ')<br />';
142
  flush();
@@ -151,7 +162,7 @@ class Lengow_Export_Model_Generate extends Varien_Object {
151
  $total_product = count($products);
152
  $pi = 1;
153
  Mage::helper('lensync/data')->log('Find ' . $total_product . ' product' . ($total_product > 1 ? 's ' : ' '));
154
- if(!$this->_stream) {
155
  echo date('Y-m-d h:i:s') . ' - Find ' . $total_product . ' product' . ($total_product > 1 ? 's ' : ' ') . '<br />';
156
  flush();
157
  }
@@ -163,12 +174,13 @@ class Lengow_Export_Model_Generate extends Varien_Object {
163
  $count_grouped = 0;
164
  $count_virtual = 0;
165
  // Generate data
166
- foreach($products as $p) {
167
  $array_data = array();
168
  $parent = false;
169
  $pi++;
170
- if($total_product < $pi)
171
  $last = true;
 
172
  $product = Mage::getModel('lenexport/catalog_product')
173
  ->setStoreId($this->_id_store)
174
  ->setOriginalCurrency($this->getOriginalCurrency())
@@ -182,7 +194,7 @@ class Lengow_Export_Model_Generate extends Varien_Object {
182
  $parent_id = null;
183
  $product_type = 'simple';
184
  $variation_name = '';
185
- if($product->getTypeId() == 'configurable') {
186
  $count_configurable++;
187
  $product_type = 'parent';
188
  $product_temp = $product;
@@ -192,19 +204,19 @@ class Lengow_Export_Model_Generate extends Varien_Object {
192
  ->setStoreId($this->_id_store)
193
  ->getTypeInstance(true)
194
  ->getConfigurableAttributesAsArray($product);
195
- if($variations) {
196
  foreach ($variations as $variation) {
197
  $variation_name .= $variation['frontend_label'] . ',';
198
  }
199
  $variation_name = rtrim($variation_name, ',');
200
  }
201
  }
202
- if($product->getTypeId() == 'virtual') {
203
  $count_virtual++;
204
  $product_type = 'virtual';
205
  }
206
- if($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle') {
207
- if($product->getTypeId() == 'bundle') {
208
  $count_bundle++;
209
  $product_type = 'bundle';
210
  } else {
@@ -221,47 +233,50 @@ class Lengow_Export_Model_Generate extends Varien_Object {
221
  }, array());
222
  foreach ($childrenIds as $childrenId) {
223
  $product_temporary = Mage::getModel('catalog/product')
224
- ->setOriginalCurrency($this->getOriginalCurrency())
225
- ->setCurrentCurrencyCode($this->getCurrentCurrencyCode())
226
- ->setStoreId($this->_id_store)
227
- ->load($childrenId);
228
  $qtys[] = $product_temporary->getData('stock_item')->getQty();
229
  unset($product_temporary);
230
  }
231
  $qty_temp = min($qtys) > 0 ? min($qtys) : 0;
232
  }
233
- if($product->getTypeId() == 'simple') {
234
  $count_simple++;
235
  $parents = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($p['entity_id']);
236
- if(!empty($parents)) {
237
 
238
  $parent_instance = $this->_getParentEntity((int)$parents[0]);
239
 
240
  // Exclude if parent is disabled
241
- if($parent_instance && $parent_instance->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
242
  $count_simple_disabled++;
243
- if(!$this->_stream) {
244
- if($pi % 20 == 0)
245
- echo date('Y-m-d h:i:s') .' - Export ' . $pi . ' products<br />';
 
246
  flush();
247
  }
248
- if(method_exists($product, 'clearInstance')) {
249
  $product->clearInstance();
250
- if($parent != null)
251
  $parent->clearInstance();
252
- if($parent_instance != null)
 
253
  $parent_instance->clearInstance();
 
254
  }
255
 
256
  unset($array_data);
257
  continue;
258
  }
259
- if($parent_instance && $parent_instance->getId() && $parent_instance->getTypeId() == 'configurable') {
260
  $parent_id = $parent_instance->getId();
261
 
262
  $variations = $parent_instance->getTypeInstance(true)
263
  ->getConfigurableAttributesAsArray($parent_instance);
264
- if($variations) {
265
  foreach ($variations as $variation) {
266
  $variation_name .= $variation['frontend_label'] . ',';
267
  }
@@ -272,13 +287,13 @@ class Lengow_Export_Model_Generate extends Varien_Object {
272
  }
273
  }
274
  $parents = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($parent_id ? $parent_id : $p['entity_id']);
275
- if(!empty($parents)) {
276
  $temp_instance = Mage::getModel('catalog/product')
277
  ->setOriginalCurrency($this->getOriginalCurrency())
278
  ->setCurrentCurrencyCode($this->getCurrentCurrencyCode())
279
  ->setStoreId($this->_id_store)
280
  ->getCollection()
281
- ->addAttributeToFilter('type_id','grouped')
282
  ->addAttributeToFilter('entity_id', array('in' => $parents))
283
  ->getFirstItem();
284
 
@@ -288,32 +303,44 @@ class Lengow_Export_Model_Generate extends Varien_Object {
288
  // Default data
289
  $array_data['sku'] = $product->getSku();
290
  $array_data['product_id'] = $product->getId();
291
- $array_data['qty'] = (integer) $qty->getQty();
292
- if($this->_config_model->get('data/without_product_ordering'))
293
- $array_data['qty'] = $array_data['qty'] - (integer) $qty->getQtyOrdered();
294
- if($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle')
295
- $array_data['qty'] = (integer) $qty_temp;
 
 
296
  $array_data['status'] = $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED ? 'Disabled' : 'Enabled';
297
- $array_data = array_merge($array_data, $product->getCategories($product, $parent_instance, $this->_id_store, $this->categoryCache));
298
- $array_data = array_merge($array_data, $product->getPrices($product, $configurable_instance, $this->_id_store));
 
 
299
  $array_data = array_merge($array_data, $product->getShippingInfo($product));
300
  // Images, gestion de la fusion parent / enfant
301
- if($this->_config_model->get('data/parentsimages') && isset($parent_instance) && $parent_instance !== false)
302
- $array_data = array_merge($array_data, $product->getImages($data['media_gallery']['images'], $parent_instance->getData('media_gallery')));
303
- else
 
304
  $array_data = array_merge($array_data, $product->getImages($data['media_gallery']['images']));
 
305
  // formatdata -> replace special chars with html chars
306
  $formatData = $this->_config_model->get('data/formatdata') == 1 ? true : false;
307
- if($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($parent_instance)) {
308
  $array_data['product-url'] = $parent_instance->getUrlInStore() ? $parent_instance->getUrlInStore() : $parent_instance->getProductUrl();
309
- $array_data['name'] = $this->_helper->cleanData($parent_instance->getName(), $formatData, in_array('name', $this->_config_model->getHtmlAttributes()));
310
- $array_data['description'] = $this->_helper->cleanData($parent_instance->getDescription(), $formatData, in_array('description', $this->_config_model->getHtmlAttributes()));
311
- $array_data['short_description'] = $this->_helper->cleanData($parent_instance->getShortDescription(), $formatData, in_array('short_description', $this->_config_model->getHtmlAttributes()));
 
 
 
312
  } else {
313
  $array_data['product-url'] = $product->getUrlInStore() ? $product->getUrlInStore() : $product->getProductUrl();
314
- $array_data['name'] = $this->_helper->cleanData($product->getName(), $formatData, in_array('name', $this->_config_model->getHtmlAttributes()));
315
- $array_data['description'] = $this->_helper->cleanData($product->getDescription(), $formatData, in_array('description', $this->_config_model->getHtmlAttributes()));
316
- $array_data['short_description'] = $this->_helper->cleanData($product->getShortDescription(), $formatData, in_array('short_description', $this->_config_model->getHtmlAttributes()));
 
 
 
317
  }
318
  $array_data['parent_id'] = $parent_id;
319
  // Product variation
@@ -322,39 +349,45 @@ class Lengow_Export_Model_Generate extends Varien_Object {
322
  $array_data['image_default'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
323
  $array_data['child_name'] = $this->_helper->cleanData($product->getName(), $formatData);
324
  // Selected attributes to export with Frond End value of current shop
325
- if(!empty($attributes_to_export)) {
326
- foreach($attributes_to_export as $field => $attr) {
327
- if(!in_array($field, $this->_excludes) && !isset($array_data[$field])) {
328
- if($product->getData($field) === null)
329
  $array_data[$attr] = '';
330
- else if(is_array($product->getData($field)))
331
- $array_data[$attr] = implode(',', $product->getData($field));
332
- else
333
- $array_data[$attr] = $this->_helper->cleanData($product->getResource()->getAttribute($field)->getFrontend()->getValue($product), $formatData, in_array($field, $this->_config_model->getHtmlAttributes()));
 
 
 
 
334
  }
335
  }
336
  }
337
  // Get header of feed
338
- if($first) {
339
  $fields_header = array();
340
- foreach($array_data as $name => $value) {
341
  $fields_header[] = $name;
342
  }
343
  // Get content type if streamed feed
344
- if($this->_stream)
345
  header('Content-Type: ' . $feed->getContentType() . '; charset=utf-8');
 
346
  $feed->setFields($fields_header);
347
  $this->_write($feed->makeHeader());
348
  $first = false;
349
  }
350
  $this->_write($feed->makeData($array_data, array('last' => $last)));
351
- if(!$this->_stream) {
352
- if($pi % 20 == 0)
353
- echo date('Y-m-d h:i:s') .' - Export ' . $pi . ' products<br />';
 
354
  flush();
355
  }
356
  // Fix Sébastien Ledan
357
- if(method_exists($product, 'clearInstance')) {
358
  $product->clearInstance();
359
  }
360
  unset($array_data);
@@ -371,30 +404,32 @@ class Lengow_Export_Model_Generate extends Varien_Object {
371
  . $count_virtual . ' virtual product' . ($count_virtual > 1 ? 's ' : '') . ')';
372
  Mage::helper('lensync/data')->log($message_count);
373
  if ($count_simple_disabled > 1) {
374
- if ($count_simple_disabled == 1)
375
  $message_warning = 'WARNING ! 1 simple product is associated with a disabled configurable product';
376
- else
377
  $message_warning = 'WARNING ! ' . $count_simple_disabled . ' simple products are associated with configurable products disabled';
 
378
  Mage::helper('lensync/data')->log($message_warning);
379
  if (!$this->_stream) {
380
- echo date('Y-m-d h:i:s') .' - ' . $message_warning . '<br />';
381
  flush();
382
  }
383
  }
384
- if(!$this->_stream) {
385
- echo date('Y-m-d h:i:s') .' - ' . $message_count . '<br />';
386
  flush();
387
  $this->_copyFile();
388
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
389
  $url_file = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'lengow' . DS . $store_code . DS . $this->_fileName . '.' . $this->_format;
390
- echo $this->_helper->__('Your feed is available here : %s' , '<a href="' . $url_file . '">' . $url_file . '</a>');
 
391
  Mage::helper('lensync/data')->log('Export of the store ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ') generated a file here : ' . $url_file);
392
  }
393
 
394
  $time_end = $this->microtime_float();
395
  $time = $time_end - $time_start;
396
- if(!$this->_stream) {
397
- echo "<br/> Memory Usage ".memory_get_usage()/1000000;
398
  echo "<br/> Execution time $time secondes";
399
  }
400
  }
@@ -402,22 +437,23 @@ class Lengow_Export_Model_Generate extends Varien_Object {
402
  /**
403
  * Temporary store Parent Identity
404
  *
405
- * @param integer $parent_id Parent Entity Id
406
  *
407
  * @return object Catalog/product
408
  */
409
- protected function _getParentEntity($parent_id){
410
- $this->_clear_parent_cache ++;
411
- if (!isset($this->storeParents[$parent_id])){
 
412
  $parent = Mage::getModel('lenexport/catalog_product')
413
  ->setStoreId($this->_id_store)
414
  ->setOriginalCurrency($this->getOriginalCurrency())
415
  ->setCurrentCurrencyCode($this->getCurrentCurrencyCode())
416
  ->load($parent_id);
417
- $this->storeParents[$parent_id] = $parent;
418
  }
419
- if ($this->_clear_parent_cache>300){
420
- if(method_exists($this->storeParents[0], 'clearInstance')) {
421
  $maxStoreParent = count($this->storeParents);
422
  for ($i = 0; $i < $maxStoreParent; $i++) {
423
  $this->storeParents[0]->clearInstance();
@@ -432,75 +468,86 @@ class Lengow_Export_Model_Generate extends Varien_Object {
432
  /**
433
  * Get products collection for export
434
  *
435
- * @param varchar $types Type(s) of product
436
- * @param varchar $status Status of product to export
437
- * @param boolean $export_child Export child of product
438
- * @param boolean $out_of_stock Export product out of stock
439
- * @param boolean $selected_products Export selected product
440
- * @param integer $limit The number of product to be exported
441
- * @param integer $offset From what product export
442
- * @param array $ids_product Ids product to export
443
  *
444
  * @return array
445
  */
446
- protected function _getProductsCollection($types = null,
447
- $status = null,
448
- $export_child = null,
449
- $out_of_stock = null,
450
- $selected_products = null,
451
- $limit = null,
452
- $offset = null,
453
- $ids_product = null)
454
- {
 
455
  // Filter types
456
- if($types) {
457
  $_types = explode(',', $types);
458
  } else {
459
  $_types = $this->_config_model->get('global/producttype');
460
  $_types = explode(',', $_types);
461
  }
462
- if(is_null($selected_products))
463
  $selected_products = $this->_config_model->onlySelectedProducts();
 
464
  // Search product to export
465
  $products = $this->_product_model
466
- ->getCollection()
467
- ->addAttributeToSelect('sku')
468
- ->setStoreId($this->_id_store)
469
- ->addStoreFilter($this->_id_store)
470
- ->addAttributeToFilter('type_id', array('in' => $_types))
471
- ->joinField('store_id', Mage::getConfig()->getTablePrefix() . 'catalog_category_product_index', 'store_id', 'product_id=entity_id', '{{table}}.store_id = '.$this->_id_store, 'left');
 
472
  // Filter status
473
- if(is_null($status))
474
- $status = (string) $this->_config_model->get('global/productstatus');
475
- if($status === (string) Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
 
476
  $products->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
477
- else if($status === (string) Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
478
- $products->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED));
 
 
 
 
479
  // Export only selected products
480
- if($selected_products) {
481
  $products->addAttributeToFilter('lengow_product', 1);
482
  }
483
  // Filter out of stock
484
- if(is_null($out_of_stock))
485
  $out_of_stock = $this->_config_model->isExportSoldout();
486
- $products->joinTable('cataloginventory/stock_item', 'product_id=entity_id', array('qty' => 'qty', 'is_in_stock' => 'is_in_stock'), $this->_getOutOfStockSQL($out_of_stock), 'inner');
 
 
487
  // Ids product
488
- if($ids_product) {
489
  $ids_product = explode(',', $ids_product);
490
  $products->addAttributeToFilter('entity_id', array('in' => $ids_product));
491
  }
492
  // Limit & Offset
493
- if($limit) {
494
- if($offset)
495
  $products->getSelect()->limit($limit, $offset);
496
- else
497
  $products->getSelect()->limit($limit);
 
498
  }
499
  // Filter to hide products
500
  Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
501
  $products->getSelect()
502
- ->distinct(true)
503
- ->group('entity_id');
504
  return $products->getData();
505
  }
506
 
@@ -514,7 +561,7 @@ class Lengow_Export_Model_Generate extends Varien_Object {
514
  protected function _getOutOfStockSQL($out_of_stock = false)
515
  {
516
  // Filter product without stock
517
- if(!$out_of_stock) {
518
  $config = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
519
  $sql = '({{table}}.`is_in_stock` = 1) '
520
  . ' OR IF({{table}}.`use_config_manage_stock` = 1, ' . $config . ', {{table}}.`manage_stock`) = 0';
@@ -531,8 +578,9 @@ class Lengow_Export_Model_Generate extends Varien_Object {
531
  protected function _getAttributesFromConfig()
532
  {
533
  $attributes = $this->_config_model->getSelectedAttributes();
534
- foreach($attributes as $name => $value)
535
  self::$DEFAULT_FIELDS[$name] = $value;
 
536
  return self::$DEFAULT_FIELDS;
537
  }
538
 
@@ -545,12 +593,12 @@ class Lengow_Export_Model_Generate extends Varien_Object {
545
  */
546
  protected function getAttributesFromConfig($exist = false)
547
  {
548
- $attributes = $this->_config_model->getMappingAllAttributes();
549
- if($exist) {
550
  $product = Mage::getModel('catalog/product');
551
- foreach ($attributes as $key=>$code) {
552
  $attribute = $product->getResource()->getAttribute($code);
553
- if($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute && $attribute->getId() && $attribute->getFrontendInput() != 'weee') {
554
  $attributes[$key] = $code;
555
  }
556
  }
@@ -563,10 +611,10 @@ class Lengow_Export_Model_Generate extends Varien_Object {
563
  *
564
  * @param array $data
565
  */
566
- protected function _write($data)
567
  {
568
- if($this->_stream == false) {
569
- if(!$this->_file) {
570
  $this->_initFile();
571
  }
572
  $this->_file->streamLock();
@@ -581,9 +629,11 @@ class Lengow_Export_Model_Generate extends Varien_Object {
581
  /**
582
  * Create File for export
583
  */
584
- protected function _initFile()
585
  {
586
- if (!$this->_createDirectory()){ exit(); }
 
 
587
 
588
  $this->_fileTimeStamp = time();
589
  $this->_file = new Varien_Io_File;
@@ -591,14 +641,15 @@ class Lengow_Export_Model_Generate extends Varien_Object {
591
  $this->_file->streamOpen($this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat, 'w+');
592
  }
593
 
594
- protected function _createDirectory(){
 
595
  try {
596
  $file = new Varien_Io_File;
597
  $file->checkAndCreateFolder($this->_config['directory_path']);
598
  } catch (Exception $e) {
599
- Mage::helper('lensync/data')->log('can\'t create folder '.$this->_config['directory_path'].'');
600
- if ($this->_debug){
601
- $this->_log('can\'t create folder '.$this->_config['directory_path']);
602
  }
603
  return false;
604
  }
@@ -610,19 +661,20 @@ class Lengow_Export_Model_Generate extends Varien_Object {
610
  *
611
  * @return boolean
612
  */
613
- protected function _isAlreadyLaunch(){
 
614
 
615
  $directory = $this->_config['directory_path'];
616
- if (!$this->_createDirectory()){
617
  exit();
618
  }
619
 
620
  try {
621
  $listFiles = array_diff(scandir($directory), array('..', '.'));
622
  } catch (Exception $e) {
623
- Mage::helper('lensync/data')->log('Can\'t access folder '.$this->_config['directory_path']);
624
- if ($this->_debug){
625
- $this->_log('Can\'t access folder '.$this->_config['directory_path']);
626
  }
627
  exit();
628
  }
@@ -649,10 +701,11 @@ class Lengow_Export_Model_Generate extends Varien_Object {
649
  /**
650
  * Copies the file to the correct folder
651
  */
652
- protected function _copyFile()
653
  {
654
  $file_path = $this->_config['directory_path'];
655
- copy($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat, $file_path . $this->_fileName . '.' . $this->_fileFormat);
 
656
  unlink($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat);
657
  }
658
 
@@ -666,10 +719,13 @@ class Lengow_Export_Model_Generate extends Varien_Object {
666
  }
667
 
668
 
669
- protected function stop($time_start, $string){
 
670
  $time_end = $this->microtime_float();
671
  $time = $time_end - $time_start;
672
- if ($time<0.0001){ $time = 0;}
673
- echo round($time,4)." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $string secondes <br/>";
 
 
674
  }
675
  }
1
  <?php
2
+
3
  /**
4
  * Lengow adminhtml export controller
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Generate extends Varien_Object
13
+ {
14
 
15
  protected $_id_store;
16
 
40
 
41
  var $storeParents = array();
42
 
43
+ protected $_excludes = array(
44
+ 'media_gallery',
45
  'tier_price',
46
  'short_description',
47
  'description',
48
+ 'quantity'
49
+ );
50
+
51
  /**
52
  * Default fields.
53
  */
54
+ public static $DEFAULT_FIELDS = array(
55
+ 'sku' => 'sku',
56
+ 'entity_id' => 'product-id',
57
+ 'parent-id' => 'parent-id',
58
+ 'qty' => 'qty',
59
+ 'name' => 'name',
60
+ 'description' => 'description',
61
+ 'short_description' => 'short_description',
62
+ 'price-ttc' => 'price-ttc',
63
+ 'shipping-name' => 'shipping-name',
64
+ 'image-url-1' => 'image-url-1',
65
+ 'product-url' => 'product-url'
66
+ );
67
 
68
  /**
69
  * Construct generator
82
  /**
83
  * Make the feed
84
  *
85
+ * @param integer $id_store ID of store
86
+ * @param varchar $mode The mode of export
87
  * size : display only count of products to export
88
  * full : export simple product + configured product
89
  * xxx,yyy : export xxx type product + yyy type product
90
+ * @param varchar $format Format of export
91
+ * @param varchar $types Type(s) of product
92
+ * @param varchar $status Status of product to export
93
+ * @param boolean $export_child Export child of product
94
+ * @param boolean $out_of_stock Export product out of stock
95
+ * @param boolean $selected_products Export selected product
96
+ * @param boolean $stream Export in file or not
97
+ * @param integer $limit The number of product to be exported
98
+ * @param integer $offset From what product export
99
+ * @param array $ids_product Ids product to export
100
  *
101
  * @return Mage_Catalog_Model_Product
102
  */
103
+ public function exec(
104
+ $id_store,
105
  $mode = null,
106
  $format = null,
107
  $types = null,
112
  $stream = null,
113
  $limit = null,
114
  $offset = null,
115
+ $ids_product = null
116
+ ) {
117
 
118
  //store start time export
119
  $time_start = $this->microtime_float();
123
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
124
  $this->_config['directory_path'] = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store_code . DS;
125
 
126
+ if (!is_null($format)) {
127
  $this->_format = $format;
128
+ }
129
  $this->_fileFormat = $this->_format;
130
 
131
+ if ($this->_isAlreadyLaunch()) {
132
  Mage::helper('lensync/data')->log('Feed already launch');
133
 
134
+ if (!$this->_stream) {
135
  echo date('Y-m-d h:i:s') . ' - FEED ALREADY LAUNCH<br />';
136
  }
137
  exit();
138
  }
139
 
140
  // Get products list to export
141
+ $products = $this->_getProductsCollection($types, $status, $export_child, $out_of_stock, $selected_products,
142
+ $limit, $offset, $ids_product);
143
  // Mode size, return count of products
144
+ if ($mode == 'size') {
145
+ die((string)sizeof($products));
146
+ }
147
+ if (!is_null($stream)) {
148
  $this->_stream = $stream;
149
+ }
150
+ if (!$this->_stream) {
151
  header('Content-Type: text/html; charset=utf-8');
152
  echo date('Y-m-d h:i:s') . ' - Start export in store ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ')<br />';
153
  flush();
162
  $total_product = count($products);
163
  $pi = 1;
164
  Mage::helper('lensync/data')->log('Find ' . $total_product . ' product' . ($total_product > 1 ? 's ' : ' '));
165
+ if (!$this->_stream) {
166
  echo date('Y-m-d h:i:s') . ' - Find ' . $total_product . ' product' . ($total_product > 1 ? 's ' : ' ') . '<br />';
167
  flush();
168
  }
174
  $count_grouped = 0;
175
  $count_virtual = 0;
176
  // Generate data
177
+ foreach ($products as $p) {
178
  $array_data = array();
179
  $parent = false;
180
  $pi++;
181
+ if ($total_product < $pi) {
182
  $last = true;
183
+ }
184
  $product = Mage::getModel('lenexport/catalog_product')
185
  ->setStoreId($this->_id_store)
186
  ->setOriginalCurrency($this->getOriginalCurrency())
194
  $parent_id = null;
195
  $product_type = 'simple';
196
  $variation_name = '';
197
+ if ($product->getTypeId() == 'configurable') {
198
  $count_configurable++;
199
  $product_type = 'parent';
200
  $product_temp = $product;
204
  ->setStoreId($this->_id_store)
205
  ->getTypeInstance(true)
206
  ->getConfigurableAttributesAsArray($product);
207
+ if ($variations) {
208
  foreach ($variations as $variation) {
209
  $variation_name .= $variation['frontend_label'] . ',';
210
  }
211
  $variation_name = rtrim($variation_name, ',');
212
  }
213
  }
214
+ if ($product->getTypeId() == 'virtual') {
215
  $count_virtual++;
216
  $product_type = 'virtual';
217
  }
218
+ if ($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle') {
219
+ if ($product->getTypeId() == 'bundle') {
220
  $count_bundle++;
221
  $product_type = 'bundle';
222
  } else {
233
  }, array());
234
  foreach ($childrenIds as $childrenId) {
235
  $product_temporary = Mage::getModel('catalog/product')
236
+ ->setOriginalCurrency($this->getOriginalCurrency())
237
+ ->setCurrentCurrencyCode($this->getCurrentCurrencyCode())
238
+ ->setStoreId($this->_id_store)
239
+ ->load($childrenId);
240
  $qtys[] = $product_temporary->getData('stock_item')->getQty();
241
  unset($product_temporary);
242
  }
243
  $qty_temp = min($qtys) > 0 ? min($qtys) : 0;
244
  }
245
+ if ($product->getTypeId() == 'simple') {
246
  $count_simple++;
247
  $parents = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($p['entity_id']);
248
+ if (!empty($parents)) {
249
 
250
  $parent_instance = $this->_getParentEntity((int)$parents[0]);
251
 
252
  // Exclude if parent is disabled
253
+ if ($parent_instance && $parent_instance->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
254
  $count_simple_disabled++;
255
+ if (!$this->_stream) {
256
+ if ($pi % 20 == 0) {
257
+ echo date('Y-m-d h:i:s') . ' - Export ' . $pi . ' products<br />';
258
+ }
259
  flush();
260
  }
261
+ if (method_exists($product, 'clearInstance')) {
262
  $product->clearInstance();
263
+ if ($parent != null) {
264
  $parent->clearInstance();
265
+ }
266
+ if ($parent_instance != null) {
267
  $parent_instance->clearInstance();
268
+ }
269
  }
270
 
271
  unset($array_data);
272
  continue;
273
  }
274
+ if ($parent_instance && $parent_instance->getId() && $parent_instance->getTypeId() == 'configurable') {
275
  $parent_id = $parent_instance->getId();
276
 
277
  $variations = $parent_instance->getTypeInstance(true)
278
  ->getConfigurableAttributesAsArray($parent_instance);
279
+ if ($variations) {
280
  foreach ($variations as $variation) {
281
  $variation_name .= $variation['frontend_label'] . ',';
282
  }
287
  }
288
  }
289
  $parents = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($parent_id ? $parent_id : $p['entity_id']);
290
+ if (!empty($parents)) {
291
  $temp_instance = Mage::getModel('catalog/product')
292
  ->setOriginalCurrency($this->getOriginalCurrency())
293
  ->setCurrentCurrencyCode($this->getCurrentCurrencyCode())
294
  ->setStoreId($this->_id_store)
295
  ->getCollection()
296
+ ->addAttributeToFilter('type_id', 'grouped')
297
  ->addAttributeToFilter('entity_id', array('in' => $parents))
298
  ->getFirstItem();
299
 
303
  // Default data
304
  $array_data['sku'] = $product->getSku();
305
  $array_data['product_id'] = $product->getId();
306
+ $array_data['qty'] = (integer)$qty->getQty();
307
+ if ($this->_config_model->get('data/without_product_ordering')) {
308
+ $array_data['qty'] = $array_data['qty'] - (integer)$qty->getQtyOrdered();
309
+ }
310
+ if ($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle') {
311
+ $array_data['qty'] = (integer)$qty_temp;
312
+ }
313
  $array_data['status'] = $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED ? 'Disabled' : 'Enabled';
314
+ $array_data = array_merge($array_data,
315
+ $product->getCategories($product, $parent_instance, $this->_id_store, $this->categoryCache));
316
+ $array_data = array_merge($array_data,
317
+ $product->getPrices($product, $configurable_instance, $this->_id_store));
318
  $array_data = array_merge($array_data, $product->getShippingInfo($product));
319
  // Images, gestion de la fusion parent / enfant
320
+ if ($this->_config_model->get('data/parentsimages') && isset($parent_instance) && $parent_instance !== false) {
321
+ $array_data = array_merge($array_data,
322
+ $product->getImages($data['media_gallery']['images'], $parent_instance->getData('media_gallery')));
323
+ } else {
324
  $array_data = array_merge($array_data, $product->getImages($data['media_gallery']['images']));
325
+ }
326
  // formatdata -> replace special chars with html chars
327
  $formatData = $this->_config_model->get('data/formatdata') == 1 ? true : false;
328
+ if ($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($parent_instance)) {
329
  $array_data['product-url'] = $parent_instance->getUrlInStore() ? $parent_instance->getUrlInStore() : $parent_instance->getProductUrl();
330
+ $array_data['name'] = $this->_helper->cleanData($parent_instance->getName(), $formatData,
331
+ in_array('name', $this->_config_model->getHtmlAttributes()));
332
+ $array_data['description'] = $this->_helper->cleanData($parent_instance->getDescription(), $formatData,
333
+ in_array('description', $this->_config_model->getHtmlAttributes()));
334
+ $array_data['short_description'] = $this->_helper->cleanData($parent_instance->getShortDescription(),
335
+ $formatData, in_array('short_description', $this->_config_model->getHtmlAttributes()));
336
  } else {
337
  $array_data['product-url'] = $product->getUrlInStore() ? $product->getUrlInStore() : $product->getProductUrl();
338
+ $array_data['name'] = $this->_helper->cleanData($product->getName(), $formatData,
339
+ in_array('name', $this->_config_model->getHtmlAttributes()));
340
+ $array_data['description'] = $this->_helper->cleanData($product->getDescription(), $formatData,
341
+ in_array('description', $this->_config_model->getHtmlAttributes()));
342
+ $array_data['short_description'] = $this->_helper->cleanData($product->getShortDescription(),
343
+ $formatData, in_array('short_description', $this->_config_model->getHtmlAttributes()));
344
  }
345
  $array_data['parent_id'] = $parent_id;
346
  // Product variation
349
  $array_data['image_default'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
350
  $array_data['child_name'] = $this->_helper->cleanData($product->getName(), $formatData);
351
  // Selected attributes to export with Frond End value of current shop
352
+ if (!empty($attributes_to_export)) {
353
+ foreach ($attributes_to_export as $field => $attr) {
354
+ if (!in_array($field, $this->_excludes) && !isset($array_data[$field])) {
355
+ if ($product->getData($field) === null) {
356
  $array_data[$attr] = '';
357
+ } else {
358
+ if (is_array($product->getData($field))) {
359
+ $array_data[$attr] = implode(',', $product->getData($field));
360
+ } else {
361
+ $array_data[$attr] = $this->_helper->cleanData($product->getResource()->getAttribute($field)->getFrontend()->getValue($product),
362
+ $formatData, in_array($field, $this->_config_model->getHtmlAttributes()));
363
+ }
364
+ }
365
  }
366
  }
367
  }
368
  // Get header of feed
369
+ if ($first) {
370
  $fields_header = array();
371
+ foreach ($array_data as $name => $value) {
372
  $fields_header[] = $name;
373
  }
374
  // Get content type if streamed feed
375
+ if ($this->_stream) {
376
  header('Content-Type: ' . $feed->getContentType() . '; charset=utf-8');
377
+ }
378
  $feed->setFields($fields_header);
379
  $this->_write($feed->makeHeader());
380
  $first = false;
381
  }
382
  $this->_write($feed->makeData($array_data, array('last' => $last)));
383
+ if (!$this->_stream) {
384
+ if ($pi % 20 == 0) {
385
+ echo date('Y-m-d h:i:s') . ' - Export ' . $pi . ' products<br />';
386
+ }
387
  flush();
388
  }
389
  // Fix Sébastien Ledan
390
+ if (method_exists($product, 'clearInstance')) {
391
  $product->clearInstance();
392
  }
393
  unset($array_data);
404
  . $count_virtual . ' virtual product' . ($count_virtual > 1 ? 's ' : '') . ')';
405
  Mage::helper('lensync/data')->log($message_count);
406
  if ($count_simple_disabled > 1) {
407
+ if ($count_simple_disabled == 1) {
408
  $message_warning = 'WARNING ! 1 simple product is associated with a disabled configurable product';
409
+ } else {
410
  $message_warning = 'WARNING ! ' . $count_simple_disabled . ' simple products are associated with configurable products disabled';
411
+ }
412
  Mage::helper('lensync/data')->log($message_warning);
413
  if (!$this->_stream) {
414
+ echo date('Y-m-d h:i:s') . ' - ' . $message_warning . '<br />';
415
  flush();
416
  }
417
  }
418
+ if (!$this->_stream) {
419
+ echo date('Y-m-d h:i:s') . ' - ' . $message_count . '<br />';
420
  flush();
421
  $this->_copyFile();
422
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
423
  $url_file = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'lengow' . DS . $store_code . DS . $this->_fileName . '.' . $this->_format;
424
+ echo $this->_helper->__('Your feed is available here : %s',
425
+ '<a href="' . $url_file . '">' . $url_file . '</a>');
426
  Mage::helper('lensync/data')->log('Export of the store ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ') generated a file here : ' . $url_file);
427
  }
428
 
429
  $time_end = $this->microtime_float();
430
  $time = $time_end - $time_start;
431
+ if (!$this->_stream) {
432
+ echo "<br/> Memory Usage " . memory_get_usage() / 1000000;
433
  echo "<br/> Execution time $time secondes";
434
  }
435
  }
437
  /**
438
  * Temporary store Parent Identity
439
  *
440
+ * @param integer $parent_id Parent Entity Id
441
  *
442
  * @return object Catalog/product
443
  */
444
+ protected function _getParentEntity($parent_id)
445
+ {
446
+ $this->_clear_parent_cache++;
447
+ if (!isset($this->storeParents[$parent_id])) {
448
  $parent = Mage::getModel('lenexport/catalog_product')
449
  ->setStoreId($this->_id_store)
450
  ->setOriginalCurrency($this->getOriginalCurrency())
451
  ->setCurrentCurrencyCode($this->getCurrentCurrencyCode())
452
  ->load($parent_id);
453
+ $this->storeParents[$parent_id] = $parent;
454
  }
455
+ if ($this->_clear_parent_cache > 300) {
456
+ if (method_exists($this->storeParents[0], 'clearInstance')) {
457
  $maxStoreParent = count($this->storeParents);
458
  for ($i = 0; $i < $maxStoreParent; $i++) {
459
  $this->storeParents[0]->clearInstance();
468
  /**
469
  * Get products collection for export
470
  *
471
+ * @param varchar $types Type(s) of product
472
+ * @param varchar $status Status of product to export
473
+ * @param boolean $export_child Export child of product
474
+ * @param boolean $out_of_stock Export product out of stock
475
+ * @param boolean $selected_products Export selected product
476
+ * @param integer $limit The number of product to be exported
477
+ * @param integer $offset From what product export
478
+ * @param array $ids_product Ids product to export
479
  *
480
  * @return array
481
  */
482
+ protected function _getProductsCollection(
483
+ $types = null,
484
+ $status = null,
485
+ $export_child = null,
486
+ $out_of_stock = null,
487
+ $selected_products = null,
488
+ $limit = null,
489
+ $offset = null,
490
+ $ids_product = null
491
+ ) {
492
  // Filter types
493
+ if ($types) {
494
  $_types = explode(',', $types);
495
  } else {
496
  $_types = $this->_config_model->get('global/producttype');
497
  $_types = explode(',', $_types);
498
  }
499
+ if (is_null($selected_products)) {
500
  $selected_products = $this->_config_model->onlySelectedProducts();
501
+ }
502
  // Search product to export
503
  $products = $this->_product_model
504
+ ->getCollection()
505
+ ->addAttributeToSelect('sku')
506
+ ->setStoreId($this->_id_store)
507
+ ->addStoreFilter($this->_id_store)
508
+ ->addAttributeToFilter('type_id', array('in' => $_types))
509
+ ->joinField('store_id', Mage::getConfig()->getTablePrefix() . 'catalog_category_product_index', 'store_id',
510
+ 'product_id=entity_id', '{{table}}.store_id = ' . $this->_id_store, 'left');
511
  // Filter status
512
+ if (is_null($status)) {
513
+ $status = (string)$this->_config_model->get('global/productstatus');
514
+ }
515
+ if ($status === (string)Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
516
  $products->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));
517
+ } else {
518
+ if ($status === (string)Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
519
+ $products->addAttributeToFilter('status',
520
+ array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED));
521
+ }
522
+ }
523
  // Export only selected products
524
+ if ($selected_products) {
525
  $products->addAttributeToFilter('lengow_product', 1);
526
  }
527
  // Filter out of stock
528
+ if (is_null($out_of_stock)) {
529
  $out_of_stock = $this->_config_model->isExportSoldout();
530
+ }
531
+ $products->joinTable('cataloginventory/stock_item', 'product_id=entity_id',
532
+ array('qty' => 'qty', 'is_in_stock' => 'is_in_stock'), $this->_getOutOfStockSQL($out_of_stock), 'inner');
533
  // Ids product
534
+ if ($ids_product) {
535
  $ids_product = explode(',', $ids_product);
536
  $products->addAttributeToFilter('entity_id', array('in' => $ids_product));
537
  }
538
  // Limit & Offset
539
+ if ($limit) {
540
+ if ($offset) {
541
  $products->getSelect()->limit($limit, $offset);
542
+ } else {
543
  $products->getSelect()->limit($limit);
544
+ }
545
  }
546
  // Filter to hide products
547
  Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
548
  $products->getSelect()
549
+ ->distinct(true)
550
+ ->group('entity_id');
551
  return $products->getData();
552
  }
553
 
561
  protected function _getOutOfStockSQL($out_of_stock = false)
562
  {
563
  // Filter product without stock
564
+ if (!$out_of_stock) {
565
  $config = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
566
  $sql = '({{table}}.`is_in_stock` = 1) '
567
  . ' OR IF({{table}}.`use_config_manage_stock` = 1, ' . $config . ', {{table}}.`manage_stock`) = 0';
578
  protected function _getAttributesFromConfig()
579
  {
580
  $attributes = $this->_config_model->getSelectedAttributes();
581
+ foreach ($attributes as $name => $value) {
582
  self::$DEFAULT_FIELDS[$name] = $value;
583
+ }
584
  return self::$DEFAULT_FIELDS;
585
  }
586
 
593
  */
594
  protected function getAttributesFromConfig($exist = false)
595
  {
596
+ $attributes = $this->_config_model->getMappingAllAttributes();
597
+ if ($exist) {
598
  $product = Mage::getModel('catalog/product');
599
+ foreach ($attributes as $key => $code) {
600
  $attribute = $product->getResource()->getAttribute($code);
601
+ if ($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute && $attribute->getId() && $attribute->getFrontendInput() != 'weee') {
602
  $attributes[$key] = $code;
603
  }
604
  }
611
  *
612
  * @param array $data
613
  */
614
+ protected function _write($data)
615
  {
616
+ if ($this->_stream == false) {
617
+ if (!$this->_file) {
618
  $this->_initFile();
619
  }
620
  $this->_file->streamLock();
629
  /**
630
  * Create File for export
631
  */
632
+ protected function _initFile()
633
  {
634
+ if (!$this->_createDirectory()) {
635
+ exit();
636
+ }
637
 
638
  $this->_fileTimeStamp = time();
639
  $this->_file = new Varien_Io_File;
641
  $this->_file->streamOpen($this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat, 'w+');
642
  }
643
 
644
+ protected function _createDirectory()
645
+ {
646
  try {
647
  $file = new Varien_Io_File;
648
  $file->checkAndCreateFolder($this->_config['directory_path']);
649
  } catch (Exception $e) {
650
+ Mage::helper('lensync/data')->log('can\'t create folder ' . $this->_config['directory_path'] . '');
651
+ if ($this->_debug) {
652
+ $this->_log('can\'t create folder ' . $this->_config['directory_path']);
653
  }
654
  return false;
655
  }
661
  *
662
  * @return boolean
663
  */
664
+ protected function _isAlreadyLaunch()
665
+ {
666
 
667
  $directory = $this->_config['directory_path'];
668
+ if (!$this->_createDirectory()) {
669
  exit();
670
  }
671
 
672
  try {
673
  $listFiles = array_diff(scandir($directory), array('..', '.'));
674
  } catch (Exception $e) {
675
+ Mage::helper('lensync/data')->log('Can\'t access folder ' . $this->_config['directory_path']);
676
+ if ($this->_debug) {
677
+ $this->_log('Can\'t access folder ' . $this->_config['directory_path']);
678
  }
679
  exit();
680
  }
701
  /**
702
  * Copies the file to the correct folder
703
  */
704
+ protected function _copyFile()
705
  {
706
  $file_path = $this->_config['directory_path'];
707
+ copy($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat,
708
+ $file_path . $this->_fileName . '.' . $this->_fileFormat);
709
  unlink($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat);
710
  }
711
 
719
  }
720
 
721
 
722
+ protected function stop($time_start, $string)
723
+ {
724
  $time_end = $this->microtime_float();
725
  $time = $time_end - $time_start;
726
+ if ($time < 0.0001) {
727
+ $time = 0;
728
+ }
729
+ echo round($time, 4) . " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $string secondes <br/>";
730
  }
731
  }
app/code/community/Lengow/Export/Model/Generateoptimize.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml export controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Generateoptimize extends Varien_Object {
 
12
 
13
  protected $_id_store;
14
  protected $_websiteId;
@@ -56,25 +58,29 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
56
  //option in magento configration
57
  protected $_config = array();
58
 
59
- protected $_excludes = array('media_gallery',
 
60
  'tier_price',
61
  'short_description',
62
  'description',
63
- 'quantity');
 
64
  /**
65
  * Default fields.
66
  */
67
- public static $DEFAULT_FIELDS = array('sku' => 'sku' ,
68
- 'entity_id' => 'product-id' ,
69
- 'parent-id' => 'parent-id' ,
70
- 'qty' => 'qty' ,
71
- 'name' => 'name' ,
72
- 'description' => 'description' ,
73
- 'short_description' => 'short_description' ,
74
- 'price-ttc' => 'price-ttc' ,
75
- 'shipping-name' => 'shipping-name' ,
76
- 'image-url-1' => 'image-url-1' ,
77
- 'product-url' => 'product-url');
 
 
78
 
79
  protected $_attributes = array(
80
  'sku',
@@ -169,8 +175,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
169
  //get configuration data
170
  $this->_config['category_max_level'] = $this->_config_model->get('data/levelcategory');
171
  $this->_config['number_product_by_query'] = 2000;
172
- $this->_config["query_url_option"] = (version_compare(Mage::getVersion(), '1.6.0', '<')) ? 'options=\'\'' : 'ISNULL(options)';
173
-
174
 
175
  //Get Table Definition
176
  $this->_coreResource = Mage::getSingleton('core/resource');
@@ -214,8 +220,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
214
  }
215
 
216
 
217
- public function getTotalProductStore($storeId){
218
-
219
  $this->_id_store = $storeId;
220
  $this->_websiteId = Mage::getModel('core/store')->load($this->_id_store)->getWebsiteId();
221
 
@@ -226,18 +232,17 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
226
  return $productCollection->getFirstItem()->getTotal();
227
  }
228
 
229
- public function _getQuery(){
230
-
231
-
232
  $productCollection = Mage::getModel('lenexport/product_collection')->getCollection()->addStoreFilter($this->_id_store);
233
 
234
  // Filter status
235
- if ($this->_config['product_status'] !== null){
236
  $productCollection->addAttributeToFilter('status', array('eq' => $this->_config['product_status']));
237
  }
238
 
239
  //filter type
240
- if($this->_config['force_type']) {
241
  $_types = explode(',', $this->_config['force_type']);
242
  } else {
243
  $_types = $this->_config_model->get('global/producttype');
@@ -251,10 +256,10 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
251
 
252
  $this->_joinStock($productCollection);
253
 
254
- if ($this->_config['only_selected_product']){
255
  $productCollection->addAttributeToFilter('lengow_product', array('eq' => 1));
256
  }
257
- if ($this->_config['product_ids']){
258
  $productCollection->addAttributeToFilter('entity_id', array('in' => $this->_config['product_ids']));
259
  }
260
 
@@ -262,7 +267,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
262
  'url.product_id=e.entity_id AND url.target_path NOT LIKE "category%" AND is_system=1 AND ' . $this->_config["query_url_option"] . ' AND url.store_id=' . $this->_id_store,
263
  array('request_path' => 'MAX(DISTINCT request_path)'));
264
 
265
- $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product'] . ' AS categories', 'categories.product_id=e.entity_id');
 
266
  $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product_index'] . ' AS categories_index',
267
  '((categories_index.category_id=categories.category_id AND categories_index.product_id=categories.product_id) ) AND categories_index.store_id=' . $this->_id_store,
268
  array('categories_ids' => 'GROUP_CONCAT(DISTINCT categories_index.category_id)'));
@@ -284,18 +290,18 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
284
  /**
285
  * Make the feed
286
  *
287
- * @param integer $id_store ID of store
288
- * @param varchar $mode The mode of export
289
  * size : display only count of products to export
290
  * full : export simple product + configured product
291
  * xxx,yyy : export xxx type product + yyy type product
292
- * @param varchar $format Format of export
293
- * @param array $params List of options
294
  *
295
  * @return Mage_Catalog_Model_Product
296
  */
297
- public function exec($id_store, $format, $params = array()) {
298
-
299
  $this->_debug = true;
300
 
301
  //store start time export
@@ -306,23 +312,26 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
306
 
307
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
308
 
309
- $this->_config['include_tax'] = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $this->_id_store);
 
310
  $this->_config['directory_path'] = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store_code . DS;
311
- $this->_config['image_base_url'] = substr(Mage::app()->getStore($this->_id_store)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA, false), 0, -1).'/catalog/product';
312
- $this->_config['force_type'] = array_key_exists('forced_type',$params) ? $params['forced_type'] : false;
313
- $this->_config['product_status'] = array_key_exists('status',$params) ? $params['status'] : null;
314
- $this->_config['product_ids'] = array_key_exists('product_ids',$params) ? $params['product_ids'] : false;
315
- $this->_debug = array_key_exists('debug',$params) ? $params["debug"] : false;
316
-
317
- $this->_config['offset'] = array_key_exists('offset',$params) ? $params['offset'] : false;
318
- $this->_productLimit = array_key_exists('limit',$params) ? $params['limit'] : false;
319
- if ($this->_config['product_status'] === null){
320
- $this->_config['product_status'] = (string) $this->_config_model->get('global/productstatus');
321
- if($this->_config['product_status'] === Mage_Catalog_Model_Product_Status::STATUS_ENABLED
322
- OR $this->_config['product_status'] === Mage_Catalog_Model_Product_Status::STATUS_DISABLED){
323
- $this->_config['product_status'] = $this->_config['product_status'];
324
- }else{
325
- $this->_config['product_status'] = null;
 
 
326
  }
327
  }
328
 
@@ -330,46 +339,46 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
330
  $this->_config['attribute_html'] = !empty($attributes) ? explode(',', $attributes) : array();
331
  $this->_config['shipping_price'] = $this->_config_model->get('data/default_shipping_price', $this->_id_store);
332
 
333
- $outOfStock = array_key_exists('out_of_stock',$params) ? $params['out_of_stock'] : null;
334
- if ($outOfStock === null){
335
  $this->_config['out_of_stock'] = (int)$this->_config_model->get('global/export_soldout');
336
  }
337
 
338
- $selectedProduct = array_key_exists('forced_type',$params) ? $params['selected_products'] : null;
339
- if ($selectedProduct === null){
340
  $this->_config['only_selected_product'] = (int)$this->_config_model->onlySelectedProducts();
341
  }
342
- if ($format === null){
343
  $this->_fileFormat = $this->_config_model->get('data/format');
344
- }else{
345
  $this->_fileFormat = $format;
346
  }
347
- $this->_config['mode'] = array_key_exists('mode',$params) ? $params['mode'] : false;
348
 
349
 
350
- $stream = array_key_exists('stream',$params) ? $params['stream'] : null;
351
- if ($stream === null){
352
  $this->_stream = $this->_config_model->get('performances/usesavefile') ? false : true;
 
 
353
  }
354
 
355
- if ($this->_isAlreadyLaunch()){
356
  Mage::helper('lensync/data')->log('Feed already launch');
357
-
358
- if(!$this->_stream) {
359
  $this->_log('/!\ Feed already Launch');
360
  }
361
  exit();
362
  }
363
 
364
- if(!$this->_stream) {
365
  header('Content-Type: text/html; charset=utf-8');
366
  $this->_log('Start Store = ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ')');
367
  }
368
 
369
- if ($this->_config['mode'] == 'size'){
370
-
371
- $this->_log('Total Products :'.$this->getTotalProductStore($this->_id_store));
372
- $this->_log('Memory Usage '.(memory_get_usage()/1000000));
373
  $this->_stop($this->_startScript, 'Execution time ');
374
  exit();
375
  }
@@ -377,50 +386,45 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
377
  // Get products list to export
378
  $this->_getProductsCollection($format, $params);
379
 
380
- if(!$this->_stream) {
381
- $this->_log('Memory Usage '.(memory_get_usage()/1000000));
382
  $this->_stop($this->_startScript, 'Execution time ');
383
  }
384
-
385
  }
386
 
387
  /**
388
  * Get Product Collection
389
  *
390
- * @param varchar $mode The mode of export
391
  * size : display only count of products to export
392
  * full : export simple product + configured product
393
  * xxx,yyy : export xxx type product + yyy type product
394
- * @param varchar $format Format of export
395
- * @param array $params Parameters
396
  *
397
  * @return float price
398
  */
399
-
400
-
401
  protected function _getProductsCollection($format, $params = array())
402
  {
403
-
404
  //$out_of_stock = array_key_exists('out_of_stock',$params) ? $params['out_of_stock'] : false;
405
 
406
-
407
  $this->_loadTaxes();
408
  $this->_loadSelectedAttributes();
409
  $this->_loadProductAttributes();
410
  $this->_loadProductAttributeValues();
 
411
  $this->_loadConfigurableProducts();
412
  $this->_loadImages();
413
  $this->_loadCategories();
414
  $this->_loadGroupedProducts();
415
  $this->_buildCsvHeader();
416
 
417
-
418
  $productCollection = $this->_getQuery();
419
 
420
  $tempProductCollection = clone $productCollection;
421
  $tempProductCollection->getSelect()->columns('COUNT(DISTINCT e.entity_id) As total');
422
  $nbProduct = $tempProductCollection->getFirstItem()->getTotal();
423
- if ($this->_productLimit && $nbProduct > $this->_productLimit){
424
  $nbProduct = $this->_productLimit;
425
  }
426
  $totalQueryToExecute = ceil($nbProduct / $this->_config['number_product_by_query']);
@@ -428,19 +432,19 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
428
  $productCollection->getSelect()->group(array('e.entity_id'))->order('e.entity_id');
429
  $nbQueryExecuted = 0;
430
 
431
- if ($this->_debug){
432
- $this->_log('Total items calculated ('.$nbProduct.' in '.$totalQueryToExecute.' queries )');
433
  }
434
  Mage::helper('lensync/data')->log('Find ' . $nbProduct . ' product' . ($nbProduct > 1 ? 's ' : ' '));
435
 
436
  $formatData = $this->_config_model->get('data/formatdata') == 1 ? true : false;
437
 
438
-
439
  $feed = Mage::getModel('Lengow_Export_Model_Feed_' . ucfirst($this->_fileFormat));
440
 
441
  // Get content type if streamed feed
442
- if($this->_stream)
443
  header('Content-Type: ' . $feed->getContentType() . '; charset=utf-8');
 
444
  $feed->setFields($this->_listHeaderCsvFile);
445
  $this->_write($feed->makeHeader());
446
 
@@ -449,22 +453,20 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
449
  while ($nbQueryExecuted < $totalQueryToExecute) {
450
  $currentProductCollection = clone $productCollection;
451
 
452
-
453
- if ($this->_config['offset']){
454
  $offset = (int)$this->_config['offset'];
455
- }else{
456
  $offset = ($this->_config['number_product_by_query'] * $nbQueryExecuted);
457
  }
458
 
459
- if ($this->_config['number_product_by_query']){
460
- if ($this->_productLimit && $this->_config['number_product_by_query'] > $this->_productLimit){
461
  $currentProductCollection->getSelect()->limit($this->_productLimit, $offset);
462
- }else{
463
  $currentProductCollection->getSelect()->limit($this->_config['number_product_by_query'], $offset);
464
  }
465
  }
466
 
467
-
468
  ++$nbQueryExecuted;
469
 
470
  if ($this->_config['number_product_by_query'] * $nbQueryExecuted > $nbProduct) {
@@ -472,17 +474,15 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
472
  } else {
473
  $totalOffset = $this->_config['number_product_by_query'] * $nbQueryExecuted;
474
  }
475
- //if ($this->_debug){
476
- $this->_log('Fetching products from ' . ($this->_config['number_product_by_query'] * ($nbQueryExecuted - 1) + 1) . ' to ' . $totalOffset);
477
- //echo $currentProductCollection->getSelect();
478
- //}
479
 
480
  foreach ($currentProductCollection as $product) {
481
  ++$pi;
482
  $data = array();
483
  $data['type'] = $product->getTypeId();
484
- foreach($this->_listAttributeToShow as $attributeToShow){
485
- switch($attributeToShow){
486
  case 'sku':
487
  $data['sku'] = $product->getSku();
488
  break;
@@ -491,7 +491,7 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
491
  break;
492
  case 'qty':
493
  //todo : what quantity for configurable / bundle product ???
494
- switch($product->getTypeId()){
495
  case 'grouped':
496
  $data['qty'] = (int)$this->_listGroupedProducts[$product->getId()]['qty'];
497
  break;
@@ -501,7 +501,7 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
501
  }
502
  break;
503
  case 'status':
504
- switch($product->getTypeId()){
505
  case 'grouped':
506
  $data['status'] = $this->_listGroupedProducts[$product->getId()]['status'];
507
  break;
@@ -513,69 +513,78 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
513
  break;
514
  case 'categories':
515
  $categoryTemp = array();
516
- if($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($this->_listChildrenIds[$product->getId()])){
517
- $currentPathCategory = explode(',', $this->_listChildrenIds[$product->getId()]['categories_id']);
518
- }else{
 
519
  $currentPathCategory = explode(',', $product->getCategoriesIds());
520
  }
521
- $currentCategoryId = end($currentPathCategory);;
522
  $i = 0;
523
- if (!$currentCategoryId){
524
  $data['category'] = '';
525
  $data['category-url'] = '';
526
- }else{
527
  $level = 0;
528
- foreach($currentPathCategory as $category){
529
- if ($this->_listCategories[$category]['level'] > $level){
 
530
  $level = $this->_listCategories[$category]['level'];
531
  $currentCategoryId = $category;
532
  }
533
  }
534
- $fullPathCategory = explode('/', $this->_listCategories[$currentCategoryId]['path']);
535
- foreach ($fullPathCategory as $categoryId){
536
- if($i == 0) { ++$i; continue; }
537
- $categoryTemp[] = $this->_listCategories[$categoryId]['name'];
538
-
539
- if($i == 1) {
540
- $data['category'] = $this->_listCategories[$categoryId]['name'];
541
- $data['category-url'] = $this->_listCategories[$categoryId]['url'];
542
- } elseif($i <= $this->_config['category_max_level']) {
543
- $data['category-sub-'.($i-1)] = $this->_listCategories[$categoryId]['name'];
544
- $data['category-url-sub-'.($i-1)] = $this->_listCategories[$categoryId]['url'];
 
 
 
 
 
545
  }
546
- ++$i;
547
  }
548
  }
549
  for ($j = $i; $j <= $this->_config['category_max_level']; ++$j) {
550
- $data['category-sub-'.$j] = '';
551
- $data['category-url-sub-'.$j] = '';
552
  }
553
-
554
- $data['category_breadcrumb'] = join(' > ',$categoryTemp);
555
  break;
556
  case 'prices':
557
- if ($product->getIndexPrice()>0){
558
  $product["price"] = $product->getIndexPrice();
559
  }
560
- if ($product->getIndexFinalPrice()>0){
561
  $product["final_price"] = $product->getIndexFinalPrice();
562
  }
563
- if ($product["final_price"]==0){
564
  $product["final_price"] = $product["price"];
565
  }
566
- switch($product->getTypeId()){
567
  case 'grouped':
568
- $data["price_ttc"] = $this->_calculatePrice($this->_listGroupedProducts[$product->getId()]['price'], $product->getTaxClassId());
569
- $data["price_before_discount"] = $data["price_ttc"];
 
570
  break;
571
  default:
572
- $data["price_ttc"] = $this->_calculatePrice($product["final_price"], $product->getTaxClassId());
573
- $data["price_before_discount"] = $this->_calculatePrice($product["price"], $product->getTaxClassId());
 
 
574
  break;
575
  }
576
- $discountAmount = ((float)$data["price_before_discount"]-(float)$data["price_ttc"]);
577
  $data['discount_amount'] = $discountAmount > 0 ? round($discountAmount, 2) : '0';
578
- $data['discount_percent'] = $discountAmount > 0 ? round(($discountAmount * 100) / (float)$data['price_before_discount'], 0) : '0';
 
579
  $data['start_date_discount'] = $product->getSpecialFromDate();
580
  $data['end_date_discount'] = $product->getSpecialToDate();
581
  break;
@@ -584,20 +593,20 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
584
  $data['shipping_price'] = '';
585
  $data['shipping_delay'] = $this->_config_model->get('data/default_shipping_delay');
586
  $carrier = $this->_config_model->get('data/default_shipping_method');
587
- if ($carrier == 'flatrate_flatrate' || $carrier == ''){
588
  $data['shipping_name'] = 'Flatrate';
589
  $data['shipping_price'] = $this->_config['shipping_price'];
590
- }else{
591
- if(!empty($carrier)){
592
- $carrierTab = explode('_',$carrier);
593
- list($carrierCode,$methodCode) = $carrierTab;
594
  //todo : wrong shipping name ?
595
  $data['shipping_name'] = ucfirst($methodCode);
596
  $shippingPrice = 0;
597
  $countryCode = $this->_config_model->get('data/shipping_price_based_on');
598
 
599
  $shippingPrice = $product->_getShippingPrice($product, $carrier, $countryCode);
600
- if(!$shippingPrice) {
601
  $shippingPrice = $this->_config['shipping_price'];
602
  }
603
  $data['shipping_price'] = $shippingPrice;
@@ -606,90 +615,95 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
606
  break;
607
  case 'images':
608
  $max_image = $this->_config_model->getCountExportImages();
609
- for($i = 1; $i <= $max_image; ++$i) {
610
- $data['image-url-'.$i] = '';
611
  }
612
 
613
- if (isset($this->_listImages[$product->getId()])){
614
  $productImage = $this->_listImages[$product->getId()];
615
  $i = 1;
616
- foreach($productImage as $image){
617
- if ($image['disabled']==0){
618
- $data['image-url-' . $i] = $this->_config['image_base_url'].$image['src'];
619
  ++$i;
620
  }
621
  }
622
  for ($j = $i; $j < $max_image; ++$j) {
623
- $data['image-url-'.$j] = '';
624
  }
625
  }
626
 
627
- if ($data['image-url-1']=='' && isset($this->_listChildrenIds[$product->getId()])){
628
- if (isset($this->_listImages[$this->_listChildrenIds[$product->getId()]['id']])){
629
- foreach($this->_listImages[$this->_listChildrenIds[$product->getId()]['id']] as $img){
630
- $data['image-url-1'] = $this->_config['image_base_url'].$img['src'];
631
  }
632
  }
633
  }
634
  $data['image_default'] = $data['image-url-1'];
635
  break;
636
  case 'product_url':
637
- if($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($this->_listChildrenIds[$product->getId()])) {
638
  $data['product_url'] = $this->_listChildrenIds[$product->getId()]['url'];
639
- }else{
640
- if ($product->getProductUrl() == "" && isset($this->_listChildrenIds[$product->getId()]['url'])){
641
  $data['product_url'] = $this->_listChildrenIds[$product->getId()]['url'];
642
- } else{
643
  $data['product_url'] = $product->getProductUrl();
644
  }
645
  }
646
  break;
647
  case 'name':
648
- if($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($this->_listChildrenIds[$product->getId()])) {
649
- if ($this->_listChildrenIds[$product->getId()] !=''){
650
- $data['name'] = $this->_helper->cleanData($this->_listChildrenIds[$product->getId()]['name'], $formatData, in_array('name', $this->_config['attribute_html']));
651
- }else{
652
- $data['name'] = $this->_helper->cleanData($product->getName(), $formatData, in_array('name', $this->_config['attribute_html']));
 
 
653
  }
654
- }else{
655
- $data['name'] = $this->_helper->cleanData($product->getName(), $formatData, in_array('name', $this->_config['attribute_html']));
 
656
  }
657
  break;
658
  case 'description':
659
- $data['description'] = $this->_helper->cleanData($product->getDescription(), $formatData, in_array('description', $this->_config['attribute_html']));
 
660
  break;
661
  case 'short_description':
662
- $data['short_description'] = $this->_helper->cleanData($product->getShortDescription(), $formatData, in_array('short_description', $this->_config['attribute_html']));
 
663
  break;
664
  case 'parent_informations':
665
- if (isset($this->_listChildrenIds[$product->getId()])){
666
  $data['parent_id'] = $this->_listChildrenIds[$product->getId()]['id'];
667
  $data['product_type'] = 'child';
668
  $data['child_name'] = $this->_listChildrenIds[$product->getId()]['name'];
669
- if (isset($this->_listConfigurableVariation[$this->_listChildrenIds[$product->getId()]['id']])){
670
  $variation = array();
671
- foreach($this->_listConfigurableVariation[$this->_listChildrenIds[$product->getId()]['id']] as $variationAttributeId){
672
  $variation[] = $this->_listCodeAttributes[$variationAttributeId]['frontend_label'];
673
  }
674
  $data['product_variation'] = join(',', $variation);
675
- }else{
676
  $data['product_variation'] = '';
677
  }
678
- }else{
679
- if (isset($this->_listParentIds[$product->getId()])){
680
  $data['parent_id'] = '';
681
  $data['product_type'] = 'parent';
682
  $data['child_name'] = $product->getName();
683
- if (isset($this->_listConfigurableVariation[$product->getId()])){
684
  $variation = array();
685
- foreach($this->_listConfigurableVariation[$product->getId()] as $variationAttributeId){
686
  $variation[] = $this->_listCodeAttributes[$variationAttributeId]['frontend_label'];
687
  }
688
  $data['product_variation'] = join(',', $variation);
689
- }else{
690
  $data['product_variation'] = '';
691
  }
692
- }else{
693
  $data['parent_id'] = '';
694
  $data['product_type'] = 'simple';
695
  $data['child_name'] = $product->getName();
@@ -699,12 +713,15 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
699
  break;
700
  }
701
  }
702
- foreach($this->_attributesAdditional as $attributeCode){
703
  if (!isset($data[$attributeCode])) {
704
  if (!in_array($attributeCode, $this->_listForbiddenAttributes)) {
705
- if (in_array($this->_listCodeAttributes[$this->_listAttributeCode[$attributeCode]]['backend_type'], array('text','varchar'))){
706
- $data[$attributeCode] = $this->_helper->cleanData($this->_getAttributeValue($product->getId(), $attributeCode), $formatData, in_array($attributeCode, $this->_config['attribute_html']));
707
- }else{
 
 
 
708
  $data[$attributeCode] = $this->_getAttributeValue($product->getId(), $attributeCode);
709
  }
710
  } else {
@@ -712,49 +729,48 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
712
  }
713
  }
714
  }
715
- //print_r($data);
716
 
717
- if ($pi >= $nbProduct)
718
  $this->_write($feed->makeData($data, array('last' => true)));
719
- else
720
  $this->_write($feed->makeData($data));
721
-
722
  unset($data);
723
  }
724
  }
725
 
726
  $this->_write($feed->makeFooter());
727
- if(!$this->_stream) {
728
  flush();
729
  $this->_copyFile();
730
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
731
  $url_file = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'lengow' . DS . $store_code . DS . $this->_fileName . '.' . $this->_fileFormat;
732
- $this->_log($this->_helper->__('Your feed is available here : %s' , '<a href=\'' . $url_file . '\'>' . $url_file . '</a>'));
 
733
  Mage::helper('lensync/data')->log('Export of the store ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ') generated a file here : ' . $url_file);
734
  }
735
 
736
  }
737
 
738
-
739
- protected function _buildCsvHeader(){
740
-
741
  $tmpHeader = $this->_listHeaderCsvFile;
742
  $this->_listHeaderCsvFile = array();
743
- foreach($tmpHeader as $header){
744
- switch($header){
745
  case 'lengow_categories_header':
746
  $this->_listHeaderCsvFile[] = 'category';
747
  $this->_listHeaderCsvFile[] = 'category-url';
748
  for ($j = 1; $j <= $this->_config['category_max_level']; ++$j) {
749
- $this->_listHeaderCsvFile[] = 'category-sub-'.$j;
750
- $this->_listHeaderCsvFile[] = 'category-url-sub-'.$j;
751
  }
752
  $this->_listHeaderCsvFile[] = 'category_breadcrumb';
753
  break;
754
  case 'lengow_images_header':
755
  $max_image = $this->_config_model->getCountExportImages();
756
- for($i = 1; $i <= $max_image; ++$i) {
757
- $this->_listHeaderCsvFile[]= 'image-url-'.$i;
758
  }
759
  break;
760
  default:
@@ -762,44 +778,45 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
762
  break;
763
  }
764
  }
765
- foreach($this->_attributesAdditional as $header){
766
  $this->_listHeaderCsvFile[] = $header;
767
  }
768
 
769
  }
770
 
771
-
772
  /**
773
  * Set stock on query
774
  * @param object $productCollection
775
  *
776
  * @return object $productCollection
777
  */
778
-
779
- protected function _joinStock($productCollection){
780
  if (!$this->_config['out_of_stock']) {
781
  $conditions = ' AND ((stock.is_in_stock = 1) '
782
  . ' OR (IF(stock.use_config_manage_stock = 1,
783
  ' . (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK) . ',
784
  stock.manage_stock) = 0)) AND is_in_stock IS NOT NULL';
785
 
786
- $productCollection->getSelect()->join($this->_table['cataloginventory_stock_item'] . ' AS stock', 'stock.product_id=e.entity_id ' . $conditions, array(
787
- 'qty' => 'qty',
788
- 'is_in_stock' => 'is_in_stock',
789
- 'manage_stock' => 'manage_stock',
790
- 'use_config_manage_stock' => 'use_config_manage_stock',
791
- 'backorders' => 'backorders',
792
- 'use_config_backorders' => 'use_config_backorders'
793
- ));
794
- }else{
795
- $productCollection->getSelect()->joinLeft($this->_table['cataloginventory_stock_item'] . ' AS stock', 'stock.product_id=e.entity_id ', array(
796
- 'qty' => 'qty',
797
- 'is_in_stock' => 'is_in_stock',
798
- 'manage_stock' => 'manage_stock',
799
- 'use_config_manage_stock' => 'use_config_manage_stock',
800
- 'backorders' => 'backorders',
801
- 'use_config_backorders' => 'use_config_backorders'
802
- ));
 
 
803
  }
804
  return $productCollection;
805
  }
@@ -809,9 +826,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
809
  *
810
  * @return void
811
  */
812
-
813
- protected function _loadImages(){
814
-
815
  $connection = $this->_coreResource->getConnection('core_read');
816
 
817
  $query = $connection->select(array('DISTINCT value'));
@@ -826,13 +842,12 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
826
  $this->_listImages = array();
827
  foreach ($rows as $row) {
828
  if ($row['disabled'] != 1 && $row['value'] != '') {
829
- $this->_listImages[$row['entity_id']][] = array('src' => $row['value'], 'disabled' => $row['disabled']) ;
830
  }
831
  }
832
 
833
- if ($this->_debug){
834
- $this->_log('Load Images ('.count($this->_listImages).')');
835
- //print_r($this->_listImages);
836
  }
837
  }
838
 
@@ -841,11 +856,11 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
841
  *
842
  * @return void
843
  */
844
-
845
- protected function _loadCategories(){
846
  $categories = Mage::getModel('catalog/category')->getCollection()
847
  ->setStoreId($this->_id_store)
848
- ->addAttributeToSelect('name','store_id')
849
  ->addAttributeToSelect('is_active')
850
  ->addAttributeToSelect('include_in_menu');
851
  $this->_listCategories = array();
@@ -856,9 +871,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
856
  $this->_listCategories[$category->getId()]['url'] = $category->getUrl();
857
  }
858
 
859
- if ($this->_debug){
860
- $this->_log('Load Categories ('.count($this->_listCategories).')');
861
- //print_r($this->_listCategories);
862
  }
863
  }
864
 
@@ -869,13 +883,12 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
869
  *
870
  * @return void
871
  */
872
-
873
- protected function _loadGroupedProducts(){
874
-
875
  $productCollection = Mage::getModel('lenexport/product_collection')->getCollection()->addStoreFilter($this->_id_store);
876
  $productCollection->addAttributeToFilter('type_id', array('in' => 'grouped'));
877
- $productCollection->addAttributeToSelect('name','product_url');
878
- if ($this->_config['product_status'] !== null){
879
  $productCollection->addAttributeToFilter('status', array('eq' => $this->_config['product_status']));
880
  }
881
  $productCollection->getSelect()->joinLeft($this->_table['catalog_product_link'] . ' AS cpl',
@@ -885,12 +898,13 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
885
  'stock.product_id=cpl.linked_product_id',
886
  array('child_qtys' => 'GROUP_CONCAT( qty)'));
887
  $productCollection->getSelect()->joinLeft($this->_table['catalog_product_entity_int'] . ' AS entity_int',
888
- 'entity_int.entity_id=cpl.linked_product_id AND entity_int.attribute_id ='.$this->_attributeStatusId ,
889
  array('child_status' => 'GROUP_CONCAT( entity_int.value)'));
890
  $productCollection->getSelect()->joinLeft($this->_table['catalog_product_index_price'] . ' AS price_index',
891
  'price_index.entity_id=cpl.linked_product_id AND customer_group_id=0 AND price_index.website_id=' . $this->_websiteId,
892
  array('child_prices' => 'GROUP_CONCAT( final_price )'));
893
- $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product'] . ' AS categories', 'categories.product_id=e.entity_id');
 
894
  $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product_index'] . ' AS categories_index',
895
  '((categories_index.category_id=categories.category_id AND categories_index.product_id=categories.product_id) ) AND categories_index.store_id=' . $this->_id_store,
896
  array('categories_ids' => 'GROUP_CONCAT(DISTINCT categories_index.category_id)'));
@@ -915,10 +929,13 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
915
  $quantities[] = $qty >= 0 ? $qty : 0;
916
  }
917
  foreach (explode(',', $product->getChildStatus()) as $status) {
918
- if ($status==0){ $status = false; break; }
 
 
 
919
  }
920
  foreach (explode(',', $product->getChildPrices()) as $price) {
921
- $totalPrice+=$price;
922
  }
923
  //keep the minimum quantity of product
924
  $this->_listGroupedProducts[$product->getId()]['qty'] = min($quantities);
@@ -926,10 +943,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
926
  $this->_listGroupedProducts[$product->getId()]['price'] = $totalPrice;
927
  }
928
 
929
- if ($this->_debug){
930
- $this->_log('Load Grouped ('.count($this->_listGroupedProducts).')');
931
- //print_r($this->_listGroupedProducts);
932
- //print_r($this->_listParentIds);
933
  }
934
  }
935
 
@@ -939,53 +954,61 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
939
  *
940
  * @return void
941
  */
942
-
943
- protected function _loadConfigurableProducts(){
944
-
945
  $connection = $this->_coreResource->getConnection('core_read');
946
- $query = 'SELECT * FROM '.$this->_table['catalog_product_super_attribute'];
947
 
948
  $configurableAttributeCollection = $connection->fetchAll($query);
949
- foreach($configurableAttributeCollection as $sa){
950
  $this->_listConfigurableVariation[$sa['product_id']][] = $sa['attribute_id'];
951
  }
952
 
953
- $productCollection = Mage::getModel('lenexport/product_collection')->getCollection()->addStoreFilter($this->_id_store);
954
- $productCollection->addAttributeToFilter('type_id', array('in' => 'configurable'));
955
- $productCollection->addAttributeToSelect('name');
956
- if ($this->_config['product_status'] !== null){
957
- $productCollection->addAttributeToFilter('status', array('eq' => $this->_config['product_status']));
958
- }
959
- $productCollection->getSelect()->joinLeft($this->_table['catalog_product_super_link'] . ' AS sl',
960
- 'sl.parent_id=e.entity_id',
961
- array('child_ids' => 'GROUP_CONCAT( sl.product_id)'));
962
- $productCollection->getSelect()->joinLeft($this->_table['catalog_product_entity_int'] . ' AS entity_int',
963
- 'sl.parent_id=entity_int.entity_id AND entity_int.attribute_id = '.$this->_attributeStatusId,
964
- array('child_statuses' => 'GROUP_CONCAT( entity_int.value)'));
965
- $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product'] . ' AS categories', 'categories.product_id=e.entity_id');
966
- $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product_index'] . ' AS categories_index',
967
- '((categories_index.category_id=categories.category_id AND categories_index.product_id=categories.product_id) ) AND categories_index.store_id=' . $this->_id_store,
968
- array('categories_ids' => 'GROUP_CONCAT(DISTINCT categories_index.category_id)'));
969
-
970
- $productCollection->getSelect()->joinLeft($this->_table['core_url_rewrite'] . ' AS url',
971
- 'url.product_id=e.entity_id AND url.target_path NOT LIKE "category%" AND is_system=1 AND ' . $this->_config["query_url_option"] . ' AND url.store_id=' . $this->_id_store,
972
- array('request_path' => 'MAX(DISTINCT request_path)'));
973
-
974
- $productCollection->getSelect()->group(array('sl.parent_id'));
975
-
976
- foreach ($productCollection as $product) {
977
- $this->_listParentIds[$product->getId()] = true;
978
- $name = $product->getName();
979
- $categoriesId = $product->getCategoriesIds();
980
- $url = $product->getProductUrl();
981
-
982
- foreach (explode(',', $product->getChildIds()) as $id) {
983
- $this->_listChildrenIds[$id] = array(
984
- 'name' => $name,
985
- 'id' => $product->getId(),
986
- 'categories_id' => $categoriesId,
987
- 'url' => $url,
988
- );
 
 
 
 
 
 
 
 
 
989
  // foreach (explode(',', $product->getPrice()) as $price) {
990
  // $this->_listChildrenIds[$id]['price'] = $price;
991
  // break;
@@ -994,13 +1017,12 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
994
  // $this->_listChildrenIds[$id]['final_price'] = $price;
995
  // break;
996
  // }
 
997
  }
998
  }
999
 
1000
- if ($this->_debug){
1001
  $this->_log('Load Configurable');
1002
- //print_r($this->_listParentIds);
1003
- //print_r($this->_listChildrenIds);
1004
  }
1005
  }
1006
 
@@ -1011,10 +1033,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1011
  *
1012
  * @return void
1013
  */
1014
-
1015
- protected function _loadTaxes(){
1016
-
1017
-
1018
  $taxCalculation = Mage::getModel('tax/calculation');
1019
  $request = $taxCalculation->getRateRequest(null, null, null, $this->_id_store);
1020
 
@@ -1022,11 +1042,14 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1022
 
1023
  $query = $connection->select();
1024
  $query->from($this->_table['tax_class'])->order(array('class_id', 'tax_calculation_rate_id'));
1025
- $query->joinleft(array('tc' => $this->_table['tax_calculation']), 'tc.product_tax_class_id = ' . $this->_table['tax_class']. '.class_id',
 
1026
  'tc.tax_calculation_rate_id');
1027
- $query->joinleft(array('tcr' => $this->_table['tax_calculation_rate']), 'tcr.tax_calculation_rate_id = tc.tax_calculation_rate_id',
 
1028
  array('tcr.rate', 'tax_country_id', 'tax_region_id'));
1029
- $query->joinleft(array('dcr' => $this->_table['directory_country_region']), 'dcr.region_id=tcr.tax_region_id', 'code');
 
1030
  $query->joinInner(array('cg' => $this->_table['customer_group']),
1031
  'cg.tax_class_id=tc.customer_tax_class_id AND cg.customer_group_code=\'NOT LOGGED IN\'');
1032
  $taxCollection = $connection->fetchAll($query);
@@ -1040,19 +1063,18 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1040
  ++$classValue;
1041
  }
1042
  $tempClassId = $tax['class_id'];
1043
- if ($request['country_id'] == $tax['tax_country_id']){
1044
  $this->_listTaxes[$tax['class_id']] = $tax['rate'];
1045
  //$this->_listTaxes[$tax['class_id']][$classValue]['code'] = $tax['code'];
1046
  //$this->_listTaxes[$tax['class_id']][$classValue]['country'] = $tax['tax_country_id'];
1047
  }
1048
  }
1049
- if ($this->_debug){
1050
- $this->_log('Load Tax Class ('.count($this->_listTaxes).')');
1051
- //print_r($this->_listTaxes);
1052
  }
1053
 
1054
- if (count($this->_listTaxes)==0){
1055
- Mage::helper('lensync/data')->log('Tax configuration is not correct, please enable country : '.$request['country_id']);
1056
  }
1057
  }
1058
 
@@ -1062,20 +1084,21 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1062
  *
1063
  * @return void
1064
  */
1065
-
1066
- protected function _loadSelectedAttributes(){
1067
  $attributeToExport = $this->_config_model->getMappingAllAttributes($this->_id_store);
1068
 
1069
- foreach($attributeToExport as $key => $value){
1070
- if ($key == 'none') { continue; }
1071
- if (!in_array($key, $this->_attributes)){
 
 
1072
  $this->_attributesAdditional[] = $key;
1073
  }
1074
  }
1075
 
1076
- if ($this->_debug){
1077
- $this->_log('Load New Attributes ('.count($attributeToExport).')');
1078
- //print_r($this->_attributes);
1079
  }
1080
 
1081
  }
@@ -1092,9 +1115,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1092
  *
1093
  * @return void
1094
  */
1095
-
1096
- protected function _loadProductAttributes(){
1097
-
1098
  $attributeCollection = Mage::getResourceModel('eav/entity_attribute_collection')
1099
  ->setEntityTypeFilter($this->_catalogProductEntityId)
1100
  ->addSetInfo()
@@ -1112,9 +1134,8 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1112
 
1113
  $findDiff = array_diff($this->_attributes, $listAttributes);
1114
  $this->_attributes = array_diff($this->_attributes, $findDiff);
1115
- if ($this->_debug){
1116
- $this->_log('Load Attributes ('.count($this->_listCodeAttributes).')');
1117
- //print_r($this->_listCodeAttributes);
1118
  }
1119
  }
1120
 
@@ -1125,38 +1146,38 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1125
  *
1126
  * @return void
1127
  */
1128
-
1129
- protected function _loadOptionValues(){
1130
  $attributeIdToQuery = array();
1131
- foreach($this->_listCodeAttributes as $codeAttribute){
1132
- if ( in_array($codeAttribute['frontend_input'], array('select','multiselect') )){
1133
  $attributeIdToQuery[] = $codeAttribute['attribute_id'];
1134
  }
1135
  }
1136
 
1137
- if (count($attributeIdToQuery)){
1138
  $connection = $this->_coreResource->getConnection('core_read');
1139
- $query = 'SELECT * FROM '.$this->_table['eav_attribute_option'].' eavo
1140
- LEFT JOIN '.$this->_table['eav_attribute_option_value'].' eavov ON ( eavo.option_id = eavov.option_id )
1141
- WHERE eavo.attribute_id IN ('.join(',',$attributeIdToQuery).') AND eavov.store_id = 0';
1142
  $entityOptionValueCollection = $connection->fetchAll($query);
1143
- foreach($entityOptionValueCollection as $optionValue){
1144
  $this->_listOptionValues[$optionValue['attribute_id']][$optionValue['option_id']] = $optionValue['value'];
1145
  }
1146
 
1147
  $connection = $this->_coreResource->getConnection('core_read');
1148
- $query = 'SELECT * FROM '.$this->_table['eav_attribute_option'].' eavo
1149
- LEFT JOIN '.$this->_table['eav_attribute_option_value'].' eavov ON ( eavo.option_id = eavov.option_id )
1150
- WHERE eavo.attribute_id IN ('.join(',',$attributeIdToQuery).') AND eavov.store_id = '.$this->_id_store;
 
1151
  $entityOptionValueCollection = $connection->fetchAll($query);
1152
- foreach($entityOptionValueCollection as $optionValue){
1153
  $this->_listOptionValues[$optionValue['attribute_id']][$optionValue['option_id']] = $optionValue['value'];
1154
  }
1155
  }
1156
 
1157
- if ($this->_debug){
1158
- $this->_log('Load Option Values ('.count($this->_listOptionValues).')');
1159
- //print_r($this->_listOptionValues);
1160
  }
1161
  }
1162
 
@@ -1167,130 +1188,143 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1167
  *
1168
  * @return void
1169
  */
1170
-
1171
- protected function _loadProductAttributeValues(){
1172
-
1173
- $this->_loadOptionValues();
1174
- $this->_loadAttributeValuesByType('int', $this->_table['catalog_product_entity_int']);
1175
- $this->_loadAttributeValuesByType('varchar', $this->_table['catalog_product_entity_varchar']);
1176
- $this->_loadAttributeValuesByType('datetime', $this->_table['catalog_product_entity_datetime']);
1177
- $this->_loadAttributeValuesByType('text', $this->_table['catalog_product_entity_text']);
1178
- $this->_loadAttributeValuesByType('decimal', $this->_table['catalog_product_entity_decimal']);
1179
-
1180
- if ($this->_debug){
1181
- $this->_log('Load Attributes Values ('.count($this->_listAttributeValues).')');
1182
- //print_r($this->_listCodeAttributes);
1183
- }
1184
-
1185
  }
1186
 
1187
  /**
1188
  * Load attributes values for all entities by type
1189
  *
1190
- * @param string $type Entity Type (int/varchar/text/decimal/float)
1191
- * @param string $tableName Table Name by Entity Type
1192
  *
1193
  * @return void
1194
  */
1195
-
1196
- protected function _loadAttributeValuesByType($type, $tableName){
1197
  $connection = $this->_coreResource->getConnection('core_read');
1198
 
1199
  $attributeIdToQuery = array();
1200
- foreach($this->_listCodeAttributes as $codeAttribute){
1201
- if ($codeAttribute['backend_type'] == $type){
1202
  //load only selected attributes
1203
- if (in_array($codeAttribute['attribute_code'], $this->_attributesAdditional)){
1204
  $attributeIdToQuery[] = $codeAttribute['attribute_id'];
1205
  }
1206
  }
1207
  }
1208
 
1209
- if ($this->_config['product_ids']){
1210
- $sqlWhere = ' AND entity_id IN ('.$this->_config['product_ids'].') ';
1211
- }else{
1212
  $sqlWhere = '';
1213
  }
1214
 
1215
- if (count($attributeIdToQuery)>0){
1216
- $query = 'SELECT attribute_id, value, entity_id FROM '.$tableName.' WHERE attribute_id IN ('.join(',',$attributeIdToQuery).') AND store_id = 0 '.$sqlWhere;
1217
- $entityIntCollection = $connection->fetchAll($query);
1218
- foreach($entityIntCollection as $int){
1219
- if ($int['value']==''){
1220
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = '';
1221
- }else{
1222
- if ($this->_listCodeAttributes[$int['attribute_id']]['frontend_input'] == 'select' && $this->_listCodeAttributes[$int['attribute_id']]['backend_type'] == 'int'){
1223
- if (isset($this->_listOptionValues[$int['attribute_id']][$int['value']])){
1224
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $this->_listOptionValues[$int['attribute_id']][$int['value']] ;
1225
- }else{
1226
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
 
 
 
 
 
 
 
 
 
 
 
 
 
1227
  }
1228
- }else{
1229
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
1230
  }
1231
  }
1232
  }
1233
- $query = 'SELECT attribute_id, value, entity_id FROM '.$tableName.' WHERE attribute_id IN ('.join(',',$attributeIdToQuery).') AND store_id = '.$this->_id_store.' '.$sqlWhere;
1234
- $entityIntCollection = $connection->fetchAll($query);
1235
- foreach($entityIntCollection as $int){
1236
- if ($int['value']==''){
1237
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = '';
1238
- }else{
1239
- if ($this->_listCodeAttributes[$int['attribute_id']]['frontend_input'] == 'select' && $this->_listCodeAttributes[$int['attribute_id']]['backend_type'] == 'int'){
1240
- if (isset($this->_listOptionValues[$int['attribute_id']][$int['value']])){
1241
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $this->_listOptionValues[$int['attribute_id']][$int['value']] ;
1242
- }else{
1243
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
 
 
 
 
 
 
 
 
 
 
1244
  }
1245
- }else{
1246
- $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
1247
  }
1248
  }
1249
  }
1250
  }
1251
 
1252
- if ($this->_debug){
1253
- $this->_log('Load Attributes Values '.$type.' ('.count($this->_listAttributeValues).')');
1254
- //print_r($this->_listAttributeValues);
1255
  }
1256
-
1257
  }
1258
 
1259
  /**
1260
  * Calculate price with Taxes
1261
  *
1262
- * @param float $price Price
1263
- * @param integer $taxClassId Tax Class Id
1264
  *
1265
  * @return float price
1266
  */
1267
-
1268
- protected function _calculatePrice($price, $taxClassId){
1269
  $currentRate = $this->_listTaxes;
1270
  if (!$this->_config['include_tax'] && isset($currentRate[$taxClassId])) {
1271
  if (count($currentRate[$taxClassId]) > 1) {
1272
- return round($price,2);
1273
  } else {
1274
- return round($price * ($currentRate[$taxClassId] / 100 + 1),2);
1275
  }
1276
  } else {
1277
- return round($price,2);
1278
  }
1279
  }
1280
 
1281
  /**
1282
  * Get Store attribute value
1283
  *
1284
- * @param integer $productId Id Product
1285
- * @param varchar $attributeCode Attribute Code
1286
  *
1287
  * @return float price
1288
  */
1289
-
1290
- protected function _getAttributeValue($productId,$attributeCode){
1291
- if (isset($this->_listAttributeValues[$productId]) && isset($this->_listAttributeValues[$productId][$attributeCode])){
1292
  return $this->_listAttributeValues[$productId][$attributeCode];
1293
- }else{
1294
  return '';
1295
  }
1296
  }
@@ -1300,10 +1334,10 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1300
  *
1301
  * @param array $data
1302
  */
1303
- protected function _write($data)
1304
  {
1305
- if($this->_stream == false) {
1306
- if(!$this->_file) {
1307
  $this->_initFile();
1308
  }
1309
  $this->_file->streamLock();
@@ -1317,9 +1351,11 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1317
  /**
1318
  * Create File for export
1319
  */
1320
- protected function _initFile()
1321
  {
1322
- if (!$this->_createDirectory()){ exit(); }
 
 
1323
 
1324
  $this->_fileTimeStamp = time();
1325
  $this->_file = new Varien_Io_File;
@@ -1327,14 +1363,15 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1327
  $this->_file->streamOpen($this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat, 'w+');
1328
  }
1329
 
1330
- protected function _createDirectory(){
 
1331
  try {
1332
  $file = new Varien_Io_File;
1333
  $file->checkAndCreateFolder($this->_config['directory_path']);
1334
  } catch (Exception $e) {
1335
- Mage::helper('lensync/data')->log('can\'t create folder '.$this->_config['directory_path'].'');
1336
- if ($this->_debug){
1337
- $this->_log('can\'t create folder '.$this->_config['directory_path']);
1338
  }
1339
  return false;
1340
  }
@@ -1344,10 +1381,11 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1344
  /**
1345
  * Copies the file to the correct folder
1346
  */
1347
- protected function _copyFile()
1348
  {
1349
  $file_path = $this->_config['directory_path'];
1350
- copy($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat, $file_path . $this->_fileName . '.' . $this->_fileFormat);
 
1351
  unlink($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat);
1352
  }
1353
 
@@ -1370,11 +1408,14 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1370
  *
1371
  * @return void
1372
  */
1373
- protected function _stop($timeStart, $title){
 
1374
  $time_end = $this->microtime_float();
1375
  $time = $time_end - $timeStart;
1376
- if ($time<0.0001){ $time = 0;}
1377
- echo round($time,4).' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '.$title.' secondes <br/>';
 
 
1378
  }
1379
 
1380
  /**
@@ -1384,12 +1425,15 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1384
  *
1385
  * @return void
1386
  */
1387
- protected function _log($title){
1388
- if($this->_stream){ return;}
 
 
 
1389
  $time_end = $this->microtime_float();
1390
  $time = $time_end - $this->_startScript;
1391
-
1392
- echo date('Y-m-d h:i:s').'|'.str_pad(sprintf('%0.4f', round($time,4)),10,'0',STR_PAD_LEFT).' '.str_pad($title, 40, '=', STR_PAD_BOTH).'<br/>';
1393
  }
1394
 
1395
  /**
@@ -1397,19 +1441,19 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1397
  *
1398
  * @return boolean
1399
  */
1400
- protected function _isAlreadyLaunch(){
1401
-
1402
  $directory = $this->_config['directory_path'];
1403
- if (!$this->_createDirectory()){
1404
  exit();
1405
  }
1406
 
1407
  try {
1408
  $listFiles = array_diff(scandir($directory), array('..', '.'));
1409
  } catch (Exception $e) {
1410
- Mage::helper('lensync/data')->log('Can\'t access folder '.$this->_config['directory_path']);
1411
- if ($this->_debug){
1412
- $this->_log('Can\'t access folder '.$this->_config['directory_path']);
1413
  }
1414
  exit();
1415
  }
@@ -1432,5 +1476,4 @@ class Lengow_Export_Model_Generateoptimize extends Varien_Object {
1432
  }
1433
  return false;
1434
  }
1435
-
1436
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model generateoptimize
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Generateoptimize extends Varien_Object
13
+ {
14
 
15
  protected $_id_store;
16
  protected $_websiteId;
58
  //option in magento configration
59
  protected $_config = array();
60
 
61
+ protected $_excludes = array(
62
+ 'media_gallery',
63
  'tier_price',
64
  'short_description',
65
  'description',
66
+ 'quantity'
67
+ );
68
  /**
69
  * Default fields.
70
  */
71
+ public static $DEFAULT_FIELDS = array(
72
+ 'sku' => 'sku',
73
+ 'entity_id' => 'product-id',
74
+ 'parent-id' => 'parent-id',
75
+ 'qty' => 'qty',
76
+ 'name' => 'name',
77
+ 'description' => 'description',
78
+ 'short_description' => 'short_description',
79
+ 'price-ttc' => 'price-ttc',
80
+ 'shipping-name' => 'shipping-name',
81
+ 'image-url-1' => 'image-url-1',
82
+ 'product-url' => 'product-url'
83
+ );
84
 
85
  protected $_attributes = array(
86
  'sku',
175
  //get configuration data
176
  $this->_config['category_max_level'] = $this->_config_model->get('data/levelcategory');
177
  $this->_config['number_product_by_query'] = 2000;
178
+ $this->_config["query_url_option"] = (version_compare(Mage::getVersion(), '1.6.0',
179
+ '<')) ? 'options=\'\'' : 'ISNULL(options)';
180
 
181
  //Get Table Definition
182
  $this->_coreResource = Mage::getSingleton('core/resource');
220
  }
221
 
222
 
223
+ public function getTotalProductStore($storeId)
224
+ {
225
  $this->_id_store = $storeId;
226
  $this->_websiteId = Mage::getModel('core/store')->load($this->_id_store)->getWebsiteId();
227
 
232
  return $productCollection->getFirstItem()->getTotal();
233
  }
234
 
235
+ public function _getQuery()
236
+ {
 
237
  $productCollection = Mage::getModel('lenexport/product_collection')->getCollection()->addStoreFilter($this->_id_store);
238
 
239
  // Filter status
240
+ if ($this->_config['product_status'] !== null) {
241
  $productCollection->addAttributeToFilter('status', array('eq' => $this->_config['product_status']));
242
  }
243
 
244
  //filter type
245
+ if ($this->_config['force_type']) {
246
  $_types = explode(',', $this->_config['force_type']);
247
  } else {
248
  $_types = $this->_config_model->get('global/producttype');
256
 
257
  $this->_joinStock($productCollection);
258
 
259
+ if ($this->_config['only_selected_product']) {
260
  $productCollection->addAttributeToFilter('lengow_product', array('eq' => 1));
261
  }
262
+ if ($this->_config['product_ids']) {
263
  $productCollection->addAttributeToFilter('entity_id', array('in' => $this->_config['product_ids']));
264
  }
265
 
267
  'url.product_id=e.entity_id AND url.target_path NOT LIKE "category%" AND is_system=1 AND ' . $this->_config["query_url_option"] . ' AND url.store_id=' . $this->_id_store,
268
  array('request_path' => 'MAX(DISTINCT request_path)'));
269
 
270
+ $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product'] . ' AS categories',
271
+ 'categories.product_id=e.entity_id');
272
  $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product_index'] . ' AS categories_index',
273
  '((categories_index.category_id=categories.category_id AND categories_index.product_id=categories.product_id) ) AND categories_index.store_id=' . $this->_id_store,
274
  array('categories_ids' => 'GROUP_CONCAT(DISTINCT categories_index.category_id)'));
290
  /**
291
  * Make the feed
292
  *
293
+ * @param integer $id_store ID of store
294
+ * @param varchar $mode The mode of export
295
  * size : display only count of products to export
296
  * full : export simple product + configured product
297
  * xxx,yyy : export xxx type product + yyy type product
298
+ * @param varchar $format Format of export
299
+ * @param array $params List of options
300
  *
301
  * @return Mage_Catalog_Model_Product
302
  */
303
+ public function exec($id_store, $format, $params = array())
304
+ {
305
  $this->_debug = true;
306
 
307
  //store start time export
312
 
313
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
314
 
315
+ $this->_config['include_tax'] = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX,
316
+ $this->_id_store);
317
  $this->_config['directory_path'] = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store_code . DS;
318
+ $this->_config['image_base_url'] = substr(Mage::app()->getStore($this->_id_store)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA,
319
+ false), 0, -1) . '/catalog/product';
320
+ $this->_config['force_type'] = array_key_exists('forced_type', $params) ? $params['forced_type'] : false;
321
+ $this->_config['product_status'] = array_key_exists('status', $params) ? $params['status'] : null;
322
+ $this->_config['product_ids'] = array_key_exists('product_ids', $params) ? $params['product_ids'] : false;
323
+ $this->_debug = array_key_exists('debug', $params) ? $params["debug"] : false;
324
+
325
+ $this->_config['offset'] = array_key_exists('offset', $params) ? $params['offset'] : false;
326
+ $this->_productLimit = array_key_exists('limit', $params) ? $params['limit'] : false;
327
+ if ($this->_config['product_status'] === null) {
328
+ $this->_config['product_status'] = (string)$this->_config_model->get('global/productstatus');
329
+ if ($this->_config['product_status'] === Mage_Catalog_Model_Product_Status::STATUS_ENABLED
330
+ OR $this->_config['product_status'] === Mage_Catalog_Model_Product_Status::STATUS_DISABLED
331
+ ) {
332
+ $this->_config['product_status'] = $this->_config['product_status'];
333
+ } else {
334
+ $this->_config['product_status'] = null;
335
  }
336
  }
337
 
339
  $this->_config['attribute_html'] = !empty($attributes) ? explode(',', $attributes) : array();
340
  $this->_config['shipping_price'] = $this->_config_model->get('data/default_shipping_price', $this->_id_store);
341
 
342
+ $outOfStock = array_key_exists('out_of_stock', $params) ? $params['out_of_stock'] : null;
343
+ if ($outOfStock === null) {
344
  $this->_config['out_of_stock'] = (int)$this->_config_model->get('global/export_soldout');
345
  }
346
 
347
+ $selectedProduct = array_key_exists('forced_type', $params) ? $params['selected_products'] : null;
348
+ if ($selectedProduct === null) {
349
  $this->_config['only_selected_product'] = (int)$this->_config_model->onlySelectedProducts();
350
  }
351
+ if ($format === null) {
352
  $this->_fileFormat = $this->_config_model->get('data/format');
353
+ } else {
354
  $this->_fileFormat = $format;
355
  }
356
+ $this->_config['mode'] = array_key_exists('mode', $params) ? $params['mode'] : false;
357
 
358
 
359
+ $stream = array_key_exists('stream', $params) ? $params['stream'] : null;
360
+ if ($stream === null) {
361
  $this->_stream = $this->_config_model->get('performances/usesavefile') ? false : true;
362
+ } else {
363
+ $this->_stream = $stream;
364
  }
365
 
366
+ if ($this->_isAlreadyLaunch()) {
367
  Mage::helper('lensync/data')->log('Feed already launch');
368
+ if (!$this->_stream) {
 
369
  $this->_log('/!\ Feed already Launch');
370
  }
371
  exit();
372
  }
373
 
374
+ if (!$this->_stream) {
375
  header('Content-Type: text/html; charset=utf-8');
376
  $this->_log('Start Store = ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ')');
377
  }
378
 
379
+ if ($this->_config['mode'] == 'size') {
380
+ $this->_log('Total Products :' . $this->getTotalProductStore($this->_id_store));
381
+ $this->_log('Memory Usage ' . (memory_get_usage() / 1000000));
 
382
  $this->_stop($this->_startScript, 'Execution time ');
383
  exit();
384
  }
386
  // Get products list to export
387
  $this->_getProductsCollection($format, $params);
388
 
389
+ if (!$this->_stream) {
390
+ $this->_log('Memory Usage ' . (memory_get_usage() / 1000000));
391
  $this->_stop($this->_startScript, 'Execution time ');
392
  }
 
393
  }
394
 
395
  /**
396
  * Get Product Collection
397
  *
398
+ * @param varchar $mode The mode of export
399
  * size : display only count of products to export
400
  * full : export simple product + configured product
401
  * xxx,yyy : export xxx type product + yyy type product
402
+ * @param varchar $format Format of export
403
+ * @param array $params Parameters
404
  *
405
  * @return float price
406
  */
 
 
407
  protected function _getProductsCollection($format, $params = array())
408
  {
 
409
  //$out_of_stock = array_key_exists('out_of_stock',$params) ? $params['out_of_stock'] : false;
410
 
 
411
  $this->_loadTaxes();
412
  $this->_loadSelectedAttributes();
413
  $this->_loadProductAttributes();
414
  $this->_loadProductAttributeValues();
415
+
416
  $this->_loadConfigurableProducts();
417
  $this->_loadImages();
418
  $this->_loadCategories();
419
  $this->_loadGroupedProducts();
420
  $this->_buildCsvHeader();
421
 
 
422
  $productCollection = $this->_getQuery();
423
 
424
  $tempProductCollection = clone $productCollection;
425
  $tempProductCollection->getSelect()->columns('COUNT(DISTINCT e.entity_id) As total');
426
  $nbProduct = $tempProductCollection->getFirstItem()->getTotal();
427
+ if ($this->_productLimit && $nbProduct > $this->_productLimit) {
428
  $nbProduct = $this->_productLimit;
429
  }
430
  $totalQueryToExecute = ceil($nbProduct / $this->_config['number_product_by_query']);
432
  $productCollection->getSelect()->group(array('e.entity_id'))->order('e.entity_id');
433
  $nbQueryExecuted = 0;
434
 
435
+ if ($this->_debug) {
436
+ $this->_log('Total items calculated (' . $nbProduct . ' in ' . $totalQueryToExecute . ' queries )');
437
  }
438
  Mage::helper('lensync/data')->log('Find ' . $nbProduct . ' product' . ($nbProduct > 1 ? 's ' : ' '));
439
 
440
  $formatData = $this->_config_model->get('data/formatdata') == 1 ? true : false;
441
 
 
442
  $feed = Mage::getModel('Lengow_Export_Model_Feed_' . ucfirst($this->_fileFormat));
443
 
444
  // Get content type if streamed feed
445
+ if ($this->_stream) {
446
  header('Content-Type: ' . $feed->getContentType() . '; charset=utf-8');
447
+ }
448
  $feed->setFields($this->_listHeaderCsvFile);
449
  $this->_write($feed->makeHeader());
450
 
453
  while ($nbQueryExecuted < $totalQueryToExecute) {
454
  $currentProductCollection = clone $productCollection;
455
 
456
+ if ($this->_config['offset']) {
 
457
  $offset = (int)$this->_config['offset'];
458
+ } else {
459
  $offset = ($this->_config['number_product_by_query'] * $nbQueryExecuted);
460
  }
461
 
462
+ if ($this->_config['number_product_by_query']) {
463
+ if ($this->_productLimit && $this->_config['number_product_by_query'] > $this->_productLimit) {
464
  $currentProductCollection->getSelect()->limit($this->_productLimit, $offset);
465
+ } else {
466
  $currentProductCollection->getSelect()->limit($this->_config['number_product_by_query'], $offset);
467
  }
468
  }
469
 
 
470
  ++$nbQueryExecuted;
471
 
472
  if ($this->_config['number_product_by_query'] * $nbQueryExecuted > $nbProduct) {
474
  } else {
475
  $totalOffset = $this->_config['number_product_by_query'] * $nbQueryExecuted;
476
  }
477
+
478
+ $this->_log('Fetching products from ' . ($this->_config['number_product_by_query'] * ($nbQueryExecuted - 1) + 1) . ' to ' . $totalOffset);
 
 
479
 
480
  foreach ($currentProductCollection as $product) {
481
  ++$pi;
482
  $data = array();
483
  $data['type'] = $product->getTypeId();
484
+ foreach ($this->_listAttributeToShow as $attributeToShow) {
485
+ switch ($attributeToShow) {
486
  case 'sku':
487
  $data['sku'] = $product->getSku();
488
  break;
491
  break;
492
  case 'qty':
493
  //todo : what quantity for configurable / bundle product ???
494
+ switch ($product->getTypeId()) {
495
  case 'grouped':
496
  $data['qty'] = (int)$this->_listGroupedProducts[$product->getId()]['qty'];
497
  break;
501
  }
502
  break;
503
  case 'status':
504
+ switch ($product->getTypeId()) {
505
  case 'grouped':
506
  $data['status'] = $this->_listGroupedProducts[$product->getId()]['status'];
507
  break;
513
  break;
514
  case 'categories':
515
  $categoryTemp = array();
516
+ if ($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($this->_listChildrenIds[$product->getId()])) {
517
+ $currentPathCategory = explode(',',
518
+ $this->_listChildrenIds[$product->getId()]['categories_id']);
519
+ } else {
520
  $currentPathCategory = explode(',', $product->getCategoriesIds());
521
  }
522
+ $currentCategoryId = end($currentPathCategory);;
523
  $i = 0;
524
+ if (!$currentCategoryId) {
525
  $data['category'] = '';
526
  $data['category-url'] = '';
527
+ } else {
528
  $level = 0;
529
+ foreach ($currentPathCategory as $category) {
530
+ if (isset($this->_listCategories[$category]['level']) &&
531
+ $this->_listCategories[$category]['level'] > $level) {
532
  $level = $this->_listCategories[$category]['level'];
533
  $currentCategoryId = $category;
534
  }
535
  }
536
+ if (isset($this->_listCategories[$currentCategoryId])) {
537
+ $fullPathCategory = explode('/', $this->_listCategories[$currentCategoryId]['path']);
538
+ foreach ($fullPathCategory as $categoryId) {
539
+ if ($i == 0) {
540
+ ++$i;
541
+ continue;
542
+ }
543
+ $categoryTemp[] = $this->_listCategories[$categoryId]['name'];
544
+ if ($i == 1) {
545
+ $data['category'] = $this->_listCategories[$categoryId]['name'];
546
+ $data['category-url'] = $this->_listCategories[$categoryId]['url'];
547
+ } elseif ($i <= $this->_config['category_max_level']) {
548
+ $data['category-sub-' . ($i - 1)] = $this->_listCategories[$categoryId]['name'];
549
+ $data['category-url-sub-' . ($i - 1)] = $this->_listCategories[$categoryId]['url'];
550
+ }
551
+ ++$i;
552
  }
 
553
  }
554
  }
555
  for ($j = $i; $j <= $this->_config['category_max_level']; ++$j) {
556
+ $data['category-sub-' . $j] = '';
557
+ $data['category-url-sub-' . $j] = '';
558
  }
559
+ $data['category_breadcrumb'] = join(' > ', $categoryTemp);
 
560
  break;
561
  case 'prices':
562
+ if ($product->getIndexPrice() > 0) {
563
  $product["price"] = $product->getIndexPrice();
564
  }
565
+ if ($product->getIndexFinalPrice() > 0) {
566
  $product["final_price"] = $product->getIndexFinalPrice();
567
  }
568
+ if ($product["final_price"] == 0) {
569
  $product["final_price"] = $product["price"];
570
  }
571
+ switch ($product->getTypeId()) {
572
  case 'grouped':
573
+ $data["price_ttc"] = $this->_calculatePrice($this->_listGroupedProducts[$product->getId()]['price'],
574
+ $product->getTaxClassId());
575
+ $data["price_before_discount"] = $data["price_ttc"];
576
  break;
577
  default:
578
+ $data["price_ttc"] = $this->_calculatePrice($product["final_price"],
579
+ $product->getTaxClassId());
580
+ $data["price_before_discount"] = $this->_calculatePrice($product["price"],
581
+ $product->getTaxClassId());
582
  break;
583
  }
584
+ $discountAmount = ((float)$data["price_before_discount"] - (float)$data["price_ttc"]);
585
  $data['discount_amount'] = $discountAmount > 0 ? round($discountAmount, 2) : '0';
586
+ $data['discount_percent'] = $discountAmount > 0 ? round(($discountAmount * 100) / (float)$data['price_before_discount'],
587
+ 0) : '0';
588
  $data['start_date_discount'] = $product->getSpecialFromDate();
589
  $data['end_date_discount'] = $product->getSpecialToDate();
590
  break;
593
  $data['shipping_price'] = '';
594
  $data['shipping_delay'] = $this->_config_model->get('data/default_shipping_delay');
595
  $carrier = $this->_config_model->get('data/default_shipping_method');
596
+ if ($carrier == 'flatrate_flatrate' || $carrier == '') {
597
  $data['shipping_name'] = 'Flatrate';
598
  $data['shipping_price'] = $this->_config['shipping_price'];
599
+ } else {
600
+ if (!empty($carrier)) {
601
+ $carrierTab = explode('_', $carrier);
602
+ list($carrierCode, $methodCode) = $carrierTab;
603
  //todo : wrong shipping name ?
604
  $data['shipping_name'] = ucfirst($methodCode);
605
  $shippingPrice = 0;
606
  $countryCode = $this->_config_model->get('data/shipping_price_based_on');
607
 
608
  $shippingPrice = $product->_getShippingPrice($product, $carrier, $countryCode);
609
+ if (!$shippingPrice) {
610
  $shippingPrice = $this->_config['shipping_price'];
611
  }
612
  $data['shipping_price'] = $shippingPrice;
615
  break;
616
  case 'images':
617
  $max_image = $this->_config_model->getCountExportImages();
618
+ for ($i = 1; $i <= $max_image; ++$i) {
619
+ $data['image-url-' . $i] = '';
620
  }
621
 
622
+ if (isset($this->_listImages[$product->getId()])) {
623
  $productImage = $this->_listImages[$product->getId()];
624
  $i = 1;
625
+ foreach ($productImage as $image) {
626
+ if ($image['disabled'] == 0) {
627
+ $data['image-url-' . $i] = $this->_config['image_base_url'] . $image['src'];
628
  ++$i;
629
  }
630
  }
631
  for ($j = $i; $j < $max_image; ++$j) {
632
+ $data['image-url-' . $j] = '';
633
  }
634
  }
635
 
636
+ if ($data['image-url-1'] == '' && isset($this->_listChildrenIds[$product->getId()])) {
637
+ if (isset($this->_listImages[$this->_listChildrenIds[$product->getId()]['id']])) {
638
+ foreach ($this->_listImages[$this->_listChildrenIds[$product->getId()]['id']] as $img) {
639
+ $data['image-url-1'] = $this->_config['image_base_url'] . $img['src'];
640
  }
641
  }
642
  }
643
  $data['image_default'] = $data['image-url-1'];
644
  break;
645
  case 'product_url':
646
+ if ($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($this->_listChildrenIds[$product->getId()])) {
647
  $data['product_url'] = $this->_listChildrenIds[$product->getId()]['url'];
648
+ } else {
649
+ if ($product->getProductUrl() == "" && isset($this->_listChildrenIds[$product->getId()]['url'])) {
650
  $data['product_url'] = $this->_listChildrenIds[$product->getId()]['url'];
651
+ } else {
652
  $data['product_url'] = $product->getProductUrl();
653
  }
654
  }
655
  break;
656
  case 'name':
657
+ if ($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE && isset($this->_listChildrenIds[$product->getId()])) {
658
+ if ($this->_listChildrenIds[$product->getId()] != '') {
659
+ $data['name'] = $this->_helper->cleanData($this->_listChildrenIds[$product->getId()]['name'],
660
+ $formatData, in_array('name', $this->_config['attribute_html']));
661
+ } else {
662
+ $data['name'] = $this->_helper->cleanData($product->getName(), $formatData,
663
+ in_array('name', $this->_config['attribute_html']));
664
  }
665
+ } else {
666
+ $data['name'] = $this->_helper->cleanData($product->getName(), $formatData,
667
+ in_array('name', $this->_config['attribute_html']));
668
  }
669
  break;
670
  case 'description':
671
+ $data['description'] = $this->_helper->cleanData($product->getDescription(), $formatData,
672
+ in_array('description', $this->_config['attribute_html']));
673
  break;
674
  case 'short_description':
675
+ $data['short_description'] = $this->_helper->cleanData($product->getShortDescription(),
676
+ $formatData, in_array('short_description', $this->_config['attribute_html']));
677
  break;
678
  case 'parent_informations':
679
+ if (isset($this->_listChildrenIds[$product->getId()])) {
680
  $data['parent_id'] = $this->_listChildrenIds[$product->getId()]['id'];
681
  $data['product_type'] = 'child';
682
  $data['child_name'] = $this->_listChildrenIds[$product->getId()]['name'];
683
+ if (isset($this->_listConfigurableVariation[$this->_listChildrenIds[$product->getId()]['id']])) {
684
  $variation = array();
685
+ foreach ($this->_listConfigurableVariation[$this->_listChildrenIds[$product->getId()]['id']] as $variationAttributeId) {
686
  $variation[] = $this->_listCodeAttributes[$variationAttributeId]['frontend_label'];
687
  }
688
  $data['product_variation'] = join(',', $variation);
689
+ } else {
690
  $data['product_variation'] = '';
691
  }
692
+ } else {
693
+ if (isset($this->_listParentIds[$product->getId()])) {
694
  $data['parent_id'] = '';
695
  $data['product_type'] = 'parent';
696
  $data['child_name'] = $product->getName();
697
+ if (isset($this->_listConfigurableVariation[$product->getId()])) {
698
  $variation = array();
699
+ foreach ($this->_listConfigurableVariation[$product->getId()] as $variationAttributeId) {
700
  $variation[] = $this->_listCodeAttributes[$variationAttributeId]['frontend_label'];
701
  }
702
  $data['product_variation'] = join(',', $variation);
703
+ } else {
704
  $data['product_variation'] = '';
705
  }
706
+ } else {
707
  $data['parent_id'] = '';
708
  $data['product_type'] = 'simple';
709
  $data['child_name'] = $product->getName();
713
  break;
714
  }
715
  }
716
+ foreach ($this->_attributesAdditional as $attributeCode) {
717
  if (!isset($data[$attributeCode])) {
718
  if (!in_array($attributeCode, $this->_listForbiddenAttributes)) {
719
+ if (in_array($this->_listCodeAttributes[$this->_listAttributeCode[$attributeCode]]['backend_type'],
720
+ array('text', 'varchar'))) {
721
+ $data[$attributeCode] = $this->_helper->cleanData($this->_getAttributeValue($product->getId(),
722
+ $attributeCode), $formatData,
723
+ in_array($attributeCode, $this->_config['attribute_html']));
724
+ } else {
725
  $data[$attributeCode] = $this->_getAttributeValue($product->getId(), $attributeCode);
726
  }
727
  } else {
729
  }
730
  }
731
  }
 
732
 
733
+ if ($pi >= $nbProduct) {
734
  $this->_write($feed->makeData($data, array('last' => true)));
735
+ } else {
736
  $this->_write($feed->makeData($data));
737
+ }
738
  unset($data);
739
  }
740
  }
741
 
742
  $this->_write($feed->makeFooter());
743
+ if (!$this->_stream) {
744
  flush();
745
  $this->_copyFile();
746
  $store_code = Mage::app()->getStore($this->_id_store)->getCode();
747
  $url_file = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'lengow' . DS . $store_code . DS . $this->_fileName . '.' . $this->_fileFormat;
748
+ $this->_log($this->_helper->__('Your feed is available here : %s',
749
+ '<a href=\'' . $url_file . '\'>' . $url_file . '</a>'));
750
  Mage::helper('lensync/data')->log('Export of the store ' . Mage::app()->getStore($this->_id_store)->getName() . '(' . $this->_id_store . ') generated a file here : ' . $url_file);
751
  }
752
 
753
  }
754
 
755
+ protected function _buildCsvHeader()
756
+ {
 
757
  $tmpHeader = $this->_listHeaderCsvFile;
758
  $this->_listHeaderCsvFile = array();
759
+ foreach ($tmpHeader as $header) {
760
+ switch ($header) {
761
  case 'lengow_categories_header':
762
  $this->_listHeaderCsvFile[] = 'category';
763
  $this->_listHeaderCsvFile[] = 'category-url';
764
  for ($j = 1; $j <= $this->_config['category_max_level']; ++$j) {
765
+ $this->_listHeaderCsvFile[] = 'category-sub-' . $j;
766
+ $this->_listHeaderCsvFile[] = 'category-url-sub-' . $j;
767
  }
768
  $this->_listHeaderCsvFile[] = 'category_breadcrumb';
769
  break;
770
  case 'lengow_images_header':
771
  $max_image = $this->_config_model->getCountExportImages();
772
+ for ($i = 1; $i <= $max_image; ++$i) {
773
+ $this->_listHeaderCsvFile[] = 'image-url-' . $i;
774
  }
775
  break;
776
  default:
778
  break;
779
  }
780
  }
781
+ foreach ($this->_attributesAdditional as $header) {
782
  $this->_listHeaderCsvFile[] = $header;
783
  }
784
 
785
  }
786
 
 
787
  /**
788
  * Set stock on query
789
  * @param object $productCollection
790
  *
791
  * @return object $productCollection
792
  */
793
+ protected function _joinStock($productCollection)
794
+ {
795
  if (!$this->_config['out_of_stock']) {
796
  $conditions = ' AND ((stock.is_in_stock = 1) '
797
  . ' OR (IF(stock.use_config_manage_stock = 1,
798
  ' . (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK) . ',
799
  stock.manage_stock) = 0)) AND is_in_stock IS NOT NULL';
800
 
801
+ $productCollection->getSelect()->join($this->_table['cataloginventory_stock_item'] . ' AS stock',
802
+ 'stock.product_id=e.entity_id ' . $conditions, array(
803
+ 'qty' => 'qty',
804
+ 'is_in_stock' => 'is_in_stock',
805
+ 'manage_stock' => 'manage_stock',
806
+ 'use_config_manage_stock' => 'use_config_manage_stock',
807
+ 'backorders' => 'backorders',
808
+ 'use_config_backorders' => 'use_config_backorders'
809
+ ));
810
+ } else {
811
+ $productCollection->getSelect()->joinLeft($this->_table['cataloginventory_stock_item'] . ' AS stock',
812
+ 'stock.product_id=e.entity_id ', array(
813
+ 'qty' => 'qty',
814
+ 'is_in_stock' => 'is_in_stock',
815
+ 'manage_stock' => 'manage_stock',
816
+ 'use_config_manage_stock' => 'use_config_manage_stock',
817
+ 'backorders' => 'backorders',
818
+ 'use_config_backorders' => 'use_config_backorders'
819
+ ));
820
  }
821
  return $productCollection;
822
  }
826
  *
827
  * @return void
828
  */
829
+ protected function _loadImages()
830
+ {
 
831
  $connection = $this->_coreResource->getConnection('core_read');
832
 
833
  $query = $connection->select(array('DISTINCT value'));
842
  $this->_listImages = array();
843
  foreach ($rows as $row) {
844
  if ($row['disabled'] != 1 && $row['value'] != '') {
845
+ $this->_listImages[$row['entity_id']][] = array('src' => $row['value'], 'disabled' => $row['disabled']);
846
  }
847
  }
848
 
849
+ if ($this->_debug) {
850
+ $this->_log('Load Images (' . count($this->_listImages) . ')');
 
851
  }
852
  }
853
 
856
  *
857
  * @return void
858
  */
859
+ protected function _loadCategories()
860
+ {
861
  $categories = Mage::getModel('catalog/category')->getCollection()
862
  ->setStoreId($this->_id_store)
863
+ ->addAttributeToSelect('name', 'store_id')
864
  ->addAttributeToSelect('is_active')
865
  ->addAttributeToSelect('include_in_menu');
866
  $this->_listCategories = array();
871
  $this->_listCategories[$category->getId()]['url'] = $category->getUrl();
872
  }
873
 
874
+ if ($this->_debug) {
875
+ $this->_log('Load Categories (' . count($this->_listCategories) . ')');
 
876
  }
877
  }
878
 
883
  *
884
  * @return void
885
  */
886
+ protected function _loadGroupedProducts()
887
+ {
 
888
  $productCollection = Mage::getModel('lenexport/product_collection')->getCollection()->addStoreFilter($this->_id_store);
889
  $productCollection->addAttributeToFilter('type_id', array('in' => 'grouped'));
890
+ $productCollection->addAttributeToSelect('name', 'product_url');
891
+ if ($this->_config['product_status'] !== null) {
892
  $productCollection->addAttributeToFilter('status', array('eq' => $this->_config['product_status']));
893
  }
894
  $productCollection->getSelect()->joinLeft($this->_table['catalog_product_link'] . ' AS cpl',
898
  'stock.product_id=cpl.linked_product_id',
899
  array('child_qtys' => 'GROUP_CONCAT( qty)'));
900
  $productCollection->getSelect()->joinLeft($this->_table['catalog_product_entity_int'] . ' AS entity_int',
901
+ 'entity_int.entity_id=cpl.linked_product_id AND entity_int.attribute_id =' . $this->_attributeStatusId,
902
  array('child_status' => 'GROUP_CONCAT( entity_int.value)'));
903
  $productCollection->getSelect()->joinLeft($this->_table['catalog_product_index_price'] . ' AS price_index',
904
  'price_index.entity_id=cpl.linked_product_id AND customer_group_id=0 AND price_index.website_id=' . $this->_websiteId,
905
  array('child_prices' => 'GROUP_CONCAT( final_price )'));
906
+ $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product'] . ' AS categories',
907
+ 'categories.product_id=e.entity_id');
908
  $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product_index'] . ' AS categories_index',
909
  '((categories_index.category_id=categories.category_id AND categories_index.product_id=categories.product_id) ) AND categories_index.store_id=' . $this->_id_store,
910
  array('categories_ids' => 'GROUP_CONCAT(DISTINCT categories_index.category_id)'));
929
  $quantities[] = $qty >= 0 ? $qty : 0;
930
  }
931
  foreach (explode(',', $product->getChildStatus()) as $status) {
932
+ if ($status == 0) {
933
+ $status = false;
934
+ break;
935
+ }
936
  }
937
  foreach (explode(',', $product->getChildPrices()) as $price) {
938
+ $totalPrice += $price;
939
  }
940
  //keep the minimum quantity of product
941
  $this->_listGroupedProducts[$product->getId()]['qty'] = min($quantities);
943
  $this->_listGroupedProducts[$product->getId()]['price'] = $totalPrice;
944
  }
945
 
946
+ if ($this->_debug) {
947
+ $this->_log('Load Grouped (' . count($this->_listGroupedProducts) . ')');
 
 
948
  }
949
  }
950
 
954
  *
955
  * @return void
956
  */
957
+ protected function _loadConfigurableProducts()
958
+ {
 
959
  $connection = $this->_coreResource->getConnection('core_read');
960
+ $query = 'SELECT * FROM ' . $this->_table['catalog_product_super_attribute'];
961
 
962
  $configurableAttributeCollection = $connection->fetchAll($query);
963
+ foreach ($configurableAttributeCollection as $sa) {
964
  $this->_listConfigurableVariation[$sa['product_id']][] = $sa['attribute_id'];
965
  }
966
 
967
+ $perPage = 1000;
968
+
969
+ $query = 'SELECT COUNT(*) as total FROM '.$this->_table['catalog_product_entity'].' WHERE type_id = "configurable" ';
970
+ $totalQuery = $connection->fetchRow($query);
971
+ $total = $totalQuery["total"];
972
+ $nbPage = ceil($total / $perPage);
973
+ for ($i = 1; $i <= $nbPage; $i++) {
974
+ $productCollection = Mage::getModel('lenexport/product_collection')->getCollection()->addStoreFilter($this->_id_store);
975
+ $productCollection->addAttributeToFilter('type_id', array('in' => 'configurable'));
976
+ $productCollection->addAttributeToSelect('name');
977
+ if ($this->_config['product_status'] !== null) {
978
+ $productCollection->addAttributeToFilter('status', array('eq' => $this->_config['product_status']));
979
+ }
980
+ $productCollection->getSelect()->joinLeft($this->_table['catalog_product_super_link'] . ' AS sl',
981
+ 'sl.parent_id=e.entity_id',
982
+ array('child_ids' => 'GROUP_CONCAT( sl.product_id)'));
983
+ $productCollection->getSelect()->joinLeft($this->_table['catalog_product_entity_int'] . ' AS entity_int',
984
+ 'sl.parent_id=entity_int.entity_id AND entity_int.attribute_id = ' . $this->_attributeStatusId,
985
+ array('child_statuses' => 'GROUP_CONCAT( entity_int.value)'));
986
+ $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product'] . ' AS categories',
987
+ 'categories.product_id=e.entity_id');
988
+ $productCollection->getSelect()->joinLeft($this->_table['catalog_category_product_index'] . ' AS categories_index',
989
+ '((categories_index.category_id=categories.category_id AND categories_index.product_id=categories.product_id) ) AND categories_index.store_id=' . $this->_id_store,
990
+ array('categories_ids' => 'GROUP_CONCAT(DISTINCT categories_index.category_id)'));
991
+
992
+ $productCollection->getSelect()->joinLeft($this->_table['core_url_rewrite'] . ' AS url',
993
+ 'url.product_id=e.entity_id AND url.target_path NOT LIKE "category%" AND is_system=1 AND ' . $this->_config["query_url_option"] . ' AND url.store_id=' . $this->_id_store,
994
+ array('request_path' => 'MAX(DISTINCT request_path)'));
995
+
996
+ $productCollection->getSelect()->group(array('sl.parent_id'));
997
+ $productCollection->getSelect()->limit($perPage, ($i-1)*$perPage);
998
+
999
+ foreach ($productCollection as $product) {
1000
+ $this->_listParentIds[$product->getId()] = true;
1001
+ $name = $product->getName();
1002
+ $categoriesId = $product->getCategoriesIds();
1003
+ $url = $product->getProductUrl();
1004
+
1005
+ foreach (explode(',', $product->getChildIds()) as $id) {
1006
+ $this->_listChildrenIds[$id] = array(
1007
+ 'name' => $name,
1008
+ 'id' => $product->getId(),
1009
+ 'categories_id' => $categoriesId,
1010
+ 'url' => $url,
1011
+ );
1012
  // foreach (explode(',', $product->getPrice()) as $price) {
1013
  // $this->_listChildrenIds[$id]['price'] = $price;
1014
  // break;
1017
  // $this->_listChildrenIds[$id]['final_price'] = $price;
1018
  // break;
1019
  // }
1020
+ }
1021
  }
1022
  }
1023
 
1024
+ if ($this->_debug) {
1025
  $this->_log('Load Configurable');
 
 
1026
  }
1027
  }
1028
 
1033
  *
1034
  * @return void
1035
  */
1036
+ protected function _loadTaxes()
1037
+ {
 
 
1038
  $taxCalculation = Mage::getModel('tax/calculation');
1039
  $request = $taxCalculation->getRateRequest(null, null, null, $this->_id_store);
1040
 
1042
 
1043
  $query = $connection->select();
1044
  $query->from($this->_table['tax_class'])->order(array('class_id', 'tax_calculation_rate_id'));
1045
+ $query->joinleft(array('tc' => $this->_table['tax_calculation']),
1046
+ 'tc.product_tax_class_id = ' . $this->_table['tax_class'] . '.class_id',
1047
  'tc.tax_calculation_rate_id');
1048
+ $query->joinleft(array('tcr' => $this->_table['tax_calculation_rate']),
1049
+ 'tcr.tax_calculation_rate_id = tc.tax_calculation_rate_id',
1050
  array('tcr.rate', 'tax_country_id', 'tax_region_id'));
1051
+ $query->joinleft(array('dcr' => $this->_table['directory_country_region']), 'dcr.region_id=tcr.tax_region_id',
1052
+ 'code');
1053
  $query->joinInner(array('cg' => $this->_table['customer_group']),
1054
  'cg.tax_class_id=tc.customer_tax_class_id AND cg.customer_group_code=\'NOT LOGGED IN\'');
1055
  $taxCollection = $connection->fetchAll($query);
1063
  ++$classValue;
1064
  }
1065
  $tempClassId = $tax['class_id'];
1066
+ if ($request['country_id'] == $tax['tax_country_id']) {
1067
  $this->_listTaxes[$tax['class_id']] = $tax['rate'];
1068
  //$this->_listTaxes[$tax['class_id']][$classValue]['code'] = $tax['code'];
1069
  //$this->_listTaxes[$tax['class_id']][$classValue]['country'] = $tax['tax_country_id'];
1070
  }
1071
  }
1072
+ if ($this->_debug) {
1073
+ $this->_log('Load Tax Class (' . count($this->_listTaxes) . ')');
 
1074
  }
1075
 
1076
+ if (count($this->_listTaxes) == 0) {
1077
+ Mage::helper('lensync/data')->log('Tax configuration is not correct, please enable country : ' . $request['country_id']);
1078
  }
1079
  }
1080
 
1084
  *
1085
  * @return void
1086
  */
1087
+ protected function _loadSelectedAttributes()
1088
+ {
1089
  $attributeToExport = $this->_config_model->getMappingAllAttributes($this->_id_store);
1090
 
1091
+ foreach ($attributeToExport as $key => $value) {
1092
+ if ($key == 'none') {
1093
+ continue;
1094
+ }
1095
+ if (!in_array($key, $this->_attributes)) {
1096
  $this->_attributesAdditional[] = $key;
1097
  }
1098
  }
1099
 
1100
+ if ($this->_debug) {
1101
+ $this->_log('Load New Attributes (' . count($attributeToExport) . ')');
 
1102
  }
1103
 
1104
  }
1115
  *
1116
  * @return void
1117
  */
1118
+ protected function _loadProductAttributes()
1119
+ {
 
1120
  $attributeCollection = Mage::getResourceModel('eav/entity_attribute_collection')
1121
  ->setEntityTypeFilter($this->_catalogProductEntityId)
1122
  ->addSetInfo()
1134
 
1135
  $findDiff = array_diff($this->_attributes, $listAttributes);
1136
  $this->_attributes = array_diff($this->_attributes, $findDiff);
1137
+ if ($this->_debug) {
1138
+ $this->_log('Load Attributes (' . count($this->_listCodeAttributes) . ')');
 
1139
  }
1140
  }
1141
 
1146
  *
1147
  * @return void
1148
  */
1149
+ protected function _loadOptionValues()
1150
+ {
1151
  $attributeIdToQuery = array();
1152
+ foreach ($this->_listCodeAttributes as $codeAttribute) {
1153
+ if (in_array($codeAttribute['frontend_input'], array('select', 'multiselect'))) {
1154
  $attributeIdToQuery[] = $codeAttribute['attribute_id'];
1155
  }
1156
  }
1157
 
1158
+ if (count($attributeIdToQuery)) {
1159
  $connection = $this->_coreResource->getConnection('core_read');
1160
+ $query = 'SELECT * FROM ' . $this->_table['eav_attribute_option'] . ' eavo
1161
+ LEFT JOIN ' . $this->_table['eav_attribute_option_value'] . ' eavov ON ( eavo.option_id = eavov.option_id )
1162
+ WHERE eavo.attribute_id IN (' . join(',', $attributeIdToQuery) . ') AND eavov.store_id = 0';
1163
  $entityOptionValueCollection = $connection->fetchAll($query);
1164
+ foreach ($entityOptionValueCollection as $optionValue) {
1165
  $this->_listOptionValues[$optionValue['attribute_id']][$optionValue['option_id']] = $optionValue['value'];
1166
  }
1167
 
1168
  $connection = $this->_coreResource->getConnection('core_read');
1169
+ $query = 'SELECT * FROM ' . $this->_table['eav_attribute_option'] . ' eavo
1170
+ LEFT JOIN ' . $this->_table['eav_attribute_option_value'] . ' eavov ON ( eavo.option_id = eavov.option_id )
1171
+ WHERE eavo.attribute_id IN (' . join(',',
1172
+ $attributeIdToQuery) . ') AND eavov.store_id = ' . $this->_id_store;
1173
  $entityOptionValueCollection = $connection->fetchAll($query);
1174
+ foreach ($entityOptionValueCollection as $optionValue) {
1175
  $this->_listOptionValues[$optionValue['attribute_id']][$optionValue['option_id']] = $optionValue['value'];
1176
  }
1177
  }
1178
 
1179
+ if ($this->_debug) {
1180
+ $this->_log('Load Option Values (' . count($this->_listOptionValues) . ')');
 
1181
  }
1182
  }
1183
 
1188
  *
1189
  * @return void
1190
  */
1191
+ protected function _loadProductAttributeValues()
1192
+ {
1193
+ $this->_loadOptionValues();
1194
+ $this->_loadAttributeValuesByType('int', $this->_table['catalog_product_entity_int']);
1195
+ $this->_loadAttributeValuesByType('varchar', $this->_table['catalog_product_entity_varchar']);
1196
+ $this->_loadAttributeValuesByType('datetime', $this->_table['catalog_product_entity_datetime']);
1197
+ $this->_loadAttributeValuesByType('text', $this->_table['catalog_product_entity_text']);
1198
+ $this->_loadAttributeValuesByType('decimal', $this->_table['catalog_product_entity_decimal']);
1199
+ if ($this->_debug) {
1200
+ $this->_log('Load Attributes Values (' . count($this->_listAttributeValues) . ')');
1201
+ }
 
 
 
 
1202
  }
1203
 
1204
  /**
1205
  * Load attributes values for all entities by type
1206
  *
1207
+ * @param string $type Entity Type (int/varchar/text/decimal/float)
1208
+ * @param string $tableName Table Name by Entity Type
1209
  *
1210
  * @return void
1211
  */
1212
+ protected function _loadAttributeValuesByType($type, $tableName)
1213
+ {
1214
  $connection = $this->_coreResource->getConnection('core_read');
1215
 
1216
  $attributeIdToQuery = array();
1217
+ foreach ($this->_listCodeAttributes as $codeAttribute) {
1218
+ if ($codeAttribute['backend_type'] == $type) {
1219
  //load only selected attributes
1220
+ if (in_array($codeAttribute['attribute_code'], $this->_attributesAdditional)) {
1221
  $attributeIdToQuery[] = $codeAttribute['attribute_id'];
1222
  }
1223
  }
1224
  }
1225
 
1226
+ if ($this->_config['product_ids']) {
1227
+ $sqlWhere = ' AND entity_id IN (' . $this->_config['product_ids'] . ') ';
1228
+ } else {
1229
  $sqlWhere = '';
1230
  }
1231
 
1232
+ $perPage = 20000;
1233
+ if (count($attributeIdToQuery) > 0) {
1234
+ $query = 'SELECT COUNT(*) as total FROM ' . $tableName . ' WHERE attribute_id IN (' . join(',',
1235
+ $attributeIdToQuery) . ') AND store_id = 0 ' . $sqlWhere;
1236
+
1237
+ $totalQuery = $connection->fetchRow($query);
1238
+ $total = $totalQuery["total"];
1239
+ $nbPage = ceil($total / $perPage);
1240
+ for ($i = 1; $i <= $nbPage; $i++) {
1241
+ $query = 'SELECT '.$tableName.'.attribute_id, '.$tableName.'.value, '.$tableName.'.entity_id
1242
+ FROM ' . $tableName . ' WHERE '.$tableName.'.attribute_id IN (' . join(',',
1243
+ $attributeIdToQuery) . ') AND '.$tableName.'.store_id = 0 ' . $sqlWhere.' LIMIT '.(($i-1)*$perPage).','.$perPage;
1244
+ $entityIntCollection = $connection->fetchAll($query);
1245
+ foreach ($entityIntCollection as $int) {
1246
+ if ($int['value'] == '') {
1247
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = '';
1248
+ } else {
1249
+ if ($this->_listCodeAttributes[$int['attribute_id']]['frontend_input'] == 'select' && $this->_listCodeAttributes[$int['attribute_id']]['backend_type'] == 'int') {
1250
+ if (isset($this->_listOptionValues[$int['attribute_id']][$int['value']])) {
1251
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $this->_listOptionValues[$int['attribute_id']][$int['value']];
1252
+ } else {
1253
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
1254
+ }
1255
+ } else {
1256
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
1257
  }
 
 
1258
  }
1259
  }
1260
  }
1261
+ $query = 'SELECT COUNT(*) as total FROM ' . $tableName . ' WHERE attribute_id IN (' . join(',',
1262
+ $attributeIdToQuery) . ') AND store_id = '.$this->_id_store.' ' . $sqlWhere;
1263
+ $totalQuery = $connection->fetchRow($query);
1264
+ $total = $totalQuery["total"];
1265
+ $nbPage = ceil($total / $perPage);
1266
+ for ($i = 1; $i <= $nbPage; $i++) {
1267
+ $query = 'SELECT attribute_id, value, entity_id FROM ' . $tableName . ' WHERE attribute_id IN (' . join(',',
1268
+ $attributeIdToQuery) . ') AND store_id = ' . $this->_id_store . ' ' . $sqlWhere . ' LIMIT ' . (($i - 1) * $perPage) . ',' . $perPage;
1269
+ $entityIntCollection = $connection->fetchAll($query);
1270
+ foreach ($entityIntCollection as $int) {
1271
+ if ($int['value'] == '') {
1272
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = '';
1273
+ } else {
1274
+ if ($this->_listCodeAttributes[$int['attribute_id']]['frontend_input'] == 'select' && $this->_listCodeAttributes[$int['attribute_id']]['backend_type'] == 'int') {
1275
+ if (isset($this->_listOptionValues[$int['attribute_id']][$int['value']])) {
1276
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $this->_listOptionValues[$int['attribute_id']][$int['value']];
1277
+ } else {
1278
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
1279
+ }
1280
+ } else {
1281
+ $this->_listAttributeValues[$int['entity_id']][$this->_listCodeAttributes[$int['attribute_id']]['attribute_code']] = $int['value'];
1282
  }
 
 
1283
  }
1284
  }
1285
  }
1286
  }
1287
 
1288
+ if ($this->_debug) {
1289
+ $this->_log('Load Attributes Values ' . $type . ' (' . count($this->_listAttributeValues) . ')');
 
1290
  }
 
1291
  }
1292
 
1293
  /**
1294
  * Calculate price with Taxes
1295
  *
1296
+ * @param float $price Price
1297
+ * @param integer $taxClassId Tax Class Id
1298
  *
1299
  * @return float price
1300
  */
1301
+ protected function _calculatePrice($price, $taxClassId)
1302
+ {
1303
  $currentRate = $this->_listTaxes;
1304
  if (!$this->_config['include_tax'] && isset($currentRate[$taxClassId])) {
1305
  if (count($currentRate[$taxClassId]) > 1) {
1306
+ return round($price, 2);
1307
  } else {
1308
+ return round($price * ($currentRate[$taxClassId] / 100 + 1), 2);
1309
  }
1310
  } else {
1311
+ return round($price, 2);
1312
  }
1313
  }
1314
 
1315
  /**
1316
  * Get Store attribute value
1317
  *
1318
+ * @param integer $productId Id Product
1319
+ * @param varchar $attributeCode Attribute Code
1320
  *
1321
  * @return float price
1322
  */
1323
+ protected function _getAttributeValue($productId, $attributeCode)
1324
+ {
1325
+ if (isset($this->_listAttributeValues[$productId]) && isset($this->_listAttributeValues[$productId][$attributeCode])) {
1326
  return $this->_listAttributeValues[$productId][$attributeCode];
1327
+ } else {
1328
  return '';
1329
  }
1330
  }
1334
  *
1335
  * @param array $data
1336
  */
1337
+ protected function _write($data)
1338
  {
1339
+ if ($this->_stream == false) {
1340
+ if (!$this->_file) {
1341
  $this->_initFile();
1342
  }
1343
  $this->_file->streamLock();
1351
  /**
1352
  * Create File for export
1353
  */
1354
+ protected function _initFile()
1355
  {
1356
+ if (!$this->_createDirectory()) {
1357
+ exit();
1358
+ }
1359
 
1360
  $this->_fileTimeStamp = time();
1361
  $this->_file = new Varien_Io_File;
1363
  $this->_file->streamOpen($this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat, 'w+');
1364
  }
1365
 
1366
+ protected function _createDirectory()
1367
+ {
1368
  try {
1369
  $file = new Varien_Io_File;
1370
  $file->checkAndCreateFolder($this->_config['directory_path']);
1371
  } catch (Exception $e) {
1372
+ Mage::helper('lensync/data')->log('can\'t create folder ' . $this->_config['directory_path'] . '');
1373
+ if ($this->_debug) {
1374
+ $this->_log('can\'t create folder ' . $this->_config['directory_path']);
1375
  }
1376
  return false;
1377
  }
1381
  /**
1382
  * Copies the file to the correct folder
1383
  */
1384
+ protected function _copyFile()
1385
  {
1386
  $file_path = $this->_config['directory_path'];
1387
+ copy($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat,
1388
+ $file_path . $this->_fileName . '.' . $this->_fileFormat);
1389
  unlink($file_path . $this->_fileName . '.' . $this->_fileTimeStamp . '.' . $this->_fileFormat);
1390
  }
1391
 
1408
  *
1409
  * @return void
1410
  */
1411
+ protected function _stop($timeStart, $title)
1412
+ {
1413
  $time_end = $this->microtime_float();
1414
  $time = $time_end - $timeStart;
1415
+ if ($time < 0.0001) {
1416
+ $time = 0;
1417
+ }
1418
+ echo round($time, 4) . ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' . $title . ' secondes <br/>';
1419
  }
1420
 
1421
  /**
1425
  *
1426
  * @return void
1427
  */
1428
+ protected function _log($title)
1429
+ {
1430
+ if ($this->_stream) {
1431
+ return;
1432
+ }
1433
  $time_end = $this->microtime_float();
1434
  $time = $time_end - $this->_startScript;
1435
+ echo date('Y-m-d h:i:s') . '|' . str_pad(sprintf('%0.4f', round($time, 4)), 10, '0',
1436
+ STR_PAD_LEFT) . ' ' . str_pad($title, 40, '=', STR_PAD_BOTH) . '<br/>';
1437
  }
1438
 
1439
  /**
1441
  *
1442
  * @return boolean
1443
  */
1444
+ protected function _isAlreadyLaunch()
1445
+ {
1446
  $directory = $this->_config['directory_path'];
1447
+ if (!$this->_createDirectory()) {
1448
  exit();
1449
  }
1450
 
1451
  try {
1452
  $listFiles = array_diff(scandir($directory), array('..', '.'));
1453
  } catch (Exception $e) {
1454
+ Mage::helper('lensync/data')->log('Can\'t access folder ' . $this->_config['directory_path']);
1455
+ if ($this->_debug) {
1456
+ $this->_log('Can\'t access folder ' . $this->_config['directory_path']);
1457
  }
1458
  exit();
1459
  }
1476
  }
1477
  return false;
1478
  }
1479
+ }
 
app/code/community/Lengow/Export/Model/Observer.php CHANGED
@@ -5,11 +5,12 @@
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
- * @copyright 2015 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Export_Model_Observer {
 
13
 
14
  /**
15
  * Exports products for each store with cron job
@@ -24,34 +25,36 @@ class Lengow_Export_Model_Observer {
24
  ini_set('memory_limit', '1G');
25
  $store_collection = Mage::getResourceModel('core/store_collection')->addFieldToFilter('is_active', 1);
26
  $exceptions = array();
27
- foreach($store_collection as $store) {
28
  try {
29
  if (Mage::getStoreConfig('lenexport/global/active_store', $store)) {
30
  Mage::helper('lensync/data')->log('Start cron export in Store ' . $store->getName() . '(' . $store->getId() . ')');
31
  $_configModel = Mage::getSingleton('lenexport/config');
32
  $_configModel->setStore($store->getId());
33
- $format =Mage::getStoreConfig('lenexport/data/format', $store);
34
- if(Mage::getStoreConfig('lenexport/performances/optimizeexport'))
35
  $generate = Mage::getModel('lenexport/generateoptimize');
36
- else
37
  $generate = Mage::getModel('lenexport/generate');
 
38
  $generate->setCurrentStore($store->getId());
39
  $generate->setOriginalCurrency($store->getCurrentCurrencyCode());
40
- if(Mage::getStoreConfig('lenexport/performances/optimizeexport'))
41
  $generate->exec(
42
- $store->getId(),
43
  $format,
44
  array(
45
  'stream' => false
46
  )
47
  );
48
- else
49
  $generate->exec($store->getId(), null, $format, null, null, null, null, null, false, false);
 
50
  } else {
51
  Mage::helper('lensync/data')->log('Stop cron export - Store ' . $store->getName() . '(' . $store->getId() . ') is disabled');
52
  }
53
  } catch (Exception $e) {
54
- Mage::helper('lensync/data')->log('Stop cron export - Store ' . $store->getName() . '(' . $store->getId() . ') - Error: '.$e->getMessage());
55
  Mage::log($e->getMessage());
56
  Mage::log($e->getTraceAsString());
57
  }
@@ -67,7 +70,7 @@ class Lengow_Export_Model_Observer {
67
  public function autoExportProduct($observer)
68
  {
69
  $_config = Mage::getSingleton('lenexport/config');
70
- if($_config->isAutoExportProduct()) {
71
  $_product = $observer->getEvent()->getProduct();
72
  try {
73
  $_product->setLengowProduct(1);
@@ -75,11 +78,13 @@ class Lengow_Export_Model_Observer {
75
  Mage::log($e->getMessage());
76
  Mage::log($e->getTraceAsString());
77
  }
78
- Mage::log('Auto export product ' . $_product->getId(). ' (SKU ' . $_product->getSku(). ') to Lengow');
79
  }
80
  }
81
 
82
-
 
 
83
  public function afterSaveConfiguration($observer)
84
  {
85
  $postData = $observer->getEvent()->getData();
@@ -93,18 +98,13 @@ class Lengow_Export_Model_Observer {
93
  }
94
  }
95
 
96
- if (is_null($postData['store']) && $postData['website']) //check for website scope
97
- {
98
  //do nothing
99
- }
100
- elseif($postData['store']) //check for store scope
101
- {
102
  $current_store = Mage::getModel('core/store')->load($postData['store']);
103
  //delete feed
104
  $this->_deleteStoreFiles($current_store);
105
- }
106
- else //for default scope
107
- {
108
  //check individual store
109
  //delete all feeds
110
  foreach (Mage::app()->getWebsites() as $website) {
@@ -112,27 +112,30 @@ class Lengow_Export_Model_Observer {
112
  $stores = $group->getStores();
113
  foreach ($stores as $store) {
114
  //check if individual value is on
115
- if (Mage::getStoreConfig('lenexport/global/active_store', $store)==0){
116
  $this->_deleteStoreFiles($store);
117
  }
118
  }
119
  }
120
  }
121
  }
122
-
123
  }
124
 
125
-
 
 
 
 
 
126
  private function _deleteStoreFiles($store)
127
  {
128
- $formatFeed = array("csv","xml","yaml","json");
129
- foreach($formatFeed as $format){
130
- $filePath = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store->getCode() . DS."lengow_feed.".$format;
131
- if (file_exists($filePath)){
132
  unlink($filePath);
133
- Mage::helper('lensync/data')->log('Store '.$store->getName().' desactived - Feed delete : '.$filePath);
134
  }
135
  }
136
  }
137
-
138
- }
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Observer
13
+ {
14
 
15
  /**
16
  * Exports products for each store with cron job
25
  ini_set('memory_limit', '1G');
26
  $store_collection = Mage::getResourceModel('core/store_collection')->addFieldToFilter('is_active', 1);
27
  $exceptions = array();
28
+ foreach ($store_collection as $store) {
29
  try {
30
  if (Mage::getStoreConfig('lenexport/global/active_store', $store)) {
31
  Mage::helper('lensync/data')->log('Start cron export in Store ' . $store->getName() . '(' . $store->getId() . ')');
32
  $_configModel = Mage::getSingleton('lenexport/config');
33
  $_configModel->setStore($store->getId());
34
+ $format = Mage::getStoreConfig('lenexport/data/format', $store);
35
+ if (Mage::getStoreConfig('lenexport/performances/optimizeexport')) {
36
  $generate = Mage::getModel('lenexport/generateoptimize');
37
+ } else {
38
  $generate = Mage::getModel('lenexport/generate');
39
+ }
40
  $generate->setCurrentStore($store->getId());
41
  $generate->setOriginalCurrency($store->getCurrentCurrencyCode());
42
+ if (Mage::getStoreConfig('lenexport/performances/optimizeexport')) {
43
  $generate->exec(
44
+ $store->getId(),
45
  $format,
46
  array(
47
  'stream' => false
48
  )
49
  );
50
+ } else {
51
  $generate->exec($store->getId(), null, $format, null, null, null, null, null, false, false);
52
+ }
53
  } else {
54
  Mage::helper('lensync/data')->log('Stop cron export - Store ' . $store->getName() . '(' . $store->getId() . ') is disabled');
55
  }
56
  } catch (Exception $e) {
57
+ Mage::helper('lensync/data')->log('Stop cron export - Store ' . $store->getName() . '(' . $store->getId() . ') - Error: ' . $e->getMessage());
58
  Mage::log($e->getMessage());
59
  Mage::log($e->getTraceAsString());
60
  }
70
  public function autoExportProduct($observer)
71
  {
72
  $_config = Mage::getSingleton('lenexport/config');
73
+ if ($_config->isAutoExportProduct()) {
74
  $_product = $observer->getEvent()->getProduct();
75
  try {
76
  $_product->setLengowProduct(1);
78
  Mage::log($e->getMessage());
79
  Mage::log($e->getTraceAsString());
80
  }
81
+ Mage::log('Auto export product ' . $_product->getId() . ' (SKU ' . $_product->getSku() . ') to Lengow');
82
  }
83
  }
84
 
85
+ /**
86
+ * Delete files for disable store
87
+ */
88
  public function afterSaveConfiguration($observer)
89
  {
90
  $postData = $observer->getEvent()->getData();
98
  }
99
  }
100
 
101
+ if (is_null($postData['store']) && $postData['website']) {
 
102
  //do nothing
103
+ } elseif ($postData['store']) {
 
 
104
  $current_store = Mage::getModel('core/store')->load($postData['store']);
105
  //delete feed
106
  $this->_deleteStoreFiles($current_store);
107
+ } else {
 
 
108
  //check individual store
109
  //delete all feeds
110
  foreach (Mage::app()->getWebsites() as $website) {
112
  $stores = $group->getStores();
113
  foreach ($stores as $store) {
114
  //check if individual value is on
115
+ if (Mage::getStoreConfig('lenexport/global/active_store', $store) == 0) {
116
  $this->_deleteStoreFiles($store);
117
  }
118
  }
119
  }
120
  }
121
  }
 
122
  }
123
 
124
+ /**
125
+ * Deletes files of disabled shops
126
+ *
127
+ * @param $store
128
+ *
129
+ */
130
  private function _deleteStoreFiles($store)
131
  {
132
+ $formatFeed = array("csv", "xml", "yaml", "json");
133
+ foreach ($formatFeed as $format) {
134
+ $filePath = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store->getCode() . DS . 'lengow_feed.' . $format;
135
+ if (file_exists($filePath)) {
136
  unlink($filePath);
137
+ Mage::helper('lensync/data')->log('Store ' . $store->getName() . ' desactived - Feed delete : ' . $filePath);
138
  }
139
  }
140
  }
141
+ }
 
app/code/community/Lengow/Export/Model/Product/Collection.php CHANGED
@@ -1,5 +1,14 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
3
  class Lengow_Export_Model_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
4
  {
5
 
@@ -7,7 +16,9 @@ class Lengow_Export_Model_Product_Collection extends Mage_Catalog_Model_Resource
7
  {
8
  return false;
9
  }
10
- public function getCollection(){
 
 
11
  return $this;
12
  }
13
 
@@ -17,9 +28,7 @@ class Lengow_Export_Model_Product_Collection extends Mage_Catalog_Model_Resource
17
  */
18
  protected function _construct()
19
  {
20
-
21
  $this->_init('lenexport/catalog_product');
22
  $this->_initTables();
23
  }
24
-
25
- }
1
  <?php
2
 
3
+ /**
4
+ * Lengow export model product collection
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
  class Lengow_Export_Model_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
13
  {
14
 
16
  {
17
  return false;
18
  }
19
+
20
+ public function getCollection()
21
+ {
22
  return $this;
23
  }
24
 
28
  */
29
  protected function _construct()
30
  {
 
31
  $this->_init('lenexport/catalog_product');
32
  $this->_initTables();
33
  }
34
+ }
 
app/code/community/Lengow/Export/Model/Resource/Catalog/Product.php CHANGED
@@ -1,8 +1,15 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
3
  class Lengow_Export_Model_Resource_Catalog_Product extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product
4
  {
5
 
6
-
7
-
8
- }
1
  <?php
2
 
3
+ /**
4
+ * Lengow export model resource catalog product
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
  class Lengow_Export_Model_Resource_Catalog_Product extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product
13
  {
14
 
15
+ }
 
 
app/code/community/Lengow/Export/Model/Shipping/Carrier/Lengow.php CHANGED
@@ -1,15 +1,16 @@
1
  <?php
2
 
3
  /**
4
- * Lengow shipping model
5
  *
6
- * @category Lengow
7
- * @package Profileolabs_Lengow
8
- * @author kassim belghait
 
 
9
  */
10
- class Lengow_Export_Model_Shipping_Carrier_Lengow
11
- extends Mage_Shipping_Model_Carrier_Abstract
12
- implements Mage_Shipping_Model_Carrier_Interface {
13
 
14
  protected $_code = 'lengow';
15
  protected $_isFixed = true;
@@ -20,7 +21,8 @@ class Lengow_Export_Model_Shipping_Carrier_Lengow
20
  * @param Mage_Shipping_Model_Rate_Request $request
21
  * @return Mage_Shipping_Model_Rate_Result
22
  */
23
- public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
 
24
  if (!$this->isActive()) {
25
  return false;
26
  }
@@ -32,34 +34,39 @@ class Lengow_Export_Model_Shipping_Carrier_Lengow
32
  $method->setMethodTitle($this->getConfigData('name'));
33
  $method->setPrice($this->getSession()->getShippingPrice());
34
  $method->setCost($this->getSession()->getShippingPrice());
35
- $result->append($method);
36
  return $result;
37
  }
38
-
39
  /**
40
- * Processing additional validation to check is carrier applicable.
41
- *
42
- * @param Mage_Shipping_Model_Rate_Request $request
43
- * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
44
- */
45
- public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request) {
46
- if(Mage::getVersion() == '1.4.1.0')
47
- return $this->isActive();
48
- return parent::proccessAdditionalValidation($request);
 
 
49
  }
50
-
51
- public function getSession() {
52
- return Mage::getSingleton('checkout/session');
 
53
  }
54
-
55
- public function isActive() {
56
- if($this->getSession()->getIsLengow())
 
57
  return true;
58
- return false;
 
59
  }
60
 
61
- public function getAllowedMethods() {
62
- return array('lengow'=>$this->getConfigData('name'));
 
63
  }
64
-
65
  }
1
  <?php
2
 
3
  /**
4
+ * Lengow export model shipping carrier lengow
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Shipping_Carrier_Lengow extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
13
+ {
 
14
 
15
  protected $_code = 'lengow';
16
  protected $_isFixed = true;
21
  * @param Mage_Shipping_Model_Rate_Request $request
22
  * @return Mage_Shipping_Model_Rate_Result
23
  */
24
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
25
+ {
26
  if (!$this->isActive()) {
27
  return false;
28
  }
34
  $method->setMethodTitle($this->getConfigData('name'));
35
  $method->setPrice($this->getSession()->getShippingPrice());
36
  $method->setCost($this->getSession()->getShippingPrice());
37
+ $result->append($method);
38
  return $result;
39
  }
40
+
41
  /**
42
+ * Processing additional validation to check is carrier applicable.
43
+ *
44
+ * @param Mage_Shipping_Model_Rate_Request $request
45
+ * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
46
+ */
47
+ public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
48
+ {
49
+ if (Mage::getVersion() == '1.4.1.0') {
50
+ return $this->isActive();
51
+ }
52
+ return parent::proccessAdditionalValidation($request);
53
  }
54
+
55
+ public function getSession()
56
+ {
57
+ return Mage::getSingleton('checkout/session');
58
  }
59
+
60
+ public function isActive()
61
+ {
62
+ if ($this->getSession()->getIsLengow()) {
63
  return true;
64
+ }
65
+ return false;
66
  }
67
 
68
+ public function getAllowedMethods()
69
+ {
70
+ return array('lengow' => $this->getConfigData('name'));
71
  }
 
72
  }
app/code/community/Lengow/Export/Model/Source/Attributes.php CHANGED
@@ -1,20 +1,24 @@
1
  <?php
 
2
  /**
3
- * Lengow export model export source attributes
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Source_Attributes {
 
12
 
13
- public function toOptionArray() {
14
- $attributes = Mage::getSingleton('lenexport/convert_parser_product')->getExternalAttributes();
15
- array_unshift($attributes, array('value' => 'none' ,
16
- 'label' => Mage::helper('adminhtml')->__('Select attribut to map')));
17
- return $attributes;
 
 
 
18
  }
19
-
20
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model source attributes
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Source_Attributes
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
+ $attributes = Mage::getSingleton('lenexport/convert_parser_product')->getExternalAttributes();
18
+ array_unshift($attributes, array(
19
+ 'value' => 'none',
20
+ 'label' => Mage::helper('adminhtml')->__('Select attribut to map')
21
+ ));
22
+ return $attributes;
23
  }
 
24
  }
app/code/community/Lengow/Export/Model/Source/Types.php CHANGED
@@ -1,20 +1,24 @@
1
  <?php
 
2
  /**
3
  * Lengow export model source types
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_Source_Types {
 
12
 
13
- public function toOptionArray() {
14
- $attributes = Mage::getSingleton('lenexport/convert_parser_product')->getExternalAttributes();
15
- array_unshift($attributes, array('value' => 'none' ,
16
- 'label' => $this->__('Sélectionnez l\'attribut à mapper')));
17
- return $attributes;
 
 
 
18
  }
19
-
20
  }
1
  <?php
2
+
3
  /**
4
  * Lengow export model source types
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_Source_Types
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
+ $attributes = Mage::getSingleton('lenexport/convert_parser_product')->getExternalAttributes();
18
+ array_unshift($attributes, array(
19
+ 'value' => 'none',
20
+ 'label' => $this->__('Sélectionnez l\'attribut à mapper')
21
+ ));
22
+ return $attributes;
23
  }
 
24
  }
app/code/community/Lengow/Export/Model/System/Config/Backend/Apikey.php CHANGED
@@ -1,24 +1,28 @@
1
  <?php
 
2
  /**
3
  * Lengow Backend Model for Config Api key
4
- * @category Lengow
5
- * @package Lengow_Export
6
- * @author Ludovic Drin <ludovic@lengow.com>
7
- * @copyright 2013 Lengow SAS
 
 
8
  */
9
- class Lengow_Export_Model_System_Config_Backend_Apikey extends Mage_Core_Model_Config_Data {
10
-
11
- protected function _beforeSave() {
12
- parent::_beforeSave();
13
- if((boolean)$this->getFieldsetDataValue('enabled') && $this->getValue() == '')
14
- Mage::throwException(Mage::helper('lensync')->__('API Key (Token) is empty'));
15
- if($this->isValueChanged()) {
16
- /* @var $service Lengow_Export_Model_ManageOrders_Service */
17
- $service = Mage::getSingleton('Lengow_Export/manageorders_service');
18
- if((boolean)$this->getFieldsetDataValue('enabled') && !$service->checkApiKey($this->getValue()))
19
- Mage::throwException(Mage::helper('lensync')->__('API key (Token) not valid'));
20
-
21
- }
22
- }
23
-
24
- }
 
1
  <?php
2
+
3
  /**
4
  * Lengow Backend Model for Config Api key
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_System_Config_Backend_Apikey extends Mage_Core_Model_Config_Data
13
+ {
14
+ protected function _beforeSave()
15
+ {
16
+ parent::_beforeSave();
17
+ if ((boolean)$this->getFieldsetDataValue('enabled') && $this->getValue() == '') {
18
+ Mage::throwException(Mage::helper('lensync')->__('API Key (Token) is empty'));
19
+ }
20
+ if ($this->isValueChanged()) {
21
+ /* @var $service Lengow_Export_Model_ManageOrders_Service */
22
+ $service = Mage::getSingleton('Lengow_Export/manageorders_service');
23
+ if ((boolean)$this->getFieldsetDataValue('enabled') && !$service->checkApiKey($this->getValue())) {
24
+ Mage::throwException(Mage::helper('lensync')->__('API key (Token) not valid'));
25
+ }
26
+ }
27
+ }
28
+ }
app/code/community/Lengow/Export/Model/System/Config/Source/Category/Level.php CHANGED
@@ -1,22 +1,23 @@
1
  <?php
 
2
  /**
3
  * Lengow export model system config source category level
4
- * Level of deep category
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
- * @author Ludovic Drin <ludovic@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Export_Model_System_Config_Source_Category_Level extends Mage_Core_Model_Config_Data {
 
13
 
14
- public function toOptionArray() {
 
15
  $array = array();
16
- for($i = 1; $i <= 10; $i++) {
17
  $array[] = array('value' => $i, 'label' => $i);
18
  }
19
  return $array;
20
  }
21
-
22
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export model system config source category level
 
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_System_Config_Source_Category_Level extends Mage_Core_Model_Config_Data
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
  $array = array();
18
+ for ($i = 1; $i <= 10; $i++) {
19
  $array[] = array('value' => $i, 'label' => $i);
20
  }
21
  return $array;
22
  }
23
+ }
 
app/code/community/Lengow/Export/Model/System/Config/Source/Format.php CHANGED
@@ -1,34 +1,45 @@
1
  <?php
 
2
  /**
3
- * Lengow export model systems config source format
4
- * format of export
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
- * @author Ludovic Drin <ludovic@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Export_Model_System_Config_Source_Format extends Mage_Core_Model_Config_Data {
 
13
 
14
- public function toOptionArray() {
 
15
  return array(
16
- array('value' => 'csv',
17
- 'label' => 'csv'),
18
- array('value' => 'xml',
19
- 'label' => 'xml'),
20
- array('value' => 'json',
21
- 'label' => 'json'),
22
- array('value' => 'yaml',
23
- 'label' => 'yaml'),
 
 
 
 
 
 
 
 
24
  );
25
  }
26
-
27
- public function toSelectArray() {
 
28
  $select = array();
29
- foreach($this->toOptionArray() as $option) {
30
  $select[$option['value']] = $option['label'];
31
  }
32
  return $select;
33
  }
34
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model systems config source format
 
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_System_Config_Source_Format extends Mage_Core_Model_Config_Data
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
  return array(
18
+ array(
19
+ 'value' => 'csv',
20
+ 'label' => 'csv'
21
+ ),
22
+ array(
23
+ 'value' => 'xml',
24
+ 'label' => 'xml'
25
+ ),
26
+ array(
27
+ 'value' => 'json',
28
+ 'label' => 'json'
29
+ ),
30
+ array(
31
+ 'value' => 'yaml',
32
+ 'label' => 'yaml'
33
+ ),
34
  );
35
  }
36
+
37
+ public function toSelectArray()
38
+ {
39
  $select = array();
40
+ foreach ($this->toOptionArray() as $option) {
41
  $select[$option['value']] = $option['label'];
42
  }
43
  return $select;
44
  }
45
+ }
app/code/community/Lengow/Export/Model/System/Config/Source/Getattributes.php CHANGED
@@ -1,31 +1,34 @@
1
  <?php
 
2
  /**
3
- * Lengow export model config
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Model_System_Config_Source_Getattributes extends Mage_Core_Model_Config_Data {
 
12
 
13
- public function toOptionArray() {
 
14
  $attribute = Mage::getResourceModel('eav/entity_attribute_collection')
15
- ->setEntityTypeFilter(Mage::getModel('catalog/product')
16
- ->getResource()
17
- ->getTypeId());
18
  $attributeArray = array();
19
- $attributeArray[] = array('value' => 'none',
20
- 'label' => '',
21
- );
 
22
  foreach ($attribute as $option) {
23
  $attributeArray[] = array(
24
  'value' => $option->getAttributeCode(),
25
  'label' => $option->getAttributeCode()
26
  );
27
- }
28
  return $attributeArray;
29
  }
30
-
31
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow export model system config source getattributes
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_System_Config_Source_Getattributes extends Mage_Core_Model_Config_Data
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
  $attribute = Mage::getResourceModel('eav/entity_attribute_collection')
18
+ ->setEntityTypeFilter(Mage::getModel('catalog/product')
19
+ ->getResource()
20
+ ->getTypeId());
21
  $attributeArray = array();
22
+ $attributeArray[] = array(
23
+ 'value' => 'none',
24
+ 'label' => '',
25
+ );
26
  foreach ($attribute as $option) {
27
  $attributeArray[] = array(
28
  'value' => $option->getAttributeCode(),
29
  'label' => $option->getAttributeCode()
30
  );
31
+ }
32
  return $attributeArray;
33
  }
 
34
  }
app/code/community/Lengow/Export/Model/System/Config/Source/Images.php CHANGED
@@ -1,31 +1,35 @@
1
  <?php
 
2
  /**
3
  * Lengow export model system config source count images
4
- * Number of images to export
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
- * @author Ludovic Drin <ludovic@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Export_Model_System_Config_Source_Images extends Mage_Core_Model_Config_Data {
 
13
 
14
- public function toOptionArray() {
 
15
  $array = array();
16
- for($i = 5; $i <= 20; $i++) {
17
- $array[] = array('value' => $i,
18
- 'label' => $i);
 
 
19
  }
20
  return $array;
21
  }
22
-
23
- public function toSelectArray() {
 
24
  $select = array();
25
- foreach($this->toOptionArray() as $option) {
26
  $select[$option['value']] = $option['label'];
27
  }
28
  return $select;
29
  }
30
-
31
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export model system config source count images
 
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_System_Config_Source_Images extends Mage_Core_Model_Config_Data
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
  $array = array();
18
+ for ($i = 5; $i <= 20; $i++) {
19
+ $array[] = array(
20
+ 'value' => $i,
21
+ 'label' => $i
22
+ );
23
  }
24
  return $array;
25
  }
26
+
27
+ public function toSelectArray()
28
+ {
29
  $select = array();
30
+ foreach ($this->toOptionArray() as $option) {
31
  $select[$option['value']] = $option['label'];
32
  }
33
  return $select;
34
  }
35
+ }
 
app/code/community/Lengow/Export/Model/System/Config/Source/Status.php CHANGED
@@ -1,33 +1,41 @@
1
  <?php
 
2
  /**
3
  * Lengow export model system config source status
4
- * Status of product to export
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
- * @author Ludovic Drin <ludovic@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Export_Model_System_Config_Source_Status extends Mage_Core_Model_Config_Data {
 
13
 
14
- public function toOptionArray() {
 
15
  return array(
16
- array('value' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
17
- 'label' => Mage::helper('adminhtml')->__('Enabled')),
18
- array('value' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED,
19
- 'label' => Mage::helper('adminhtml')->__('Disabled')),
20
- array('value' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED . ',' . Mage_Catalog_Model_Product_Status::STATUS_DISABLED,
21
- 'label' => Mage::helper('adminhtml')->__('Enabled') . ', ' . Mage::helper('adminhtml')->__('Disabled')),
 
 
 
 
 
 
22
  );
23
  }
24
-
25
- public function toSelectArray() {
 
26
  $select = array();
27
- foreach($this->toOptionArray() as $option) {
28
  $select[$option['value']] = $option['label'];
29
  }
30
  return $select;
31
  }
32
-
33
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export model system config source status
 
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_System_Config_Source_Status extends Mage_Core_Model_Config_Data
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
  return array(
18
+ array(
19
+ 'value' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
20
+ 'label' => Mage::helper('adminhtml')->__('Enabled')
21
+ ),
22
+ array(
23
+ 'value' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED,
24
+ 'label' => Mage::helper('adminhtml')->__('Disabled')
25
+ ),
26
+ array(
27
+ 'value' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED . ',' . Mage_Catalog_Model_Product_Status::STATUS_DISABLED,
28
+ 'label' => Mage::helper('adminhtml')->__('Enabled') . ', ' . Mage::helper('adminhtml')->__('Disabled')
29
+ ),
30
  );
31
  }
32
+
33
+ public function toSelectArray()
34
+ {
35
  $select = array();
36
+ foreach ($this->toOptionArray() as $option) {
37
  $select[$option['value']] = $option['label'];
38
  }
39
  return $select;
40
  }
41
+ }
 
app/code/community/Lengow/Export/Model/System/Config/Source/Types.php CHANGED
@@ -1,37 +1,49 @@
1
  <?php
 
2
  /**
3
  * Lengow export model system config source types
4
- * Types of product to export
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
- * @author Ludovic Drin <ludovic@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Export_Model_System_Config_Source_Types extends Mage_Core_Model_Config_Data {
 
13
 
14
- public function toOptionArray() {
 
15
  return array(
16
- array('value' => 'configurable',
17
- 'label' => Mage::helper('adminhtml')->__('Configurable')),
18
- array('value' => 'simple',
19
- 'label' => Mage::helper('adminhtml')->__('Simple')),
20
- array('value' => 'bundle',
21
- 'label' => Mage::helper('adminhtml')->__('Bundle')),
22
- array('value' => 'grouped',
23
- 'label' => Mage::helper('adminhtml')->__('Grouped')),
24
- array('value' => 'virtual',
25
- 'label' => Mage::helper('adminhtml')->__('Virtual')),
 
 
 
 
 
 
 
 
 
 
26
  );
27
  }
28
 
29
- public function toSelectArray() {
 
30
  $select = array();
31
- foreach($this->toOptionArray() as $option) {
32
  $select[$option['value']] = $option['label'];
33
  }
34
  return $select;
35
  }
36
-
37
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export model system config source types
 
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Model_System_Config_Source_Types extends Mage_Core_Model_Config_Data
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
  return array(
18
+ array(
19
+ 'value' => 'configurable',
20
+ 'label' => Mage::helper('adminhtml')->__('Configurable')
21
+ ),
22
+ array(
23
+ 'value' => 'simple',
24
+ 'label' => Mage::helper('adminhtml')->__('Simple')
25
+ ),
26
+ array(
27
+ 'value' => 'bundle',
28
+ 'label' => Mage::helper('adminhtml')->__('Bundle')
29
+ ),
30
+ array(
31
+ 'value' => 'grouped',
32
+ 'label' => Mage::helper('adminhtml')->__('Grouped')
33
+ ),
34
+ array(
35
+ 'value' => 'virtual',
36
+ 'label' => Mage::helper('adminhtml')->__('Virtual')
37
+ ),
38
  );
39
  }
40
 
41
+ public function toSelectArray()
42
+ {
43
  $select = array();
44
+ foreach ($this->toOptionArray() as $option) {
45
  $select[$option['value']] = $option['label'];
46
  }
47
  return $select;
48
  }
49
+ }
 
app/code/community/Lengow/Export/controllers/Adminhtml/Lengow/{ExportController.php → ProductController.php} RENAMED
@@ -1,16 +1,18 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml export controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_Adminhtml_Lengow_ExportController extends Mage_Adminhtml_Controller_Action {
 
12
 
13
- public function indexAction()
14
  {
15
  $this->loadLayout();
16
  $this->renderLayout();
@@ -28,29 +30,30 @@ class Lengow_Export_Adminhtml_Lengow_ExportController extends Mage_Adminhtml_Con
28
  );
29
  }
30
 
31
- public function massPublishAction()
32
  {
33
- $_product_ids = (array) $this->getRequest()->getParam('product');
34
- $_store_id = (integer) $this->getRequest()->getParam('store', Mage::app()->getStore()->getId());
35
- $_publish = (integer) $this->getRequest()->getParam('publish');
36
- $resource = Mage::getResourceModel('catalog/product');
37
- $_entity_type_id = $resource->getEntityType()->getId();
38
  try {
39
  //update all attribute in one query
40
  $product_action = Mage::getSingleton('catalog/product_action');
41
  if ($_store_id != 0) {
42
  $defaultStoreProductToUpdate = array();
43
  foreach ($_product_ids as $_product_id) {
44
- $lengow_product_value = Mage::getResourceModel('catalog/product')->getAttributeRawValue($_product_id, 'lengow_product', 0);
45
- if ($lengow_product_value === false){
 
46
  $defaultStoreProductToUpdate[] = $_product_id;
47
  }
48
  }
49
  //need to set default value if not set
50
- if (count($defaultStoreProductToUpdate)>0){
51
  $product_action->updateAttributes($defaultStoreProductToUpdate, array('lengow_product' => 0), 0);
52
  }
53
- if ($_store_id != 0){
54
  //set value for other store
55
  $product_action->updateAttributes($_product_ids, array('lengow_product' => $_publish), $_store_id);
56
  }
@@ -60,26 +63,23 @@ class Lengow_Export_Adminhtml_Lengow_ExportController extends Mage_Adminhtml_Con
60
  $this->_getSession()->addSuccess(
61
  Mage::helper('lenexport')->__('Total of %d record(s) were successfully updated', count($_product_ids))
62
  );
63
- }
64
- catch (Mage_Core_Model_Exception $e) {
65
  $this->_getSession()->addError($e->getMessage());
66
- }
67
- catch (Exception $e) {
68
- $this->_getSession()->addException($e, $e->getMessage() . Mage::helper('lenexport')->__('There was an error while updating product(s) publication'));
69
  }
70
 
71
- $this->_redirect('*/*/', array('store'=> $_store_id));
72
  }
73
 
74
-
75
- protected function _getSession()
76
  {
77
- return Mage::getSingleton('adminhtml/session');
78
- }
79
 
80
  protected function _isAllowed()
81
  {
82
  return Mage::getSingleton('admin/session')->isAllowed('lengow/export');
83
  }
84
-
85
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow export adminhtml lengow exportcontroller
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_Adminhtml_Lengow_ProductController extends Mage_Adminhtml_Controller_Action
13
+ {
14
 
15
+ public function indexAction()
16
  {
17
  $this->loadLayout();
18
  $this->renderLayout();
30
  );
31
  }
32
 
33
+ public function massPublishAction()
34
  {
35
+ $_product_ids = (array)$this->getRequest()->getParam('product');
36
+ $_store_id = (integer)$this->getRequest()->getParam('store', Mage::app()->getStore()->getId());
37
+ $_publish = (integer)$this->getRequest()->getParam('publish');
38
+ $resource = Mage::getResourceModel('catalog/product');
39
+ $_entity_type_id = $resource->getEntityType()->getId();
40
  try {
41
  //update all attribute in one query
42
  $product_action = Mage::getSingleton('catalog/product_action');
43
  if ($_store_id != 0) {
44
  $defaultStoreProductToUpdate = array();
45
  foreach ($_product_ids as $_product_id) {
46
+ $lengow_product_value = Mage::getResourceModel('catalog/product')->getAttributeRawValue($_product_id,
47
+ 'lengow_product', 0);
48
+ if ($lengow_product_value === false) {
49
  $defaultStoreProductToUpdate[] = $_product_id;
50
  }
51
  }
52
  //need to set default value if not set
53
+ if (count($defaultStoreProductToUpdate) > 0) {
54
  $product_action->updateAttributes($defaultStoreProductToUpdate, array('lengow_product' => 0), 0);
55
  }
56
+ if ($_store_id != 0) {
57
  //set value for other store
58
  $product_action->updateAttributes($_product_ids, array('lengow_product' => $_publish), $_store_id);
59
  }
63
  $this->_getSession()->addSuccess(
64
  Mage::helper('lenexport')->__('Total of %d record(s) were successfully updated', count($_product_ids))
65
  );
66
+ } catch (Mage_Core_Model_Exception $e) {
 
67
  $this->_getSession()->addError($e->getMessage());
68
+ } catch (Exception $e) {
69
+ $this->_getSession()->addException($e,
70
+ $e->getMessage() . Mage::helper('lenexport')->__('There was an error while updating product(s) publication'));
71
  }
72
 
73
+ $this->_redirect('*/*/', array('store' => $_store_id));
74
  }
75
 
76
+ protected function _getSession()
 
77
  {
78
+ return Mage::getSingleton('adminhtml/session');
79
+ }
80
 
81
  protected function _isAllowed()
82
  {
83
  return Mage::getSingleton('admin/session')->isAllowed('lengow/export');
84
  }
85
+ }
 
app/code/community/Lengow/Export/controllers/FeedController.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
  * Lengow export controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Export_FeedController extends Mage_Core_Controller_Front_Action {
 
12
 
13
  /**
14
  * Exports products for each store
@@ -21,7 +23,7 @@ class Lengow_Export_FeedController extends Mage_Core_Controller_Front_Action {
21
  ini_set('memory_limit', '1G');
22
  $mode = $this->getRequest()->getParam('mode');
23
  $helper = Mage::helper('lenexport/security');
24
- if($helper->checkIp()) {
25
  Mage::helper('lensync/data')->log('## Start manual export ##');
26
  $_configModel = Mage::getSingleton('lenexport/config');
27
  try {
@@ -34,18 +36,21 @@ class Lengow_Export_FeedController extends Mage_Core_Controller_Front_Action {
34
  // get store
35
  $storeCode = $this->getRequest()->getParam('code', null);
36
  if ($storeCode) //if store code is in URL
37
- $id_store = (int) Mage::getModel('core/store')->load($storeCode, 'code')->getId();
38
- else // if store id is in URL
39
- $id_store = (integer) $this->getRequest()->getParam('store', Mage::app()->getStore()->getId());
 
 
 
40
 
41
  // config store
42
  $_configModel->setStore($id_store);
43
  Mage::app()->getStore()->setCurrentStore($id_store);
44
 
45
  // check if store is enable for export
46
- if(Mage::getStoreConfig('lenexport/global/active_store', Mage::app()->getStore($id_store))) {
47
-
48
- if(Mage::getStoreConfig('lenexport/performances/optimizeexport')) {
49
  $generate = Mage::getSingleton('lenexport/generateoptimize');
50
  } else {
51
  $generate = Mage::getSingleton('lenexport/generate');
@@ -74,16 +79,16 @@ class Lengow_Export_FeedController extends Mage_Core_Controller_Front_Action {
74
  // translation now works
75
  Mage::app()->getTranslator()->init('frontend', true);
76
  }
77
- if($currency = $this->getRequest()->getParam('currency', null)) {
78
  $generate->setCurrentCurrencyCode($currency);
79
  }
80
  Mage::helper('lensync/data')->log('Start manual export in store ' . Mage::app()->getStore($id_store)->getName() . '(' . $id_store . ')');
81
 
82
  try {
83
- if(Mage::getStoreConfig('lenexport/performances/optimizeexport')) {
84
  $generate->exec(
85
  $id_store,
86
- $format,
87
  array(
88
  'mode' => $mode,
89
  'types' => $types,
@@ -99,11 +104,12 @@ class Lengow_Export_FeedController extends Mage_Core_Controller_Front_Action {
99
  )
100
  );
101
  } else {
102
- $generate->exec($id_store, $mode, $format, $types, $status, $export_child, $out_of_stock, $selected_products, $stream, $limit, $offset, $ids_product);
 
103
  }
104
  } catch (Exception $e) {
105
  Mage::helper('lensync/data')->log('Stop manual export - Store ' . Mage::app()->getStore($id_store)->getName() . '(' . $id_store . ') - Error: ' . $e->getMessage());
106
- echo 'Error: '.$e->getMessage();
107
  flush();
108
  }
109
  } else {
@@ -117,4 +123,4 @@ class Lengow_Export_FeedController extends Mage_Core_Controller_Front_Action {
117
  echo Mage::helper('lenexport')->__('Unauthorised IP : %s', $_SERVER['REMOTE_ADDR']);
118
  }
119
  }
120
- }
1
  <?php
2
+
3
  /**
4
  * Lengow export controller
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Export_FeedController extends Mage_Core_Controller_Front_Action
13
+ {
14
 
15
  /**
16
  * Exports products for each store
23
  ini_set('memory_limit', '1G');
24
  $mode = $this->getRequest()->getParam('mode');
25
  $helper = Mage::helper('lenexport/security');
26
+ if ($helper->checkIp()) {
27
  Mage::helper('lensync/data')->log('## Start manual export ##');
28
  $_configModel = Mage::getSingleton('lenexport/config');
29
  try {
36
  // get store
37
  $storeCode = $this->getRequest()->getParam('code', null);
38
  if ($storeCode) //if store code is in URL
39
+ {
40
+ $id_store = (int)Mage::getModel('core/store')->load($storeCode, 'code')->getId();
41
+ } else // if store id is in URL
42
+ {
43
+ $id_store = (integer)$this->getRequest()->getParam('store', Mage::app()->getStore()->getId());
44
+ }
45
 
46
  // config store
47
  $_configModel->setStore($id_store);
48
  Mage::app()->getStore()->setCurrentStore($id_store);
49
 
50
  // check if store is enable for export
51
+ if (Mage::getStoreConfig('lenexport/global/active_store', Mage::app()->getStore($id_store))) {
52
+
53
+ if (Mage::getStoreConfig('lenexport/performances/optimizeexport')) {
54
  $generate = Mage::getSingleton('lenexport/generateoptimize');
55
  } else {
56
  $generate = Mage::getSingleton('lenexport/generate');
79
  // translation now works
80
  Mage::app()->getTranslator()->init('frontend', true);
81
  }
82
+ if ($currency = $this->getRequest()->getParam('currency', null)) {
83
  $generate->setCurrentCurrencyCode($currency);
84
  }
85
  Mage::helper('lensync/data')->log('Start manual export in store ' . Mage::app()->getStore($id_store)->getName() . '(' . $id_store . ')');
86
 
87
  try {
88
+ if (Mage::getStoreConfig('lenexport/performances/optimizeexport')) {
89
  $generate->exec(
90
  $id_store,
91
+ $format,
92
  array(
93
  'mode' => $mode,
94
  'types' => $types,
104
  )
105
  );
106
  } else {
107
+ $generate->exec($id_store, $mode, $format, $types, $status, $export_child, $out_of_stock,
108
+ $selected_products, $stream, $limit, $offset, $ids_product);
109
  }
110
  } catch (Exception $e) {
111
  Mage::helper('lensync/data')->log('Stop manual export - Store ' . Mage::app()->getStore($id_store)->getName() . '(' . $id_store . ') - Error: ' . $e->getMessage());
112
+ echo 'Error: ' . $e->getMessage();
113
  flush();
114
  }
115
  } else {
123
  echo Mage::helper('lenexport')->__('Unauthorised IP : %s', $_SERVER['REMOTE_ADDR']);
124
  }
125
  }
126
+ }
app/code/community/Lengow/Export/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Lengow_Export>
5
- <version>2.1.2</version>
6
  </Lengow_Export>
7
  </modules>
8
  <admin>
@@ -117,7 +117,7 @@
117
  <children>
118
  <export translate="title" module="lenexport">
119
  <title>Manage Products Export</title>
120
- <action>adminhtml/lengow_export</action>
121
  <sort_order>200</sort_order>
122
  </export>
123
  </children>
2
  <config>
3
  <modules>
4
  <Lengow_Export>
5
+ <version>2.2.4</version>
6
  </Lengow_Export>
7
  </modules>
8
  <admin>
117
  <children>
118
  <export translate="title" module="lenexport">
119
  <title>Manage Products Export</title>
120
+ <action>adminhtml/lengow_product</action>
121
  <sort_order>200</sort_order>
122
  </export>
123
  </children>
app/code/community/Lengow/Export/etc/system.xml CHANGED
@@ -83,16 +83,6 @@
83
  <show_in_store>1</show_in_store>
84
  <source_model>lenexport/system_config_source_status</source_model>
85
  </productstatus>
86
- <!--<productchildren>
87
- <label>Export child product</label>
88
- <comment>Export child for configurable product</comment>
89
- <frontend_type>select</frontend_type>
90
- <sort_order>90</sort_order>
91
- <show_in_default>1</show_in_default>
92
- <show_in_website>1</show_in_website>
93
- <show_in_store>1</show_in_store>
94
- <source_model>adminhtml/system_config_source_yesno</source_model>
95
- </productchildren>-->
96
  </fields>
97
  </global>
98
  <data translate="label comment">
83
  <show_in_store>1</show_in_store>
84
  <source_model>lenexport/system_config_source_status</source_model>
85
  </productstatus>
 
 
 
 
 
 
 
 
 
 
86
  </fields>
87
  </global>
88
  <data translate="label comment">
app/code/community/Lengow/Feed/Block/Adminhtml/Feed.php DELETED
@@ -1,57 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow grid products block
5
- *
6
- * @category Lengow
7
- * @package Lengow_Feed
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Feed_Block_Adminhtml_Feed extends Mage_Adminhtml_Block_Widget_Container {
13
-
14
- /**
15
- * Set template
16
- */
17
- public function __construct() {
18
- parent::__construct();
19
- }
20
-
21
- /**
22
- * Prepare button and grid
23
- *
24
- * @return Mage_Adminhtml_Block_Catalog_Product
25
- */
26
- protected function _prepareLayout() {
27
- $this->_addButton('migrate', array(
28
- 'label' => Mage::helper('lenfeed')->__('Migrate all selected feeds'),
29
- 'onclick' => 'form_grid_feed.submit()',
30
- 'class' => 'save'
31
- ));
32
- $this->setChild('grid', $this->getLayout()->createBlock('lenfeed/adminhtml_feed_grid', 'feed.grid'));
33
- return parent::_prepareLayout();
34
- }
35
-
36
- /**
37
- * Render grid
38
- *
39
- * @return string
40
- */
41
- public function getGridHtml() {
42
- return $this->getChildHtml('grid');
43
- }
44
-
45
- /**
46
- * Check whether it is single store mode
47
- *
48
- * @return bool
49
- */
50
- public function isSingleStoreMode() {
51
- if (!Mage::app()->isSingleStoreMode()) {
52
- return false;
53
- }
54
- return true;
55
- }
56
-
57
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Grid.php DELETED
@@ -1,216 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow grid feed
5
- *
6
- * @category Lengow
7
- * @package Lengow_Feed
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Feed_Block_Adminhtml_Feed_Grid extends Mage_Adminhtml_Block_Widget_Grid {
13
-
14
- protected $_data = array();
15
- protected $_config_model;
16
-
17
- public function __construct() {
18
- parent::__construct();
19
- $this->setId('feed');
20
- $this->setDefaultSort('feed_id[]');
21
- $this->setDefaultDir('asc');
22
- $this->setSaveParametersInSession(true);
23
- $this->setUseAjax(true);
24
- $this->_filterVisibility = false;
25
- $this->_pagerVisibility = false;
26
- $this->_config_model = Mage::getSingleton('lenfeed/config');
27
-
28
- // Set datas
29
- $this->setData('id_client', $this->_config_model->get('lentracker/general/login'));
30
- $_lengow_ids_group = array();
31
- $_store_id = $this->getRequest()->getParam('store');
32
- $_group = Mage::getModel('lensync/config')->setStore($_store_id)->getConfig('lentracker/general/group');
33
- $this->setData('id_group', $_group);
34
- $this->setData('api_key', $this->_config_model->get('lentracker/general/api_key'));
35
- $args = array();
36
- if(!empty($_store_id))
37
- $args['store'] = $_store_id;
38
- $this->setData('form_url', $this->getUrl('*/*/migrate', $args));
39
- $this->setData('json_feed', $this->_config_model->get('lenfeed/general/json_feed'));
40
-
41
- }
42
-
43
- protected function _getStore() {
44
- $storeId = (int) $this->getRequest()->getParam('store', 0);
45
- return Mage::app()->getStore($storeId);
46
- }
47
-
48
-
49
- protected function _prepareCollection() {
50
- $connector = Mage::helper('lenfeed/data')->getConnector($this->getData('id_client'), $this->getData('api_key'));
51
-
52
- $args = array(
53
- 'idClient' => (integer) $this->getData('id_client'),
54
- 'idGroup' => (integer) $this->getData('id_group')
55
- );
56
- $feeds = $connector->api('getRootFeed', $args);
57
- $collection = new Varien_Data_Collection();
58
- $data_feeds = json_decode($this->getData('json_feed'));
59
-
60
- if(!empty($feeds['feeds'])) {
61
- foreach ($feeds['feeds'] as $key => $feed) {
62
-
63
- $obj_feed = new Varien_Object();
64
-
65
- $obj_feed->setData('id', $key);
66
- $obj_feed->setData('name', $feed['name']);
67
- $obj_feed->setData('url', $feed['url']);
68
-
69
- if(isset($data_feeds->{$key})) {
70
- $obj_feed->setData('selected_products', $data_feeds->{$key}->selected_products);
71
- $obj_feed->setData('product_out_stock', $data_feeds->{$key}->product_out_stock);
72
- $obj_feed->setData('product_type', $data_feeds->{$key}->product_type);
73
- $obj_feed->setData('product_status', $data_feeds->{$key}->product_status);
74
- $obj_feed->setData('product_child', (!empty($data_feeds->{$key}->product_child) ? $data_feeds->{$key}->product_child : ''));
75
- $obj_feed->setData('format', $data_feeds->{$key}->format);
76
- } else {
77
- // Apply default parameters
78
- $obj_feed->setData('selected_products', $this->_config_model->get('lenexport/global/export_only_selected'));
79
- $obj_feed->setData('product_out_stock', $this->_config_model->get('lenexport/global/export_soldout'));
80
- $obj_feed->setData('product_type', explode(',', $this->_config_model->get('lenexport/global/producttype')));
81
- $obj_feed->setData('product_status', $this->_config_model->get('lenexport/global/productstatus'));
82
- $obj_feed->setData('product_child', $this->_config_model->get('lenexport/global/productchildren'));
83
- $obj_feed->setData('format', $this->_config_model->get('lenexport/data/format'));
84
- }
85
- $collection->addItem($obj_feed);
86
- }
87
- } else {
88
- Mage::getSingleton('core/session')->addError(Mage::helper('lenfeed')->__('Error API, please try to refresh the page.'));
89
- }
90
- $this->setCollection($collection);
91
- parent::_prepareCollection();
92
- }
93
-
94
- protected function _prepareColumns() {
95
- $this->addColumn('', array(
96
- 'width' => '20px',
97
- 'type' => 'checkbox',
98
- 'index' => 'id',
99
- 'filter' => false,
100
- 'sortable' => false,
101
- 'field_name' => 'feed_id[]',
102
- ));
103
- $this->addColumn('id', array(
104
- 'header' => Mage::helper('lenfeed')->__('Feed ID'),
105
- 'width' => '50px',
106
- 'index' => 'id',
107
- 'filter' => false,
108
- 'sortable' => false
109
- ));
110
- $this->addColumn('name', array(
111
- 'header' => Mage::helper('lenfeed')->__('Feed Name'),
112
- 'index' => 'name',
113
- 'filter' => false,
114
- 'sortable' => false,
115
- ));
116
- $this->addColumn('url', array(
117
- 'header' => Mage::helper('lenfeed')->__('Current Feed'),
118
- 'index' => 'url',
119
- 'width' => '100px',
120
- 'filter' => false,
121
- 'sortable' => false,
122
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_url',
123
- ));
124
- $this->addColumn('selected_products', array(
125
- 'header' => Mage::helper('lenfeed')->__('Export only selected product'),
126
- 'index' => 'selected_products',
127
- 'type' => 'select',
128
- 'width' => '50px',
129
- 'options' => array(
130
- 1 => __('Yes'),
131
- 0 => __('No'),
132
- ),
133
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_select',
134
- 'filter' => false,
135
- 'sortable' => false,
136
- ));
137
- $this->addColumn('product_out_stock', array(
138
- 'header' => Mage::helper('lenfeed')->__('Export product out of stock'),
139
- 'index' => 'product_out_stock',
140
- 'options' => array(
141
- 1 => __('Yes'),
142
- 0 => __('No'),
143
- ),
144
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_select',
145
- 'filter' => false,
146
- 'sortable' => false,
147
- ));
148
- $this->addColumn('product_type', array(
149
- 'header' => Mage::helper('lenfeed')->__('Product type to export'),
150
- 'index' => 'product_type',
151
- 'options' => Mage::getModel('lenexport/system_config_source_types')->toSelectArray(),
152
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_select',
153
- 'filter' => false,
154
- 'sortable' => false,
155
- 'multiple' => true,
156
- ));
157
- $this->addColumn('product_status', array(
158
- 'header' => Mage::helper('lenfeed')->__('Status of product to export'),
159
- 'index' => 'product_status',
160
- 'width' => '50px',
161
- 'options' => Mage::getModel('lenexport/system_config_source_status')->toSelectArray(),
162
- 'filter' => false,
163
- 'sortable' => false,
164
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_select',
165
- ));
166
- /*
167
- $this->addColumn('product_child', array(
168
- 'header' => Mage::helper('lenfeed')->__('Export child product'),
169
- 'index' => 'product_child',
170
- 'width' => '50px',
171
- 'options' => array(
172
- 1 => __('Yes'),
173
- 0 => __('No'),
174
- ),
175
- 'filter' => false,
176
- 'sortable' => false,
177
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_select',
178
- ));*/
179
- $this->addColumn('format', array(
180
- 'header' => Mage::helper('lenfeed')->__('Format export'),
181
- 'index' => 'format',
182
- 'width' => '50px',
183
- 'options' => Mage::getModel('lenexport/system_config_source_format')->toSelectArray(),
184
- 'filter' => false,
185
- 'sortable' => false,
186
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_select',
187
- ));
188
- $this->addColumn('action', array(
189
- 'header' => Mage::helper('lenfeed')->__('Action'),
190
- 'width' => '120',
191
- 'align' => 'left',
192
- 'filter' => false,
193
- 'sortable' => false,
194
- 'renderer' => 'lenfeed/adminhtml_feed_renderer_migrate',
195
- ));
196
- return parent::_prepareColumns();
197
- }
198
-
199
- protected function _prepareMassaction() {
200
-
201
- return $this;
202
- }
203
-
204
- public function getGridUrl() {
205
- return $this->getUrl('*/*/grid', array('_current' => true));
206
- }
207
-
208
- public function getRowUrl($row) {
209
- return '';
210
- }
211
-
212
- private function _getGroups($data) {
213
- $_groups = trim(str_replace(array("\r\n", ';', '-', '|', ' '), ';', $data), ',');
214
- return explode(',', $_groups);
215
- }
216
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Renderer/Migrate.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow Feed Action Renderer
5
- *
6
- * @category Lengow
7
- * @package Lengow_Feed
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Feed_Block_Adminhtml_Feed_Renderer_Migrate extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
13
-
14
- /**
15
- * Renders grid column
16
- *
17
- * @param Varien_Object $row
18
- * @return string
19
- */
20
- public function render(Varien_Object $row) {
21
- return sprintf('<button type="submit" class="scalable save" name="submit" value="%s">%s</button>',
22
- $row->getData('id'),
23
- Mage::helper('lenfeed')->__('Migrate Feed'));
24
- }
25
-
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Renderer/Select.php DELETED
@@ -1,54 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow Feed Action Renderer
5
- *
6
- * @category Lengow
7
- * @package Lengow_Feed
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Feed_Block_Adminhtml_Feed_Renderer_Select
13
- extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
14
- {
15
- /**
16
- * Renders grid column
17
- *
18
- * @param Varien_Object $row
19
- * @return string
20
- */
21
- public function render(Varien_Object $row)
22
- {
23
- $column = $this->getColumn();
24
- $index = $column->getIndex();
25
- $options = '';
26
-
27
- $multiple = '';
28
- $additional_name = '';
29
-
30
- if($column->getMultiple() == true) {
31
- $multiple = 'multiple';
32
- $additional_name = '[]';
33
- }
34
-
35
- foreach($column->getOptions() as $key => $value) {
36
- $selected = '';
37
-
38
- if((string)$key === $row->getData($index))
39
- $selected = 'selected="selected"';
40
- elseif(is_array($row->getData($index)) && in_array($key, $row->getData($index)))
41
- $selected = 'selected="selected"';
42
-
43
- $options .= '<option value="' . $key . '" ' . $selected . ' >' . $value . '</option>';
44
- }
45
-
46
- return sprintf('<select name="%s[%s]%s" %s width="%s">%s</select>',
47
- $column->getIndex(),
48
- $row->getData('id'),
49
- $additional_name,
50
- $multiple,
51
- $column->getWidth(),
52
- $options);
53
- }
54
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/Block/Adminhtml/Feed/Renderer/Url.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow Feed Action Renderer
5
- *
6
- * @category Lengow
7
- * @package Lengow_Feed
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Feed_Block_Adminhtml_Feed_Renderer_Url extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
13
-
14
- /**
15
- * Renders grid column
16
- *
17
- * @param Varien_Object $row
18
- * @return string
19
- */
20
- public function render(Varien_Object $row) {
21
- $url = $row->getData('url');
22
- echo '<a class="popup-link" target="_blank" data-link="' . $url . '" href="' . $url . '">' . Mage::helper('lenfeed')->__('View feed') . '</a>';
23
- }
24
-
25
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/Helper/Data.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- /**
3
- * Lengow Feed Helper
4
- *
5
- * @category Lengow
6
- * @package Lengow_Feed
7
- * @author Romain Le Polh <romain@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
- */
11
- class Lengow_Feed_Helper_Data extends Mage_Core_Helper_Abstract {
12
-
13
- /**
14
- * Get list of available export format
15
- *
16
- * @return array File format
17
- */
18
- public function getArrayFormat() {
19
- $format_array = Mage::getModel('lenexport/system_config_source_format')->toOptionArray();
20
- $formats = array();
21
- foreach($format_array as $format) {
22
- $formats[] = $format['value'];
23
- }
24
- return $formats;
25
- }
26
-
27
- /**
28
- * Get list of product type export
29
- *
30
- * @return array Product type
31
- */
32
- public function getProductTypeFormat() {
33
- $product_type_array = Mage::getModel('lenexport/system_config_source_types')->toOptionArray();
34
- $types = array();
35
- foreach($product_type_array as $type) {
36
- $types[] = $type['value'];
37
- }
38
- }
39
-
40
- /**
41
- * Get Sync connector
42
- *
43
- * @return mixed Lengow connector object
44
- */
45
- public function getConnector($id_client, $api_key) {
46
- $connector = Mage::getSingleton('lensync/connector');
47
- $connector->init((integer) $id_client, $api_key);
48
- return $connector;
49
- }
50
-
51
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/Model/Config.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow dashboard model config
5
- *
6
- * @category Lengow
7
- * @package Lengow_Feed
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Feed_Model_Config extends Varien_Object {
13
-
14
- public function setStore($id_store) {
15
- $this->_id_store = $id_store;
16
- }
17
-
18
- public function get($key) {
19
- return Mage::getStoreConfig($key, $this->_id_store);
20
- }
21
-
22
- public function set($key, $value) {
23
- return 1;
24
- }
25
-
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/Model/Feed.php DELETED
@@ -1,136 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Lengow Feed model
5
- *
6
- * @category Lengow
7
- * @package Lengow_Feed
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
- */
12
- class Lengow_Feed_Model_Feed extends Varien_Object {
13
-
14
- protected $_id;
15
-
16
- /**
17
- *
18
- * @var boolean Export only selected product
19
- */
20
- protected $_selected_products;
21
-
22
- /**
23
- *
24
- * @var boolean Export product out of stock
25
- */
26
- protected $_product_out_stock;
27
-
28
- /**
29
- *
30
- * @var string Product type to export
31
- */
32
- protected $_product_type;
33
-
34
- /**
35
- *
36
- * @var string Status of product to export
37
- */
38
- protected $_product_status;
39
-
40
- /**
41
- *
42
- * @var boolean Export product child
43
- */
44
- protected $_product_child;
45
-
46
- /**
47
- *
48
- * @var string Export Format
49
- */
50
- protected $_format;
51
-
52
- /**
53
- *
54
- * @var string Url feed
55
- */
56
- protected $_url;
57
-
58
- /**
59
- *
60
- * @var integer ID store
61
- */
62
- protected $_id_store;
63
-
64
- protected $_idClient;
65
- protected $_idGroup;
66
- protected $_api_key;
67
-
68
- /**
69
- * Buid feed object
70
- *
71
- * @param integer $id
72
- * @param boolean $selected_products
73
- * @param boolean $product_out_stock
74
- * @param string $product_type
75
- * @param string $product_status
76
- * @param boolean $product_child
77
- * @param string $format
78
- */
79
- public function __construct($args) {
80
- $this->_id = $args['feed_id'];
81
- $this->_selected_products = $args['selected_products'];
82
- $this->_product_out_stock = $args['product_out_stock'];
83
- $this->_product_type = Mage::helper('core')->jsonEncode($args['product_type']);
84
- $this->_product_status = $args['product_status'];
85
- //$this->_product_child = $args['product_child'];
86
- $this->_format = $args['format'];
87
-
88
- $this->_config_model = Mage::getSingleton('lenfeed/config');
89
-
90
- $this->_idClient = $this->_config_model->get('lentracker/general/login');
91
- $this->_idGroup = $args['group_id'];
92
- $this->_id_store = $args['store_id'];
93
- //$this->_config_model->get('tracker/general/group');
94
- $this->_api_key = $this->_config_model->get('lentracker/general/api_key');
95
- parent::__construct();
96
- }
97
-
98
- /**
99
- * Build url before update
100
- */
101
- private function _buildUrl() {
102
- $params = 'selected_products/' . $this->_selected_products;
103
- $params .= '/product_out_stock/' . $this->_product_out_stock;
104
- $params .= '/product_type/' . join(',', Mage::helper('core')->jsonDecode($this->_product_type));
105
- $params .= '/product_status/' . $this->_product_status;
106
- //$params .= '/product_child/' . $this->_product_child;
107
- $params .= '/format/' . $this->_format;
108
- if($this->_id_store != 0)
109
- $params .= '/store/' . $this->_id_store;
110
-
111
- $new_flow = Mage::getUrl('lengow/feed/index') . $params;
112
- $this->_url = $new_flow;
113
- }
114
-
115
- /**
116
- * Update feed on Lengow
117
- */
118
- public function update() {
119
- $this->_buildUrl();
120
- $connector = Mage::helper('lenfeed/data')->getConnector($this->_idClient, $this->_api_key);
121
- $args = array(
122
- 'idClient' => $this->_idClient,
123
- 'idGroup' => $this->_idGroup,
124
- 'urlFlux' => $this->_url,
125
- 'idFlux' => $this->_id
126
- );
127
- Mage::helper('lensync/data')->log('Test udate group ' . $this->_idGroup . ' : ' . $this->_url);
128
- return true;
129
- return $connector->api('updateRootFeed', $args);
130
- }
131
-
132
- private function _cleanGroup($data) {
133
- return trim(str_replace(array("\r\n", ';', '-', '|', ' '), ';', $data), ',');
134
- }
135
-
136
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/controllers/Adminhtml/Lengow/FeedController.php DELETED
@@ -1,105 +0,0 @@
1
- <?php
2
- /**
3
- * Lengow adminhtml export controller
4
- *
5
- * @category Lengow
6
- * @package Lengow_Feed
7
- * @author Romain Le Polh <romain@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
- */
11
- class Lengow_Feed_Adminhtml_Lengow_FeedController extends Mage_Adminhtml_Controller_Action {
12
-
13
- public function indexAction()
14
- {
15
- $this->loadLayout();
16
- $this->renderLayout();
17
- return $this;
18
- }
19
-
20
- /**
21
- * Product grid for AJAX request
22
- */
23
- public function gridAction()
24
- {
25
- $this->loadLayout();
26
- $this->getResponse()->setBody(
27
- $this->getLayout()->createBlock('lenfeed/adminhtml_feed')->toHtml()
28
- );
29
- }
30
-
31
- protected function _getSession()
32
- {
33
- return Mage::getSingleton('adminhtml/session');
34
- }
35
-
36
- /**
37
- * Migrate feed
38
- */
39
- public function migrateAction()
40
- {
41
- $feed_ids = $this->getRequest()->getParam('feed_id');
42
- $selected_products = $this->getRequest()->getParam('selected_products');
43
- $product_out_stock = $this->getRequest()->getParam('product_out_stock');
44
- $product_type = $this->getRequest()->getParam('product_type');
45
- $product_status = $this->getRequest()->getParam('product_status');
46
- //$product_child = $this->getRequest()->getParam('product_child');
47
- $format = $this->getRequest()->getParam('format');
48
- $_lengow_ids_group = array();
49
- $_store_id = $this->getRequest()->getParam('store');
50
- Mage::helper('lensync/data')->log('Test store : ' . $_store_id);
51
- $_group = Mage::getModel('lensync/config')->setStore($_store_id)->getConfig('lentracker/general/group');
52
-
53
- if($this->getRequest()->getParam('submit')) {
54
- $feed_ids = array($this->getRequest()->getParam('submit'));
55
- }
56
-
57
- $error = false;
58
- $message = '';
59
- $data_feeds = json_decode(Mage::getSingleton('lenfeed/config')->get('lenfeed/general/json_feed'));
60
- if(empty($data_feeds))
61
- $data_feeds = new stdClass;
62
- if(!empty($feed_ids)) {
63
- foreach($feed_ids as $feed_id) {
64
-
65
- $args = array(
66
- 'feed_id' => $feed_id,
67
- 'group_id' => $_group,
68
- 'store_id' => $_store_id,
69
- 'selected_products' => $selected_products[$feed_id],
70
- 'product_out_stock' => $product_out_stock[$feed_id],
71
- 'product_type' => $product_type[$feed_id],
72
- 'product_status' => $product_status[$feed_id],
73
- //'product_child' => $product_child[$feed_id],
74
- 'format' => $format[$feed_id]);
75
-
76
- $feed = Mage::getModel('lenfeed/feed', $args);
77
- if(!$feed->update()) {
78
- $error = true;
79
- $message .= Mage::helper('lenfeed')->__('Error update feed %s', '#' . $feed_id . '<br />');
80
- } else {
81
- $data_feeds->{$feed_id} = $args;
82
- }
83
- }
84
- Mage::getConfig()->saveConfig('lenfeed/general/json_feed', json_encode($data_feeds));
85
- } else {
86
- $error = 'true';
87
- $message = Mage::helper('lenfeed')->__('');
88
- }
89
-
90
- if($error)
91
- Mage::getSingleton('core/session')->addError($message);
92
- else
93
- Mage::getSingleton('core/session')->addSuccess(Mage::helper('lenfeed')->__('Update success'));
94
- if(!empty($_store_id))
95
- $this->_redirect('*/*/index/', array('store' => $_store_id));
96
- else
97
- $this->_redirect('*/*/index');
98
- }
99
-
100
- protected function _isAllowed()
101
- {
102
- return Mage::getSingleton('admin/session')->isAllowed('lengow/feed');
103
- }
104
-
105
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/etc/config.xml DELETED
@@ -1,112 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Lengow_Feed>
5
- <version>2.1.2</version>
6
- </Lengow_Feed>
7
- </modules>
8
- <admin>
9
- <routers>
10
- <adminhtml>
11
- <args>
12
- <modules>
13
- <lenfeed before="Mage_Adminhtml">Lengow_Feed_Adminhtml</lenfeed>
14
- </modules>
15
- </args>
16
- </adminhtml>
17
- </routers>
18
- </admin>
19
- <global>
20
- <models>
21
- <lenfeed>
22
- <class>Lengow_Feed_Model</class>
23
- <resourceModel>feed_mysql4</resourceModel>
24
- </lenfeed>
25
- <feed_mysql4>
26
- <class>Lengow_Feed_Model_Mysql4</class>
27
- <entities>
28
- <manageorders_log>
29
- <table>lengow_log</table>
30
- </manageorders_log>
31
- </entities>
32
- </feed_mysql4>
33
- </models>
34
- <resources>
35
- <lenfeed_setup>
36
- <connection>
37
- <use>core_setup</use>
38
- </connection>
39
- </lenfeed_setup>
40
- <lenfeed_write>
41
- <connection>
42
- <use>core_write</use>
43
- </connection>
44
- </lenfeed_write>
45
- <lenfeed_read>
46
- <connection>
47
- <use>core_read</use>
48
- </connection>
49
- </lenfeed_read>
50
- </resources>
51
- <blocks>
52
- <lenfeed>
53
- <class>Lengow_Feed_Block</class>
54
- </lenfeed>
55
- </blocks>
56
- <helpers>
57
- <lenfeed>
58
- <class>Lengow_Feed_Helper</class>
59
- </lenfeed>
60
- </helpers>
61
- </global>
62
- <adminhtml>
63
- <translate>
64
- <modules>
65
- <Lengow_Feed>
66
- <files>
67
- <default>Lengow_Connector.csv</default>
68
- </files>
69
- </Lengow_Feed>
70
- </modules>
71
- </translate>
72
- <menu>
73
- <lengow>
74
- <title>Lengow</title>
75
- <sort_order>20</sort_order>
76
- <children>
77
- <feed translate="title" module="lenfeed">
78
- <title>Manage Feeds</title>
79
- <action>adminhtml/lengow_feed</action>
80
- <sort_order>300</sort_order>
81
- </feed>
82
- </children>
83
- </lengow>
84
- </menu>
85
- <acl>
86
- <resources>
87
- <admin>
88
- <children>
89
- <system>
90
- <children>
91
- <config>
92
- <children>
93
- <lenfeed translate="title" module="lenfeed">
94
- <title>Products</title>
95
- </lenfeed>
96
- </children>
97
- </config>
98
- </children>
99
- </system>
100
- <lengow translate="title" module="lenfeed">
101
- <children>
102
- <feed translate="title" module="lenfeed">
103
- <title>Manage Feeds</title>
104
- </feed>
105
- </children>
106
- </lengow>
107
- </children>
108
- </admin>
109
- </resources>
110
- </acl>
111
- </adminhtml>
112
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Feed/etc/system.xml DELETED
@@ -1,40 +0,0 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <tabs>
4
- <lengow translate="label" module="lenfeed">
5
- <label>Lengow</label>
6
- <sort_order>210</sort_order>
7
- </lengow>
8
- </tabs>
9
- <sections>
10
- <lenfeed translate="label" module="lenfeed">
11
- <label>Feed configuration</label>
12
- <tab>lengow</tab>
13
- <frontend_type>text</frontend_type>
14
- <sort_order>90</sort_order>
15
- <show_in_default>1</show_in_default>
16
- <show_in_website>1</show_in_website>
17
- <show_in_store>1</show_in_store>
18
- <groups>
19
- <general translate="label comment">
20
- <label>Global</label>
21
- <show_in_default>0</show_in_default>
22
- <show_in_website>0</show_in_website>
23
- <show_in_store>0</show_in_store>
24
- <sort_order>1</sort_order>
25
- <fields>
26
- <json_feed>
27
- <label>JSON Feed backup</label>
28
- <comment><![CDATA[Backup of feed]]></comment>
29
- <frontend_type>text</frontend_type>
30
- <sort_order>6</sort_order>
31
- <show_in_default>0</show_in_default>
32
- <show_in_website>0</show_in_website>
33
- <show_in_store>0</show_in_store>
34
- </json_feed>
35
- </fields>
36
- </general>
37
- </groups>
38
- </lenfeed>
39
- </sections>
40
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Sync/Block/Adminhtml/Cron.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
- * Lengow grid products block
4
  *
5
  * @category Lengow
6
- * @package Lengow_Cron
7
- * @author Pierre Basile <pierre.basile@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Block_Adminhtml_Cron extends Mage_Adminhtml_Block_Widget_Grid_Container {
 
12
 
13
  public function __construct()
14
  {
1
  <?php
2
+
3
  /**
4
+ * Lengow sync block adminhtml cron
5
  *
6
  * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Block_Adminhtml_Cron extends Mage_Adminhtml_Block_Widget_Grid_Container
13
+ {
14
 
15
  public function __construct()
16
  {
app/code/community/Lengow/Sync/Block/Adminhtml/Cron/Grid.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml cron grid
4
  *
5
  * @category Lengow
6
- * @package Lengow_Cron
7
- * @author Pierre Basile <pierre.basile@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Block_Adminhtml_Cron_Grid extends Mage_Adminhtml_Block_Widget_Grid {
 
12
 
13
  public function __construct()
14
  {
@@ -36,15 +38,13 @@ class Lengow_Sync_Block_Adminhtml_Cron_Grid extends Mage_Adminhtml_Block_Widget_
36
 
37
  protected function _prepareColumns()
38
  {
39
-
40
-
41
- $viewHelper = $this->helper('lensync/cron');
42
 
43
  $this->addColumn('id', array(
44
- 'header'=> Mage::helper('lensync')->__('ID'),
45
  'index' => 'schedule_id',
46
  'width' => '80px',
47
- 'type' => 'text',
48
  ));
49
  $this->addColumn('job_code', array(
50
  'header' => Mage::helper('lensync')->__('Code'),
@@ -78,8 +78,8 @@ class Lengow_Sync_Block_Adminhtml_Cron_Grid extends Mage_Adminhtml_Block_Widget_
78
  $this->addColumn(
79
  'status',
80
  array(
81
- 'header' => Mage::helper('lensync')->__('Status'),
82
- 'index' => 'status',
83
  'frame_callback' => array($viewHelper, 'decorateStatus'),
84
  )
85
  );
@@ -88,7 +88,6 @@ class Lengow_Sync_Block_Adminhtml_Cron_Grid extends Mage_Adminhtml_Block_Widget_
88
 
89
  public function getGridUrl()
90
  {
91
- return $this->getUrl('*/*/grid', array('_current'=>true));
92
  }
93
-
94
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync block adminhtml cron grid
5
  *
6
  * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Block_Adminhtml_Cron_Grid extends Mage_Adminhtml_Block_Widget_Grid
13
+ {
14
 
15
  public function __construct()
16
  {
38
 
39
  protected function _prepareColumns()
40
  {
41
+ $viewHelper = $this->helper('lensync/cron');
 
 
42
 
43
  $this->addColumn('id', array(
44
+ 'header' => Mage::helper('lensync')->__('ID'),
45
  'index' => 'schedule_id',
46
  'width' => '80px',
47
+ 'type' => 'text',
48
  ));
49
  $this->addColumn('job_code', array(
50
  'header' => Mage::helper('lensync')->__('Code'),
78
  $this->addColumn(
79
  'status',
80
  array(
81
+ 'header' => Mage::helper('lensync')->__('Status'),
82
+ 'index' => 'status',
83
  'frame_callback' => array($viewHelper, 'decorateStatus'),
84
  )
85
  );
88
 
89
  public function getGridUrl()
90
  {
91
+ return $this->getUrl('*/*/grid', array('_current' => true));
92
  }
93
+ }
 
app/code/community/Lengow/Sync/Block/Adminhtml/Import.php CHANGED
@@ -1,8 +1,19 @@
1
  <?php
2
- class Lengow_Order_Block_Manageorders_Adminhtml_Sync extends Mage_Adminhtml_Block_Template {
3
-
4
- public function getSyncOrdersUrl() {
5
- return $this->getUrl('*/*/SyncOrders');
 
 
 
 
 
 
 
 
 
 
 
 
6
  }
7
-
8
  }
1
  <?php
2
+
3
+ /**
4
+ * Lengow order block manageorders adminhtml sync
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Order_Block_Manageorders_Adminhtml_Sync extends Mage_Adminhtml_Block_Template
13
+ {
14
+
15
+ public function getSyncOrdersUrl()
16
+ {
17
+ return $this->getUrl('*/*/SyncOrders');
18
  }
 
19
  }
app/code/community/Lengow/Sync/Block/Adminhtml/Log.php CHANGED
@@ -1,25 +1,28 @@
1
  <?php
 
2
  /**
3
- * Lengow logs
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Block_Adminhtml_Log extends Mage_Adminhtml_Block_Widget_Grid_Container {
 
12
 
13
- public function __construct() {
14
- parent::__construct();
15
- $this->_controller = 'adminhtml_log';
16
- $this->_blockGroup = 'lensync';
17
- $this->_headerText = $this->__('Lengow logs');
18
- $this->_removeButton('add');
19
- $this->_addButton('deleteAll', array(
20
- 'label' => Mage::helper('lensync')->__('Flush logs'),
21
- 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/delete') . '\')',
22
- 'class' => 'delete'
23
- ));
24
- }
25
- }
 
1
  <?php
2
+
3
  /**
4
+ * Lengow sync block adminhtml logs
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Block_Adminhtml_Log extends Mage_Adminhtml_Block_Widget_Grid_Container
13
+ {
14
 
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ $this->_controller = 'adminhtml_log';
19
+ $this->_blockGroup = 'lensync';
20
+ $this->_headerText = $this->__('Lengow logs');
21
+ $this->_removeButton('add');
22
+ $this->_addButton('deleteAll', array(
23
+ 'label' => Mage::helper('lensync')->__('Flush logs'),
24
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/delete') . '\')',
25
+ 'class' => 'delete'
26
+ ));
27
+ }
28
+ }
app/code/community/Lengow/Sync/Block/Adminhtml/Log/Grid.php CHANGED
@@ -1,16 +1,19 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml log grid
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Block_Adminhtml_Log_Grid extends Mage_Adminhtml_Block_Widget_Grid {
 
12
 
13
- public function __construct() {
 
14
  parent::__construct();
15
  $this->setId('sales_sync_log_grid');
16
  $this->setUseAjax(true);
@@ -19,17 +22,19 @@ class Lengow_Sync_Block_Adminhtml_Log_Grid extends Mage_Adminhtml_Block_Widget_G
19
  $this->setSaveParametersInSession(true);
20
  }
21
 
22
- protected function _prepareCollection() {
23
- $collection = Mage::getModel('lensync/log')->getCollection();
 
24
  $this->setCollection($collection);
25
  return parent::_prepareCollection();
26
  }
27
 
28
- protected function _prepareColumns() {
 
29
  $this->addColumn('id', array(
30
- 'header'=> Mage::helper('lensync')->__('ID'),
31
  'width' => '80px',
32
- 'type' => 'text',
33
  'index' => 'id',
34
  ));
35
  $this->addColumn('date', array(
@@ -45,8 +50,8 @@ class Lengow_Sync_Block_Adminhtml_Log_Grid extends Mage_Adminhtml_Block_Widget_G
45
  return parent::_prepareColumns();
46
  }
47
 
48
- public function getGridUrl() {
49
- return $this->getUrl('*/*/grid', array('_current'=>true));
 
50
  }
51
-
52
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync block adminhtml log grid
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Block_Adminhtml_Log_Grid extends Mage_Adminhtml_Block_Widget_Grid
13
+ {
14
 
15
+ public function __construct()
16
+ {
17
  parent::__construct();
18
  $this->setId('sales_sync_log_grid');
19
  $this->setUseAjax(true);
22
  $this->setSaveParametersInSession(true);
23
  }
24
 
25
+ protected function _prepareCollection()
26
+ {
27
+ $collection = Mage::getModel('lensync/log')->getCollection();
28
  $this->setCollection($collection);
29
  return parent::_prepareCollection();
30
  }
31
 
32
+ protected function _prepareColumns()
33
+ {
34
  $this->addColumn('id', array(
35
+ 'header' => Mage::helper('lensync')->__('ID'),
36
  'width' => '80px',
37
+ 'type' => 'text',
38
  'index' => 'id',
39
  ));
40
  $this->addColumn('date', array(
50
  return parent::_prepareColumns();
51
  }
52
 
53
+ public function getGridUrl()
54
+ {
55
+ return $this->getUrl('*/*/grid', array('_current' => true));
56
  }
 
57
  }
app/code/community/Lengow/Sync/Block/Adminhtml/Order.php CHANGED
@@ -1,34 +1,38 @@
1
  <?php
 
2
  /**
3
- * Lengow grid products block
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Block_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container {
 
12
 
13
- public function __construct() {
14
- parent::__construct();
15
- $this->_controller = 'adminhtml_order';
16
- $this->_blockGroup = 'lensync';
17
- $this->_headerText = $this->__('Lengow orders');
18
- }
 
19
 
20
  /**
21
  * Prepare button and grid
22
  *
23
  * @return Mage_Adminhtml_Block_Catalog_Product
24
  */
25
- protected function _prepareLayout() {
26
- $this->_removeButton('add');
 
27
  $this->_addButton('import', array(
28
- 'label' => Mage::helper('catalog')->__('Manuel import'),
29
  'onclick' => 'setLocation(\'' . $this->getUrl('*/*/import') . '\')',
30
- 'class' => 'add'
31
  ));
32
  return parent::_prepareLayout();
33
  }
34
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync block adminhtml order
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Block_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
13
+ {
14
 
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ $this->_controller = 'adminhtml_order';
19
+ $this->_blockGroup = 'lensync';
20
+ $this->_headerText = $this->__('Lengow orders');
21
+ }
22
 
23
  /**
24
  * Prepare button and grid
25
  *
26
  * @return Mage_Adminhtml_Block_Catalog_Product
27
  */
28
+ protected function _prepareLayout()
29
+ {
30
+ $this->_removeButton('add');
31
  $this->_addButton('import', array(
32
+ 'label' => Mage::helper('catalog')->__('Manuel import'),
33
  'onclick' => 'setLocation(\'' . $this->getUrl('*/*/import') . '\')',
34
+ 'class' => 'add'
35
  ));
36
  return parent::_prepareLayout();
37
  }
38
+ }
app/code/community/Lengow/Sync/Block/Adminhtml/Order/Grid.php CHANGED
@@ -1,18 +1,21 @@
1
  <?php
 
2
  /**
3
- * Lengow grid orders block grid
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid {
12
-
13
- protected $_withGrid = true;
 
14
 
15
- public function __construct() {
 
16
  parent::__construct();
17
  $this->setId('sales_sync_order_grid');
18
  $this->setUseAjax(true);
@@ -26,47 +29,51 @@ class Lengow_Sync_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget
26
  *
27
  * @return string
28
  */
29
- protected function _getCollectionClass() {
30
- $path = Mage::getBaseDir() .'/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php';
31
- if(file_exists($path))
32
- return 'sales/order_grid_collection';
33
- $this->_withGrid = false;
 
 
34
  return 'sales/order_collection';
35
  }
36
 
37
- protected function _prepareCollection() {
 
38
  $collection = Mage::getResourceModel($this->_getCollectionClass());
39
- $collection->addAttributeToFilter('from_lengow', array('gt' => 0));
40
- if(!$this->_withGrid) {
41
- $collection->addAttributeToSelect('*')
42
- ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
43
- ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
44
- ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
45
- ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
46
- ->addExpressionAttributeToSelect('billing_name',
47
- 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
48
- array('billing_firstname', 'billing_lastname'))
49
- ->addExpressionAttributeToSelect('shipping_name',
50
- 'CONCAT({{shipping_firstname}}, IFNULL(CONCAT(\' \', {{shipping_lastname}}), \'\'))',
51
- array('shipping_firstname', 'shipping_lastname'));
52
- }
53
  $this->setCollection($collection);
54
  return parent::_prepareCollection();
55
  }
56
 
57
- protected function _prepareColumns() {
 
58
  $this->addColumn('real_Sync_id', array(
59
- 'header'=> Mage::helper('sales')->__('Order #'),
60
  'width' => '80px',
61
- 'type' => 'text',
62
  'index' => 'increment_id',
63
  ));
64
  if (!Mage::app()->isSingleStoreMode()) {
65
  $this->addColumn('store_id', array(
66
- 'header' => Mage::helper('sales')->__('Purchased From (Store)'),
67
- 'index' => 'store_id',
68
- 'type' => 'store',
69
- 'store_view'=> true,
70
  'display_deleted' => true,
71
  ));
72
  }
@@ -87,115 +94,115 @@ class Lengow_Sync_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget
87
  $this->addColumn('base_grand_total', array(
88
  'header' => Mage::helper('sales')->__('G.T. (Base)'),
89
  'index' => 'base_grand_total',
90
- 'type' => 'currency',
91
  'currency' => 'base_currency_code',
92
  ));
93
  $this->addColumn('grand_total', array(
94
  'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
95
  'index' => 'grand_total',
96
- 'type' => 'currency',
97
  'currency' => 'order_currency_code',
98
- ));
99
  // Add datas from Lengow
100
  $this->addColumn('order_id_lengow', array(
101
  'header' => Mage::helper('lensync')->__('Id lengow'),
102
  'index' => 'order_id_lengow',
103
  ));
104
-
105
  $this->addColumn('marketplace_lengow', array(
106
  'header' => Mage::helper('lensync')->__('Marketplace'),
107
  'index' => 'marketplace_lengow',
108
  ));
109
-
110
  $this->addColumn('fees_lengow', array(
111
- 'header'=> Mage::helper('lensync')->__('Fees'),
112
- 'type' => 'currency',
113
  'index' => 'fees_lengow',
114
- 'currency' => 'base_currency_code',
115
  ));
116
  // End datas from Lengow
117
  $this->addColumn('status', array(
118
  'header' => Mage::helper('sales')->__('Status'),
119
  'index' => 'status',
120
- 'type' => 'options',
121
  'width' => '70px',
122
  'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
123
  ));
124
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
125
  $this->addColumn('action',
126
  array(
127
- 'header' => Mage::helper('sales')->__('Action'),
128
- 'width' => '50px',
129
- 'type' => 'action',
130
- 'getter' => 'getId',
131
- 'actions' => array(
132
  array(
133
  'caption' => Mage::helper('sales')->__('View'),
134
- 'url' => array('base'=>'adminhtml/sales_order/view'),
135
- 'field' => 'order_id'
136
  )
137
  ),
138
- 'filter' => false,
139
- 'sortable' => false,
140
- 'index' => 'stores',
141
  'is_system' => true,
142
- ));
143
  }
144
  $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
145
  $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
146
  return parent::_prepareColumns();
147
  }
148
 
149
- protected function _prepareMassaction() {
 
150
  $this->setMassactionIdField('entity_id');
151
  $this->getMassactionBlock()->setFormFieldName('order_ids');
152
  $this->getMassactionBlock()->setUseSelectAll(false);
153
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
154
  $this->getMassactionBlock()->addItem('cancel_order', array(
155
- 'label'=> Mage::helper('sales')->__('Cancel'),
156
- 'url' => $this->getUrl('adminhtml/sales_order/massCancel'),
157
  ));
158
  }
159
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
160
  $this->getMassactionBlock()->addItem('hold_order', array(
161
- 'label'=> Mage::helper('sales')->__('Hold'),
162
- 'url' => $this->getUrl('adminhtml/sales_order/massHold'),
163
  ));
164
  }
165
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
166
  $this->getMassactionBlock()->addItem('unhold_order', array(
167
- 'label'=> Mage::helper('sales')->__('Unhold'),
168
- 'url' => $this->getUrl('adminhtml/sales_order/massUnhold'),
169
  ));
170
  }
171
  $this->getMassactionBlock()->addItem('pdfinvoices_order', array(
172
- 'label'=> Mage::helper('sales')->__('Print Invoices'),
173
- 'url' => $this->getUrl('adminhtml/sales_order/pdfinvoices'),
174
  ));
175
  $this->getMassactionBlock()->addItem('pdfshipments_order', array(
176
- 'label'=> Mage::helper('sales')->__('Print Packingslips'),
177
- 'url' => $this->getUrl('adminhtml/sales_order/pdfshipments'),
178
  ));
179
  $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
180
- 'label'=> Mage::helper('sales')->__('Print Credit Memos'),
181
- 'url' => $this->getUrl('adminhtml/sales_order/pdfcreditmemos'),
182
  ));
183
  $this->getMassactionBlock()->addItem('pdfdocs_order', array(
184
- 'label'=> Mage::helper('sales')->__('Print All'),
185
- 'url' => $this->getUrl('adminhtml/sales_order/pdfdocs'),
186
  ));
187
  return $this;
188
  }
189
 
190
- public function getRowUrl($row) {
 
191
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
192
  return $this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId()));
193
  }
194
  return false;
195
  }
196
 
197
- public function getGridUrl() {
198
- return $this->getUrl('*/*/grid', array('_current'=>true));
 
199
  }
200
-
201
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync block adminhtml order grid
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
13
+ {
14
+
15
+ protected $_withGrid = true;
16
 
17
+ public function __construct()
18
+ {
19
  parent::__construct();
20
  $this->setId('sales_sync_order_grid');
21
  $this->setUseAjax(true);
29
  *
30
  * @return string
31
  */
32
+ protected function _getCollectionClass()
33
+ {
34
+ $path = Mage::getBaseDir() . '/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php';
35
+ if (file_exists($path)) {
36
+ return 'sales/order_grid_collection';
37
+ }
38
+ $this->_withGrid = false;
39
  return 'sales/order_collection';
40
  }
41
 
42
+ protected function _prepareCollection()
43
+ {
44
  $collection = Mage::getResourceModel($this->_getCollectionClass());
45
+ $collection->addAttributeToFilter('from_lengow', array('gt' => 0));
46
+ if (!$this->_withGrid) {
47
+ $collection->addAttributeToSelect('*')
48
+ ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
49
+ ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
50
+ ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
51
+ ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
52
+ ->addExpressionAttributeToSelect('billing_name',
53
+ 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
54
+ array('billing_firstname', 'billing_lastname'))
55
+ ->addExpressionAttributeToSelect('shipping_name',
56
+ 'CONCAT({{shipping_firstname}}, IFNULL(CONCAT(\' \', {{shipping_lastname}}), \'\'))',
57
+ array('shipping_firstname', 'shipping_lastname'));
58
+ }
59
  $this->setCollection($collection);
60
  return parent::_prepareCollection();
61
  }
62
 
63
+ protected function _prepareColumns()
64
+ {
65
  $this->addColumn('real_Sync_id', array(
66
+ 'header' => Mage::helper('sales')->__('Order #'),
67
  'width' => '80px',
68
+ 'type' => 'text',
69
  'index' => 'increment_id',
70
  ));
71
  if (!Mage::app()->isSingleStoreMode()) {
72
  $this->addColumn('store_id', array(
73
+ 'header' => Mage::helper('sales')->__('Purchased From (Store)'),
74
+ 'index' => 'store_id',
75
+ 'type' => 'store',
76
+ 'store_view' => true,
77
  'display_deleted' => true,
78
  ));
79
  }
94
  $this->addColumn('base_grand_total', array(
95
  'header' => Mage::helper('sales')->__('G.T. (Base)'),
96
  'index' => 'base_grand_total',
97
+ 'type' => 'currency',
98
  'currency' => 'base_currency_code',
99
  ));
100
  $this->addColumn('grand_total', array(
101
  'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
102
  'index' => 'grand_total',
103
+ 'type' => 'currency',
104
  'currency' => 'order_currency_code',
105
+ ));
106
  // Add datas from Lengow
107
  $this->addColumn('order_id_lengow', array(
108
  'header' => Mage::helper('lensync')->__('Id lengow'),
109
  'index' => 'order_id_lengow',
110
  ));
 
111
  $this->addColumn('marketplace_lengow', array(
112
  'header' => Mage::helper('lensync')->__('Marketplace'),
113
  'index' => 'marketplace_lengow',
114
  ));
 
115
  $this->addColumn('fees_lengow', array(
116
+ 'header' => Mage::helper('lensync')->__('Fees'),
117
+ 'type' => 'currency',
118
  'index' => 'fees_lengow',
119
+ 'currency' => 'base_currency_code',
120
  ));
121
  // End datas from Lengow
122
  $this->addColumn('status', array(
123
  'header' => Mage::helper('sales')->__('Status'),
124
  'index' => 'status',
125
+ 'type' => 'options',
126
  'width' => '70px',
127
  'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
128
  ));
129
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
130
  $this->addColumn('action',
131
  array(
132
+ 'header' => Mage::helper('sales')->__('Action'),
133
+ 'width' => '50px',
134
+ 'type' => 'action',
135
+ 'getter' => 'getId',
136
+ 'actions' => array(
137
  array(
138
  'caption' => Mage::helper('sales')->__('View'),
139
+ 'url' => array('base' => 'adminhtml/sales_order/view'),
140
+ 'field' => 'order_id'
141
  )
142
  ),
143
+ 'filter' => false,
144
+ 'sortable' => false,
145
+ 'index' => 'stores',
146
  'is_system' => true,
147
+ ));
148
  }
149
  $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
150
  $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
151
  return parent::_prepareColumns();
152
  }
153
 
154
+ protected function _prepareMassaction()
155
+ {
156
  $this->setMassactionIdField('entity_id');
157
  $this->getMassactionBlock()->setFormFieldName('order_ids');
158
  $this->getMassactionBlock()->setUseSelectAll(false);
159
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
160
  $this->getMassactionBlock()->addItem('cancel_order', array(
161
+ 'label' => Mage::helper('sales')->__('Cancel'),
162
+ 'url' => $this->getUrl('adminhtml/sales_order/massCancel'),
163
  ));
164
  }
165
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
166
  $this->getMassactionBlock()->addItem('hold_order', array(
167
+ 'label' => Mage::helper('sales')->__('Hold'),
168
+ 'url' => $this->getUrl('adminhtml/sales_order/massHold'),
169
  ));
170
  }
171
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
172
  $this->getMassactionBlock()->addItem('unhold_order', array(
173
+ 'label' => Mage::helper('sales')->__('Unhold'),
174
+ 'url' => $this->getUrl('adminhtml/sales_order/massUnhold'),
175
  ));
176
  }
177
  $this->getMassactionBlock()->addItem('pdfinvoices_order', array(
178
+ 'label' => Mage::helper('sales')->__('Print Invoices'),
179
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfinvoices'),
180
  ));
181
  $this->getMassactionBlock()->addItem('pdfshipments_order', array(
182
+ 'label' => Mage::helper('sales')->__('Print Packingslips'),
183
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfshipments'),
184
  ));
185
  $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
186
+ 'label' => Mage::helper('sales')->__('Print Credit Memos'),
187
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfcreditmemos'),
188
  ));
189
  $this->getMassactionBlock()->addItem('pdfdocs_order', array(
190
+ 'label' => Mage::helper('sales')->__('Print All'),
191
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfdocs'),
192
  ));
193
  return $this;
194
  }
195
 
196
+ public function getRowUrl($row)
197
+ {
198
  if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
199
  return $this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId()));
200
  }
201
  return false;
202
  }
203
 
204
+ public function getGridUrl()
205
+ {
206
+ return $this->getUrl('*/*/grid', array('_current' => true));
207
  }
 
208
  }
app/code/community/Lengow/Sync/Block/Adminhtml/Order/Tab.php CHANGED
@@ -1,17 +1,20 @@
1
  <?php
 
2
  /**
3
- * Lengow select products block
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Romain Le Pohl <romain@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
  class Lengow_Sync_Block_Adminhtml_Order_Tab extends Mage_Adminhtml_Block_Sales_Order_Abstract
12
- implements Mage_Adminhtml_Block_Widget_Tab_Interface {
 
13
 
14
- protected function _construct() {
 
15
  $this->setTemplate('lengow/sales/order/tab/info.phtml');
16
  }
17
 
@@ -20,7 +23,8 @@ class Lengow_Sync_Block_Adminhtml_Order_Tab extends Mage_Adminhtml_Block_Sales_O
20
  *
21
  * @return Mage_Sales_Model_Order
22
  */
23
- public function getOrder() {
 
24
  return Mage::registry('current_order');
25
  }
26
 
@@ -29,24 +33,29 @@ class Lengow_Sync_Block_Adminhtml_Order_Tab extends Mage_Adminhtml_Block_Sales_O
29
  *
30
  * @return Mage_Sales_Model_Order
31
  */
32
- public function getSource() {
 
33
  return $this->getOrder();
34
  }
35
 
36
 
37
- public function getTabLabel() {
 
38
  return Mage::helper('sales')->__('Lengow');
39
  }
40
 
41
- public function getTabTitle() {
 
42
  return Mage::helper('sales')->__('Lengow');
43
  }
44
 
45
- public function canShowTab() {
 
46
  return true;
47
  }
48
 
49
- public function isHidden() {
 
50
  return false;
51
  }
52
 
@@ -55,7 +64,8 @@ class Lengow_Sync_Block_Adminhtml_Order_Tab extends Mage_Adminhtml_Block_Sales_O
55
  *
56
  * @return Array
57
  */
58
- public function getFields() {
 
59
  $fields = array();
60
  $order = $this->getOrder();
61
 
@@ -108,7 +118,8 @@ class Lengow_Sync_Block_Adminhtml_Order_Tab extends Mage_Adminhtml_Block_Sales_O
108
  *
109
  * @return boolean
110
  */
111
- public function isLengowOrder() {
 
112
  return $this->getOrder()->getData('from_lengow');
113
  }
114
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync block adminhtml order tab
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Sync_Block_Adminhtml_Order_Tab extends Mage_Adminhtml_Block_Sales_Order_Abstract
13
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
14
+ {
15
 
16
+ protected function _construct()
17
+ {
18
  $this->setTemplate('lengow/sales/order/tab/info.phtml');
19
  }
20
 
23
  *
24
  * @return Mage_Sales_Model_Order
25
  */
26
+ public function getOrder()
27
+ {
28
  return Mage::registry('current_order');
29
  }
30
 
33
  *
34
  * @return Mage_Sales_Model_Order
35
  */
36
+ public function getSource()
37
+ {
38
  return $this->getOrder();
39
  }
40
 
41
 
42
+ public function getTabLabel()
43
+ {
44
  return Mage::helper('sales')->__('Lengow');
45
  }
46
 
47
+ public function getTabTitle()
48
+ {
49
  return Mage::helper('sales')->__('Lengow');
50
  }
51
 
52
+ public function canShowTab()
53
+ {
54
  return true;
55
  }
56
 
57
+ public function isHidden()
58
+ {
59
  return false;
60
  }
61
 
64
  *
65
  * @return Array
66
  */
67
+ public function getFields()
68
+ {
69
  $fields = array();
70
  $order = $this->getOrder();
71
 
118
  *
119
  * @return boolean
120
  */
121
+ public function isLengowOrder()
122
+ {
123
  return $this->getOrder()->getData('from_lengow');
124
  }
125
  }
app/code/community/Lengow/Sync/Block/Payment/Info/Purchaseorder.php CHANGED
@@ -1,18 +1,20 @@
1
  <?php
 
2
  /**
3
  * Lengow sync block payment info purchaseorder
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Block_Payment_Info_Purchaseorder extends Mage_Payment_Block_Info {
 
12
 
13
- protected function _construct() {
 
14
  parent::_construct();
15
  $this->setTemplate('lengow/sales/payment/info/purchaseorder.phtml');
16
  }
17
-
18
  }
1
  <?php
2
+
3
  /**
4
  * Lengow sync block payment info purchaseorder
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Block_Payment_Info_Purchaseorder extends Mage_Payment_Block_Info
13
+ {
14
 
15
+ protected function _construct()
16
+ {
17
  parent::_construct();
18
  $this->setTemplate('lengow/sales/payment/info/purchaseorder.phtml');
19
  }
 
20
  }
app/code/community/Lengow/Sync/Block/System/Config/Form/Hidden.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow Sync model system config source getmarkeplace
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Block_System_Config_Form_Hidden extends Mage_Adminhtml_Block_System_Config_Form_Field
13
+ {
14
+ /**
15
+ * Render element html
16
+ *
17
+ * @param Varien_Data_Form_Element_Abstract $element
18
+ * @return string
19
+ */
20
+ public function render(Varien_Data_Form_Element_Abstract $element)
21
+ {
22
+ return sprintf('<tr id="row_%s" style="display:none;"><td>%s</td></tr>', $element->getHtmlId(), $element->getElementHtml());
23
+ }
24
+ }
app/code/community/Lengow/Sync/Helper/Api.php CHANGED
@@ -1,17 +1,19 @@
1
  <?php
 
2
  /**
3
- * Lengow sync helper data
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2014 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Helper_Api extends Mage_Core_Helper_Abstract {
 
12
 
13
- public function getVersion() {
14
- return (string) Mage::getConfig()->getNode()->modules->Lengow_Sync->version;
 
15
  }
16
-
17
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync helper api
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Helper_Api extends Mage_Core_Helper_Abstract
13
+ {
14
 
15
+ public function getVersion()
16
+ {
17
+ return (string)Mage::getConfig()->getNode()->modules->Lengow_Sync->version;
18
  }
19
+ }
 
app/code/community/Lengow/Sync/Helper/Cron.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php
2
 
3
  /**
4
- * Lengow sync helper data
5
  *
6
  * @category Lengow
7
- * @package Lengow_Cron
8
- * @author Pierre Basile <pierre.basile@lengow.com>
9
- * @copyright 2015 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Sync_Helper_Cron extends Mage_Core_Helper_Abstract
@@ -59,4 +59,4 @@ class Lengow_Sync_Helper_Cron extends Mage_Core_Helper_Abstract
59
  break;
60
  }
61
  }
62
- }
1
  <?php
2
 
3
  /**
4
+ * Lengow sync helper cron
5
  *
6
  * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Sync_Helper_Cron extends Mage_Core_Helper_Abstract
59
  break;
60
  }
61
  }
62
+ }
app/code/community/Lengow/Sync/Helper/Data.php CHANGED
@@ -1,43 +1,51 @@
1
  <?php
 
2
  /**
3
  * Lengow sync helper data
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Helper_Data extends Mage_Core_Helper_Abstract {
 
12
 
13
  /**
14
  * Transform SimpleXMLElement to associative array
15
  * SimpleXMLElement must be conform structure, generated by assocToXml()
16
  *
17
  * @param SimpleXMLElement $xml
 
18
  * @return array
19
  */
20
- public function xmlToAssoc(SimpleXMLElement $xml)
21
  {
22
  $array = array();
23
  foreach ($xml as $key => $value) {
 
 
 
24
  $array[$key] = trim((string)$value);
25
- if (empty($array[$key]) && !empty($value))
26
  $array[$key] = self::xmlToAssoc($value);
27
- else
28
  $array[$key] = (string)$value;
 
29
  }
30
  return $array;
31
  }
32
 
33
- /**
34
  * Returns the node and children as an array
35
- * values ares trimed
36
  *
37
  * @param bool $isCanonical - whether to ignore attributes
 
38
  * @return array|string
39
  */
40
- public function asArray(SimpleXMLElement $xml,$isCanonical = true)
41
  {
42
  $result = array();
43
  if (!$isCanonical) {
@@ -51,18 +59,19 @@ class Lengow_Sync_Helper_Data extends Mage_Core_Helper_Abstract {
51
  // add children values
52
  if ($xml->hasChildren()) {
53
  foreach ($xml->children() as $childName => $child) {
54
- if(!$child->hasChildren())
55
- $result[$childName] = $this->asArray($child,$isCanonical);
56
- else
57
- $result[$childName][] = $this->asArray($child,$isCanonical);
 
58
  }
59
  } else {
60
  if (empty($result)) {
61
  // return as string, if nothing was found
62
- $result = trim((string) $xml);
63
  } else {
64
  // value has zero key element
65
- $result[0] = trim((string) $xml);
66
  }
67
  }
68
  return $result;
@@ -71,16 +80,15 @@ class Lengow_Sync_Helper_Data extends Mage_Core_Helper_Abstract {
71
  /**
72
  * Writes log
73
  *
74
- * @param string $message log message
75
- * @param string $id_order lengow order id
76
- *
77
  * @return Lengow_Sync_Helper_Data
78
  */
79
  public function log($message, $id_order = null)
80
  {
81
- $log_model = Mage::getModel('lensync/log');
82
- $log_model->log($message, $id_order);
83
- return $this;
84
  }
85
 
86
  /**
@@ -91,37 +99,62 @@ class Lengow_Sync_Helper_Data extends Mage_Core_Helper_Abstract {
91
  $resource = Mage::getSingleton('core/resource');
92
  $writeConnection = $resource->getConnection('core_write');
93
  $table = $resource->getTableName('lensync/log');
94
- $query = "DELETE FROM ".$table." WHERE date < DATE_SUB(NOW(),INTERVAL 20 DAY)";
95
  $writeConnection->query($query);
96
  }
97
 
98
  /**
99
  * Clean None utf-8 characters
 
100
  * @param string $value
 
101
  * @return string $value
102
  */
103
  public function cleanNotUtf8($value)
104
  {
105
- $value = Mage::helper('core/string')->cleanString($value);
106
- //reject overly long 2 byte sequences, as well as characters above U+10000 and replace with blank
107
- $value = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]'.
108
- '|[\x00-\x7F][\x80-\xBF]+'.
109
- '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*'.
110
- '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})'.
111
- '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S',
112
- '', $value );
113
- //reject overly long 3 byte sequences and UTF-16 surrogates and replace with blank
114
- $value = preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]'.
115
- '|\xED[\xA0-\xBF][\x80-\xBF]/S','', $value );
116
- /*$value = preg_replace("/([\x80-\xFF])/e",
117
- "chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
118
- $value);*/
119
- $value = str_replace(chr(31),"", $value);
120
- $value = str_replace(chr(30),"", $value);
121
- $value = str_replace(chr(29),"", $value);
122
- $value = str_replace(chr(28),"", $value);
123
- //$value = iconv("UTF-8","UTF-8//IGNORE",$value);
124
- return $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
126
 
127
  /**
@@ -131,12 +164,13 @@ class Lengow_Sync_Helper_Data extends Mage_Core_Helper_Abstract {
131
  {
132
  $config = Mage::getSingleton('lensync/config');
133
  $mp_update = $config->get('hidden/last_synchro');
134
- if (!$mp_update || !$mp_update == '0000-00-00' ||$mp_update != date('Y-m-d'))
135
  $config->updateMarketPlaceConfiguration();
 
136
  }
137
 
138
  public function cleanMethod($method)
139
  {
140
  return str_replace(array(' ', '-', '\''), '_', $method);
141
  }
142
- }
1
  <?php
2
+
3
  /**
4
  * Lengow sync helper data
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Helper_Data extends Mage_Core_Helper_Abstract
13
+ {
14
 
15
  /**
16
  * Transform SimpleXMLElement to associative array
17
  * SimpleXMLElement must be conform structure, generated by assocToXml()
18
  *
19
  * @param SimpleXMLElement $xml
20
+ *
21
  * @return array
22
  */
23
+ public function xmlToAssoc($xml)
24
  {
25
  $array = array();
26
  foreach ($xml as $key => $value) {
27
+ if (is_array($value)) {
28
+ continue;
29
+ }
30
  $array[$key] = trim((string)$value);
31
+ if (empty($array[$key]) && !empty($value)) {
32
  $array[$key] = self::xmlToAssoc($value);
33
+ } else {
34
  $array[$key] = (string)$value;
35
+ }
36
  }
37
  return $array;
38
  }
39
 
40
+ /**
41
  * Returns the node and children as an array
42
+ * values ares trimed
43
  *
44
  * @param bool $isCanonical - whether to ignore attributes
45
+ *
46
  * @return array|string
47
  */
48
+ public function asArray(SimpleXMLElement $xml, $isCanonical = true)
49
  {
50
  $result = array();
51
  if (!$isCanonical) {
59
  // add children values
60
  if ($xml->hasChildren()) {
61
  foreach ($xml->children() as $childName => $child) {
62
+ if (!$child->hasChildren()) {
63
+ $result[$childName] = $this->asArray($child, $isCanonical);
64
+ } else {
65
+ $result[$childName][] = $this->asArray($child, $isCanonical);
66
+ }
67
  }
68
  } else {
69
  if (empty($result)) {
70
  // return as string, if nothing was found
71
+ $result = trim((string)$xml);
72
  } else {
73
  // value has zero key element
74
+ $result[0] = trim((string)$xml);
75
  }
76
  }
77
  return $result;
80
  /**
81
  * Writes log
82
  *
83
+ * @param string $message log message
84
+ * @param string $id_order lengow order id
85
+ *
86
  * @return Lengow_Sync_Helper_Data
87
  */
88
  public function log($message, $id_order = null)
89
  {
90
+ $log_model = Mage::getModel('lensync/log');
91
+ return $log_model->log($message, $id_order);
 
92
  }
93
 
94
  /**
99
  $resource = Mage::getSingleton('core/resource');
100
  $writeConnection = $resource->getConnection('core_write');
101
  $table = $resource->getTableName('lensync/log');
102
+ $query = "DELETE FROM " . $table . " WHERE date < DATE_SUB(NOW(),INTERVAL 20 DAY)";
103
  $writeConnection->query($query);
104
  }
105
 
106
  /**
107
  * Clean None utf-8 characters
108
+ *
109
  * @param string $value
110
+ *
111
  * @return string $value
112
  */
113
  public function cleanNotUtf8($value)
114
  {
115
+ $value = Mage::helper('core/string')->cleanString($value);
116
+ //reject overly long 2 byte sequences, as well as characters above U+10000 and replace with blank
117
+ $value = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' .
118
+ '|[\x00-\x7F][\x80-\xBF]+' .
119
+ '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' .
120
+ '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' .
121
+ '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S',
122
+ '', $value);
123
+ //reject overly long 3 byte sequences and UTF-16 surrogates and replace with blank
124
+ $value = preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]' .
125
+ '|\xED[\xA0-\xBF][\x80-\xBF]/S', '', $value);
126
+ /*$value = preg_replace("/([\x80-\xFF])/e",
127
+ "chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
128
+ $value);*/
129
+ $value = str_replace(chr(31), "", $value);
130
+ $value = str_replace(chr(30), "", $value);
131
+ $value = str_replace(chr(29), "", $value);
132
+ $value = str_replace(chr(28), "", $value);
133
+ //$value = iconv("UTF-8","UTF-8//IGNORE",$value);
134
+ return $value;
135
+ }
136
+
137
+ /**
138
+ * get connector by store
139
+ *
140
+ * @param $store
141
+ *
142
+ * @return mixed
143
+ */
144
+ public function getConnectorByStore($store)
145
+ {
146
+ $lentracker_config = Mage::getModel('lentracker/config', array('store' => $store));
147
+ $account_id = (integer)$lentracker_config->get('general/account_id');
148
+ $access_token = $lentracker_config->get('general/access_token');
149
+ $secret = $lentracker_config->get('general/secret');
150
+ if (!empty($account_id) || is_numeric($account_id) || !empty($access_token) || !empty($secret)) {
151
+ $connector = Mage::getModel('lensync/connector');
152
+ $connector->init($access_token, $secret);
153
+ if ($connector->isValidAuth($account_id)) {
154
+ return $connector;
155
+ }
156
+ }
157
+ return false;
158
  }
159
 
160
  /**
164
  {
165
  $config = Mage::getSingleton('lensync/config');
166
  $mp_update = $config->get('hidden/last_synchro');
167
+ if (!$mp_update || !$mp_update == '0000-00-00' || $mp_update != date('Y-m-d')) {
168
  $config->updateMarketPlaceConfiguration();
169
+ }
170
  }
171
 
172
  public function cleanMethod($method)
173
  {
174
  return str_replace(array(' ', '-', '\''), '_', $method);
175
  }
176
+ }
app/code/community/Lengow/Sync/Model/Config.php CHANGED
@@ -1,43 +1,47 @@
1
  <?php
 
2
  /**
3
  * Lengow sync model config
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Config extends Varien_Object {
 
12
 
13
  /**
14
  * Config key "Debug mode"
15
  */
16
  const DEBUG_MODE = 'performances/debug';
17
 
 
18
  const MP_CONF_LENGOW = 'http://kml.lengow.com/mp.xml';
19
 
20
  protected $store;
21
 
22
  protected $_file;
23
 
 
24
  public static $ADDRESS_ATTRIBUTES = array(
25
- 'prefix' => 'na',
26
- 'firstname' => 'firstname',
27
- 'middlename' => 'na',
28
- 'lastname' => 'lastname',
29
- 'suffix' => 'na',
30
- 'company' => 'society',
31
- 'street' => array('address', 'address_2', 'address_complement'),
32
- 'city' => 'city',
33
- 'country_id' => 'country',
34
- 'region' => 'na',
35
- 'region_id' => 'na',
36
- 'postcode' => 'zipcode',
37
- 'telephone' => 'phone_home',
38
- 'fax' => 'phone_office',
39
- 'vat_id' => 'na',
40
- );
41
 
42
  /**
43
  * Constructor
@@ -45,16 +49,17 @@ class Lengow_Sync_Model_Config extends Varien_Object {
45
  public function __construct($args = null)
46
  {
47
  parent::__construct();
48
- if (isset($args['store']))
49
  $this->setStore($args['store']);
 
50
  }
51
 
52
  /**
53
  * Set store
54
  *
55
  * @param $store
56
- *
57
- * @return Lengow_Sync_Model_Config
58
  */
59
  public function setStore($store)
60
  {
@@ -65,7 +70,7 @@ class Lengow_Sync_Model_Config extends Varien_Object {
65
  /**
66
  * Get store from config
67
  *
68
- * @return
69
  */
70
  public function getStore()
71
  {
@@ -76,30 +81,19 @@ class Lengow_Sync_Model_Config extends Varien_Object {
76
  * Get data from config
77
  *
78
  * @param string $key
79
- *
80
  * @return mixed
81
  */
82
  public function get($key)
83
  {
84
- if (is_null($this->store))
85
  $id_store = null;
86
- else
87
  $id_store = $this->store->getId();
 
88
  return Mage::getStoreConfig('lensync/' . $key, $id_store);
89
  }
90
 
91
- /**
92
- * Map Magento address attribute codes with Neteven ones
93
- *
94
- * @param string $attribute_code
95
- *
96
- * @return mixed
97
- */
98
- public function getMappedAddressAttributeCode($attribute_code)
99
- {
100
- return self::$ADDRESS_ATTRIBUTES[$attribute_code];
101
- }
102
-
103
  /**
104
  * Is debug mode
105
  *
@@ -107,23 +101,7 @@ class Lengow_Sync_Model_Config extends Varien_Object {
107
  */
108
  public function isDebugMode()
109
  {
110
- return $this->get(self::DEBUG_MODE) == 1 ? true : false;
111
- }
112
-
113
- /**
114
- * Check and update xml of marketplace's configuration.
115
- *
116
- * @return boolean.
117
- */
118
- public function updateMarketPlaceConfiguration()
119
- {
120
- if ($xml = fopen(self::MP_CONF_LENGOW, 'r')) {
121
- $markeplace = Mage::getModel('lensync/marketplace');
122
- $handle = fopen(Mage::getModuleDir('etc', 'Lengow_Sync') . DS . $markeplace::$XML_MARKETPLACES . '', 'w');
123
- stream_copy_to_stream($xml, $handle);
124
- fclose($handle);
125
- Mage::getModel('core/config')->saveConfig('lensync/hidden/last_synchro', date('Y-m-d'));
126
- }
127
  }
128
 
129
  /**
@@ -133,11 +111,12 @@ class Lengow_Sync_Model_Config extends Varien_Object {
133
  */
134
  public function importCanStart()
135
  {
136
- if (is_null($this->_file))
137
  $this->getFlagFile();
 
138
  if (!$this->addFlagToFile()) {
139
  $timestamp = $this->readFlagFile();
140
- if ($timestamp !== false && (time() - (integer) $timestamp) > (60*25)) {
141
  $this->addFlagToFile();
142
  return true;
143
  }
@@ -145,9 +124,9 @@ class Lengow_Sync_Model_Config extends Varien_Object {
145
  }
146
  return true;
147
  }
148
-
149
  /**
150
- * Finish import
151
  *
152
  */
153
  public function importSetEnd()
@@ -159,38 +138,38 @@ class Lengow_Sync_Model_Config extends Varien_Object {
159
  }
160
 
161
  /**
162
- * Add flag to file
163
  *
164
  * @param boolean $reset
165
  *
166
- * @return boolean
167
  */
168
  public function addFlagToFile($reset = false)
169
  {
170
 
171
  if ($this->_file->streamLock()) {
172
  if ($reset) {
173
- if ($this->_file->streamErase())
174
  $this->_file->streamWrite('0');
175
- }
176
- else {
177
  $this->_file->streamWrite(time());
178
  }
179
  return true;
180
- }
181
- else
182
  return false;
 
183
  }
184
 
185
  /**
186
- * Read file flag
187
  *
188
- * @return boolean
189
  */
190
- public function readFlagFile()
191
  {
192
- $file_path = Mage::getBaseDir('media') . DS . 'lengow' . DS;
193
- if(is_file($file_path . 'import.flag')) {
194
  $this->_file->cd($file_path);
195
  $this->_file->streamLock();
196
  return $this->_file->streamRead(4096);
@@ -200,17 +179,48 @@ class Lengow_Sync_Model_Config extends Varien_Object {
200
  }
201
 
202
  /**
203
- * Create file flag
204
  *
205
- * @return boolean
206
  */
207
- public function getFlagFile()
208
  {
209
  $this->_file = new Lengow_Sync_Model_File();
210
- $file_path = Mage::getBaseDir('media') . DS . 'lengow' . DS;
211
  $this->_file->checkAndCreateFolder($file_path);
212
  $this->_file->cd($file_path);
213
  $this->_file->streamOpen('import.flag', 'w+');
214
  Mage::helper('lensync/data')->log('Write on file log');
215
  }
216
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+
3
  /**
4
  * Lengow sync model config
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Config extends Varien_Object
13
+ {
14
 
15
  /**
16
  * Config key "Debug mode"
17
  */
18
  const DEBUG_MODE = 'performances/debug';
19
 
20
+ //V2
21
  const MP_CONF_LENGOW = 'http://kml.lengow.com/mp.xml';
22
 
23
  protected $store;
24
 
25
  protected $_file;
26
 
27
+ //V2
28
  public static $ADDRESS_ATTRIBUTES = array(
29
+ 'prefix' => 'na',
30
+ 'firstname' => 'firstname',
31
+ 'middlename' => 'na',
32
+ 'lastname' => 'lastname',
33
+ 'suffix' => 'na',
34
+ 'company' => 'society',
35
+ 'street' => array('address', 'address_2', 'address_complement'),
36
+ 'city' => 'city',
37
+ 'country_id' => 'country',
38
+ 'region' => 'na',
39
+ 'region_id' => 'na',
40
+ 'postcode' => 'zipcode',
41
+ 'telephone' => 'phone_home',
42
+ 'fax' => 'phone_office',
43
+ 'vat_id' => 'na',
44
+ );
45
 
46
  /**
47
  * Constructor
49
  public function __construct($args = null)
50
  {
51
  parent::__construct();
52
+ if (isset($args['store'])) {
53
  $this->setStore($args['store']);
54
+ }
55
  }
56
 
57
  /**
58
  * Set store
59
  *
60
  * @param $store
61
+ *
62
+ * @return Lengow_Sync_Model_Config
63
  */
64
  public function setStore($store)
65
  {
70
  /**
71
  * Get store from config
72
  *
73
+ * @return
74
  */
75
  public function getStore()
76
  {
81
  * Get data from config
82
  *
83
  * @param string $key
84
+ *
85
  * @return mixed
86
  */
87
  public function get($key)
88
  {
89
+ if (is_null($this->store)) {
90
  $id_store = null;
91
+ } else {
92
  $id_store = $this->store->getId();
93
+ }
94
  return Mage::getStoreConfig('lensync/' . $key, $id_store);
95
  }
96
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  /**
98
  * Is debug mode
99
  *
101
  */
102
  public function isDebugMode()
103
  {
104
+ return $this->get(self::DEBUG_MODE) == 1 ? true : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
 
107
  /**
111
  */
112
  public function importCanStart()
113
  {
114
+ if (is_null($this->_file)) {
115
  $this->getFlagFile();
116
+ }
117
  if (!$this->addFlagToFile()) {
118
  $timestamp = $this->readFlagFile();
119
+ if ($timestamp !== false && (time() - (integer)$timestamp) > (60 * 25)) {
120
  $this->addFlagToFile();
121
  return true;
122
  }
124
  }
125
  return true;
126
  }
127
+
128
  /**
129
+ * Close import
130
  *
131
  */
132
  public function importSetEnd()
138
  }
139
 
140
  /**
141
+ * Add a flag to file
142
  *
143
  * @param boolean $reset
144
  *
145
+ * @return boolean.
146
  */
147
  public function addFlagToFile($reset = false)
148
  {
149
 
150
  if ($this->_file->streamLock()) {
151
  if ($reset) {
152
+ if ($this->_file->streamErase()) {
153
  $this->_file->streamWrite('0');
154
+ }
155
+ } else {
156
  $this->_file->streamWrite(time());
157
  }
158
  return true;
159
+ } else {
 
160
  return false;
161
+ }
162
  }
163
 
164
  /**
165
+ * Create file flag.
166
  *
167
+ * @return boolean.
168
  */
169
+ public function readFlagFile()
170
  {
171
+ $file_path = Mage::getBaseDir('media').DS.'lengow'.DS;
172
+ if (is_file($file_path.'import.flag')) {
173
  $this->_file->cd($file_path);
174
  $this->_file->streamLock();
175
  return $this->_file->streamRead(4096);
179
  }
180
 
181
  /**
182
+ * Create file flag.
183
  *
184
+ * @return boolean.
185
  */
186
+ public function getFlagFile()
187
  {
188
  $this->_file = new Lengow_Sync_Model_File();
189
+ $file_path = Mage::getBaseDir('media').DS.'lengow'.DS;
190
  $this->_file->checkAndCreateFolder($file_path);
191
  $this->_file->cd($file_path);
192
  $this->_file->streamOpen('import.flag', 'w+');
193
  Mage::helper('lensync/data')->log('Write on file log');
194
  }
195
+
196
+
197
+
198
+ /*V2*/
199
+ /**
200
+ * Map Magento address attribute codes with Neteven ones
201
+ *
202
+ * @param string $attribute_code
203
+ *
204
+ * @return mixed
205
+ */
206
+ public function getMappedAddressAttributeCode($attribute_code)
207
+ {
208
+ return self::$ADDRESS_ATTRIBUTES[$attribute_code];
209
+ }
210
+
211
+ /**
212
+ * Check and update xml of marketplace's configuration.
213
+ *
214
+ * @return boolean.
215
+ */
216
+ public function updateMarketPlaceConfiguration()
217
+ {
218
+ if ($xml = fopen(self::MP_CONF_LENGOW, 'r')) {
219
+ $markeplace = Mage::getModel('lensync/marketplacev2');
220
+ $handle = fopen(Mage::getModuleDir('etc', 'Lengow_Sync').DS.$markeplace::$XML_MARKETPLACES, 'w');
221
+ stream_copy_to_stream($xml, $handle);
222
+ fclose($handle);
223
+ Mage::getModel('core/config')->saveConfig('lensync/hidden/last_synchro', date('Y-m-d'));
224
+ }
225
+ }
226
+ }
app/code/community/Lengow/Sync/Model/Connector.php CHANGED
@@ -1,132 +1,101 @@
1
  <?php
2
 
3
- /**
4
- * Copyright 2013 Lengow.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
7
- * not use this file except in compliance with the License. You may obtain
8
- * a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- * License for the specific language governing permissions and limitations
16
- * under the License.
17
- */
18
-
19
  if (!function_exists('curl_init')) {
20
- throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the CURL PHP extension.', -1);
21
  }
22
  if (!function_exists('json_decode')) {
23
- throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the JSON PHP extension.', -2);
24
  }
25
  if (!function_exists('simplexml_load_string')) {
26
- throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the SIMPLE XML PHP extension.', -3);
27
  }
28
 
29
  /**
30
- * The Lengow connector API.
31
  *
32
- * @author Ludovic Drin <ludovic@lengow.com>
33
- * @copyright 2013 Lengow SAS
 
 
 
34
  */
35
- class Lengow_Sync_Model_Connector {
 
36
 
37
- /**
38
- * Version.
39
- */
40
- const VERSION = '1.0.1';
41
 
42
- /**
43
- * Error.
44
- */
45
  public $error;
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  /**
48
  * Default options for curl.
49
  */
50
  public static $CURL_OPTS = array(
51
- //CURLOPT_SSL_VERIFYPEER => false, // Unquote if you want desactivate ssl check
52
  CURLOPT_CONNECTTIMEOUT => 10,
53
  CURLOPT_RETURNTRANSFER => true,
54
- CURLOPT_TIMEOUT => 300,
55
- CURLOPT_USERAGENT => 'lengow-api-1.0',
56
  );
57
 
58
  /**
59
- * Lengow webservices domains.
60
- */
61
- public static $DOMAIN_LENGOW = array(
62
- 'solution' => array('protocol' => 'https',
63
- 'url' => 'solution.lengow.com',
64
- 'format' => 'json'),
65
- 'api' => array('protocol' => 'http',
66
- 'url' => 'api.lengow.com',
67
- 'format' => 'xml'),
68
- 'statistics' => array('protocol' => 'http',
69
- 'url' => 'statistics.lengow.com',
70
- 'format' => 'xml'),
71
- );
72
-
73
- /**
74
- * Lengow methods API.
75
- */
76
- public static $API_METHODS_LENGOW = array(
77
- 'getListingFeeds' => array('service' => 'solution'),
78
- 'updateFeed' => array('service' => 'solution'),
79
- 'getHistoryFeed' => array('service' => 'solution'),
80
- 'updateInformationsClient' => array('service' => 'solution'),
81
- 'getListingGroups' => array('service' => 'solution'),
82
- 'createGroup' => array('service' => 'solution'),
83
- 'updateGroup' => array('service' => 'solution'),
84
- 'getListingVip' => array('service' => 'solution'),
85
- 'createVip' => array('service' => 'solution'),
86
- 'updateVip' => array('service' => 'solution'),
87
- 'getLeads' => array('service' => 'solution'),
88
- 'statusLead' => array('service' => 'solution'),
89
- 'updatePrestaInternalOrderId' => array('service' => 'solution'),
90
- 'updateTrackingMagento' => array('service' => 'solution'),
91
- 'updateRootFeed' => array('service' => 'solution'),
92
- 'getRootFeed' => array('service' => 'solution'),
93
- 'updateEcommerceSolution' => array('service' => 'solution'),
94
- 'getInternalOrderId' => array('service' => 'solution'),
95
- 'statistics' => array('service' => 'statistics'),
96
- 'commands' => array('service' => 'api'),
97
- );
98
-
99
- /**
100
- * Lengow token.
101
  */
102
- public $token;
 
 
 
 
103
 
104
- /**
105
- * Lengow ID customer.
106
- */
107
- public $id_customer;
108
 
109
  /**
110
- * Make a new Lengow API Connector.
 
 
111
  *
112
- * @param integer $id_customer Your customer ID.
113
- * @param varchar $token Your token Lengow API.
114
  */
115
- public function init($id_customer, $token) {
116
- try {
117
- if (is_integer($id_customer))
118
- $this->id_customer = $id_customer;
119
- else
120
- throw new Lengow_Sync_Model_Connector_Exception('Error Lengow Customer ID', 1);
121
- if (strlen($token) > 10)
122
- $this->token = $token;
123
- else
124
- throw new Lengow_Sync_Model_Connector_Exception('Error Lengow Token API', 2);
125
- } catch (Lengow_Sync_Model_Connector_Exception $e) {
126
- $this->error = $e;
 
 
 
 
 
127
  return false;
128
  }
129
- return true;
130
  }
131
 
132
  /**
@@ -134,167 +103,147 @@ class Lengow_Sync_Model_Connector {
134
  *
135
  * @param varchar $method Lengow method API call.
136
  * @param varchar $array Lengow method API parameters
 
 
137
  *
138
  * @return array The formated data response
139
  */
140
- public function api($method, $array) {
 
 
141
  try {
142
- if(!$api = $this->_getMethod($method))
143
- throw new Lengow_Sync_Model_Connector_Exception('Error unknow method API', 3);
144
- else
145
- $data = $this->_callAction($api['service'], $method, $array);
146
- } catch (Lengow_Sync_Model_Connector_Exception $e) {
147
  return $e->getMessage();
148
  }
149
  return $data;
150
  }
151
 
152
- /**
153
- * Call the Lengow service with accepted method.
154
- *
155
- * @param varchar $service Lengow service name
156
- * @param varchar $method Lengow method API call.
157
- * @param varchar $array Lengow method API parameters
158
- *
159
- * @return array The formated data response
160
- */
161
- private function _callAction($service, $method, $array) {
162
- switch ($service) {
163
- case 'solution' :
164
- $url = $this->_getUrlService($service, $method, $array);
165
- break;
166
- case 'api' :
167
- $url = $this->_getUrlOrders($service, $array);
168
- break;
169
- case 'statistics' :
170
- $url = $this->_getUrlStatistics($service, $array);
171
- break;
172
- }
173
- $result = $this->_makeRequest($url);
174
- return $this->_format($result, self::$DOMAIN_LENGOW[$service]['format']);
175
  }
176
 
177
- /**
178
- * Makes the Service API Url.
179
- *
180
- * @param string $service The URL to make the request to
181
- * @param string $array The array of query parameters
182
- *
183
- * @return string The url
184
- */
185
- private function _getUrlService($service, $method, $array) {
186
- $url = self::$DOMAIN_LENGOW[$service]['protocol']
187
- . '://'
188
- . self::$DOMAIN_LENGOW[$service]['url']
189
- . '/wsdl/connector/call.json?'
190
- . 'token=' . $this->token
191
- . '&idClient=' . $this->id_customer
192
- . '&method=' . $method
193
- . '&array=' . urlencode(serialize($array));
194
- return $url;
195
  }
196
 
197
- /**
198
- * Makes the Orders API Url.
199
- *
200
- * @param string $service The URL to make the request to
201
- * @param string $array The array of query parameters
202
- *
203
- * @return string The url
204
- */
205
- private function _getUrlOrders($service, $array) {
206
- $url = self::$DOMAIN_LENGOW[$service]['protocol']
207
- . '://'
208
- . self::$DOMAIN_LENGOW[$service]['url'] . '/'
209
- . 'v2/'
210
- . $array['dateFrom'] . '/'
211
- . $array['dateTo'] . '/'
212
- . $this->id_customer .'/'
213
- . $array['id_group'] .'/'
214
- . (isset($array['id']) && !empty($array['id']) ? $array['id'] : 'orders')
215
- . '/commands/'
216
- . (isset($array['state']) && !empty($array['state']) ? $array['state'] . '/' : '');
217
- return $url;
218
  }
219
 
220
- /**
221
- * Makes the Statisctics API Url.
222
- *
223
- * @param string $service The URL to make the request to
224
- * @param string $array The array of query parameters
225
- *
226
- * @return string The url
227
- */
228
- private function _getUrlStatistics($service, $array) {
229
- $url = self::$DOMAIN_LENGOW[$service]['protocol']
230
- . '://'
231
- . self::$DOMAIN_LENGOW[$service]['url']
232
- . $array['dateFrom'] . '/'
233
- . $array['dateTo'] . '/'
234
- . $this->id_customer .'/'
235
- . $array['id']
236
- . '/total-All/';
237
- return $url;
238
  }
239
 
240
- /**
241
- * Get the method of Lengow API if exist.
242
- *
243
- * @param string $method The method's name
244
- *
245
- * @return string The method with service
246
- */
247
- private function _getMethod($method) {
248
- if(self::$API_METHODS_LENGOW[$method])
249
- return self::$API_METHODS_LENGOW[$method];
250
- else
251
- return false;
252
  }
253
 
254
- /**
255
- * Format data with good format.
256
- *
257
- * @param string $data the data's response of method request
258
- * @param string $format the return format
259
- *
260
- * @return string Data formated
261
- */
262
- private function _format($data, $format) {
263
- switch($format) {
264
- case 'xml' :
265
- return simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
266
- case 'json' :
 
 
267
  return json_decode($data, true);
 
 
 
 
 
 
268
  }
269
- return null;
270
  }
271
 
272
- /**
273
- * Makes an HTTP request.
274
- *
275
- * @param string $url The URL to make the request to
276
- *
277
- * @return string The response text
278
- */
279
- protected function _makeRequest($url) {
280
- Mage::helper('lensync/data')->log('Connector ' . $url);
281
  $ch = curl_init();
282
  // Options
283
  $opts = self::$CURL_OPTS;
284
- $opts[CURLOPT_URL] = $url;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  // Exectute url request
286
  curl_setopt_array($ch, $opts);
287
  $result = curl_exec($ch);
288
- if ($result === false) {
289
- Mage::helper('lensync/data')->log('Connector Error (' . curl_error($ch) . ')' . $result);
290
- throw new Lengow_Sync_Model_Connector_Exception(
291
- array('message' => curl_error($ch),
292
- 'type' => 'CurlException',
293
- ),
294
- curl_errno($ch)
295
- );
296
- }
297
  curl_close($ch);
298
- return $result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }
300
  }
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  if (!function_exists('curl_init')) {
4
+ throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the CURL PHP extension.', -1);
5
  }
6
  if (!function_exists('json_decode')) {
7
+ throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the JSON PHP extension.', -2);
8
  }
9
  if (!function_exists('simplexml_load_string')) {
10
+ throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the SIMPLE XML PHP extension.', -3);
11
  }
12
 
13
  /**
14
+ * Lengow Sync model connector
15
  *
16
+ * @category Lengow
17
+ * @package Lengow_Sync
18
+ * @author Team Connector <team-connector@lengow.com>
19
+ * @copyright 2016 Lengow SAS
20
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
21
  */
22
+ class Lengow_Sync_Model_Connector
23
+ {
24
 
25
+ const VERSION = '1.0';
 
 
 
26
 
 
 
 
27
  public $error;
28
 
29
+ protected $access_token;
30
+
31
+ protected $secret;
32
+
33
+ protected $token;
34
+
35
+ protected $account_id;
36
+
37
+ protected $user_id;
38
+
39
+ protected $request;
40
+
41
+ const LENGOW_API_URL = 'http://api.lengow.io:80';
42
+
43
+ const LENGOW_API_SANDBOX_URL = 'http://api.lengow.net:80';
44
+
45
+
46
  /**
47
  * Default options for curl.
48
  */
49
  public static $CURL_OPTS = array(
 
50
  CURLOPT_CONNECTTIMEOUT => 10,
51
  CURLOPT_RETURNTRANSFER => true,
52
+ CURLOPT_TIMEOUT => 20,
53
+ CURLOPT_USERAGENT => 'lengow-php-sdk',
54
  );
55
 
56
  /**
57
+ * Make a new Lengow API Connector.
58
+ *
59
+ * @param varchar $access_token Your access token.
60
+ * @param varchar $secret Your secret.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  */
62
+ public function init($access_token, $secret)
63
+ {
64
+ $this->access_token = $access_token;
65
+ $this->secret = $secret;
66
+ }
67
 
68
+ public function getRequest()
69
+ {
70
+ return $this->request;
71
+ }
72
 
73
  /**
74
+ * Connectection to the API
75
+ *
76
+ * @param varchar $user_token The user token if is connected
77
  *
78
+ * @return mixed array [authorized token + account_id + user_id] or false
 
79
  */
80
+ public function connect($user_token = '')
81
+ {
82
+ $data = $this->_callAction(
83
+ '/access/get_token',
84
+ array(
85
+ 'access_token' => $this->access_token,
86
+ 'secret' => $this->secret,
87
+ 'user_token' => $user_token
88
+ ),
89
+ 'POST'
90
+ );
91
+ if (isset($data['token'])) {
92
+ $this->token = $data['token'];
93
+ $this->account_id = $data['account_id'];
94
+ $this->user_id = $data['user_id'];
95
+ return $data;
96
+ } else {
97
  return false;
98
  }
 
99
  }
100
 
101
  /**
103
  *
104
  * @param varchar $method Lengow method API call.
105
  * @param varchar $array Lengow method API parameters
106
+ * @param varchar $type type of request GET|POST|PUT|HEAD|DELETE|PATCH
107
+ * @param varchar $format return format of API
108
  *
109
  * @return array The formated data response
110
  */
111
+ public function call($method, $array = array(), $type = 'GET', $format = 'json')
112
+ {
113
+ $this->connect();
114
  try {
115
+ if (!array_key_exists('account_id', $array)) {
116
+ $array['account_id'] = $this->account_id;
117
+ }
118
+ $data = $this->_callAction($method, $array, $type, $format);
119
+ } catch (Exception $e) {
120
  return $e->getMessage();
121
  }
122
  return $data;
123
  }
124
 
125
+ public function get($method, $array = array(), $format = 'json')
126
+ {
127
+ return $this->call($method, $array, 'GET', $format);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
 
130
+ public function post($method, $array = array(), $format = 'json')
131
+ {
132
+ return $this->call($method, $array, 'POST', $format);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
 
135
+ public function head($method, $array = array(), $format = 'json')
136
+ {
137
+ return $this->call($method, $array, 'HEAD', $format);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
140
+ public function put($method, $array = array(), $format = 'json')
141
+ {
142
+ return $this->call($method, $array, 'PUT', $format);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
 
145
+ public function delete($method, $array = array(), $format = 'json')
146
+ {
147
+ return $this->call($method, $array, 'DELETE', $format);
 
 
 
 
 
 
 
 
 
148
  }
149
 
150
+ public function patch($method, $array = array(), $format = 'json')
151
+ {
152
+ return $this->call($method, $array, 'PATCH', $format);
153
+ }
154
+
155
+ private function _callAction($api, $args, $type, $format = 'json')
156
+ {
157
+ $result = $this->_makeRequest($type, self::LENGOW_API_URL . $api, $args, $this->token);
158
+ return $this->_format($result, $format);
159
+ }
160
+
161
+ private function _format($data, $format)
162
+ {
163
+ switch ($format) {
164
+ case 'json':
165
  return json_decode($data, true);
166
+ case 'csv':
167
+ return $data;
168
+ case 'xml':
169
+ return simplexml_load_string($data);
170
+ case 'stream':
171
+ return $data;
172
  }
 
173
  }
174
 
175
+ protected function _makeRequest($type, $url, $args, $token)
176
+ {
 
 
 
 
 
 
 
177
  $ch = curl_init();
178
  // Options
179
  $opts = self::$CURL_OPTS;
180
+ $opts[CURLOPT_CUSTOMREQUEST] = strtoupper($type);
181
+ $url = parse_url($url);
182
+ $opts[CURLOPT_PORT] = $url['port'];
183
+ $opts[CURLOPT_HEADER] = true;
184
+ $opts[CURLOPT_RETURNTRANSFER] = true;
185
+ $opts[CURLOPT_VERBOSE] = false;
186
+ if (isset($token)) {
187
+ $opts[CURLOPT_HTTPHEADER] = array(
188
+ 'Authorization: '.$token
189
+ );
190
+ }
191
+ $url = $url['scheme'].'://'.$url['host'].$url['path'];
192
+ switch ($type) {
193
+ case "GET":
194
+ $opts[CURLOPT_URL] = $url.'?'.http_build_query($args);
195
+ Mage::helper('lensync/data')->log('Connector: '.$opts[CURLOPT_URL]);
196
+ break;
197
+ case "PATCH":
198
+ if (isset($token)) {
199
+ $opts[CURLOPT_HTTPHEADER] = array_merge(
200
+ $opts[CURLOPT_HTTPHEADER],
201
+ array('Content-Type: application/json')
202
+ );
203
+ }
204
+ $opts[CURLOPT_URL] = $url;
205
+ $opts[CURLOPT_POST] = count($args);
206
+ $opts[CURLOPT_POSTFIELDS] = json_encode($args);
207
+ break;
208
+ default:
209
+ $opts[CURLOPT_URL] = $url;
210
+ $opts[CURLOPT_POST] = count($args);
211
+ $opts[CURLOPT_POSTFIELDS] = http_build_query($args);
212
+ break;
213
+ }
214
  // Exectute url request
215
  curl_setopt_array($ch, $opts);
216
  $result = curl_exec($ch);
217
+ $error = curl_errno($ch);
218
+ list($header, $data) = explode("\r\n\r\n", $result, 2);
219
+ $information = curl_getinfo($ch, CURLINFO_HEADER_OUT);
 
 
 
 
 
 
220
  curl_close($ch);
221
+ if ($data === false) {
222
+ throw new Exception('Bad request '.$error['code']);
223
+ return false;
224
+ }
225
+ return $data;
226
+ }
227
+
228
+ public function getAccountId()
229
+ {
230
+ return $this->account_id;
231
+ }
232
+
233
+ /**
234
+ * Check API Authentification
235
+ *
236
+ * @param integer $account_id Account id
237
+ *
238
+ * @return boolean
239
+ */
240
+ public function isValidAuth($account_id)
241
+ {
242
+ $result = $this->connect();
243
+ if (isset($result['token']) && $account_id != 0 && is_integer($account_id)) {
244
+ return true;
245
+ } else {
246
+ return false;
247
+ }
248
  }
249
  }
app/code/community/Lengow/Sync/Model/Connector/Exception.php CHANGED
@@ -1,58 +1,71 @@
1
  <?php
 
2
  /**
3
- * Thrown when an API call returns an exception.
4
  *
5
- * @author Ludovic Drin <ludovic@lengow.com>
 
 
 
 
6
  */
7
- class Lengow_Sync_Model_Connector_Exception extends Exception {
 
8
 
9
- /**
10
- * The result from the API server that represents the exception information.
11
- */
12
- protected $result;
13
 
14
- /**
15
- * Make a new API Exception with the given result.
16
- *
17
- * @param array $result The error result
18
- */
19
- public function __construct($result, $noerror) {
20
- $this->result = $result;
21
- if(is_array($result))
22
- $msg = $result['message'];
23
- else
24
- $msg = $result;
25
- parent::__construct($msg, $noerror);
26
- }
 
 
27
 
28
- /**
29
- * Return the associated result object returned by the API server.
30
- *
31
- * @return array The result from the API server
32
- */
33
- public function getResult() {
34
- return $this->result;
35
- }
 
36
 
37
- /**
38
- * Returns the associated type for the error.
39
- *
40
- * @return string
41
- */
42
- public function getType() {
43
- if(isset($this->result['type']))
44
- return $this->result['type'];
45
- return 'Lengow_Sync_Model_Connector_Exception';
46
- }
 
 
47
 
48
- /**
49
- * To make debugging easier.
50
- *
51
- * @return string The string representation of the error
52
- */
53
- public function __toString() {
54
- if(isset($this->result['message']))
55
- return $this->result['message'];
56
- return $this->message;
57
- }
58
- }
 
 
1
  <?php
2
+
3
  /**
4
+ * Lengow sync model connector exception
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Connector_Exception extends Exception
13
+ {
14
 
15
+ /**
16
+ * The result from the API server that represents the exception information.
17
+ */
18
+ protected $result;
19
 
20
+ /**
21
+ * Make a new API Exception with the given result.
22
+ *
23
+ * @param array $result The error result
24
+ */
25
+ public function __construct($result, $noerror)
26
+ {
27
+ $this->result = $result;
28
+ if (is_array($result)) {
29
+ $msg = $result['message'];
30
+ } else {
31
+ $msg = $result;
32
+ }
33
+ parent::__construct($msg, $noerror);
34
+ }
35
 
36
+ /**
37
+ * Return the associated result object returned by the API server.
38
+ *
39
+ * @return array The result from the API server
40
+ */
41
+ public function getResult()
42
+ {
43
+ return $this->result;
44
+ }
45
 
46
+ /**
47
+ * Returns the associated type for the error.
48
+ *
49
+ * @return string
50
+ */
51
+ public function getType()
52
+ {
53
+ if (isset($this->result['type'])) {
54
+ return $this->result['type'];
55
+ }
56
+ return 'Lengow_Sync_Model_Connector_Exception';
57
+ }
58
 
59
+ /**
60
+ * To make debugging easier.
61
+ *
62
+ * @return string The string representation of the error
63
+ */
64
+ public function __toString()
65
+ {
66
+ if (isset($this->result['message'])) {
67
+ return $this->result['message'];
68
+ }
69
+ return $this->message;
70
+ }
71
+ }
app/code/community/Lengow/Sync/Model/Connectorv2.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2013 Lengow.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
7
+ * not use this file except in compliance with the License. You may obtain
8
+ * a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ * License for the specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+
19
+ if (!function_exists('curl_init')) {
20
+ throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the CURL PHP extension.', -1);
21
+ }
22
+ if (!function_exists('json_decode')) {
23
+ throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the JSON PHP extension.', -2);
24
+ }
25
+ if (!function_exists('simplexml_load_string')) {
26
+ throw new Lengow_Sync_Model_Connector_Exception('Lengow needs the SIMPLE XML PHP extension.', -3);
27
+ }
28
+
29
+ /**
30
+ * The Lengow connector API.
31
+ *
32
+ * @author Ludovic Drin <ludovic@lengow.com>
33
+ * @copyright 2013 Lengow SAS
34
+ */
35
+ class Lengow_Sync_Model_Connectorv2
36
+ {
37
+
38
+ /**
39
+ * Version.
40
+ */
41
+ const VERSION = '1.0.1';
42
+
43
+ /**
44
+ * Error.
45
+ */
46
+ public $error;
47
+
48
+ /**
49
+ * Default options for curl.
50
+ */
51
+ public static $CURL_OPTS = array(
52
+ //CURLOPT_SSL_VERIFYPEER => false, // Unquote if you want desactivate ssl check
53
+ CURLOPT_CONNECTTIMEOUT => 10,
54
+ CURLOPT_RETURNTRANSFER => true,
55
+ CURLOPT_TIMEOUT => 300,
56
+ CURLOPT_USERAGENT => 'lengow-api-1.0',
57
+ );
58
+
59
+ /**
60
+ * Lengow webservices domains.
61
+ */
62
+ public static $DOMAIN_LENGOW = array(
63
+ 'solution' => array(
64
+ 'protocol' => 'https',
65
+ 'url' => 'solution.lengow.com',
66
+ 'format' => 'json'
67
+ ),
68
+ 'api' => array(
69
+ 'protocol' => 'http',
70
+ 'url' => 'api.lengow.com',
71
+ 'format' => 'xml'
72
+ ),
73
+ 'statistics' => array(
74
+ 'protocol' => 'http',
75
+ 'url' => 'statistics.lengow.com',
76
+ 'format' => 'xml'
77
+ ),
78
+ );
79
+
80
+ /**
81
+ * Lengow methods API.
82
+ */
83
+ public static $API_METHODS_LENGOW = array(
84
+ 'getListingFeeds' => array('service' => 'solution'),
85
+ 'updateFeed' => array('service' => 'solution'),
86
+ 'getHistoryFeed' => array('service' => 'solution'),
87
+ 'updateInformationsClient' => array('service' => 'solution'),
88
+ 'getListingGroups' => array('service' => 'solution'),
89
+ 'createGroup' => array('service' => 'solution'),
90
+ 'updateGroup' => array('service' => 'solution'),
91
+ 'getListingVip' => array('service' => 'solution'),
92
+ 'createVip' => array('service' => 'solution'),
93
+ 'updateVip' => array('service' => 'solution'),
94
+ 'getLeads' => array('service' => 'solution'),
95
+ 'statusLead' => array('service' => 'solution'),
96
+ 'updatePrestaInternalOrderId' => array('service' => 'solution'),
97
+ 'updateTrackingMagento' => array('service' => 'solution'),
98
+ 'updateRootFeed' => array('service' => 'solution'),
99
+ 'getRootFeed' => array('service' => 'solution'),
100
+ 'updateEcommerceSolution' => array('service' => 'solution'),
101
+ 'getInternalOrderId' => array('service' => 'solution'),
102
+ 'statistics' => array('service' => 'statistics'),
103
+ 'commands' => array('service' => 'api'),
104
+ );
105
+
106
+ /**
107
+ * Lengow token.
108
+ */
109
+ public $token;
110
+
111
+ /**
112
+ * Lengow ID customer.
113
+ */
114
+ public $id_customer;
115
+
116
+ /**
117
+ * Make a new Lengow API Connector.
118
+ *
119
+ * @param integer $id_customer Your customer ID.
120
+ * @param string $token Your token Lengow API.
121
+ *
122
+ * @return boolean
123
+ */
124
+ public function init($id_customer, $token)
125
+ {
126
+ try {
127
+ if (is_integer($id_customer)) {
128
+ $this->id_customer = $id_customer;
129
+ } else {
130
+ throw new Lengow_Sync_Model_Connector_Exception('Error Lengow Customer ID', 1);
131
+ }
132
+ if (strlen($token) > 10) {
133
+ $this->token = $token;
134
+ } else {
135
+ throw new Lengow_Sync_Model_Connector_Exception('Error Lengow Token API', 2);
136
+ }
137
+ } catch (Lengow_Sync_Model_Connector_Exception $e) {
138
+ $this->error = $e;
139
+ return false;
140
+ }
141
+ return true;
142
+ }
143
+
144
+ /**
145
+ * The API method.
146
+ *
147
+ * @param varchar $method Lengow method API call.
148
+ * @param varchar $array Lengow method API parameters
149
+ *
150
+ * @return array The formated data response
151
+ */
152
+ public function api($method, $array)
153
+ {
154
+ try {
155
+ if (!$api = $this->_getMethod($method)) {
156
+ throw new Lengow_Sync_Model_Connector_Exception('Error unknow method API', 3);
157
+ } else {
158
+ $data = $this->_callAction($api['service'], $method, $array);
159
+ }
160
+ } catch (Lengow_Sync_Model_Connector_Exception $e) {
161
+ return $e->getMessage();
162
+ }
163
+ return $data;
164
+ }
165
+
166
+ /**
167
+ * Call the Lengow service with accepted method.
168
+ *
169
+ * @param varchar $service Lengow service name
170
+ * @param varchar $method Lengow method API call.
171
+ * @param varchar $array Lengow method API parameters
172
+ *
173
+ * @return array The formated data response
174
+ */
175
+ private function _callAction($service, $method, $array)
176
+ {
177
+ switch ($service) {
178
+ case 'solution':
179
+ $url = $this->_getUrlService($service, $method, $array);
180
+ break;
181
+ case 'api':
182
+ $url = $this->_getUrlOrders($service, $array);
183
+ break;
184
+ case 'statistics':
185
+ $url = $this->_getUrlStatistics($service, $array);
186
+ break;
187
+ }
188
+ $result = $this->_makeRequest($url);
189
+ return $this->_format($result, self::$DOMAIN_LENGOW[$service]['format']);
190
+ }
191
+
192
+ /**
193
+ * Makes the Service API Url.
194
+ *
195
+ * @param string $service The URL to make the request to
196
+ * @param string $array The array of query parameters
197
+ *
198
+ * @return string The url
199
+ */
200
+ private function _getUrlService($service, $method, $array)
201
+ {
202
+ $url = self::$DOMAIN_LENGOW[$service]['protocol']
203
+ . '://'
204
+ . self::$DOMAIN_LENGOW[$service]['url']
205
+ . '/wsdl/connector/call.json?'
206
+ . 'token=' . $this->token
207
+ . '&idClient=' . $this->id_customer
208
+ . '&method=' . $method
209
+ . '&array=' . urlencode(serialize($array));
210
+ return $url;
211
+ }
212
+
213
+ /**
214
+ * Makes the Orders API Url.
215
+ *
216
+ * @param string $service The URL to make the request to
217
+ * @param string $array The array of query parameters
218
+ *
219
+ * @return string The url
220
+ */
221
+ private function _getUrlOrders($service, $array)
222
+ {
223
+ $url = self::$DOMAIN_LENGOW[$service]['protocol']
224
+ . '://'
225
+ . self::$DOMAIN_LENGOW[$service]['url'] . '/'
226
+ . 'v2/'
227
+ . $array['dateFrom'] . '/'
228
+ . $array['dateTo'] . '/'
229
+ . $this->id_customer . '/'
230
+ . $array['id_group'] . '/'
231
+ . (isset($array['id']) && !empty($array['id']) ? $array['id'] : 'orders')
232
+ . '/commands/'
233
+ . (isset($array['state']) && !empty($array['state']) ? $array['state'] . '/' : '');
234
+ return $url;
235
+ }
236
+
237
+ /**
238
+ * Makes the Statisctics API Url.
239
+ *
240
+ * @param string $service The URL to make the request to
241
+ * @param string $array The array of query parameters
242
+ *
243
+ * @return string The url
244
+ */
245
+ private function _getUrlStatistics($service, $array)
246
+ {
247
+ $url = self::$DOMAIN_LENGOW[$service]['protocol']
248
+ . '://'
249
+ . self::$DOMAIN_LENGOW[$service]['url']
250
+ . $array['dateFrom'] . '/'
251
+ . $array['dateTo'] . '/'
252
+ . $this->id_customer . '/'
253
+ . $array['id']
254
+ . '/total-All/';
255
+ return $url;
256
+ }
257
+
258
+ /**
259
+ * Get the method of Lengow API if exist.
260
+ *
261
+ * @param string $method The method's name
262
+ *
263
+ * @return string The method with service
264
+ */
265
+ private function _getMethod($method)
266
+ {
267
+ if (self::$API_METHODS_LENGOW[$method]) {
268
+ return self::$API_METHODS_LENGOW[$method];
269
+ } else {
270
+ return false;
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Format data with good format.
276
+ *
277
+ * @param string $data the data's response of method request
278
+ * @param string $format the return format
279
+ *
280
+ * @return string Data formated
281
+ */
282
+ private function _format($data, $format)
283
+ {
284
+ switch ($format) {
285
+ case 'xml' :
286
+ return simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
287
+ case 'json' :
288
+ return json_decode($data, true);
289
+ }
290
+ return null;
291
+ }
292
+
293
+ /**
294
+ * Makes an HTTP request.
295
+ *
296
+ * @param string $url The URL to make the request to
297
+ *
298
+ * @return string The response text
299
+ */
300
+ protected function _makeRequest($url)
301
+ {
302
+ Mage::helper('lensync/data')->log('Connector ' . $url);
303
+ $ch = curl_init();
304
+ // Options
305
+ $opts = self::$CURL_OPTS;
306
+ $opts[CURLOPT_URL] = $url;
307
+ // Exectute url request
308
+ curl_setopt_array($ch, $opts);
309
+ $result = curl_exec($ch);
310
+ if ($result === false) {
311
+ Mage::helper('lensync/data')->log('Connector Error (' . curl_error($ch) . ')' . $result);
312
+ throw new Lengow_Sync_Model_Connector_Exception(
313
+ array(
314
+ 'message' => curl_error($ch),
315
+ 'type' => 'CurlException',
316
+ ),
317
+ curl_errno($ch)
318
+ );
319
+ }
320
+ curl_close($ch);
321
+ return $result;
322
+ }
323
+ }
app/code/community/Lengow/Sync/Model/Customer/Customer.php CHANGED
@@ -1,33 +1,41 @@
1
  <?php
 
2
  /**
3
- * Lengow sync model customer
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer {
 
12
 
13
  /**
14
- * Convert xml node to customer model
15
  *
16
- * @param $xml_node SimpleXMLElement
 
 
17
  */
18
- public function setFromNode(SimpleXMLElement $xml_node, $config)
19
  {
20
  $id_store = $config->getStore()->getStoreId();
21
  $id_website = Mage::getModel('core/store')->load($id_store)->getWebsiteId();
22
- $array = Mage::helper('lensync')->xmlToAssoc($xml_node);
23
- if(empty($array['billing_address']['billing_email']) || $config->isDebugMode() || $config->get('orders/fake_email'))
24
- $array['billing_address']['billing_email'] = $array['order_id'] . '-' . $array['marketplace'] . '@lengow.com';
25
-
 
 
 
 
26
  // first get by email
27
  $this->setWebsiteId($id_website)
28
- ->loadByEmail($array['billing_address']['billing_email']);
29
 
30
- if(!$this->getId()) {
31
  $this->setImportMode(true);
32
  $this->setWebsiteId($id_website);
33
  $this->setConfirmation(null);
@@ -38,29 +46,32 @@ class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer {
38
 
39
  // Billing address
40
  $temp_names = array(
41
- 'firstname' => $array['billing_address']['billing_firstname'],
42
- 'lastname' => $array['billing_address']['billing_lastname'],
43
- );
 
44
  $billing_names = self::getNames($temp_names, $config->get('orders/split_name'));
45
- $array['billing_address']['billing_firstname'] = $billing_names['firstname'];
46
- $array['billing_address']['billing_lastname'] = $billing_names['lastname'];
47
  $billing_address = $this->convertAddress($array['billing_address']);
48
  $this->addAddress($billing_address);
49
 
50
  // Shipping address
51
  $temp_names = array(
52
- 'firstname' => $array['delivery_address']['delivery_firstname'],
53
- 'lastname' => $array['delivery_address']['delivery_lastname'],
54
- );
55
- $billing_names = self::getNames($temp_names, $config->get('orders/split_name'));
56
- $array['delivery_address']['delivery_firstname'] = $billing_names['firstname'];
57
- $array['delivery_address']['delivery_lastname'] = $billing_names['lastname'];
 
58
 
59
- if ($array['tracking_informations']['tracking_relay'] != '')
60
- $array['delivery_address']['tracking_relay'] = $array['tracking_informations']['tracking_relay'];
 
61
  $shipping_address = $this->convertAddress($array['delivery_address'], 'shipping');
62
  $this->addAddress($shipping_address);
63
- Mage::helper('core')->copyFieldset('lengow_convert_billing_address', 'to_customer', $array['billing_address'], $this);
64
 
65
  // set group
66
  $this->setGroupId($config->get('orders/customer_group'));
@@ -70,11 +81,11 @@ class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer {
70
  }
71
 
72
  /**
73
- * Convert xml node to customer address model
 
 
 
74
  *
75
- * @param array $data
76
- * @param string $type
77
- *
78
  * @return Mage_Customer_Model_Address
79
  */
80
  public function convertAddress(array $data, $type = 'billing')
@@ -83,47 +94,52 @@ class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer {
83
  $address->setId(null);
84
  $address->setIsDefaultBilling(true);
85
  $address->setIsDefaultShipping(false);
86
- if($type == 'shipping') {
87
  $address->setIsDefaultBilling(false);
88
  $address->setIsDefaultShipping(true);
89
  }
90
- Mage::helper('core')->copyFieldset('lengow_convert_' . $type . '_address', 'to_' . $type . '_address', $data, $address);
91
- if($type == 'shipping')
92
- $type = 'delivery';
93
- $address_1 = $data[$type . '_address'];
94
- $address_2 = $data[$type . '_address_2'];
95
  // Fix address 1
96
- if(empty($address_1) && !empty($address_2)) {
97
  $address_1 = $address_2;
98
  $address_2 = null;
99
  }
100
  // Fix address 2
101
- if(!empty($address_2))
102
  $address_1 = $address_1 . "\n" . $address_2;
103
- $address_3 = $data[$type . '_address_complement'];
104
- if(!empty($address_3))
 
105
  $address_1 = $address_1 . "\n" . $address_3;
 
106
  // adding relay to address
107
- if (isset($data['tracking_relay']))
108
  $address_1 .= ' - Relay : ' . $data['tracking_relay'];
 
109
  $address->setStreet($address_1);
110
- $tel_1 = $data[$type . '_phone_office'];
111
- $tel_2 = $data[$type . '_phone_mobile'];
112
  // Fix tel
113
  $tel_1 = empty($tel_1) ? $tel_2 : $tel_1;
114
 
115
- if (!empty($tel_1))
116
  $this->setTelephone($tel_1);
117
- if(!empty($tel_1))
 
118
  $address->setFax($tel_1);
119
- else if(!empty($tel_2))
120
- $address->setFax($tel_2);
121
- $codeRegion = (integer) substr(str_pad($address->getPostcode(), 5, '0', STR_PAD_LEFT), 0, 2);
 
 
 
122
  $id_region = Mage::getModel('directory/region')->getCollection()
123
- ->addRegionCodeFilter($codeRegion)
124
- ->addCountryFilter($address->getCountry())
125
- ->getFirstItem()
126
- ->getId();
127
  $address->setRegionId($id_region);
128
  $address->setCustomer($this);
129
  return $address;
@@ -132,30 +148,38 @@ class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer {
132
  /**
133
  * Check if firstname or lastname are empty
134
  *
135
- * @param array $array
136
  * @param boolean $split
137
- *
138
  * @return array
139
  */
140
  protected static function getNames($array, $split)
141
  {
142
- if(empty($array['firstname'])) {
143
  if (!empty($array['lastname'])) {
144
- if ($split)
145
  $array = self::splitNames($array['lastname']);
 
146
  }
147
  }
148
  if (empty($array['lastname'])) {
149
  if (!empty($array['firstname'])) {
150
- if ($split)
151
  $array = self::splitNames($array['firstname']);
 
152
  }
153
  }
154
- if (empty($array['lastname']))
 
 
 
 
155
  $array['lastname'] = '__';
 
156
  if (empty($array['firstname'])) {
157
- $array['firstname'] = '__';
158
  }
 
159
  return $array;
160
  }
161
 
@@ -163,18 +187,19 @@ class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer {
163
  * Split fullname
164
  *
165
  * @param string $fullname
166
- *
167
  * @return array
168
  */
169
  protected static function splitNames($fullname)
170
  {
171
  $split = explode(' ', $fullname);
172
- if($split && count($split)) {
173
  $names['firstname'] = $split[0];
174
  $names['lastname'] = '';
175
- for ($i=1; $i<count($split); $i++) {
176
- if(!empty($names['lastname']))
177
- $names['lastname'] .= ' ';
 
178
 
179
  $names['lastname'] .= $split[$i];
180
  }
@@ -184,5 +209,4 @@ class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer {
184
  }
185
  return $names;
186
  }
187
-
188
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync model customer customer
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Customer_Customer extends Mage_Customer_Model_Customer
13
+ {
14
 
15
  /**
16
+ * Convert array to customer model
17
  *
18
+ * @param object $order_data
19
+ * @param array $shipping_address
20
+ * @param Lengow_Sync_Model_Config $config
21
  */
22
+ public function setFromNode($order_data, $shipping_address, $config)
23
  {
24
  $id_store = $config->getStore()->getStoreId();
25
  $id_website = Mage::getModel('core/store')->load($id_store)->getWebsiteId();
26
+ $array = array(
27
+ 'billing_address' => Mage::helper('lensync')->xmlToAssoc($order_data->billing_address),
28
+ 'delivery_address' => Mage::helper('lensync')->xmlToAssoc($shipping_address)
29
+ );
30
+ if (empty($array['billing_address']['email']) || $config->isDebugMode() || $config->get('orders/fake_email')) {
31
+ $array['billing_address']['email'] = $order_data->marketplace_order_id . '-' . $order_data->marketplace . '@lengow.com';
32
+ }
33
+
34
  // first get by email
35
  $this->setWebsiteId($id_website)
36
+ ->loadByEmail($array['billing_address']['email']);
37
 
38
+ if (!$this->getId()) {
39
  $this->setImportMode(true);
40
  $this->setWebsiteId($id_website);
41
  $this->setConfirmation(null);
46
 
47
  // Billing address
48
  $temp_names = array(
49
+ 'firstname' => $array['billing_address']['first_name'],
50
+ 'lastname' => $array['billing_address']['last_name'],
51
+ 'fullname' => $array['billing_address']['full_name']
52
+ );
53
  $billing_names = self::getNames($temp_names, $config->get('orders/split_name'));
54
+ $array['billing_address']['first_name'] = $billing_names['firstname'];
55
+ $array['billing_address']['last_name'] = $billing_names['lastname'];
56
  $billing_address = $this->convertAddress($array['billing_address']);
57
  $this->addAddress($billing_address);
58
 
59
  // Shipping address
60
  $temp_names = array(
61
+ 'firstname' => $array['delivery_address']['first_name'],
62
+ 'lastname' => $array['delivery_address']['last_name'],
63
+ 'fullname' => $array['delivery_address']['full_name']
64
+ );
65
+ $shipping_names = self::getNames($temp_names, $config->get('orders/split_name'));
66
+ $array['delivery_address']['first_name'] = $shipping_names['firstname'];
67
+ $array['delivery_address']['last_name'] = $shipping_names['lastname'];
68
 
69
+ if (count($shipping_address->trackings) > 0 && !is_null($shipping_address->trackings[0]->relay->id)) {
70
+ $array['delivery_address']['tracking_relay'] = $shipping_address->trackings[0]->relay->id;
71
+ }
72
  $shipping_address = $this->convertAddress($array['delivery_address'], 'shipping');
73
  $this->addAddress($shipping_address);
74
+ Mage::helper('core')->copyFieldset('lengow_convert_address', 'to_customer', $array['billing_address'], $this);
75
 
76
  // set group
77
  $this->setGroupId($config->get('orders/customer_group'));
81
  }
82
 
83
  /**
84
+ * Convert a array to customer address model
85
+ *
86
+ * @param array $data
87
+ * @param string $type
88
  *
 
 
 
89
  * @return Mage_Customer_Model_Address
90
  */
91
  public function convertAddress(array $data, $type = 'billing')
94
  $address->setId(null);
95
  $address->setIsDefaultBilling(true);
96
  $address->setIsDefaultShipping(false);
97
+ if ($type == 'shipping') {
98
  $address->setIsDefaultBilling(false);
99
  $address->setIsDefaultShipping(true);
100
  }
101
+ Mage::helper('core')->copyFieldset('lengow_convert_address', 'to_' . $type . '_address', $data, $address);
102
+ $address_1 = $data['first_line'];
103
+ $address_2 = $data['second_line'];
 
 
104
  // Fix address 1
105
+ if (empty($address_1) && !empty($address_2)) {
106
  $address_1 = $address_2;
107
  $address_2 = null;
108
  }
109
  // Fix address 2
110
+ if (!empty($address_2)) {
111
  $address_1 = $address_1 . "\n" . $address_2;
112
+ }
113
+ $address_3 = $data['complement'];
114
+ if (!empty($address_3)) {
115
  $address_1 = $address_1 . "\n" . $address_3;
116
+ }
117
  // adding relay to address
118
+ if (isset($data['tracking_relay'])) {
119
  $address_1 .= ' - Relay : ' . $data['tracking_relay'];
120
+ }
121
  $address->setStreet($address_1);
122
+ $tel_1 = $data['phone_office'];
123
+ $tel_2 = $data['phone_mobile'];
124
  // Fix tel
125
  $tel_1 = empty($tel_1) ? $tel_2 : $tel_1;
126
 
127
+ if (!empty($tel_1)) {
128
  $this->setTelephone($tel_1);
129
+ }
130
+ if (!empty($tel_1)) {
131
  $address->setFax($tel_1);
132
+ } else {
133
+ if (!empty($tel_2)) {
134
+ $address->setFax($tel_2);
135
+ }
136
+ }
137
+ $codeRegion = substr(str_pad($address->getPostcode(), 5, '0', STR_PAD_LEFT), 0, 2);
138
  $id_region = Mage::getModel('directory/region')->getCollection()
139
+ ->addRegionCodeFilter($codeRegion)
140
+ ->addCountryFilter($address->getCountry())
141
+ ->getFirstItem()
142
+ ->getId();
143
  $address->setRegionId($id_region);
144
  $address->setCustomer($this);
145
  return $address;
148
  /**
149
  * Check if firstname or lastname are empty
150
  *
151
+ * @param array $array
152
  * @param boolean $split
153
+ *
154
  * @return array
155
  */
156
  protected static function getNames($array, $split)
157
  {
158
+ if (empty($array['firstname'])) {
159
  if (!empty($array['lastname'])) {
160
+ if ($split) {
161
  $array = self::splitNames($array['lastname']);
162
+ }
163
  }
164
  }
165
  if (empty($array['lastname'])) {
166
  if (!empty($array['firstname'])) {
167
+ if ($split) {
168
  $array = self::splitNames($array['firstname']);
169
+ }
170
  }
171
  }
172
+ // check full name if last_name and first_name are empty
173
+ if (empty($array['lastname']) && empty($array['firstname'])) {
174
+ $array = self::splitNames($array['fullname']);
175
+ }
176
+ if (empty($array['lastname'])) {
177
  $array['lastname'] = '__';
178
+ }
179
  if (empty($array['firstname'])) {
180
+ $array['firstname'] == '__';
181
  }
182
+
183
  return $array;
184
  }
185
 
187
  * Split fullname
188
  *
189
  * @param string $fullname
190
+ *
191
  * @return array
192
  */
193
  protected static function splitNames($fullname)
194
  {
195
  $split = explode(' ', $fullname);
196
+ if ($split && count($split)) {
197
  $names['firstname'] = $split[0];
198
  $names['lastname'] = '';
199
+ for ($i = 1; $i < count($split); $i++) {
200
+ if (!empty($names['lastname'])) {
201
+ $names['lastname'] .= ' ';
202
+ }
203
 
204
  $names['lastname'] .= $split[$i];
205
  }
209
  }
210
  return $names;
211
  }
212
+ }
 
app/code/community/Lengow/Sync/Model/Customer/Customerv2.php ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow sync model customer
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Model_Customer_Customerv2 extends Mage_Customer_Model_Customer
13
+ {
14
+
15
+ /**
16
+ * Convert xml node to customer model
17
+ *
18
+ * @param $xml_node SimpleXMLElement
19
+ */
20
+ public function setFromNode(SimpleXMLElement $xml_node, $config)
21
+ {
22
+ $id_store = $config->getStore()->getStoreId();
23
+ $id_website = Mage::getModel('core/store')->load($id_store)->getWebsiteId();
24
+ $array = Mage::helper('lensync')->xmlToAssoc($xml_node);
25
+ if (empty($array['billing_address']['billing_email']) || $config->isDebugMode() || $config->get('orders/fake_email')) {
26
+ $array['billing_address']['billing_email'] = $array['order_id'] . '-' . $array['marketplace'] . '@lengow.com';
27
+ }
28
+
29
+ // first get by email
30
+ $this->setWebsiteId($id_website)
31
+ ->loadByEmail($array['billing_address']['billing_email']);
32
+
33
+ if (!$this->getId()) {
34
+ $this->setImportMode(true);
35
+ $this->setWebsiteId($id_website);
36
+ $this->setConfirmation(null);
37
+ $this->setForceConfirmed(true);
38
+ $this->setPasswordHash($this->hashPassword($this->generatePassword(8)));
39
+ $this->setFromLengow(1);
40
+ }
41
+
42
+ // Billing address
43
+ $temp_names = array(
44
+ 'firstname' => $array['billing_address']['billing_firstname'],
45
+ 'lastname' => $array['billing_address']['billing_lastname'],
46
+ );
47
+ $billing_names = self::getNames($temp_names, $config->get('orders/split_name'));
48
+ $array['billing_address']['billing_firstname'] = $billing_names['firstname'];
49
+ $array['billing_address']['billing_lastname'] = $billing_names['lastname'];
50
+ $billing_address = $this->convertAddress($array['billing_address']);
51
+ $this->addAddress($billing_address);
52
+
53
+ // Shipping address
54
+ $temp_names = array(
55
+ 'firstname' => $array['delivery_address']['delivery_firstname'],
56
+ 'lastname' => $array['delivery_address']['delivery_lastname'],
57
+ );
58
+ $billing_names = self::getNames($temp_names, $config->get('orders/split_name'));
59
+ $array['delivery_address']['delivery_firstname'] = $billing_names['firstname'];
60
+ $array['delivery_address']['delivery_lastname'] = $billing_names['lastname'];
61
+
62
+ if ($array['tracking_informations']['tracking_relay'] != '') {
63
+ $array['delivery_address']['tracking_relay'] = $array['tracking_informations']['tracking_relay'];
64
+ }
65
+ $shipping_address = $this->convertAddress($array['delivery_address'], 'shipping');
66
+ $this->addAddress($shipping_address);
67
+ Mage::helper('core')->copyFieldset('lengow_convert_billing_address', 'to_customer', $array['billing_address'],
68
+ $this);
69
+
70
+ // set group
71
+ $this->setGroupId($config->get('orders/customer_group'));
72
+
73
+ $this->save();
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * Convert xml node to customer address model
79
+ *
80
+ * @param array $data
81
+ * @param string $type
82
+ *
83
+ * @return Mage_Customer_Model_Address
84
+ */
85
+ public function convertAddress(array $data, $type = 'billing')
86
+ {
87
+ $address = Mage::getModel('customer/address');
88
+ $address->setId(null);
89
+ $address->setIsDefaultBilling(true);
90
+ $address->setIsDefaultShipping(false);
91
+ if ($type == 'shipping') {
92
+ $address->setIsDefaultBilling(false);
93
+ $address->setIsDefaultShipping(true);
94
+ }
95
+ Mage::helper('core')->copyFieldset('lengow_convert_' . $type . '_address', 'to_' . $type . '_address', $data,
96
+ $address);
97
+ if ($type == 'shipping') {
98
+ $type = 'delivery';
99
+ }
100
+ $address_1 = $data[$type . '_address'];
101
+ $address_2 = $data[$type . '_address_2'];
102
+ // Fix address 1
103
+ if (empty($address_1) && !empty($address_2)) {
104
+ $address_1 = $address_2;
105
+ $address_2 = null;
106
+ }
107
+ // Fix address 2
108
+ if (!empty($address_2)) {
109
+ $address_1 = $address_1 . "\n" . $address_2;
110
+ }
111
+ $address_3 = $data[$type . '_address_complement'];
112
+ if (!empty($address_3)) {
113
+ $address_1 = $address_1 . "\n" . $address_3;
114
+ }
115
+ // adding relay to address
116
+ if (isset($data['tracking_relay'])) {
117
+ $address_1 .= ' - Relay : ' . $data['tracking_relay'];
118
+ }
119
+ $address->setStreet($address_1);
120
+ $tel_1 = $data[$type . '_phone_office'];
121
+ $tel_2 = $data[$type . '_phone_mobile'];
122
+ // Fix tel
123
+ $tel_1 = empty($tel_1) ? $tel_2 : $tel_1;
124
+
125
+ if (!empty($tel_1)) {
126
+ $this->setTelephone($tel_1);
127
+ }
128
+ if (!empty($tel_1)) {
129
+ $address->setFax($tel_1);
130
+ } else {
131
+ if (!empty($tel_2)) {
132
+ $address->setFax($tel_2);
133
+ }
134
+ }
135
+ $codeRegion = (integer)substr(str_pad($address->getPostcode(), 5, '0', STR_PAD_LEFT), 0, 2);
136
+ $id_region = Mage::getModel('directory/region')->getCollection()
137
+ ->addRegionCodeFilter($codeRegion)
138
+ ->addCountryFilter($address->getCountry())
139
+ ->getFirstItem()
140
+ ->getId();
141
+ $address->setRegionId($id_region);
142
+ $address->setCustomer($this);
143
+ return $address;
144
+ }
145
+
146
+ /**
147
+ * Check if firstname or lastname are empty
148
+ *
149
+ * @param array $array
150
+ * @param boolean $split
151
+ *
152
+ * @return array
153
+ */
154
+ protected static function getNames($array, $split)
155
+ {
156
+ if (empty($array['firstname'])) {
157
+ if (!empty($array['lastname'])) {
158
+ if ($split) {
159
+ $array = self::splitNames($array['lastname']);
160
+ }
161
+ }
162
+ }
163
+ if (empty($array['lastname'])) {
164
+ if (!empty($array['firstname'])) {
165
+ if ($split) {
166
+ $array = self::splitNames($array['firstname']);
167
+ }
168
+ }
169
+ }
170
+ if (empty($array['lastname'])) {
171
+ $array['lastname'] = '__';
172
+ }
173
+ if (empty($array['firstname'])) {
174
+ $array['firstname'] = '__';
175
+ }
176
+ return $array;
177
+ }
178
+
179
+ /**
180
+ * Split fullname
181
+ *
182
+ * @param string $fullname
183
+ *
184
+ * @return array
185
+ */
186
+ protected static function splitNames($fullname)
187
+ {
188
+ $split = explode(' ', $fullname);
189
+ if ($split && count($split)) {
190
+ $names['firstname'] = $split[0];
191
+ $names['lastname'] = '';
192
+ for ($i = 1; $i < count($split); $i++) {
193
+ if (!empty($names['lastname'])) {
194
+ $names['lastname'] .= ' ';
195
+ }
196
+
197
+ $names['lastname'] .= $split[$i];
198
+ }
199
+ } else {
200
+ $names['firstname'] = '__';
201
+ $names['lastname'] = empty($fullname) ? '__' : $fullname;
202
+ }
203
+ return $names;
204
+ }
205
+ }
app/code/community/Lengow/Sync/Model/File.php CHANGED
@@ -1,8 +1,16 @@
1
  <?php
2
-
3
- class Lengow_Sync_Model_File extends Varien_Io_File
4
- {
5
- /**
 
 
 
 
 
 
 
 
6
  * Override adding the LOCK_NB option
7
  * @param bool $exclusive
8
  * @return bool
@@ -24,4 +32,4 @@ class Lengow_Sync_Model_File extends Varien_Io_File
24
  }
25
  return ftruncate($this->_streamHandler, 0);
26
  }
27
- }
1
  <?php
2
+ /**
3
+ * Lengow Sync model file
4
+ *
5
+ * @category Lengow
6
+ * @package Lengow_Sync
7
+ * @author Team Connector <team-connector@lengow.com>
8
+ * @copyright 2016 Lengow SAS
9
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
+ */
11
+ class Lengow_Sync_Model_File extends Varien_Io_File {
12
+
13
+ /**
14
  * Override adding the LOCK_NB option
15
  * @param bool $exclusive
16
  * @return bool
32
  }
33
  return ftruncate($this->_streamHandler, 0);
34
  }
35
+ }
app/code/community/Lengow/Sync/Model/Import.php CHANGED
@@ -5,11 +5,12 @@
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
- * @copyright 2015 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Sync_Model_Import extends Varien_Object {
 
13
 
14
  /**
15
  * @var Mage_Sales_Model_Quote
@@ -30,7 +31,7 @@ class Lengow_Sync_Model_Import extends Varien_Object {
30
  protected $_resultSendOrder = "";
31
 
32
  protected $_isUnderVersion14 = null;
33
-
34
  /**
35
  * Product model
36
  *
@@ -38,211 +39,391 @@ class Lengow_Sync_Model_Import extends Varien_Object {
38
  */
39
  protected $_productModel;
40
 
41
- protected $_connector;
42
-
43
  protected $_helper;
44
 
 
 
45
  public static $import_start = false;
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  protected $_dateFrom;
48
 
49
  protected $_dateTo;
50
 
51
  protected $_config;
52
 
53
- protected $_idCustomer;
54
 
55
- protected $_idGroup;
56
 
57
- protected $_apiToken;
58
 
59
  /**
60
- * Constructor
 
 
 
 
61
  */
62
  public function __construct($args)
63
  {
64
  parent::__construct();
65
- if(Mage::app()->getStore()->getCode() != 'admin')
66
  Mage::app()->setCurrentStore('admin');
67
-
68
- if (!is_array($args))
69
  return;
70
-
71
  foreach ($args as $key => $value) {
72
  $this->{'_'.$key} = $value;
73
  }
 
 
74
  $this->_helper = Mage::helper('lensync/data');
75
  return $this;
76
  }
77
 
78
  /**
79
  * Execute import process
 
 
80
  */
81
  public function exec()
82
  {
83
  self::$import_start = true;
84
  Mage::getSingleton('core/session')->setIsFromlengow('true');
85
  $orders = $this->getLengowOrders();
86
- if(!is_object($orders) || isset($orders->error)) {
87
- $error = (string) $orders->error;
88
- if (strtolower($error) == 'no way')
89
- $message = $this->_helper->__('API\'s connection refused with IP %s', (string) $orders->ip);
90
- $error = 'Error on lengow webservice ' . (isset($message) ? ': ' . $message : json_encode($orders));
91
- $this->_helper->log($error);
92
- return array('new' => 0, 'update' => 0, 'error' => $error);
93
- } else {
94
- $count_orders = count($orders->orders->order);
95
- if ($count_orders === 0) {
96
- $this->_helper->log(
97
- 'No orders to import between ' . $this->_dateFrom . ' and ' . $this->_dateTo,
98
- $this->force_log_output
99
- );
100
- return false;
101
- }
102
- $this->_helper->log($count_orders . ' order' . ($count_orders > 1 ? 's ' : ' ') . 'found');
103
  }
 
 
 
104
  return $this->importOrders($orders);
105
  }
106
 
107
  /**
108
  * Retrieve Lengow orders
109
- *
110
- * @return SimpleXmlElement list of orders to be imported
111
  */
112
  protected function getLengowOrders()
113
  {
114
- $this->_connector = Mage::getSingleton('lensync/connector');
115
- $this->_connector->init((integer) $this->_idCustomer, $this->_apiToken);
116
-
117
- if ($this->_connector->error)
118
- return $connector;
119
-
120
- return $this->_connector->api(
121
- 'commands',
122
- array(
123
- 'dateFrom' => $this->_dateFrom,
124
- 'dateTo' => $this->_dateTo,
125
- 'id_group' => $this->_idGroup,
126
- 'state' => 'plugin',
127
- )
128
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
 
131
  /**
132
- * Makes the Orders API Url and imports all orders
133
- *
134
- * @param SimpleXmlElement $orders List of orders to be imported
135
- *
136
- * @return array Number of new and update orders
137
- */
138
  protected function importOrders($orders)
139
  {
140
  $count_orders_updated = 0;
141
  $count_orders_added = 0;
142
-
143
- foreach($orders->orders->order as $key => $order_data) {
 
 
 
 
144
  $model_order = Mage::getModel('lensync/order');
145
  $model_order->setConfig($this->_config);
146
-
147
- $id_lengow_order = (string) $order_data->order_id;
148
-
149
- if($this->_config->isDebugMode())
150
  $id_lengow_order .= '--'.time();
151
-
152
  // check if order has a status
153
- $marketplace_status = (string) $order_data->order_status->marketplace;
154
  if (empty($marketplace_status)) {
155
  $this->_helper->log('no order\'s status', $id_lengow_order);
156
  continue;
157
  }
158
-
159
- // first check if not shipped by marketplace
160
- if ((integer) $order_data->tracking_informations->tracking_deliveringByMarketPlace == 1) {
161
- $this->_helper->log('delivery by marketplace (' . (string) $order_data->marketplace . ')', $id_lengow_order);
162
- continue;
163
- }
164
-
165
  // convert marketplace status to Lengow equivalent
166
- $marketplace = Mage::getModel('lensync/marketplace');
167
- $marketplace->set((string) $order_data->marketplace);
168
  $lengow_status = $marketplace->getStateLengow($marketplace_status);
169
-
170
- // check if order has already been imported
171
- $id_order = $model_order->isAlreadyImported($id_lengow_order, (integer) $order_data->idFlux);
172
- if ($id_order) {
173
- $order_imported = Mage::getModel('sales/order')->load($id_order);
174
- $this->_helper->log('already imported in Magento with order ID ' . $order_imported->getIncrementId(), $id_lengow_order);
175
- if ($model_order->updateState($order_imported, $lengow_status, $order_data))
176
- $count_orders_updated++;
177
- } else {
178
- // Import only process order or shipped order and not imported with previous module
179
- $id_order_magento = $this->_config->isDebugMode() ? null : (string) $order_data->order_external_id;
180
- if ($lengow_status == 'processing' || $lengow_status == 'shipped' && !$id_order_magento) {
181
-
182
- // Create or Update customer with addresses
183
- $customer = Mage::getModel('lensync/customer_customer');
184
- $customer->setFromNode($order_data, $this->_config);
185
-
186
- // rewrite order if processing fees not included
187
- if(!$this->_config->get('orders/processing_fee')) {
188
- $total_wt_proc_fees = (float) $order_data->order_amount - (float) $order_data->order_processing_fee;
189
- $order_data->order_amount = new SimpleXMLElement('<order_amount><![CDATA[' . ($total_wt_proc_fees) . ']]></order_amount>');
190
- $order_data->order_processing_fee = new SimpleXMLElement('<order_processing_fee><![CDATA[ ]]></order_processing_fee>');
191
- $this->_helper->log('rewrite amount without processing fee', $id_lengow_order);
192
- unset($total_wt_proc_fees);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
194
-
195
- try {
196
- $quote = $this->_createQuote($id_lengow_order, $order_data, $customer, $marketplace);
197
- } catch (Exception $e) {
198
- $this->_helper->log('create quote fail : ' . $e->getMessage(), $id_lengow_order);
199
- continue;
 
 
 
 
 
 
 
200
  }
201
- try {
202
- $order = $this->makeOrder($id_lengow_order, $order_data, $quote, $model_order, true);
203
- } catch (Exception $e) {
204
- $this->_helper->log('create order fail : ' . $e->getMessage(), $id_lengow_order);
205
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
- if($order) {
208
- // Sync to lengow
209
- if(!$this->_config->isDebugMode()) {
210
- $orders = $this->_connector->api('getInternalOrderId', array(
211
- 'idClient' => (integer) $this->_idCustomer,
212
- 'idFlux' => (integer) $order_data->idFlux,
213
- 'Marketplace' => (string) $order_data->marketplace,
214
- 'idCommandeMP' => $id_lengow_order,
215
- 'idCommandeMage' => $order->getId(),
216
- 'statutCommandeMP' => (string) $order_data->order_status->lengow,
217
- 'statutCommandeMage' => $order->getState(),
218
- 'idQuoteMage' => $quote->getId(),
219
- 'Message' => 'Import depuis: ' . (string) $order_data->marketplace . '<br/>idOrder: '.$id_lengow_order,
220
- 'type' => 'Magento'
221
- ));
222
- $this->_helper->log('order successfully synchronised with Lengow webservice (Order ' . $order->getIncrementId() . ')', $id_lengow_order);
223
  }
224
- $count_orders_added++;
225
- $this->_helper->log('order successfully imported (Order ' . $order->getIncrementId() . ')', $id_lengow_order);
226
- if($lengow_status == 'shipped') {
227
- $model_order->toShip($order,
228
- (string) $order_data->tracking_informations->tracking_carrier,
229
- (string) $order_data->tracking_informations->tracking_method,
230
- (string) $order_data->tracking_informations->tracking_number
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  );
232
- $this->_helper->log('update state to "shipped" (Order ' . $order->getIncrementId() . ')', $id_lengow_order);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
234
- unset($customer);
235
- unset($quote);
236
- unset($order);
237
  }
238
- } else {
239
- if($id_order_magento)
240
- $this->_helper->log('already imported in Magento with order ID ' . $id_order_magento, $id_lengow_order);
241
- else
242
- $this->_helper->log('order\'s status (' . $lengow_status . ') not available to import', $id_lengow_order);
243
  }
244
- unset($model_order);
245
  }
 
246
  }
247
  self::$import_start = false;
248
  // Clear session
@@ -251,88 +432,124 @@ class Lengow_Sync_Model_Import extends Varien_Object {
251
  }
252
 
253
  /**
254
- * Create quote
255
  *
256
- * @param string $id_lengow_order
257
- * @param SimpleXMLelement $order_data
258
- * @param Lengow_Sync_Model_Customer_Customer $customer
259
- * @param Lengow_Sync_Model_Marketplace $marketplace
260
  *
261
- * @return Lengow_Sync_Model_Quote
262
  */
263
- protected function _createQuote($id_lengow_order, SimpleXMLelement $order_data, Lengow_Sync_Model_Customer_Customer $customer, Lengow_Sync_Model_Marketplace $marketplace)
264
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  $quote = Mage::getModel('lensync/quote')
266
- ->setIsMultiShipping(false)
267
- ->setStore($this->_config->getStore())
268
- ->setIsSuperMode(true);
269
-
270
  // import customer addresses into quote
271
  // Set billing Address
272
  $customer_billing_address = Mage::getModel('customer/address')
273
- ->load($customer->getDefaultBilling());
274
  $billing_address = Mage::getModel('sales/quote_address')
275
- ->setShouldIgnoreValidation(true)
276
- ->importCustomerAddress($customer_billing_address)
277
- ->setSaveInAddressBook(0);
278
-
279
  // Set shipping Address
280
  $customer_shipping_address = Mage::getModel('customer/address')
281
- ->load($customer->getDefaultShipping());
282
  $shipping_address = Mage::getModel('sales/quote_address')
283
- ->setShouldIgnoreValidation(true)
284
- ->importCustomerAddress($customer_shipping_address)
285
- ->setSaveInAddressBook(0)
286
- ->setSameAsBilling(0);
287
  $quote->assignCustomerWithAddressChange($customer, $billing_address, $shipping_address);
288
-
289
  // check if store include tax (Product and shipping cost)
290
  $priceIncludeTax = Mage::helper('tax')->priceIncludesTax($quote->getStore());
291
  $shippingIncludeTax = Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore());
292
-
293
  // add product in quote
294
- $quote->addLengowProducts($order_data->cart->products->product, $marketplace, $id_lengow_order, $priceIncludeTax);
295
-
296
- // get shipping cost with tax
297
- $shipping_cost = (float) $order_data->order_processing_fee + (float) $order_data->order_shipping;
298
-
299
  // if shipping cost not include tax -> get shipping cost without tax
300
- if(!$shippingIncludeTax) {
301
  $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $quote->getStore());
302
- $country_id = ($basedOn == 'shipping') ? $shipping_address->getCountryId() : $billing_address->getCountryId();
303
- $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $quote->getStore());
 
 
 
 
 
304
  $taxCalculator = Mage::getModel('tax/calculation');
305
- $taxRequest = new Varien_Object();
306
  $taxRequest->setCountryId($country_id)
307
- ->setCustomerClassId($customer->getTaxClassId())
308
- ->setProductClassId($shippingTaxClass);
309
- $tax_rate = (float) $taxCalculator->getRate($taxRequest);
310
- $tax_shipping_cost = (float) $taxCalculator->calcTaxAmount($shipping_cost, $tax_rate, true);
311
  $shipping_cost = $shipping_cost - $tax_shipping_cost;
312
  }
313
-
314
- // get and update shipping rates for current order
315
- $rates = $quote->getShippingAddress()
316
- ->setCollectShippingRates(true)
317
- ->collectShippingRates()
318
- ->getShippingRatesCollection();
319
  $shipping_method = $this->updateRates($rates, $id_lengow_order, $shipping_cost);
320
-
321
- // set shipping price and shipping method for current order
322
  $quote->getShippingAddress()
323
- ->setShippingPrice($shipping_cost)
324
- ->setShippingMethod($shipping_method);
325
-
326
  // collect totals
327
  $quote->collectTotals();
328
-
329
  // Re-ajuste cents for item quote
330
  // Conversion Tax Include > Tax Exclude > Tax Include maybe make 0.01 amount error
331
  if (!$priceIncludeTax) {
332
- if($quote->getGrandTotal() != (float) $order_data->order_amount) {
333
  $quote_items = $quote->getAllItems();
334
  foreach ($quote_items as $item) {
335
- $row_total_lengow = (float) $quote->getRowTotalLengow((string) $item->getProduct()->getId());
336
  if ($row_total_lengow != $item->getRowTotalInclTax()) {
337
  $diff = $row_total_lengow - $item->getRowTotalInclTax();
338
  $item->setPriceInclTax($item->getPriceInclTax() + ($diff / $item->getQty()));
@@ -341,22 +558,20 @@ class Lengow_Sync_Model_Import extends Varien_Object {
341
  $item->setOriginalPrice($item->getPrice());
342
  $item->setRowTotal($item->getRowTotal() + $diff);
343
  $item->setBaseRowTotal($item->getRowTotal());
344
- $item->setRowTotalInclTax((float) $row_total_lengow);
345
  $item->setBaseRowTotalInclTax($item->getRowTotalInclTax());
346
  }
347
  }
348
  }
349
  }
350
-
351
  // set payment method lengow
352
  $quote->getPayment()
353
- ->importData(
354
  array(
355
- 'method' => 'lengow',
356
- 'marketplace' => (string) $order_data->marketplace . ' - ' . (string) $order_data->order_payment->payment_type,
357
- )
358
- );
359
-
360
  $quote->save();
361
  return $quote;
362
  }
@@ -364,79 +579,86 @@ class Lengow_Sync_Model_Import extends Varien_Object {
364
  /**
365
  * Create order
366
  *
367
- * @param string $id_lengow_order
368
- * @param SimpleXMLelement $order_data
369
- * @param Lengow_Sync_Model_Quote $quote
370
- * @param Lengow_Sync_Model_Order $model_order
371
- * @param boolean $invoice
372
- *
373
- * @return Mage_Sales_Model_Order
 
 
374
  */
375
- protected function makeOrder($id_lengow_order, SimpleXMLelement $order_data, Lengow_Sync_Model_Quote $quote, Mage_Sales_Model_Order $model_order, $invoice = true)
376
- {
 
 
 
 
 
 
 
377
  try {
378
- $additional_data = array('from_lengow' => true ,
379
- 'marketplace_lengow' => (string) $order_data->marketplace ,
380
- 'fees_lengow' => (float) $order_data->order_commission ,
381
- 'order_id_lengow' => $id_lengow_order ,
382
- 'feed_id_lengow' => (integer) $order_data->idFlux ,
383
- 'xml_node_lengow' => Mage::helper('Core')->jsonEncode($order_data) ,
384
- 'message_lengow' => (string) $order_data->order_comments ,
385
- 'total_paid_lengow' => (float) $order_data->order_amount ,
386
- 'carrier_lengow' => (string) $order_data->tracking_informations->tracking_carrier ,
387
- 'carrier_method_lengow' => (string) $order_data->tracking_informations->tracking_method ,
388
- 'carrier_tracking_lengow' => (string) $order_data->tracking_informations->tracking_number ,
389
- 'carrier_id_relay_lengow' => (string) $order_data->tracking_informations->tracking_relay ,
390
- 'global_currency_code' => (string) $order_data->order_currency ,
391
- 'base_currency_code' => (string) $order_data->order_currency ,
392
- 'store_currency_code' => (string) $order_data->order_currency ,
393
- 'order_currency_code' => (string) $order_data->order_currency ,
394
- );
395
-
 
 
 
396
  $service = Mage::getModel('sales/service_quote', $quote);
397
  $service->setOrderData($additional_data);
398
  $order = false;
399
- if(method_exists($service, 'submitAll')) {
400
  $service->submitAll();
401
  $order = $service->getOrder();
402
  } else {
403
  $order = $service->submit();
404
  }
405
- if (!$order)
406
  throw new Exception('service unable to create order based on given quote');
407
-
408
  $order->setIsFromLengow(true);
409
  // modify order dates to use actual dates
410
  if ($this->_config->get('orders/date_import')) {
411
- $date_mp = (string) $order_data->order_purchase_date . ' ' . (string) $order_data->order_purchase_heure;
412
- $server_timezone = date_default_timezone_get();
413
- date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
414
- $date_UTC = gmdate('Y-m-d H:i:s', strtotime($date_mp));
415
- date_default_timezone_set($server_timezone);
416
- $order->setCreatedAt($date_UTC);
417
- $order->setUpdatedAt($date_UTC);
418
  }
419
  $order->save();
420
-
421
  // Re-ajuste cents for total and shipping cost
422
- // Conversion Tax Include > Tax Exclude > Tax Include maybe make 0.01 amount error
423
  $priceIncludeTax = Mage::helper('tax')->priceIncludesTax($quote->getStore());
424
- $shippingIncludeTax = Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore());
425
  if (!$priceIncludeTax || !$shippingIncludeTax) {
426
- if($order->getGrandTotal() != (float) $order_data->order_amount) {
427
  // check Grand Total
428
- $diff = (((float) $order_data->order_amount) - $order->getGrandTotal());
429
- $order->setGrandTotal((float) $order_data->order_amount);
430
  $order->setBaseGrandTotal($order->getGrandTotal());
431
  // if the difference is only on the grand total, removing the difference of shipping cost
432
- if (($order->getSubtotalInclTax() + $order->getShippingInclTax()) == (float) $order_data->order_amount) {
433
  $order->setShippingAmount($order->getShippingAmount() + $diff);
434
  $order->setBaseShippingAmount($order->getShippingAmount());
435
  } else {
436
  // check Shipping Cost
437
  $diff_shipping = 0;
438
- $shipping_cost = (float) $order_data->order_processing_fee + (float) $order_data->order_shipping;
439
- if($order->getShippingInclTax() != (float) $shipping_cost) {
440
  $diff_shipping = ($shipping_cost - $order->getShippingInclTax());
441
  $order->setShippingAmount($order->getShippingAmount() + $diff_shipping);
442
  $order->setBaseShippingAmount($order->getShippingAmount());
@@ -452,20 +674,23 @@ class Lengow_Sync_Model_Import extends Varien_Object {
452
  }
453
  $order->save();
454
  }
455
-
456
  // generate invoice for order
457
  if ($invoice && $order->canInvoice()) {
458
  $model_order->toInvoice($order);
459
  }
460
-
461
- $carrier_name = (string) $order_data->tracking_informations->tracking_carrier;
462
- if ((string) $carrier_name === 'None' || $carrier_name == '')
463
- $carrier_name = (string) $order_data->tracking_informations->tracking_method;
464
- $order->setShippingDescription($order->getShippingDescription() . ' [marketplace shipping method : ' . $carrier_name . ']');
465
-
 
 
 
 
466
  $order->save();
467
- } catch (Exception $e){
468
- Mage::helper('lensync')->log('error create order : ' . $e->getMessage(), $id_lengow_order);
469
  }
470
  return $order;
471
  }
@@ -473,21 +698,25 @@ class Lengow_Sync_Model_Import extends Varien_Object {
473
  /**
474
  * Update Rates with shipping cost
475
  *
476
- * @param $rates
477
- * @param string $id_lengow_order
478
- * @param float $shipping_cost
479
- * @param string $shipping_method
480
- * @param boolean $first stop recursive effect
481
  *
482
  * @return boolean
483
  */
484
  protected function updateRates($rates, $id_lengow_order, $shipping_cost, $shipping_method = null, $first = true)
485
  {
486
- if (!$shipping_method)
487
  $shipping_method = $this->_config->get('orders/default_shipping');
 
 
 
 
488
  foreach ($rates as &$rate) {
489
  // make sure the chosen shipping method is correct
490
- if ($rate->getCode() == $shipping_method) {
491
  if ($rate->getPrice() != $shipping_cost) {
492
  $rate->setPrice($shipping_cost);
493
  $rate->setCost($shipping_cost);
@@ -496,10 +725,32 @@ class Lengow_Sync_Model_Import extends Varien_Object {
496
  }
497
  }
498
  // stop recursive effect
499
- if (!$first)
500
  return 'lengow_lengow';
 
501
  // get lengow shipping method if selected shipping method is unavailable
502
- $this->_helper->log('the selected shipping method is unavailable for current order. Lengow shipping method assigned.', $id_lengow_order);
 
 
 
503
  return $this->updateRates($rates, $id_lengow_order, $shipping_cost, 'lengow_lengow', false);
504
  }
505
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Import extends Varien_Object
13
+ {
14
 
15
  /**
16
  * @var Mage_Sales_Model_Quote
31
  protected $_resultSendOrder = "";
32
 
33
  protected $_isUnderVersion14 = null;
34
+
35
  /**
36
  * Product model
37
  *
39
  */
40
  protected $_productModel;
41
 
 
 
42
  protected $_helper;
43
 
44
+ protected $_connector;
45
+
46
  public static $import_start = false;
47
 
48
+ /**
49
+ * @var array states lengow to import
50
+ */
51
+ public static $STATES_LENGOW = array(
52
+ 'accepted',
53
+ 'waiting_shipment',
54
+ 'shipped',
55
+ 'closed',
56
+ );
57
+
58
+ protected $_debugMode;
59
+
60
  protected $_dateFrom;
61
 
62
  protected $_dateTo;
63
 
64
  protected $_config;
65
 
66
+ protected $_idAccount;
67
 
68
+ protected $_accessToken;
69
 
70
+ protected $_secret;
71
 
72
  /**
73
+ * Construct
74
+ *
75
+ * @param array $args
76
+ *
77
+ * @return Lengow_Sync_Model_Import
78
  */
79
  public function __construct($args)
80
  {
81
  parent::__construct();
82
+ if (Mage::app()->getStore()->getCode() != 'admin') {
83
  Mage::app()->setCurrentStore('admin');
84
+ }
85
+ if (!is_array($args)) {
86
  return;
87
+ }
88
  foreach ($args as $key => $value) {
89
  $this->{'_'.$key} = $value;
90
  }
91
+ $this->_connector = Mage::getModel('lensync/connector');
92
+ $this->_connector->init($this->_accessToken, $this->_secret);
93
  $this->_helper = Mage::helper('lensync/data');
94
  return $this;
95
  }
96
 
97
  /**
98
  * Execute import process
99
+ *
100
+ * @return array
101
  */
102
  public function exec()
103
  {
104
  self::$import_start = true;
105
  Mage::getSingleton('core/session')->setIsFromlengow('true');
106
  $orders = $this->getLengowOrders();
107
+ $count_orders = count($orders);
108
+ if ($count_orders === 0) {
109
+ $this->_helper->log(
110
+ 'No orders to import between '
111
+ .date('Y-m-d', strtotime((string)$this->_dateFrom))
112
+ .' and '
113
+ .date('Y-m-d', strtotime((string)$this->_dateTo))
114
+ );
115
+ return false;
 
 
 
 
 
 
 
 
116
  }
117
+ $this->_helper->log(
118
+ $count_orders.' order'.($count_orders > 1 ? 's ' : ' ').'found with account ID: '.$this->_idAccount
119
+ );
120
  return $this->importOrders($orders);
121
  }
122
 
123
  /**
124
  * Retrieve Lengow orders
125
+ *
126
+ * @return array list of orders to be imported
127
  */
128
  protected function getLengowOrders()
129
  {
130
+ $page = 1;
131
+ $orders = array();
132
+ if ($this->_connector->isValidAuth($this->_idAccount)) {
133
+ $this->_helper->log(
134
+ 'Connector: get orders between '.date('Y-m-d', strtotime((string)$this->_dateFrom))
135
+ .' and '.date('Y-m-d', strtotime((string)$this->_dateTo))
136
+ .' with account ID: '.$this->_idAccount
137
+ );
138
+ do {
139
+ if (defined('PHPUNIT_LENGOW_ACTIVE') === true) {
140
+ global $fileGetOrder;
141
+ $results = $fileGetOrder[$this->_idAccount];
142
+ } else {
143
+ $results = $this->_connector->get(
144
+ '/v3.0/orders',
145
+ array(
146
+ 'account_id' => $this->_idAccount,
147
+ 'updated_from' => $this->_dateFrom,
148
+ 'updated_to' => $this->_dateTo,
149
+ 'page' => $page
150
+ ),
151
+ 'stream'
152
+ );
153
+ }
154
+ if (is_null($results)) {
155
+ throw new Exception('the connection didn\'t work with the Lengow webservice');
156
+ }
157
+ $results = json_decode($results);
158
+ if (!is_object($results)) {
159
+ throw new Exception('the connection didn\'t work with the Lengow webservice');
160
+ }
161
+ if (isset($results->error)) {
162
+ throw new Exception(
163
+ 'Error on lengow webservice : '.$results->error->code.' - '.$results->error->message
164
+ );
165
+ }
166
+ // Construct array orders
167
+ foreach ($results->results as $order) {
168
+ $orders[] = $order;
169
+ }
170
+ $page++;
171
+ } while ($results->next != null);
172
+ } else {
173
+ throw new Exception('Account ID, Token access or Secret are not valid');
174
+ }
175
+ return $orders;
176
  }
177
 
178
  /**
179
+ * Imports all orders
180
+ *
181
+ * @param array $orders list of orders to be imported
182
+ *
183
+ * @return array Number of new and update orders
184
+ */
185
  protected function importOrders($orders)
186
  {
187
  $count_orders_updated = 0;
188
  $count_orders_added = 0;
189
+ $args = array(
190
+ 'connector' => $this->_connector,
191
+ 'accountId' => $this->_idAccount
192
+ );
193
+ $marketplace = Mage::getModel('lensync/marketplace', $args);
194
+ foreach ($orders as $order_data) {
195
  $model_order = Mage::getModel('lensync/order');
196
  $model_order->setConfig($this->_config);
197
+ $id_lengow_order = (string)$order_data->marketplace_order_id;
198
+ if ($this->_config->isDebugMode() && !defined('PHPUNIT_LENGOW_ACTIVE')) {
 
 
199
  $id_lengow_order .= '--'.time();
200
+ }
201
  // check if order has a status
202
+ $marketplace_status = (string)$order_data->marketplace_status;
203
  if (empty($marketplace_status)) {
204
  $this->_helper->log('no order\'s status', $id_lengow_order);
205
  continue;
206
  }
 
 
 
 
 
 
 
207
  // convert marketplace status to Lengow equivalent
208
+ $marketplace->set((string)$order_data->marketplace, $this->_idAccount);
 
209
  $lengow_status = $marketplace->getStateLengow($marketplace_status);
210
+ // if order contains no package
211
+ if (count($order_data->packages) == 0) {
212
+ $this->_helper->log('create order fail: Lengow error: no package in the order', $id_lengow_order);
213
+ continue;
214
+ }
215
+ // if first package -> import processing fees and shipping
216
+ $first = true;
217
+ foreach ($order_data->packages as $package) {
218
+ // check whether the package contains a shipping address
219
+ if (!isset($package->delivery->id)) {
220
+ $this->_helper->log('create order fail: Lengow error: no delivery address in the order', $id_lengow_order);
221
+ continue;
222
+ }
223
+ $delivery_address_id = (int)$package->delivery->id;
224
+ // check order data
225
+ if (!$this->checkOrderData($order_data, $package, $id_lengow_order)) {
226
+ continue;
227
+ }
228
+ // first check if not shipped by marketplace
229
+ if (count($package->delivery->trackings) > 0
230
+ && (integer)$package->delivery->trackings[0]->is_delivered_by_marketplace == 1
231
+ ) {
232
+ $this->_helper->log(
233
+ 'delivery by marketplace ('.(string)$marketplace->name.')',
234
+ $id_lengow_order
235
+ );
236
+ continue;
237
+ }
238
+ // check if order has already been imported
239
+ $id_order = $model_order->isAlreadyImported(
240
+ $id_lengow_order,
241
+ $delivery_address_id,
242
+ $marketplace->name,
243
+ $marketplace->legacy_code
244
+ );
245
+ if ($id_order) {
246
+ $order_imported = Mage::getModel('sales/order')->load($id_order);
247
+ $this->_helper->log(
248
+ 'order already imported with order ID '.$order_imported->getIncrementId(),
249
+ $id_lengow_order
250
+ );
251
+ if ($model_order->updateState($order_imported, $lengow_status, $package)) {
252
+ $count_orders_updated++;
253
  }
254
+ } else {
255
+ // checks if an external id already exists
256
+ $id_order_magento = false;
257
+ $external_ids = $order_data->merchant_order_id;
258
+ foreach ($external_ids as $external_id) {
259
+ $result = $model_order->getLengowIdFromLengowDeliveryAddress(
260
+ (integer)$external_id,
261
+ $delivery_address_id
262
+ );
263
+ if ($result) {
264
+ $id_order_magento = $external_id;
265
+ break;
266
+ }
267
  }
268
+ if ($this->_config->isDebugMode()) {
269
+ $id_order_magento = false;
 
 
270
  }
271
+ // Import only process order or shipped order and not imported with previous module
272
+ if ($this->checkState($lengow_status) && !$id_order_magento) {
273
+ // Create or Update customer with addresses
274
+ $customer = Mage::getModel('lensync/customer_customer');
275
+ try {
276
+ $customer->setFromNode($order_data, $package->delivery, $this->_config);
277
+ } catch (Exception $e) {
278
+ $this->_helper->log('create customer fail: '.$e->getMessage(), $id_lengow_order);
279
+ continue;
280
+ }
281
+ // rewrite processing fees and shipping cost
282
+ if (!$this->_config->get('orders/processing_fee') || $first == false) {
283
+ $order_data->processing_fee = 0;
284
+ $this->_helper->log('rewrite amount without processing fee', $id_lengow_order);
285
+ }
286
+ if ($first == false) {
287
+ $order_data->commission = 0;
288
+ $order_data->shipping = 0;
289
+ $this->_helper->log('rewrite amount without shipping cost', $id_lengow_order);
290
+ }
291
 
292
+ // get total amount and shipping
293
+ $total_amount = 0;
294
+ foreach ($package->cart as $product) {
295
+ // check whether the product is canceled for amount
296
+ if ($product->marketplace_status != null) {
297
+ if ($marketplace->getStateLengow((string)$product->marketplace_status) == 'canceled'
298
+ || $marketplace->getStateLengow((string)$product->marketplace_status) == 'refused'
299
+ ) {
300
+ continue;
301
+ }
302
+ }
303
+ $total_amount += (float)$product->amount;
 
 
 
 
304
  }
305
+ $order_amount = (float)$total_amount + (float)$order_data->processing_fee + (float)$order_data->shipping;
306
+ // create quote and order
307
+ try {
308
+ $quote = $this->_createQuote(
309
+ $id_lengow_order,
310
+ $order_data,
311
+ $package->cart,
312
+ $customer,
313
+ $marketplace,
314
+ $order_amount
315
+ );
316
+ } catch (Exception $e) {
317
+ $this->_helper->log('create quote fail: ' . $e->getMessage(), $id_lengow_order);
318
+ continue;
319
+ }
320
+ try {
321
+ $order = $this->makeOrder(
322
+ $id_lengow_order,
323
+ $order_data,
324
+ $package,
325
+ $quote,
326
+ $model_order,
327
+ $order_amount,
328
+ true
329
+ );
330
+ } catch (Exception $e) {
331
+ $this->_helper->log('create order fail: ' . $e->getMessage(), $id_lengow_order);
332
+ }
333
+ if ($order) {
334
+ // get all lines ids
335
+ $order_line_ids = array();
336
+ foreach ($package->cart as $product) {
337
+ $order_line_ids[] = (string)$product->marketplace_order_line_id;
338
+ }
339
+ // Save order line id in lengow_order_line table
340
+ $order_line_saved = false;
341
+ foreach ($order_line_ids as $order_line_id) {
342
+ $model_order->addLengowOrderLine($order, $order_line_id);
343
+ $order_line_saved .= (!$order_line_saved ? $order_line_id : ' / ' . $order_line_id);
344
+ }
345
+ if ($order_line_saved) {
346
+ $this->_helper->log('save order lines product : '.$order_line_saved, $id_lengow_order);
347
+ }
348
+ // Sync to lengow
349
+ if (!$this->_config->isDebugMode()) {
350
+ $order_ids = $model_order->getOrderIdFromLengowOrder(
351
+ $id_lengow_order,
352
+ (string)$marketplace->name
353
+ );
354
+ if (count($order_ids) > 0) {
355
+ $magento_ids = array();
356
+ foreach ($order_ids as $order_id) {
357
+ $magento_ids[] = $order_id['entity_id'];
358
+ }
359
+ $result = $this->_connector->patch(
360
+ '/v3.0/orders/moi/',
361
+ array(
362
+ 'account_id' => $this->_idAccount,
363
+ 'marketplace_order_id' => $id_lengow_order,
364
+ 'marketplace' => $order_data->marketplace,
365
+ 'merchant_order_id' => $magento_ids
366
+ )
367
+ );
368
+ if (is_null($result)
369
+ || (isset($result['detail']) && $result['detail'] == "Pas trouvé.")
370
+ || isset($result['error'])
371
+ ) {
372
+ $this->_helper->log(
373
+ 'WARNING ! Order could NOT be synchronised with Lengow webservice (Order '.$order->getIncrementId().')',
374
+ $id_lengow_order
375
+ );
376
+ } else {
377
+ $this->_helper->log(
378
+ 'order successfully synchronised with Lengow webservice (Order '.$order->getIncrementId().')',
379
+ $id_lengow_order
380
  );
381
+ }
382
+ }
383
+ }
384
+ $count_orders_added++;
385
+ $this->_helper->log(
386
+ 'order successfully imported (Order '.$order->getIncrementId().')',
387
+ $id_lengow_order
388
+ );
389
+ if ($lengow_status == 'shipped' || $lengow_status == 'closed') {
390
+ $trackings = $package->delivery->trackings;
391
+ $model_order->toShip(
392
+ $order,
393
+ (count($trackings) > 0 ? (string)$trackings[0]->carrier : null),
394
+ (count($trackings) > 0 ? (string)$trackings[0]->method : null),
395
+ (count($trackings) > 0 ? (string)$trackings[0]->number : null)
396
+ );
397
+ $this->_helper->log(
398
+ 'update state to "shipped" (Order '.$order->getIncrementId().')',
399
+ $id_lengow_order
400
+ );
401
+ }
402
+ // export is finished for current order
403
+ $order->setExportFinishLengow(true);
404
+ $order->save();
405
+ // clean objects
406
+ unset($customer);
407
+ unset($quote);
408
+ unset($order);
409
+ }
410
+ } else {
411
+ if ($id_order_magento) {
412
+ $this->_helper->log(
413
+ 'already imported in Magento with order ID '.$id_order_magento,
414
+ $id_lengow_order
415
+ );
416
+ } else {
417
+ $this->_helper->log(
418
+ 'order\'s status ( '.$lengow_status.') not available to import',
419
+ $id_lengow_order
420
+ );
421
  }
 
 
 
422
  }
 
 
 
 
 
423
  }
424
+ $first = false;
425
  }
426
+ unset($model_order);
427
  }
428
  self::$import_start = false;
429
  // Clear session
432
  }
433
 
434
  /**
435
+ * Checks if order data are present
436
  *
437
+ * @param mixed $order_data
438
+ * @param mixed $package
439
+ * @param string $id_lengow_order
 
440
  *
441
+ * @return boolean
442
  */
443
+ protected function checkOrderData($order_data, $package, $id_lengow_order)
444
  {
445
+ $error_message = false;
446
+
447
+ if (count($package->cart) == 0) {
448
+ $error_message = 'Lengow error: no product in the order';
449
+ } elseif (is_null($order_data->currency)) {
450
+ $error_message = 'Lengow error: no currency in the order';
451
+ } elseif ($order_data->total_order == -1) {
452
+ $error_message = 'Lengow error: no exchange rates available for order prices';
453
+ } elseif (is_null($order_data->billing_address)) {
454
+ $error_message = 'Lengow error: no billing address in the order';
455
+ } elseif (is_null($order_data->billing_address->common_country_iso_a2)) {
456
+ $error_message = 'Lengow error: billing address doesn\'t contain the country';
457
+ } elseif (is_null($package->delivery->common_country_iso_a2)) {
458
+ $error_message = 'Lengow error: delivery address doesn\'t contain the country';
459
+ }
460
+ if ($error_message) {
461
+ $this->_helper->log('order import failed: '.$error_message, $id_lengow_order);
462
+ return false;
463
+ }
464
+ return true;
465
+ }
466
+
467
+ /**
468
+ * Create quote
469
+ *
470
+ * @param string $id_lengow_order
471
+ * @param mixed $order_data
472
+ * @param mixed $cart
473
+ * @param Lengow_Sync_Model_Customer_Customer $customer
474
+ * @param Lengow_Sync_Model_Marketplace $marketplace
475
+ * @param float $order_amount
476
+ *
477
+ * @return
478
+ */
479
+ protected function _createQuote(
480
+ $id_lengow_order,
481
+ $order_data,
482
+ $cart,
483
+ Lengow_Sync_Model_Customer_Customer $customer,
484
+ Lengow_Sync_Model_Marketplace $marketplace,
485
+ $order_amount
486
+ ) {
487
  $quote = Mage::getModel('lensync/quote')
488
+ ->setIsMultiShipping(false)
489
+ ->setStore($this->_config->getStore())
490
+ ->setIsSuperMode(true); // set quote to supermode
 
491
  // import customer addresses into quote
492
  // Set billing Address
493
  $customer_billing_address = Mage::getModel('customer/address')
494
+ ->load($customer->getDefaultBilling());
495
  $billing_address = Mage::getModel('sales/quote_address')
496
+ ->setShouldIgnoreValidation(true)
497
+ ->importCustomerAddress($customer_billing_address)
498
+ ->setSaveInAddressBook(0);
 
499
  // Set shipping Address
500
  $customer_shipping_address = Mage::getModel('customer/address')
501
+ ->load($customer->getDefaultShipping());
502
  $shipping_address = Mage::getModel('sales/quote_address')
503
+ ->setShouldIgnoreValidation(true)
504
+ ->importCustomerAddress($customer_shipping_address)
505
+ ->setSaveInAddressBook(0)
506
+ ->setSameAsBilling(0);
507
  $quote->assignCustomerWithAddressChange($customer, $billing_address, $shipping_address);
 
508
  // check if store include tax (Product and shipping cost)
509
  $priceIncludeTax = Mage::helper('tax')->priceIncludesTax($quote->getStore());
510
  $shippingIncludeTax = Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore());
 
511
  // add product in quote
512
+ $quote->addLengowProducts($cart, $marketplace, $id_lengow_order, $priceIncludeTax);
513
+ // Get shipping cost with tax
514
+ $shipping_cost = (float)$order_data->processing_fee + (float)$order_data->shipping;
 
 
515
  // if shipping cost not include tax -> get shipping cost without tax
516
+ if (!$shippingIncludeTax) {
517
  $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $quote->getStore());
518
+ $country_id = ($basedOn == 'shipping')
519
+ ? $shipping_address->getCountryId()
520
+ : $billing_address->getCountryId();
521
+ $shippingTaxClass = Mage::getStoreConfig(
522
+ Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS,
523
+ $quote->getStore()
524
+ );
525
  $taxCalculator = Mage::getModel('tax/calculation');
526
+ $taxRequest = new Varien_Object();
527
  $taxRequest->setCountryId($country_id)
528
+ ->setCustomerClassId($customer->getTaxClassId())
529
+ ->setProductClassId($shippingTaxClass);
530
+ $tax_rate = (float)$taxCalculator->getRate($taxRequest);
531
+ $tax_shipping_cost = (float)$taxCalculator->calcTaxAmount($shipping_cost, $tax_rate, true);
532
  $shipping_cost = $shipping_cost - $tax_shipping_cost;
533
  }
534
+ // update shipping rates for current order
535
+ $rates = $quote->getShippingAddress()
536
+ ->setCollectShippingRates(true)
537
+ ->collectShippingRates()
538
+ ->getShippingRatesCollection();
 
539
  $shipping_method = $this->updateRates($rates, $id_lengow_order, $shipping_cost);
540
+ // set shipping price and shipping method for current order
 
541
  $quote->getShippingAddress()
542
+ ->setShippingPrice($shipping_cost)
543
+ ->setShippingMethod($shipping_method);
 
544
  // collect totals
545
  $quote->collectTotals();
 
546
  // Re-ajuste cents for item quote
547
  // Conversion Tax Include > Tax Exclude > Tax Include maybe make 0.01 amount error
548
  if (!$priceIncludeTax) {
549
+ if ($quote->getGrandTotal() != $order_amount) {
550
  $quote_items = $quote->getAllItems();
551
  foreach ($quote_items as $item) {
552
+ $row_total_lengow = (float)$quote->getRowTotalLengow((string)$item->getProduct()->getId());
553
  if ($row_total_lengow != $item->getRowTotalInclTax()) {
554
  $diff = $row_total_lengow - $item->getRowTotalInclTax();
555
  $item->setPriceInclTax($item->getPriceInclTax() + ($diff / $item->getQty()));
558
  $item->setOriginalPrice($item->getPrice());
559
  $item->setRowTotal($item->getRowTotal() + $diff);
560
  $item->setBaseRowTotal($item->getRowTotal());
561
+ $item->setRowTotalInclTax($row_total_lengow);
562
  $item->setBaseRowTotalInclTax($item->getRowTotalInclTax());
563
  }
564
  }
565
  }
566
  }
 
567
  // set payment method lengow
568
  $quote->getPayment()
569
+ ->importData(
570
  array(
571
+ 'method' => 'lengow',
572
+ 'marketplace' => (string)$order_data->marketplace.' - '.(string)(count($order_data->payments) > 0 ? $order_data->payments[0]->type : null),
573
+ )
574
+ );
 
575
  $quote->save();
576
  return $quote;
577
  }
579
  /**
580
  * Create order
581
  *
582
+ * @param string $id_lengow_order
583
+ * @param mixed $order_data
584
+ * @param mixed $package
585
+ * @param Lengow_Sync_Model_Quote $quote
586
+ * @param Lengow_Sync_Model_Order $model_order
587
+ * @param float $order_amount
588
+ * @param boolean $invoice
589
+ *
590
+ * @return
591
  */
592
+ protected function makeOrder(
593
+ $id_lengow_order,
594
+ $order_data,
595
+ $package,
596
+ Lengow_Sync_Model_Quote $quote,
597
+ Lengow_Sync_Model_Order $model_order,
598
+ $order_amount,
599
+ $invoice = true
600
+ ) {
601
  try {
602
+ // get tracking informations
603
+ $trackings = $package->delivery->trackings;
604
+ $additional_data = array(
605
+ 'from_lengow' => true,
606
+ 'export_finish_lengow' => false,
607
+ 'marketplace_lengow' => (string)$order_data->marketplace,
608
+ 'fees_lengow' => (float)$order_data->commission,
609
+ 'order_id_lengow' => (string)$id_lengow_order,
610
+ 'delivery_address_id_lengow' => (int)$package->delivery->id,
611
+ 'xml_node_lengow' => Mage::helper('Core')->jsonEncode($order_data),
612
+ 'message_lengow' => (string)$order_data->comments,
613
+ 'total_paid_lengow' => (float)$order_amount,
614
+ 'carrier_lengow' => (count($trackings) > 0 ? (string)$trackings[0]->carrier : null),
615
+ 'carrier_method_lengow' => (count($trackings) > 0 ? (string)$trackings[0]->method : null),
616
+ 'carrier_tracking_lengow' => (count($trackings) > 0 ? (string)$trackings[0]->number : null),
617
+ 'carrier_id_relay_lengow' => (count($trackings) > 0 ? (string)$trackings[0]->relay->id : null),
618
+ 'global_currency_code' => (string)$order_data->currency->iso_a3,
619
+ 'base_currency_code' => (string)$order_data->currency->iso_a3,
620
+ 'store_currency_code' => (string)$order_data->currency->iso_a3,
621
+ 'order_currency_code' => (string)$order_data->currency->iso_a3
622
+ );
623
  $service = Mage::getModel('sales/service_quote', $quote);
624
  $service->setOrderData($additional_data);
625
  $order = false;
626
+ if (method_exists($service, 'submitAll')) {
627
  $service->submitAll();
628
  $order = $service->getOrder();
629
  } else {
630
  $order = $service->submit();
631
  }
632
+ if (!$order) {
633
  throw new Exception('service unable to create order based on given quote');
634
+ }
635
  $order->setIsFromLengow(true);
636
  // modify order dates to use actual dates
637
  if ($this->_config->get('orders/date_import')) {
638
+ $date = date('Y-m-d H:i:s', strtotime((string)$order_data->marketplace_order_date));
639
+ $order->setCreatedAt($date);
640
+ $order->setUpdatedAt($date);
 
 
 
 
641
  }
642
  $order->save();
 
643
  // Re-ajuste cents for total and shipping cost
644
+ // Conversion Tax Include > Tax Exclude > Tax Include maybe make 0.01 amount error
645
  $priceIncludeTax = Mage::helper('tax')->priceIncludesTax($quote->getStore());
646
+ $shippingIncludeTax = Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore());
647
  if (!$priceIncludeTax || !$shippingIncludeTax) {
648
+ if ($order->getGrandTotal() != $order_amount) {
649
  // check Grand Total
650
+ $diff = $order_amount - $order->getGrandTotal();
651
+ $order->setGrandTotal($order_amount);
652
  $order->setBaseGrandTotal($order->getGrandTotal());
653
  // if the difference is only on the grand total, removing the difference of shipping cost
654
+ if (($order->getSubtotalInclTax() + $order->getShippingInclTax()) == $order_amount) {
655
  $order->setShippingAmount($order->getShippingAmount() + $diff);
656
  $order->setBaseShippingAmount($order->getShippingAmount());
657
  } else {
658
  // check Shipping Cost
659
  $diff_shipping = 0;
660
+ $shipping_cost = (float)$order_data->processing_fee + (float)$order_data->shipping;
661
+ if ($order->getShippingInclTax() != (float)$shipping_cost) {
662
  $diff_shipping = ($shipping_cost - $order->getShippingInclTax());
663
  $order->setShippingAmount($order->getShippingAmount() + $diff_shipping);
664
  $order->setBaseShippingAmount($order->getShippingAmount());
674
  }
675
  $order->save();
676
  }
 
677
  // generate invoice for order
678
  if ($invoice && $order->canInvoice()) {
679
  $model_order->toInvoice($order);
680
  }
681
+ $carrier_name = '';
682
+ if (count($trackings) > 0) {
683
+ $carrier_name = (string)$trackings[0]->carrier;
684
+ if ($carrier_name === 'None' || $carrier_name == '') {
685
+ $carrier_name = (string)$trackings[0]->method;
686
+ }
687
+ }
688
+ $order->setShippingDescription(
689
+ $order->getShippingDescription().' [marketplace shipping method : '.$carrier_name.']'
690
+ );
691
  $order->save();
692
+ } catch (Exception $e) {
693
+ $this->_helper->log('error create order : '.$e->getMessage(), $id_lengow_order);
694
  }
695
  return $order;
696
  }
698
  /**
699
  * Update Rates with shipping cost
700
  *
701
+ * @param Mage_Sales_Model_Quote_Address_Rate $rates
702
+ * @param string $id_lengow_order
703
+ * @param float $shipping_cost
704
+ * @param string $shipping_method
705
+ * @param boolean $first stop recursive effect
706
  *
707
  * @return boolean
708
  */
709
  protected function updateRates($rates, $id_lengow_order, $shipping_cost, $shipping_method = null, $first = true)
710
  {
711
+ if (!$shipping_method) {
712
  $shipping_method = $this->_config->get('orders/default_shipping');
713
+ }
714
+ if (empty($shipping_method)) {
715
+ $shipping_method = 'lengow_lengow';
716
+ }
717
  foreach ($rates as &$rate) {
718
  // make sure the chosen shipping method is correct
719
+ if ($rate->getCode() == $shipping_method) {
720
  if ($rate->getPrice() != $shipping_cost) {
721
  $rate->setPrice($shipping_cost);
722
  $rate->setCost($shipping_cost);
725
  }
726
  }
727
  // stop recursive effect
728
+ if (!$first) {
729
  return 'lengow_lengow';
730
+ }
731
  // get lengow shipping method if selected shipping method is unavailable
732
+ $this->_helper->log(
733
+ 'the selected shipping method is unavailable for current order. Lengow shipping method assigned.',
734
+ $id_lengow_order
735
+ );
736
  return $this->updateRates($rates, $id_lengow_order, $shipping_cost, 'lengow_lengow', false);
737
  }
738
+
739
+ /**
740
+ * Check if order status is valid and is available for import
741
+ *
742
+ * @param string $order_state order state
743
+ *
744
+ * @return boolean
745
+ */
746
+ protected function checkState($lengow_status)
747
+ {
748
+ if (empty($lengow_status)) {
749
+ return false;
750
+ }
751
+ if (!in_array($lengow_status, self::$STATES_LENGOW)) {
752
+ return false;
753
+ }
754
+ return true;
755
+ }
756
+ }
app/code/community/Lengow/Sync/Model/Importv2.php ADDED
@@ -0,0 +1,541 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow sync model import
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Model_Importv2 extends Varien_Object
13
+ {
14
+
15
+ /**
16
+ * @var Mage_Sales_Model_Quote
17
+ */
18
+ protected $_quote = null;
19
+
20
+ /**
21
+ * @var Mage_Customer_Model_Customer
22
+ */
23
+ protected $_customer = null;
24
+
25
+ protected $_ordersIdsImported = array();
26
+
27
+ protected $_orderIdsAlreadyImported = array();
28
+
29
+ protected $_result;
30
+
31
+ protected $_resultSendOrder = "";
32
+
33
+ protected $_isUnderVersion14 = null;
34
+
35
+ /**
36
+ * Product model
37
+ *
38
+ * @var Mage_Catalog_Model_Product
39
+ */
40
+ protected $_productModel;
41
+
42
+ protected $_connector;
43
+
44
+ protected $_helper;
45
+
46
+ public static $import_start = false;
47
+
48
+ protected $_dateFrom;
49
+
50
+ protected $_dateTo;
51
+
52
+ protected $_config;
53
+
54
+ protected $_idCustomer;
55
+
56
+ protected $_idGroup;
57
+
58
+ protected $_apiToken;
59
+
60
+ /**
61
+ * Constructor
62
+ */
63
+ public function __construct($args)
64
+ {
65
+ parent::__construct();
66
+ if (Mage::app()->getStore()->getCode() != 'admin') {
67
+ Mage::app()->setCurrentStore('admin');
68
+ }
69
+ if (!is_array($args)) {
70
+ return;
71
+ }
72
+ foreach ($args as $key => $value) {
73
+ $this->{'_'.$key} = $value;
74
+ }
75
+ $this->_helper = Mage::helper('lensync/data');
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Execute import process
81
+ */
82
+ public function exec()
83
+ {
84
+ self::$import_start = true;
85
+ Mage::getSingleton('core/session')->setIsFromlengow('true');
86
+ $orders = $this->getLengowOrders();
87
+ if (!is_object($orders) || isset($orders->error)) {
88
+ $error = (string)$orders->error;
89
+ if (strtolower($error) == 'no way') {
90
+ $message = $this->_helper->__('API\'s connection refused with IP %s', (string)$orders->ip);
91
+ }
92
+ $error = 'Error on lengow webservice '.(isset($message) ? ': '.$message : json_encode($orders));
93
+ $this->_helper->log($error);
94
+ return array('new' => 0, 'update' => 0, 'error' => $error);
95
+ } else {
96
+ $count_orders = count($orders->orders->order);
97
+ if ($count_orders === 0) {
98
+ $this->_helper->log(
99
+ 'No orders to import between '.$this->_dateFrom.' and '.$this->_dateTo,
100
+ $this->force_log_output
101
+ );
102
+ return false;
103
+ }
104
+ $this->_helper->log($count_orders.' order'.($count_orders > 1 ? 's ' : ' ').'found');
105
+ }
106
+ return $this->importOrders($orders);
107
+ }
108
+
109
+ /**
110
+ * Retrieve Lengow orders
111
+ *
112
+ * @return SimpleXmlElement list of orders to be imported
113
+ */
114
+ protected function getLengowOrders()
115
+ {
116
+ $this->_connector = Mage::getSingleton('lensync/connectorv2');
117
+ $this->_connector->init((integer)$this->_idCustomer, $this->_apiToken);
118
+ if ($this->_connector->error) {
119
+ return $connector;
120
+ }
121
+ return $this->_connector->api(
122
+ 'commands',
123
+ array(
124
+ 'dateFrom' => $this->_dateFrom,
125
+ 'dateTo' => $this->_dateTo,
126
+ 'id_group' => $this->_idGroup,
127
+ 'state' => 'plugin',
128
+ )
129
+ );
130
+ }
131
+
132
+ /**
133
+ * Makes the Orders API Url and imports all orders
134
+ *
135
+ * @param SimpleXmlElement $orders List of orders to be imported
136
+ *
137
+ * @return array Number of new and update orders
138
+ */
139
+ protected function importOrders($orders)
140
+ {
141
+ $count_orders_updated = 0;
142
+ $count_orders_added = 0;
143
+ foreach ($orders->orders->order as $key => $order_data) {
144
+ $model_order = Mage::getModel('lensync/orderv2');
145
+ $model_order->setConfig($this->_config);
146
+ $id_lengow_order = (string)$order_data->order_id;
147
+ if ($this->_config->isDebugMode()) {
148
+ $id_lengow_order .= '--' . time();
149
+ }
150
+ // check if order has a status
151
+ $marketplace_status = (string)$order_data->order_status->marketplace;
152
+ if (empty($marketplace_status)) {
153
+ $this->_helper->log('no order\'s status', $id_lengow_order);
154
+ continue;
155
+ }
156
+ // first check if not shipped by marketplace
157
+ if ((integer)$order_data->tracking_informations->tracking_deliveringByMarketPlace == 1) {
158
+ $this->_helper->log(
159
+ 'delivery by marketplace ('.(string)$order_data->marketplace.')',
160
+ $id_lengow_order
161
+ );
162
+ continue;
163
+ }
164
+ // convert marketplace status to Lengow equivalent
165
+ $marketplace = Mage::getModel('lensync/marketplacev2');
166
+ $marketplace->set((string)$order_data->marketplace);
167
+ $lengow_status = $marketplace->getStateLengow($marketplace_status);
168
+
169
+ // check if order has already been imported
170
+ $id_order = $model_order->isAlreadyImported($id_lengow_order, (integer)$order_data->idFlux);
171
+ if ($id_order) {
172
+ $order_imported = Mage::getModel('sales/order')->load($id_order);
173
+ $this->_helper->log(
174
+ 'order already imported with order ID '.$order_imported->getIncrementId(),
175
+ $id_lengow_order
176
+ );
177
+ if ($model_order->updateState($order_imported, $lengow_status, $order_data)) {
178
+ $count_orders_updated++;
179
+ }
180
+ } else {
181
+ // Import only process order or shipped order and not imported with previous module
182
+ $id_order_magento = $this->_config->isDebugMode() ? null : (string)$order_data->order_external_id;
183
+ if ($lengow_status == 'processing' || $lengow_status == 'shipped' && !$id_order_magento) {
184
+ // Create or Update customer with addresses
185
+ $customer = Mage::getModel('lensync/customer_customerv2');
186
+ $customer->setFromNode($order_data, $this->_config);
187
+ // rewrite order if processing fees not included
188
+ if (!$this->_config->get('orders/processing_fee')) {
189
+ $total_wt_proc_fees = (float)$order_data->order_amount - (float)$order_data->order_processing_fee;
190
+ $order_data->order_amount = new SimpleXMLElement(
191
+ '<order_amount><![CDATA['.($total_wt_proc_fees).']]></order_amount>'
192
+ );
193
+ $order_data->order_processing_fee = new SimpleXMLElement(
194
+ '<order_processing_fee><![CDATA[ ]]></order_processing_fee>'
195
+ );
196
+ $this->_helper->log('rewrite amount without processing fee', $id_lengow_order);
197
+ unset($total_wt_proc_fees);
198
+ }
199
+ try {
200
+ $quote = $this->_createQuote($id_lengow_order, $order_data, $customer, $marketplace);
201
+ } catch (Exception $e) {
202
+ $this->_helper->log('create quote fail : ' . $e->getMessage(), $id_lengow_order);
203
+ continue;
204
+ }
205
+ try {
206
+ $order = $this->makeOrder($id_lengow_order, $order_data, $quote, $model_order, true);
207
+ } catch (Exception $e) {
208
+ $this->_helper->log('create order fail : ' . $e->getMessage(), $id_lengow_order);
209
+ }
210
+ if ($order) {
211
+ // Sync to lengow
212
+ if (!$this->_config->isDebugMode()) {
213
+ $orders = $this->_connector->api('getInternalOrderId', array(
214
+ 'idClient' => (integer)$this->_idCustomer,
215
+ 'idFlux' => (integer)$order_data->idFlux,
216
+ 'Marketplace' => (string)$order_data->marketplace,
217
+ 'idCommandeMP' => $id_lengow_order,
218
+ 'idCommandeMage' => $order->getId(),
219
+ 'statutCommandeMP' => (string)$order_data->order_status->lengow,
220
+ 'statutCommandeMage' => $order->getState(),
221
+ 'idQuoteMage' => $quote->getId(),
222
+ 'Message' => 'Import depuis: '.(string)$order_data->marketplace.'<br/>idOrder: '.$id_lengow_order,
223
+ 'type' => 'Magento'
224
+ ));
225
+ $this->_helper->log(
226
+ 'order successfully synchronised with Lengow webservice (Order '.$order->getIncrementId().')',
227
+ $id_lengow_order
228
+ );
229
+ }
230
+ $count_orders_added++;
231
+ $this->_helper->log(
232
+ 'order successfully imported (Order '.$order->getIncrementId().')',
233
+ $id_lengow_order
234
+ );
235
+ if ($lengow_status == 'shipped') {
236
+ $model_order->toShip(
237
+ $order,
238
+ (string)$order_data->tracking_informations->tracking_carrier,
239
+ (string)$order_data->tracking_informations->tracking_method,
240
+ (string)$order_data->tracking_informations->tracking_number
241
+ );
242
+ $this->_helper->log(
243
+ 'update state to "shipped" (Order '.$order->getIncrementId().')',
244
+ $id_lengow_order
245
+ );
246
+ }
247
+ // export is finished for current order
248
+ $order->setExportFinishLengow(true);
249
+ $order->save();
250
+ // clean objects
251
+ unset($customer);
252
+ unset($quote);
253
+ unset($order);
254
+ }
255
+ } else {
256
+ if ($id_order_magento) {
257
+ $this->_helper->log(
258
+ 'already imported in Magento with order ID '.$id_order_magento,
259
+ $id_lengow_order
260
+ );
261
+ } else {
262
+ $this->_helper->log(
263
+ 'order\'s status ('.$lengow_status.') not available to import',
264
+ $id_lengow_order
265
+ );
266
+ }
267
+ }
268
+ unset($model_order);
269
+ }
270
+ }
271
+ self::$import_start = false;
272
+ // Clear session
273
+ Mage::getSingleton('core/session')->clear();
274
+ return array('new' => $count_orders_added, 'update' => $count_orders_updated);
275
+ }
276
+
277
+ /**
278
+ * Create quote
279
+ *
280
+ * @param string $id_lengow_order
281
+ * @param SimpleXMLelement $order_data
282
+ * @param Lengow_Sync_Model_Customer_Customer $customer
283
+ * @param Lengow_Sync_Model_Marketplace $marketplace
284
+ *
285
+ * @return Lengow_Sync_Model_Quote
286
+ */
287
+ protected function _createQuote(
288
+ $id_lengow_order,
289
+ SimpleXMLelement $order_data,
290
+ Lengow_Sync_Model_Customer_Customerv2 $customer,
291
+ Lengow_Sync_Model_Marketplacev2 $marketplace
292
+ ) {
293
+ $quote = Mage::getModel('lensync/quotev2')
294
+ ->setIsMultiShipping(false)
295
+ ->setStore($this->_config->getStore())
296
+ ->setIsSuperMode(true);
297
+ // import customer addresses into quote
298
+ // Set billing Address
299
+ $customer_billing_address = Mage::getModel('customer/address')
300
+ ->load($customer->getDefaultBilling());
301
+ $billing_address = Mage::getModel('sales/quote_address')
302
+ ->setShouldIgnoreValidation(true)
303
+ ->importCustomerAddress($customer_billing_address)
304
+ ->setSaveInAddressBook(0);
305
+ // Set shipping Address
306
+ $customer_shipping_address = Mage::getModel('customer/address')
307
+ ->load($customer->getDefaultShipping());
308
+ $shipping_address = Mage::getModel('sales/quote_address')
309
+ ->setShouldIgnoreValidation(true)
310
+ ->importCustomerAddress($customer_shipping_address)
311
+ ->setSaveInAddressBook(0)
312
+ ->setSameAsBilling(0);
313
+ $quote->assignCustomerWithAddressChange($customer, $billing_address, $shipping_address);
314
+ // check if store include tax (Product and shipping cost)
315
+ $priceIncludeTax = Mage::helper('tax')->priceIncludesTax($quote->getStore());
316
+ $shippingIncludeTax = Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore());
317
+ // add product in quote
318
+ $quote->addLengowProducts(
319
+ $order_data->cart->products->product,
320
+ $marketplace,
321
+ $id_lengow_order,
322
+ $priceIncludeTax
323
+ );
324
+ // get shipping cost with tax
325
+ $shipping_cost = (float)$order_data->order_processing_fee + (float)$order_data->order_shipping;
326
+ // if shipping cost not include tax -> get shipping cost without tax
327
+ if (!$shippingIncludeTax) {
328
+ $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $quote->getStore());
329
+ $country_id = ($basedOn == 'shipping')
330
+ ? $shipping_address->getCountryId()
331
+ : $billing_address->getCountryId();
332
+ $shippingTaxClass = Mage::getStoreConfig(
333
+ Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS,
334
+ $quote->getStore()
335
+ );
336
+ $taxCalculator = Mage::getModel('tax/calculation');
337
+ $taxRequest = new Varien_Object();
338
+ $taxRequest->setCountryId($country_id)
339
+ ->setCustomerClassId($customer->getTaxClassId())
340
+ ->setProductClassId($shippingTaxClass);
341
+ $tax_rate = (float)$taxCalculator->getRate($taxRequest);
342
+ $tax_shipping_cost = (float)$taxCalculator->calcTaxAmount($shipping_cost, $tax_rate, true);
343
+ $shipping_cost = $shipping_cost - $tax_shipping_cost;
344
+ }
345
+ // get and update shipping rates for current order
346
+ $rates = $quote->getShippingAddress()
347
+ ->setCollectShippingRates(true)
348
+ ->collectShippingRates()
349
+ ->getShippingRatesCollection();
350
+ $shipping_method = $this->updateRates($rates, $id_lengow_order, $shipping_cost);
351
+ // set shipping price and shipping method for current order
352
+ $quote->getShippingAddress()
353
+ ->setShippingPrice($shipping_cost)
354
+ ->setShippingMethod($shipping_method);
355
+ // collect totals
356
+ $quote->collectTotals();
357
+ // Re-ajuste cents for item quote
358
+ // Conversion Tax Include > Tax Exclude > Tax Include maybe make 0.01 amount error
359
+ if (!$priceIncludeTax) {
360
+ if ($quote->getGrandTotal() != (float)$order_data->order_amount) {
361
+ $quote_items = $quote->getAllItems();
362
+ foreach ($quote_items as $item) {
363
+ $row_total_lengow = (float)$quote->getRowTotalLengow((string)$item->getProduct()->getId());
364
+ if ($row_total_lengow != $item->getRowTotalInclTax()) {
365
+ $diff = $row_total_lengow - $item->getRowTotalInclTax();
366
+ $item->setPriceInclTax($item->getPriceInclTax() + ($diff / $item->getQty()));
367
+ $item->setBasePriceInclTax($item->getPriceInclTax());
368
+ $item->setPrice($item->getPrice() + ($diff / $item->getQty()));
369
+ $item->setOriginalPrice($item->getPrice());
370
+ $item->setRowTotal($item->getRowTotal() + $diff);
371
+ $item->setBaseRowTotal($item->getRowTotal());
372
+ $item->setRowTotalInclTax((float)$row_total_lengow);
373
+ $item->setBaseRowTotalInclTax($item->getRowTotalInclTax());
374
+ }
375
+ }
376
+ }
377
+ }
378
+ // set payment method lengow
379
+ $quote->getPayment()
380
+ ->importData(
381
+ array(
382
+ 'method' => 'lengow',
383
+ 'marketplace' => (string)$order_data->marketplace.' - '.(string)$order_data->order_payment->payment_type,
384
+ )
385
+ );
386
+ $quote->save();
387
+ return $quote;
388
+ }
389
+
390
+ /**
391
+ * Create order
392
+ *
393
+ * @param string $id_lengow_order
394
+ * @param SimpleXMLelement $order_data
395
+ * @param Lengow_Sync_Model_Quote $quote
396
+ * @param Lengow_Sync_Model_Order $model_order
397
+ * @param boolean $invoice
398
+ *
399
+ * @return Mage_Sales_Model_Order
400
+ */
401
+ protected function makeOrder(
402
+ $id_lengow_order,
403
+ SimpleXMLelement $order_data,
404
+ Lengow_Sync_Model_Quotev2 $quote,
405
+ Mage_Sales_Model_Order $model_order,
406
+ $invoice = true
407
+ ) {
408
+ try {
409
+ $additional_data = array(
410
+ 'from_lengow' => true,
411
+ 'export_finish_lengow' => false,
412
+ 'marketplace_lengow' => (string)$order_data->marketplace,
413
+ 'fees_lengow' => (float)$order_data->order_commission,
414
+ 'order_id_lengow' => $id_lengow_order,
415
+ 'feed_id_lengow' => (integer)$order_data->idFlux,
416
+ 'xml_node_lengow' => Mage::helper('Core')->jsonEncode($order_data),
417
+ 'message_lengow' => (string)$order_data->order_comments,
418
+ 'total_paid_lengow' => (float)$order_data->order_amount,
419
+ 'carrier_lengow' => (string)$order_data->tracking_informations->tracking_carrier,
420
+ 'carrier_method_lengow' => (string)$order_data->tracking_informations->tracking_method,
421
+ 'carrier_tracking_lengow' => (string)$order_data->tracking_informations->tracking_number,
422
+ 'carrier_id_relay_lengow' => (string)$order_data->tracking_informations->tracking_relay,
423
+ 'global_currency_code' => (string)$order_data->order_currency,
424
+ 'base_currency_code' => (string)$order_data->order_currency,
425
+ 'store_currency_code' => (string)$order_data->order_currency,
426
+ 'order_currency_code' => (string)$order_data->order_currency,
427
+ );
428
+ $service = Mage::getModel('sales/service_quote', $quote);
429
+ $service->setOrderData($additional_data);
430
+ $order = false;
431
+ if (method_exists($service, 'submitAll')) {
432
+ $service->submitAll();
433
+ $order = $service->getOrder();
434
+ } else {
435
+ $order = $service->submit();
436
+ }
437
+ if (!$order) {
438
+ throw new Exception('service unable to create order based on given quote');
439
+ }
440
+ $order->setIsFromLengow(true);
441
+ // modify order dates to use actual dates
442
+ if ($this->_config->get('orders/date_import')) {
443
+ $date_mp = (string)$order_data->order_purchase_date . ' ' . (string)$order_data->order_purchase_heure;
444
+ $server_timezone = date_default_timezone_get();
445
+ date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
446
+ $date_UTC = gmdate('Y-m-d H:i:s', strtotime($date_mp));
447
+ date_default_timezone_set($server_timezone);
448
+ $order->setCreatedAt($date_UTC);
449
+ $order->setUpdatedAt($date_UTC);
450
+ }
451
+ $order->save();
452
+ // Re-ajuste cents for total and shipping cost
453
+ // Conversion Tax Include > Tax Exclude > Tax Include maybe make 0.01 amount error
454
+ $priceIncludeTax = Mage::helper('tax')->priceIncludesTax($quote->getStore());
455
+ $shippingIncludeTax = Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore());
456
+ if (!$priceIncludeTax || !$shippingIncludeTax) {
457
+ if ($order->getGrandTotal() != (float)$order_data->order_amount) {
458
+ // check Grand Total
459
+ $diff = (((float)$order_data->order_amount) - $order->getGrandTotal());
460
+ $order->setGrandTotal((float)$order_data->order_amount);
461
+ $order->setBaseGrandTotal($order->getGrandTotal());
462
+ // if the difference is only on the grand total, removing the difference of shipping cost
463
+ if (($order->getSubtotalInclTax() + $order->getShippingInclTax()) == (float)$order_data->order_amount) {
464
+ $order->setShippingAmount($order->getShippingAmount() + $diff);
465
+ $order->setBaseShippingAmount($order->getShippingAmount());
466
+ } else {
467
+ // check Shipping Cost
468
+ $diff_shipping = 0;
469
+ $shipping_cost = (float)$order_data->order_processing_fee + (float)$order_data->order_shipping;
470
+ if ($order->getShippingInclTax() != (float)$shipping_cost) {
471
+ $diff_shipping = ($shipping_cost - $order->getShippingInclTax());
472
+ $order->setShippingAmount($order->getShippingAmount() + $diff_shipping);
473
+ $order->setBaseShippingAmount($order->getShippingAmount());
474
+ $order->setShippingInclTax($shipping_cost);
475
+ $order->setBaseShippingInclTax($order->getShippingInclTax());
476
+ }
477
+ // update Subtotal without shipping cost
478
+ $order->setSubtotalInclTax($order->getSubtotalInclTax() + ($diff - $diff_shipping));
479
+ $order->setBaseSubtotalInclTax($order->getSubtotalInclTax());
480
+ $order->setSubtotal($order->getSubtotal() + ($diff - $diff_shipping));
481
+ $order->setBaseSubtotal($order->getSubtotal());
482
+ }
483
+ }
484
+ $order->save();
485
+ }
486
+ // generate invoice for order
487
+ if ($invoice && $order->canInvoice()) {
488
+ $model_order->toInvoice($order);
489
+ }
490
+ $carrier_name = (string)$order_data->tracking_informations->tracking_carrier;
491
+ if ((string)$carrier_name === 'None' || $carrier_name == '') {
492
+ $carrier_name = (string)$order_data->tracking_informations->tracking_method;
493
+ }
494
+ $order->setShippingDescription(
495
+ $order->getShippingDescription().' [marketplace shipping method : '.$carrier_name.']'
496
+ );
497
+ $order->save();
498
+ } catch (Exception $e) {
499
+ Mage::helper('lensync')->log('error create order : '.$e->getMessage(), $id_lengow_order);
500
+ }
501
+ return $order;
502
+ }
503
+
504
+ /**
505
+ * Update Rates with shipping cost
506
+ *
507
+ * @param $rates
508
+ * @param string $id_lengow_order
509
+ * @param float $shipping_cost
510
+ * @param string $shipping_method
511
+ * @param boolean $first stop recursive effect
512
+ *
513
+ * @return boolean
514
+ */
515
+ protected function updateRates($rates, $id_lengow_order, $shipping_cost, $shipping_method = null, $first = true)
516
+ {
517
+ if (!$shipping_method) {
518
+ $shipping_method = $this->_config->get('orders/default_shipping');
519
+ }
520
+ foreach ($rates as &$rate) {
521
+ // make sure the chosen shipping method is correct
522
+ if ($rate->getCode() == $shipping_method) {
523
+ if ($rate->getPrice() != $shipping_cost) {
524
+ $rate->setPrice($shipping_cost);
525
+ $rate->setCost($shipping_cost);
526
+ }
527
+ return $rate->getCode();
528
+ }
529
+ }
530
+ // stop recursive effect
531
+ if (!$first) {
532
+ return 'lengow_lengow';
533
+ }
534
+ // get lengow shipping method if selected shipping method is unavailable
535
+ $this->_helper->log(
536
+ 'the selected shipping method is unavailable for current order. Lengow shipping method assigned.',
537
+ $id_lengow_order
538
+ );
539
+ return $this->updateRates($rates, $id_lengow_order, $shipping_cost, 'lengow_lengow', false);
540
+ }
541
+ }
app/code/community/Lengow/Sync/Model/Log.php CHANGED
@@ -1,34 +1,56 @@
1
  <?php
 
2
  /**
3
  * Lengow sync model log
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Log extends Mage_Core_Model_Abstract {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- protected function _construct()
14
- {
15
- $this->_init('lensync/log');
16
- }
17
-
18
- /**
19
- * Save message event
20
- * @param $message string
21
- * @param $id_order int
22
- */
23
- public function log($message, $id_order = null)
24
- {
25
- $order_message = '';
26
- if(!is_null($id_order)) {
27
- $order_message = Mage::helper('lensync')->__('ID Order') . ' Lengow #' . $id_order . ' ';
28
- }
29
- $message = $order_message . $message;
30
- $this->setMessage($message);
31
- return $this->save();
32
- }
33
-
34
- }
1
  <?php
2
+
3
  /**
4
  * Lengow sync model log
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Log extends Mage_Core_Model_Abstract
13
+ {
14
+
15
+ /**
16
+ * Constructor
17
+ */
18
+ protected function _construct()
19
+ {
20
+ $this->_init('lensync/log');
21
+ }
22
+
23
+ /**
24
+ * Save message event
25
+ * @param $message string
26
+ * @param $id_order integer
27
+ *
28
+ * @return boolean
29
+ */
30
+ public function log($message, $id_order = null)
31
+ {
32
+ if (!is_null($id_order)) {
33
+ $message = Mage::helper('lensync')->__('ID Order').' Lengow '.$id_order.' - '.$message;
34
+ }
35
+ $log = Mage::getModel('lensync/log');
36
+ if (strlen($message) > 0) {
37
+ $log->setDate(Mage::getModel('core/date')->date('Y-m-d H:i:s'));
38
+ $log->setMessage($message);
39
+ return $log->save();
40
+ } else {
41
+ return false;
42
+ }
43
+ }
44
 
45
+ /**
46
+ * Suppress log files when too old.
47
+ */
48
+ public function cleanLog()
49
+ {
50
+ $resource = Mage::getSingleton('core/resource');
51
+ $writeConnection = $resource->getConnection('core_write');
52
+ $table = $resource->getTableName('lensync/log');
53
+ $query = "DELETE FROM ".$table." WHERE `date` < DATE_SUB(NOW(),INTERVAL 20 DAY)";
54
+ $writeConnection->query($query);
55
+ }
56
+ }
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Sync/Model/Marketplace.php CHANGED
@@ -1,375 +1,500 @@
1
  <?php
2
 
3
  /**
4
- * Copyright 2013 Lengow.
5
  *
6
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
7
- * not use this file except in compliance with the License. You may obtain
8
- * a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- * License for the specific language governing permissions and limitations
16
- * under the License.
17
  */
 
 
18
 
 
 
 
 
19
 
20
- /**
21
- * The Lengow Marketplace Class.
22
- *
23
- * @author Ludovic Drin <ludovic@lengow.com>
24
- * @copyright 2013 Lengow SAS
25
- */
26
 
27
- class Lengow_Sync_Model_Marketplace {
 
 
28
 
29
- public static $XML_MARKETPLACES = 'marketplaces.xml';
30
- public static $DOM;
31
- public static $VALID_ACTIONS = array(
32
- // 'accept' ,
33
- 'shipped' ,
34
- 'refuse' ,
35
- 'link' ,
36
- );
37
- public static $WSDL_LINK_ORDER = 'https://wsdl.lengow.com/wsdl/link/#MP#/#ID_CLIENT#/#ID_FLUX#/#ORDER_ID#/#INTERNAL_ORDER_ID#/update.xml';
38
  public $name;
39
- public $object;
 
 
40
  public $is_loaded = false;
 
41
  public $states_lengow = array();
 
42
  public $states = array();
 
43
  public $actions = array();
44
- public $payments = array();
45
- public $payments_lengow = array();
46
- protected $_config;
47
- const MARKETPLACE_STATUS_NO_MATCH = -1;
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  /**
51
- * Construct a new Markerplace instance with xml configuration.
52
- *
53
- * @param string $name The name of the marketplace
54
- */
55
- public function set($name) {
56
- $this->_helper = Mage::helper('lensync/data');
57
- $this->_loadXml();
58
- $this->name = strtolower($name);
59
- $object = self::$DOM->xpath('/marketplaces/marketplace[@name=\'' . $this->name . '\']');
60
- if(!empty($object)) {
61
- $this->object = $object[0];
62
- $this->api_url = (string) $this->object->api;
63
- // States
64
- foreach($this->object->states->state as $state) {
65
- $this->states_lengow[(string) $state['name']] = (string) $state->lengow;
66
- $this->states[(string) $state->lengow] = (string) $state['name'];
67
- if(isset($state->actions)) {
68
- foreach($state->actions->action as $action) {
69
- $this->actions[(string) $action['type']] = array();
70
- $this->actions[(string) $action['type']]['name'] = (string) $action;
71
- $params = self::$DOM->xpath('/marketplaces/marketplace[@name=\'' . $this->name . '\']/additional_params/param[@usedby=\'' . (string) $action['type']. '\']');
72
- if(count($params)) {
73
- foreach($params as $param) {
74
- $this->actions[(string) $action['type']]['params'][(string) $param->type]['name'] = (string) $param->name;
75
- if(isset($param->accepted_values)) {
76
- $this->actions[(string) $action['type']]['params'][(string) $param->type]['accepted_values'] = $param->accepted_values->value;
77
- $default = self::$DOM->xpath('/marketplaces/marketplace[@name=\'' . $this->name . '\']/additional_params/param[@usedby=\'' . (string) $action['type']. '\']/accepted_values/value[@default=\'true\']');
78
- if($default)
79
- $this->actions[(string) $action['type']]['params'][(string) $param->type]['accepted_values_default'] = (string) $default[0];
80
- }
81
- }
82
  }
83
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
  }
86
- // Payment
87
- if(count($this->object->payments)) {
88
- foreach($this->object->payments->payment as $payment) {
89
- $this->payment_lengow[(string) $payment['name']] = (string) $payment->lengow;
90
- $this->payment[(string) $payment->lengow] = (string) $payment['name'];
91
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  }
93
- $this->is_loaded = true;
94
  }
 
95
  }
96
 
97
  /**
98
- * If marketplace exist in xml configuration file
99
- *
100
- * @return boolean
101
- */
102
- public function isLoaded() {
 
103
  return $this->is_loaded;
104
  }
105
 
106
  /**
107
- * Get the real lengow's state
108
- *
109
- * @param string $name The marketplace state
110
- *
111
- * @return string The lengow state
112
- */
113
- public function getStateLengow($name) {
114
- return array_key_exists($name, $this->states_lengow) ? $this->states_lengow[$name] : self::MARKETPLACE_STATUS_NO_MATCH;
 
 
 
115
  }
116
 
117
  /**
118
- * Get the marketplace's state
119
- *
120
- * @param string $name The lengow state
121
- *
122
- * @return string The marketplace state
123
- */
124
- public function getState($name) {
 
125
  return array_key_exists($name, $this->states) ? $this->states[$name] : self::MARKETPLACE_STATUS_NO_MATCH;
126
  }
127
 
128
  /**
129
- * Get the real lengow's payment
130
- *
131
- * @param string $name The payment state
132
- *
133
- * @return string The lengow payment state
134
- */
135
- public function getStatePaymentLengow($name) {
136
- return array_key_exists($name, $this->payments_lengow) ? $this->payments_lengow[$name] : self::MARKETPLACE_STATUS_NO_MATCH;
 
137
  }
138
 
139
  /**
140
- * Get the marketplace's payment
141
- *
142
- * @param string $name The lengow payment
143
- *
144
- * @return string The marketplace payment
145
- */
146
- public function getStatePayment($name) {
147
- return array_key_exists($name, $this->payments) ? $this->payments[$name] : self::MARKETPLACE_STATUS_NO_MATCH;
 
148
  }
149
 
150
  /**
151
- * Get the action with parameters
152
- *
153
- * @param string $name The action's name
154
- *
155
- * @return array
156
- */
157
- public function getAction($name) {
158
- return $this->actions[$name];
 
 
 
 
 
 
159
  }
160
 
161
  /**
162
- * If action exist
163
- *
164
- * @param string $name The marketplace state
165
- *
166
- * @return boolean
167
- */
168
- public function isAction($name) {
169
- return isset($this->actions[$name]) ? true : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  }
171
 
172
  /**
173
- * Call the Lengow WSDL for current marketplace
174
- *
175
- * @param string $action The name of the action
176
- * @param string $id_feed The flux ID
177
- * @param Mage_Sales_Model_Order $order The order
178
- * @param string $args An array of arguments
179
- */
180
- public function wsdl($action, $id_feed, Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Shipment $shipment, $args = array()) {
181
- if(!in_array($action, self::$VALID_ACTIONS))
 
 
 
 
 
 
 
 
182
  return false;
183
- if(!$this->isAction($action))
 
 
 
 
 
 
 
184
  return false;
185
- $call_url = false;
186
- switch($action) {
187
- case 'shipped' :
188
- $call_url = $this->api_url;
189
- $call_url = str_replace('#ID_FLUX#', $id_feed, $call_url);
190
- $call_url = str_replace('#ORDER_ID#', $order->getData('order_id_lengow'), $call_url);
191
- $action_array = $this->getAction($action);
192
- $action_callback = $action_array['name'];
193
- $call_url = str_replace('#ACTION#', $action_callback, $call_url);
194
- if(isset($action_array['params'])) {
195
- $gets = array();
196
- foreach($action_array['params'] as $type => $param) {
197
- switch($type) {
198
- case 'tracking' :
 
 
 
 
199
  $trackings = $shipment->getAllTracks();
200
- if(!empty($trackings)) {
201
- $first_track = $trackings[0];
202
- $gets[$param['name']] = array(
203
- 'value' => $first_track->getNumber(),
204
- 'require' => (array_key_exists('require', $param) ? explode(' ', $param['require']) : array())
205
- );
206
  }
 
207
  break;
208
- case 'carrier' :
 
209
  $trackings = $shipment->getAllTracks();
210
- if(!empty($trackings)) {
211
- $first_track = $trackings[0];
212
- $gets[$param['name']] = array(
213
- 'value' => $this->_matchCarrier($param, $first_track->getCarrierCode(), $first_track->getTitle()),
214
- 'require' => (array_key_exists('require', $param) ? explode(' ', $param['require']) : array())
215
- );
216
  }
 
 
 
217
  break;
218
- case 'tracking_url' :
 
219
  break;
220
- case 'shipping_price' :
221
- $gets[$param['name']] = array(
222
- 'value' => $order->getShippingInclTax(),
223
- 'require' => (array_key_exists('require', $param) ? explode(' ', $param['require']) : array())
224
- );
 
 
225
  break;
226
  }
227
  }
228
- // Check dependencies in parameters
229
- if(count($gets) > 0) {
230
- foreach($gets as $key => $get) {
231
- if(array_key_exists('require', $get) && !empty($get['require'])) {
232
- foreach($get['require'] as $require) {
233
- if($gets[$require]['value'] == '') {
234
- unset($gets[$require]);
235
- unset($gets[$key]);
236
- }
237
- }
238
- }
239
- }
240
- }
241
- // Build URL
242
- $url = array();
243
- foreach($gets as $key => $value) {
244
- $url[] = $key . '=' . urlencode($value['value']);
245
- }
246
- $call_url .= '?' . implode('&', $url);
247
  }
248
  break;
249
- case 'refuse' :
250
- $call_url = $this->api_url;
251
- $call_url = str_replace('#ID_FLUX#', $id_feed, $call_url);
252
- $call_url = str_replace('#ORDER_ID#', $order->getData('order_id_lengow'), $call_url);
253
- $action_array = $this->getAction($action);
254
- $action_callback = $action_array['name'];
255
- $call_url = str_replace('#ACTION#', $action_callback, $call_url);
256
- if(isset($action_array['params'])) {
257
- $gets = array();
258
- foreach($action_array['params'] as $type => $param) {
259
- switch($type) {
260
- case 'refused_reason' :
261
  break;
262
  }
263
  }
264
- if(count($gets) > 0)
265
- $call_url .= '?' . implode('&', $gets);
266
  }
267
  break;
268
- case 'link' :
269
- $call_url = self::$WSDL_LINK_ORDER;
270
- $call_url = str_replace('#MP#', $this->name, $call_url);
271
- $call_url = str_replace('#ID_CLIENT#', $args['id_client'], $call_url);
272
- $call_url = str_replace('#ID_FLUX#', $id_feed, $call_url);
273
- $call_url = str_replace('#ORDER_ID#', $order->getData('order_id_lengow'), $call_url);
274
- $call_url = str_replace('#INTERNAL_ORDER_ID#', $order->getData('entity_id'), $call_url);
275
  }
276
  try {
277
- if($call_url) {
278
- if(!Mage::getSingleton('lensync/config')->isDebugMode()) {
279
- $this->_makeRequest($call_url);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  }
281
- Mage::helper('lensync')->log('WSDL call Lengow : ' . $call_url, $order->getData('order_id_lengow'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  }
283
- } catch(Lengow_Sync_Model_Marketplace_Exception $e) {
284
- Mage::helper('lensync')->log('call error WSDL ' . $call_url, $order->getData('order_id_lengow'));
285
- Mage::helper('lensync')->log('exception ' . $e->getMessage(), $order->getData('order_id_lengow'));
286
  }
287
  }
288
 
289
  /**
290
- * Match carrier's name with accepted values
291
- *
292
- * @param Simple_Xml_Element $param The node parameters
293
- * @param string $name The carrier name
294
- *
295
- * @return string The matching carrier name
296
- */
297
- private function _matchCarrier($param, $name, $title) {
298
- // No match
299
- if(!isset($param['accepted_values']))
300
- return $title;
301
- // Exact match
302
- foreach($param['accepted_values'] as $value) {
303
- $value = (string) $value;
304
- if(preg_match('`' . $value . '`i', trim($name)))
 
 
 
 
 
 
305
  return $value;
306
-
307
  }
308
-
309
- // Approximately match
310
- foreach($param['accepted_values'] as $value) {
311
- $value = (string) $value;
312
- if(preg_match('`.*?' . $value . '.*?`i', $name))
313
- return $value;
314
-
315
  }
316
-
317
  // search by title
318
- if (strtoupper($title) == 'GLS S')
319
  $title = 'GLS';
320
- // Exact match
321
- foreach($param['accepted_values'] as $value) {
322
- $value = (string) $value;
323
- if(preg_match('`' . $value . '`i', trim($title)))
 
324
  return $value;
325
-
326
  }
327
-
328
- // Approximately match
329
- foreach($param['accepted_values'] as $value) {
330
- $value = (string) $value;
331
- if(preg_match('`.*?' . $value . '.*?`i', $title))
332
- return $value;
333
-
334
  }
335
- return $param['accepted_values_default'];
336
- }
337
-
338
- /**
339
- * Load the xml configuration of all marketplaces
340
- */
341
- private function _loadXml() {
342
- if(!self::$DOM) {
343
- self::$DOM = simplexml_load_file(Mage::getModuleDir('etc', 'Lengow_Sync') . DS . self::$XML_MARKETPLACES);
344
  }
 
345
  }
346
 
347
  /**
348
- * Makes an HTTP request.
349
- *
350
- * @param string $url The URL to make the request to
351
- *
352
- * @return string The response text
353
- */
354
- protected function _makeRequest($url) {
355
- $ch = curl_init();
356
- // Options
357
- $connector = Mage::getSingleton('lensync/connector');
358
- $opts = $connector::$CURL_OPTS;
359
- $opts[CURLOPT_URL] = $url;
360
- // Exectute url request
361
- curl_setopt_array($ch, $opts);
362
- $result = curl_exec($ch);
363
- if ($result === false) {
364
- throw new Lengow_Sync_Model_Marketplace_Exception(
365
- array('message' => curl_error($ch),
366
- 'type' => 'CurlException',
367
- ),
368
- curl_errno($ch)
369
- );
370
  }
371
- curl_close($ch);
372
- return $result;
 
 
 
 
 
 
 
 
 
 
 
 
373
  }
374
-
375
- }
1
  <?php
2
 
3
  /**
4
+ * Lengow sync model marketplace
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 
 
 
 
 
 
11
  */
12
+ class Lengow_Sync_Model_Marketplace
13
+ {
14
 
15
+ public static $VALID_ACTIONS = array(
16
+ 'ship',
17
+ 'cancel'
18
+ );
19
 
20
+ const MARKETPLACE_STATUS_NO_MATCH = -1;
 
 
 
 
 
21
 
22
+ public $MARKETPLACES;
23
+
24
+ public $marketplace;
25
 
 
 
 
 
 
 
 
 
 
26
  public $name;
27
+
28
+ public $legacy_code;
29
+
30
  public $is_loaded = false;
31
+
32
  public $states_lengow = array();
33
+
34
  public $states = array();
35
+
36
  public $actions = array();
 
 
 
 
37
 
38
+ public $arg_values = array();
39
+
40
+ public $carriers = array();
41
+
42
+ protected $_connector;
43
+
44
+ protected $_accountId;
45
+
46
+ /**
47
+ * Construct
48
+ *
49
+ * @param array $args
50
+ *
51
+ * @return Lengow_Sync_Model_Marketplace
52
+ */
53
+ public function __construct($args)
54
+ {
55
+ if (!is_array($args)) {
56
+ return;
57
+ }
58
+ foreach ($args as $key => $value) {
59
+ $this->{'_'.$key} = $value;
60
+ }
61
+ }
62
 
63
  /**
64
+ * Load a new Markerplace instance.
65
+ *
66
+ * @param string $name The name of the marketplace
67
+ */
68
+ public function set($name)
69
+ {
70
+ if ($this->_loadApiMarketplace()) {
71
+ $this->name = strtolower($name);
72
+ if (isset($this->MARKETPLACES->{$this->name})) {
73
+ $this->marketplace = $this->MARKETPLACES->{$this->name};
74
+ if (!empty($this->marketplace)) {
75
+ $this->legacy_code = $this->marketplace->legacy_code;
76
+ foreach ($this->marketplace->orders->status as $key => $state) {
77
+ foreach ($state as $value) {
78
+ $this->states_lengow[(string)$value] = (string)$key;
79
+ $this->states[(string)$key][(string)$value] = (string)$value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  }
81
  }
82
+ foreach ($this->marketplace->orders->actions as $key => $action) {
83
+ foreach ($action->status as $state) {
84
+ $this->actions[(string)$key]['status'][(string)$state] = (string)$state;
85
+ }
86
+ foreach ($action->args as $arg) {
87
+ $this->actions[(string)$key]['args'][(string)$arg] = (string)$arg;
88
+ }
89
+ foreach ($action->optional_args as $optional_arg) {
90
+ $this->actions[(string)$key]['optional_args'][(string)$optional_arg] = $optional_arg;
91
+ }
92
+ foreach ($action->args_description as $key => $arg_description) {
93
+ $valid_values = array();
94
+ if (isset($arg_description->valid_values)) {
95
+ foreach ($arg_description->valid_values as $code => $valid_value) {
96
+ $valid_values[(string)$code] = (string)$valid_value->label;
97
+ }
98
+ }
99
+ $this->arg_values[(string)$key] = array(
100
+ 'default_value' => (string)$arg_description->default_value,
101
+ 'accept_free_values' => (bool)$arg_description->accept_free_values,
102
+ 'valid_values' => $valid_values
103
+ );
104
+ }
105
+ }
106
+ if (isset($this->marketplace->orders->carriers)) {
107
+ foreach ($this->marketplace->orders->carriers as $key => $carrier) {
108
+ $this->carriers[(string)$key] = (string)$carrier->label;
109
+ }
110
+ }
111
+ $this->is_loaded = true;
112
  }
113
  }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Load the json configuration of all marketplaces
119
+ *
120
+ * @param integer $account_id
121
+ *
122
+ * @return boolean
123
+ */
124
+ private function _loadApiMarketplace()
125
+ {
126
+ if (!$this->MARKETPLACES) {
127
+ if ($this->_connector->isValidAuth($this->_accountId)) {
128
+ $results = $this->_connector->get(
129
+ '/v3.0/marketplaces',
130
+ array(
131
+ 'account_id' => $this->_accountId
132
+ ),
133
+ 'stream'
134
+ );
135
+ $this->MARKETPLACES = json_decode($results);
136
+ return true;
137
+ } else {
138
+ return false;
139
  }
 
140
  }
141
+ return true;
142
  }
143
 
144
  /**
145
+ * If marketplace exist in xml configuration file
146
+ *
147
+ * @return boolean
148
+ */
149
+ public function isLoaded()
150
+ {
151
  return $this->is_loaded;
152
  }
153
 
154
  /**
155
+ * Get the real lengow's state
156
+ *
157
+ * @param string $name The marketplace state
158
+ *
159
+ * @return string The lengow state
160
+ */
161
+ public function getStateLengow($name)
162
+ {
163
+ return array_key_exists($name, $this->states_lengow)
164
+ ? $this->states_lengow[$name]
165
+ : self::MARKETPLACE_STATUS_NO_MATCH;
166
  }
167
 
168
  /**
169
+ * Get the marketplace's state
170
+ *
171
+ * @param string $name The lengow state
172
+ *
173
+ * @return string The marketplace state
174
+ */
175
+ public function getState($name)
176
+ {
177
  return array_key_exists($name, $this->states) ? $this->states[$name] : self::MARKETPLACE_STATUS_NO_MATCH;
178
  }
179
 
180
  /**
181
+ * Get the action with parameters
182
+ *
183
+ * @param string $name The action's name
184
+ *
185
+ * @return array
186
+ */
187
+ public function getAction($name)
188
+ {
189
+ return array_key_exists($name, $this->actions) ? $this->actions[$name] : false;
190
  }
191
 
192
  /**
193
+ * If action exist
194
+ *
195
+ * @param string $name The marketplace state
196
+ *
197
+ * @return boolean
198
+ */
199
+ public function isAction($name)
200
+ {
201
+ return array_key_exists($name, $this->actions) ? true : false;
202
  }
203
 
204
  /**
205
+ * Return array of marketplaces from the marketplaces.xml file
206
+ *
207
+ * @return array $marketplaces
208
+ */
209
+ public function getMarkeplaces()
210
+ {
211
+ $marketplaces = array();
212
+ if ($this->_loadApiMarketplace()) {
213
+ foreach ($this->MARKETPLACES as $key => $marketplace) {
214
+ $marketplaces[(string)$key] = (string)$key;
215
+ }
216
+ ksort($marketplaces);
217
+ }
218
+ return $marketplaces;
219
  }
220
 
221
  /**
222
+ * Check if a status is valid for action
223
+ *
224
+ * @param array $action_status valid status for action
225
+ * @param string $current_status curent status id
226
+ *
227
+ * @return boolean
228
+ */
229
+ public function isValidState($action_status, $current_status)
230
+ {
231
+ $model_order = Mage::getModel('lensync/order');
232
+ foreach ($action_status as $status) {
233
+ if ($current_status == $model_order->getOrderState($status)) {
234
+ return true;
235
+ }
236
+ }
237
+ return false;
238
+ }
239
+
240
+ /**
241
+ * Get the default value for argument
242
+ *
243
+ * @param string $name The argument's name
244
+ *
245
+ * @return mixed
246
+ */
247
+ public function getDefaultValue($name)
248
+ {
249
+ if (array_key_exists($name, $this->arg_values)) {
250
+ $default_value = $this->arg_values[$name]['default_value'];
251
+ if (!empty($default_value)) {
252
+ return $default_value;
253
+ }
254
+ }
255
+ return false;
256
  }
257
 
258
  /**
259
+ * Call the Lengow WSDL for current marketplace
260
+ *
261
+ * @param string $action The name of the action
262
+ * @param string $id_lengow_order Lengow Order ID
263
+ * @param Mage_Sales_Model_Order $order Magento order
264
+ * @param Mage_Sales_Model_Order_Shipment $shipment Magento shipment
265
+ * @param string $args An array of arguments
266
+ *
267
+ */
268
+ public function wsdl(
269
+ $action,
270
+ $id_lengow_order,
271
+ Mage_Sales_Model_Order $order,
272
+ Mage_Sales_Model_Order_Shipment $shipment,
273
+ $args = array()
274
+ ) {
275
+ if (!in_array($action, self::$VALID_ACTIONS)) {
276
  return false;
277
+ }
278
+ if (!$this->isAction($action)) {
279
+ return false;
280
+ }
281
+ $store = $order->getStore();
282
+ $lensync_config = Mage::getModel('lensync/config', array('store' => $store));
283
+ $action_array = $this->getAction($action);
284
+ if (!$action_array) {
285
  return false;
286
+ }
287
+ $params = array(
288
+ 'account_id' => $this->_accountId,
289
+ 'marketplace_order_id' => (string)$id_lengow_order,
290
+ 'marketplace' => (string)$order->getData('marketplace_lengow')
291
+ );
292
+ if (isset($action_array['optional_args'])) {
293
+ $all_args = array_merge($action_array['args'], $action_array['optional_args']);
294
+ } else {
295
+ $all_args = $action_array['args'];
296
+ }
297
+ switch ($action) {
298
+ case 'ship':
299
+ $params['action_type'] = 'ship';
300
+ if (isset($action_array['args'])) {
301
+ foreach ($all_args as $arg) {
302
+ switch ($arg) {
303
+ case 'tracking_number':
304
  $trackings = $shipment->getAllTracks();
305
+ if (!empty($trackings)) {
306
+ $last_track = end($trackings);
 
 
 
 
307
  }
308
+ $params[$arg] = isset($last_track) ? $last_track->getNumber() : '';
309
  break;
310
+ case 'carrier':
311
+ case 'shipping_method':
312
  $trackings = $shipment->getAllTracks();
313
+ if (!empty($trackings)) {
314
+ $last_track = end($trackings);
 
 
 
 
315
  }
316
+ $params[$arg] = isset($last_track)
317
+ ? $this->_matchCarrier($last_track->getCarrierCode(), $last_track->getTitle())
318
+ : '';
319
  break;
320
+ case 'shipping_price':
321
+ $params[$arg] = $order->getShippingInclTax();
322
  break;
323
+ case 'shipping_date':
324
+ $params[$arg] = date('c');
325
+ break;
326
+ default:
327
+ $default_value = $this->getDefaultValue((string)$arg);
328
+ $param_value = $default_value ? $default_value : $arg.' not available';
329
+ $params[$arg] = $param_value;
330
  break;
331
  }
332
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  }
334
  break;
335
+ case 'cancel':
336
+ $params['action_type'] = 'cancel';
337
+ if (isset($all_args['args'])) {
338
+ foreach ($all_args as $arg) {
339
+ switch ($arg) {
340
+ default:
341
+ $default_value = $this->getDefaultValue((string)$arg);
342
+ $param_value = $default_value ? $default_value : $arg.' not available';
343
+ $params[$arg] = $param_value;
 
 
 
344
  break;
345
  }
346
  }
 
 
347
  }
348
  break;
 
 
 
 
 
 
 
349
  }
350
  try {
351
+ // if line_id is a required parameter -> send a call for each line_id
352
+ if (in_array('line', $all_args)) {
353
+ $order_line_sent = false;
354
+ $order_lines = Mage::getModel('lensync/order')->getOrderLineFromIdOrder((integer)$order->getId());
355
+ if ($order_lines) {
356
+ foreach ($order_lines as $order_line) {
357
+ $params['line'] = $order_line['id_order_line'];
358
+ if (!$lensync_config->isDebugMode()) {
359
+ $result = $this->_connector->post('/v3.0/orders/actions/', $params);
360
+ if (isset($result->id)) {
361
+ Mage::helper('lensync/data')->log(
362
+ 'WSDL : action '.$action.' successfully sent',
363
+ $id_lengow_order
364
+ );
365
+ } else {
366
+ Mage::helper('lensync/data')->log(
367
+ 'WSDL : WARNING ! action '.$action.' could NOT be sent: '.json_encode($result),
368
+ $id_lengow_order
369
+ );
370
+ }
371
+ }
372
+ // Get all params send
373
+ $param_list = false;
374
+ foreach ($params as $param => $value) {
375
+ $param_list.= (!$param_list ? '"'.$param.'": '.$value : ' -- "'.$param.'": '.$value);
376
+ }
377
+ Mage::helper('lensync/data')->log('WSDL : '.$param_list, $id_lengow_order);
378
+ }
379
  }
380
+ } else {
381
+ if (!$lensync_config->isDebugMode()) {
382
+ $result = $this->_connector->post('/v3.0/orders/actions/', $params);
383
+ if (isset($result->id)) {
384
+ Mage::helper('lensync/data')->log(
385
+ 'WSDL : action '.$action.' successfully sent',
386
+ $id_lengow_order
387
+ );
388
+ } else {
389
+ Mage::helper('lensync/data')->log(
390
+ 'WSDL : WARNING ! action '.$action.' could NOT be sent: '.json_encode($result),
391
+ $id_lengow_order
392
+ );
393
+ }
394
+ }
395
+ // Get all params send
396
+ $param_list = false;
397
+ foreach ($params as $param => $value) {
398
+ $param_list.= (!$param_list ? '"'.$param.'": '.$value : ' -- "'.$param.'": '.$value);
399
+ }
400
+ Mage::helper('lensync/data')->log('WSDL : '.$param_list, $id_lengow_order);
401
  }
402
+ } catch (Exception $e) {
403
+ Mage::helper('lensync/data')->log('call error WSDL - exception: '.$e->getMessage(), $id_lengow_order);
 
404
  }
405
  }
406
 
407
  /**
408
+ * Match carrier's name with accepted values
409
+ *
410
+ * @param string $code
411
+ * @param string $title
412
+ *
413
+ * @return string The matching carrier name
414
+ */
415
+ private function _matchCarrier($code, $title)
416
+ {
417
+ // no carrier
418
+ if (count($this->carriers) == 0) {
419
+ if ($code == 'custom') {
420
+ return $title;
421
+ }
422
+ return $code;
423
+ }
424
+ // search by code
425
+ // exact match
426
+ foreach ($this->carriers as $key => $carrier) {
427
+ $value = (string)$key;
428
+ if (preg_match('`'.$value.'`i', trim($code))) {
429
  return $value;
430
+ }
431
  }
432
+ // approximately match
433
+ foreach ($this->carriers as $key => $carrier) {
434
+ $value = (string)$key;
435
+ if (preg_match('`.*?'.$value.'.*?`i', $code)) {
436
+ return $value;
437
+ }
 
438
  }
 
439
  // search by title
440
+ if (strtoupper($title) == 'GLS S') {
441
  $title = 'GLS';
442
+ }
443
+ // exact match
444
+ foreach ($this->carriers as $key => $carrier) {
445
+ $value = (string)$key;
446
+ if (preg_match('`'.$value.'`i', trim($title))) {
447
  return $value;
448
+ }
449
  }
450
+ // approximately match
451
+ foreach ($this->carriers as $key => $carrier) {
452
+ $value = (string)$key;
453
+ if (preg_match('`.*?'.$value.'.*?`i', $title)) {
454
+ return $value;
455
+ }
 
456
  }
457
+ // no match
458
+ if ($code == 'custom') {
459
+ return $title;
 
 
 
 
 
 
460
  }
461
+ return $code;
462
  }
463
 
464
  /**
465
+ * Check and change the name of the marketplace for v3 compatibility
466
+ *
467
+ * @param Mage_Sales_Model_Order $order Magento order
468
+ *
469
+ * @return Mage_Sales_Model_Order
470
+ */
471
+ public function checkAndChangeMarketplaceName(Mage_Sales_Model_Order $order)
472
+ {
473
+ $results = $this->_connector->get(
474
+ '/v3.0/orders',
475
+ array(
476
+ 'marketplace_order_id' => (string)$order->getData('order_id_lengow'),
477
+ 'marketplace' => (string)$order->getData('marketplace_lengow'),
478
+ 'account_id' => $this->_accountId
479
+ ),
480
+ 'stream'
481
+ );
482
+ if (is_null($results)) {
483
+ return $order;
 
 
 
484
  }
485
+ $results = json_decode($results);
486
+ if (!is_object($results)) {
487
+ return $order;
488
+ }
489
+ if (isset($results->error)) {
490
+ return $order;
491
+ }
492
+ foreach ($results->results as $result) {
493
+ if ((string)$order->getData('marketplace_lengow') != (string)$result->marketplace) {
494
+ $order->setMarketplaceLengow((string)$result->marketplace);
495
+ $order->save();
496
+ }
497
+ }
498
+ return $order;
499
  }
500
+ }
 
app/code/community/Lengow/Sync/Model/Marketplace/Exception.php CHANGED
@@ -1,11 +1,16 @@
1
  <?php
2
 
3
  /**
4
- * Thrown when an WSDL call returns an exception.
5
  *
6
- * @author Ludovic Drin <ludovic@lengow.com>
 
 
 
 
7
  */
8
- class Lengow_Sync_Model_Marketplace_Exception extends Exception {
 
9
 
10
  /**
11
  * The result from the WSDL server that represents the exception information.
@@ -17,12 +22,14 @@ class Lengow_Sync_Model_Marketplace_Exception extends Exception {
17
  *
18
  * @param array $result The error result
19
  */
20
- public function __construct($result, $noerror) {
 
21
  $this->result = $result;
22
- if(is_array($result))
23
  $msg = $result['message'];
24
- else
25
  $msg = $result;
 
26
  parent::__construct($msg, $noerror);
27
  }
28
 
@@ -31,18 +38,21 @@ class Lengow_Sync_Model_Marketplace_Exception extends Exception {
31
  *
32
  * @return array The result from the WSDL server
33
  */
34
- public function getResult() {
 
35
  return $this->result;
36
  }
37
 
38
  /**
39
- * Returns the associated type for the error.
40
  *
41
  * @return string
42
  */
43
- public function getType() {
44
- if(isset($this->result['type']))
 
45
  return $this->result['type'];
 
46
  return 'Lengow_Sync_Model_Marketplace_Exception';
47
  }
48
 
@@ -51,9 +61,11 @@ class Lengow_Sync_Model_Marketplace_Exception extends Exception {
51
  *
52
  * @return string The string representation of the error
53
  */
54
- public function __toString() {
55
- if(isset($this->result['message']))
 
56
  return $this->result['message'];
57
- return $this->message;
 
58
  }
59
- }
1
  <?php
2
 
3
  /**
4
+ * Lengow sync model marketplace exception
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Marketplace_Exception extends Exception
13
+ {
14
 
15
  /**
16
  * The result from the WSDL server that represents the exception information.
22
  *
23
  * @param array $result The error result
24
  */
25
+ public function __construct($result, $noerror)
26
+ {
27
  $this->result = $result;
28
+ if (is_array($result)) {
29
  $msg = $result['message'];
30
+ } else {
31
  $msg = $result;
32
+ }
33
  parent::__construct($msg, $noerror);
34
  }
35
 
38
  *
39
  * @return array The result from the WSDL server
40
  */
41
+ public function getResult()
42
+ {
43
  return $this->result;
44
  }
45
 
46
  /**
47
+ * Returns the associated type for the error.
48
  *
49
  * @return string
50
  */
51
+ public function getType()
52
+ {
53
+ if (isset($this->result['type'])) {
54
  return $this->result['type'];
55
+ }
56
  return 'Lengow_Sync_Model_Marketplace_Exception';
57
  }
58
 
61
  *
62
  * @return string The string representation of the error
63
  */
64
+ public function __toString()
65
+ {
66
+ if (isset($this->result['message'])) {
67
  return $this->result['message'];
68
+ }
69
+ return $this->message;
70
  }
71
+ }
app/code/community/Lengow/Sync/Model/Marketplacev2.php ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Copyright 2013 Lengow.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
7
+ * not use this file except in compliance with the License. You may obtain
8
+ * a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ * License for the specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+
19
+
20
+ /**
21
+ * The Lengow Marketplace Class.
22
+ *
23
+ * @author Ludovic Drin <ludovic@lengow.com>
24
+ * @copyright 2013 Lengow SAS
25
+ */
26
+ class Lengow_Sync_Model_Marketplacev2
27
+ {
28
+
29
+ public static $XML_MARKETPLACES = 'marketplaces.xml';
30
+ public static $DOM;
31
+ public static $VALID_ACTIONS = array(
32
+ // 'accept' ,
33
+ 'shipped',
34
+ 'refuse',
35
+ 'link',
36
+ );
37
+ public static $WSDL_LINK_ORDER = 'https://wsdl.lengow.com/wsdl/link/#MP#/#ID_CLIENT#/#ID_FLUX#/#ORDER_ID#/#INTERNAL_ORDER_ID#/update.xml';
38
+ public $name;
39
+ public $object;
40
+ public $is_loaded = false;
41
+ public $states_lengow = array();
42
+ public $states = array();
43
+ public $actions = array();
44
+ public $payments = array();
45
+ public $payments_lengow = array();
46
+ protected $_config;
47
+ const MARKETPLACE_STATUS_NO_MATCH = -1;
48
+
49
+
50
+ /**
51
+ * Construct a new Markerplace instance with xml configuration.
52
+ *
53
+ * @param string $name The name of the marketplace
54
+ */
55
+ public function set($name)
56
+ {
57
+ $this->_helper = Mage::helper('lensync/data');
58
+ $this->_loadXml();
59
+ $this->name = strtolower($name);
60
+ $object = self::$DOM->xpath('/marketplaces/marketplace[@name=\''.$this->name.'\']');
61
+ if (!empty($object)) {
62
+ $this->object = $object[0];
63
+ $this->api_url = (string)$this->object->api;
64
+ // States
65
+ foreach ($this->object->states->state as $state) {
66
+ $this->states_lengow[(string)$state['name']] = (string)$state->lengow;
67
+ $this->states[(string)$state->lengow] = (string)$state['name'];
68
+ if (isset($state->actions)) {
69
+ foreach ($state->actions->action as $action) {
70
+ $this->actions[(string)$action['type']] = array();
71
+ $this->actions[(string)$action['type']]['name'] = (string)$action;
72
+ $params = self::$DOM->xpath('/marketplaces/marketplace[@name=\''.$this->name.'\']/additional_params/param[@usedby=\''.(string)$action['type'].'\']');
73
+ if (count($params)) {
74
+ foreach ($params as $param) {
75
+ $this->actions[(string)$action['type']]['params'][(string)$param->type]['name'] = (string)$param->name;
76
+ if (isset($param->accepted_values)) {
77
+ $this->actions[(string)$action['type']]['params'][(string)$param->type]['accepted_values'] = $param->accepted_values->value;
78
+ $default = self::$DOM->xpath('/marketplaces/marketplace[@name=\''.$this->name.'\']/additional_params/param[@usedby=\''.(string)$action['type'].'\']/accepted_values/value[@default=\'true\']');
79
+ if ($default) {
80
+ $this->actions[(string)$action['type']]['params'][(string)$param->type]['accepted_values_default'] = (string)$default[0];
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ // Payment
89
+ if (count($this->object->payments)) {
90
+ foreach ($this->object->payments->payment as $payment) {
91
+ $this->payment_lengow[(string)$payment['name']] = (string)$payment->lengow;
92
+ $this->payment[(string)$payment->lengow] = (string)$payment['name'];
93
+ }
94
+ }
95
+ $this->is_loaded = true;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * If marketplace exist in xml configuration file
101
+ *
102
+ * @return boolean
103
+ */
104
+ public function isLoaded()
105
+ {
106
+ return $this->is_loaded;
107
+ }
108
+
109
+ /**
110
+ * Get the real lengow's state
111
+ *
112
+ * @param string $name The marketplace state
113
+ *
114
+ * @return string The lengow state
115
+ */
116
+ public function getStateLengow($name)
117
+ {
118
+ return array_key_exists($name, $this->states_lengow)
119
+ ? $this->states_lengow[$name]
120
+ : self::MARKETPLACE_STATUS_NO_MATCH;
121
+ }
122
+
123
+ /**
124
+ * Get the marketplace's state
125
+ *
126
+ * @param string $name The lengow state
127
+ *
128
+ * @return string The marketplace state
129
+ */
130
+ public function getState($name)
131
+ {
132
+ return array_key_exists($name, $this->states) ? $this->states[$name] : self::MARKETPLACE_STATUS_NO_MATCH;
133
+ }
134
+
135
+ /**
136
+ * Get the real lengow's payment
137
+ *
138
+ * @param string $name The payment state
139
+ *
140
+ * @return string The lengow payment state
141
+ */
142
+ public function getStatePaymentLengow($name)
143
+ {
144
+ return array_key_exists($name, $this->payments_lengow)
145
+ ? $this->payments_lengow[$name]
146
+ : self::MARKETPLACE_STATUS_NO_MATCH;
147
+ }
148
+
149
+ /**
150
+ * Get the marketplace's payment
151
+ *
152
+ * @param string $name The lengow payment
153
+ *
154
+ * @return string The marketplace payment
155
+ */
156
+ public function getStatePayment($name)
157
+ {
158
+ return array_key_exists($name, $this->payments) ? $this->payments[$name] : self::MARKETPLACE_STATUS_NO_MATCH;
159
+ }
160
+
161
+ /**
162
+ * Get the action with parameters
163
+ *
164
+ * @param string $name The action's name
165
+ *
166
+ * @return array
167
+ */
168
+ public function getAction($name)
169
+ {
170
+ return $this->actions[$name];
171
+ }
172
+
173
+ /**
174
+ * If action exist
175
+ *
176
+ * @param string $name The marketplace state
177
+ *
178
+ * @return boolean
179
+ */
180
+ public function isAction($name)
181
+ {
182
+ return isset($this->actions[$name]) ? true : false;
183
+ }
184
+
185
+ /**
186
+ * Call the Lengow WSDL for current marketplace
187
+ *
188
+ * @param string $action The name of the action
189
+ * @param string $id_feed The flux ID
190
+ * @param Mage_Sales_Model_Order $order The order
191
+ * @param string $args An array of arguments
192
+ */
193
+ public function wsdl(
194
+ $action,
195
+ $id_feed,
196
+ Mage_Sales_Model_Order $order,
197
+ Mage_Sales_Model_Order_Shipment $shipment,
198
+ $args = array()
199
+ ) {
200
+ if (!in_array($action, self::$VALID_ACTIONS)) {
201
+ return false;
202
+ }
203
+ if (!$this->isAction($action)) {
204
+ return false;
205
+ }
206
+ $call_url = false;
207
+ switch ($action) {
208
+ case 'shipped':
209
+ $call_url = $this->api_url;
210
+ $call_url = str_replace('#ID_FLUX#', $id_feed, $call_url);
211
+ $call_url = str_replace('#ORDER_ID#', $order->getData('order_id_lengow'), $call_url);
212
+ $action_array = $this->getAction($action);
213
+ $action_callback = $action_array['name'];
214
+ $call_url = str_replace('#ACTION#', $action_callback, $call_url);
215
+ if (isset($action_array['params'])) {
216
+ $gets = array();
217
+ foreach ($action_array['params'] as $type => $param) {
218
+ switch ($type) {
219
+ case 'tracking':
220
+ $trackings = $shipment->getAllTracks();
221
+ if (!empty($trackings)) {
222
+ $last_track = end($trackings);;
223
+ $gets[$param['name']] = array(
224
+ 'value' => $last_track->getNumber(),
225
+ 'require' => (array_key_exists('require', $param)
226
+ ? explode(' ', $param['require'])
227
+ : array()
228
+ )
229
+ );
230
+ }
231
+ break;
232
+ case 'carrier':
233
+ $trackings = $shipment->getAllTracks();
234
+ if (!empty($trackings)) {
235
+ $last_track = end($trackings);
236
+ $gets[$param['name']] = array(
237
+ 'value' => $this->_matchCarrier(
238
+ $param,
239
+ $last_track->getCarrierCode(),
240
+ $last_track->getTitle()
241
+ ),
242
+ 'require' => (array_key_exists('require', $param)
243
+ ? explode(' ', $param['require'])
244
+ : array()
245
+ )
246
+ );
247
+ }
248
+ break;
249
+ case 'tracking_url':
250
+ break;
251
+ case 'shipping_price':
252
+ $gets[$param['name']] = array(
253
+ 'value' => $order->getShippingInclTax(),
254
+ 'require' => (array_key_exists('require', $param)
255
+ ? explode(' ', $param['require'])
256
+ : array()
257
+ )
258
+ );
259
+ break;
260
+ }
261
+ }
262
+ // Check dependencies in parameters
263
+ if (count($gets) > 0) {
264
+ foreach ($gets as $key => $get) {
265
+ if (array_key_exists('require', $get) && !empty($get['require'])) {
266
+ foreach ($get['require'] as $require) {
267
+ if ($gets[$require]['value'] == '') {
268
+ unset($gets[$require]);
269
+ unset($gets[$key]);
270
+ }
271
+ }
272
+ }
273
+ }
274
+ }
275
+ // Build URL
276
+ $url = array();
277
+ foreach ($gets as $key => $value) {
278
+ $url[] = $key.'='.urlencode($value['value']);
279
+ }
280
+ $call_url.= '?'.implode('&', $url);
281
+ }
282
+ break;
283
+ case 'refuse':
284
+ $call_url = $this->api_url;
285
+ $call_url = str_replace('#ID_FLUX#', $id_feed, $call_url);
286
+ $call_url = str_replace('#ORDER_ID#', $order->getData('order_id_lengow'), $call_url);
287
+ $action_array = $this->getAction($action);
288
+ $action_callback = $action_array['name'];
289
+ $call_url = str_replace('#ACTION#', $action_callback, $call_url);
290
+ if (isset($action_array['params'])) {
291
+ $gets = array();
292
+ foreach ($action_array['params'] as $type => $param) {
293
+ switch ($type) {
294
+ case 'refused_reason':
295
+ break;
296
+ }
297
+ }
298
+ if (count($gets) > 0) {
299
+ $call_url.= '?'.implode('&', $gets);
300
+ }
301
+ }
302
+ break;
303
+ case 'link':
304
+ $call_url = self::$WSDL_LINK_ORDER;
305
+ $call_url = str_replace('#MP#', $this->name, $call_url);
306
+ $call_url = str_replace('#ID_CLIENT#', $args['id_client'], $call_url);
307
+ $call_url = str_replace('#ID_FLUX#', $id_feed, $call_url);
308
+ $call_url = str_replace('#ORDER_ID#', $order->getData('order_id_lengow'), $call_url);
309
+ $call_url = str_replace('#INTERNAL_ORDER_ID#', $order->getData('entity_id'), $call_url);
310
+ }
311
+ try {
312
+ if ($call_url) {
313
+ if (!Mage::getSingleton('lensync/config')->isDebugMode()) {
314
+ $this->_makeRequest($call_url);
315
+ }
316
+ Mage::helper('lensync')->log('WSDL call Lengow : '.$call_url, $order->getData('order_id_lengow'));
317
+ }
318
+ } catch (Lengow_Sync_Model_Marketplace_Exception $e) {
319
+ Mage::helper('lensync')->log('call error WSDL '.$call_url, $order->getData('order_id_lengow'));
320
+ Mage::helper('lensync')->log('exception '.$e->getMessage(), $order->getData('order_id_lengow'));
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Match carrier's name with accepted values
326
+ *
327
+ * @param Simple_Xml_Element $param The node parameters
328
+ * @param string $name The carrier name
329
+ *
330
+ * @return string The matching carrier name
331
+ */
332
+ private function _matchCarrier($param, $name, $title)
333
+ {
334
+ // No match
335
+ if (!isset($param['accepted_values'])) {
336
+ return $title;
337
+ }
338
+ // Exact match
339
+ foreach ($param['accepted_values'] as $value) {
340
+ $value = (string)$value;
341
+ if (preg_match('`' . $value . '`i', trim($name))) {
342
+ return $value;
343
+ }
344
+
345
+ }
346
+ // Approximately match
347
+ foreach ($param['accepted_values'] as $value) {
348
+ $value = (string)$value;
349
+ if (preg_match('`.*?' . $value . '.*?`i', $name)) {
350
+ return $value;
351
+ }
352
+
353
+ }
354
+ // search by title
355
+ if (strtoupper($title) == 'GLS S') {
356
+ $title = 'GLS';
357
+ }
358
+ // Exact match
359
+ foreach ($param['accepted_values'] as $value) {
360
+ $value = (string)$value;
361
+ if (preg_match('`' . $value . '`i', trim($title))) {
362
+ return $value;
363
+ }
364
+
365
+ }
366
+ // Approximately match
367
+ foreach ($param['accepted_values'] as $value) {
368
+ $value = (string)$value;
369
+ if (preg_match('`.*?' . $value . '.*?`i', $title)) {
370
+ return $value;
371
+ }
372
+
373
+ }
374
+ return $param['accepted_values_default'];
375
+ }
376
+
377
+ /**
378
+ * Load the xml configuration of all marketplaces
379
+ */
380
+ private function _loadXml()
381
+ {
382
+ if (!self::$DOM) {
383
+ self::$DOM = simplexml_load_file(Mage::getModuleDir('etc', 'Lengow_Sync') . DS . self::$XML_MARKETPLACES);
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Makes an HTTP request.
389
+ *
390
+ * @param string $url The URL to make the request to
391
+ *
392
+ * @return string The response text
393
+ */
394
+ protected function _makeRequest($url)
395
+ {
396
+ $ch = curl_init();
397
+ // Options
398
+ $connector = Mage::getSingleton('lensync/connector');
399
+ $opts = $connector::$CURL_OPTS;
400
+ $opts[CURLOPT_URL] = $url;
401
+ // Exectute url request
402
+ curl_setopt_array($ch, $opts);
403
+ $result = curl_exec($ch);
404
+ if ($result === false) {
405
+ throw new Lengow_Sync_Model_Marketplace_Exception(
406
+ array(
407
+ 'message' => curl_error($ch),
408
+ 'type' => 'CurlException',
409
+ ),
410
+ curl_errno($ch)
411
+ );
412
+ }
413
+ curl_close($ch);
414
+ return $result;
415
+ }
416
+ }
app/code/community/Lengow/Sync/Model/Mysql4/Log.php CHANGED
@@ -1,16 +1,19 @@
1
  <?php
 
2
  /**
3
  * Lengow sync model mysql4 log
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Mysql4_Log extends Mage_Core_Model_Mysql4_Abstract {
 
12
 
13
- protected function _construct() {
14
- $this->_init('lensync/log', 'id');
15
- }
16
- }
 
1
  <?php
2
+
3
  /**
4
  * Lengow sync model mysql4 log
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Mysql4_Log extends Mage_Core_Model_Mysql4_Abstract
13
+ {
14
 
15
+ protected function _construct()
16
+ {
17
+ $this->_init('lensync/log', 'id');
18
+ }
19
+ }
app/code/community/Lengow/Sync/Model/Mysql4/Log/Collection.php CHANGED
@@ -1,16 +1,19 @@
1
  <?php
 
2
  /**
3
  * Lengow sync model mysql4 log collection
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Mysql4_Log_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
 
12
 
13
- protected function _construct() {
14
- $this->_init('lensync/log');
15
- }
16
- }
 
1
  <?php
2
+
3
  /**
4
  * Lengow sync model mysql4 log collection
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Mysql4_Log_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
13
+ {
14
 
15
+ protected function _construct()
16
+ {
17
+ $this->_init('lensync/log');
18
+ }
19
+ }
app/code/community/Lengow/Sync/Model/Mysql4/Orderline.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow sync model mysql4 orderline
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Model_Mysql4_Orderline extends Mage_Core_Model_Mysql4_Abstract
13
+ {
14
+
15
+ protected function _construct()
16
+ {
17
+ $this->_init('lensync/orderline', 'id');
18
+ }
19
+ }
app/code/community/Lengow/Sync/Model/Mysql4/Orderline/Collection.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow sync model mysql4 orderline collection
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Model_Mysql4_Orderline_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
13
+ {
14
+
15
+ public function _construct()
16
+ {
17
+ parent::_construct();
18
+ $this->_init('lensync/orderline');
19
+ }
20
+ }
app/code/community/Lengow/Sync/Model/Observer.php CHANGED
@@ -1,21 +1,26 @@
1
  <?php
 
2
  /**
3
  * Lengow sync model observer
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Observer {
 
12
 
13
- /**
14
- * Imports orders for each store with cron job
15
- */
16
- public function import($observer)
 
 
 
17
  {
18
- if(Mage::getStoreConfig('lensync/performances/active_cron')) {
19
  // update marketplace file
20
  Mage::helper('lensync/data')->updateMarketplaceXML();
21
  // clean old log (20 days)
@@ -25,149 +30,337 @@ class Lengow_Sync_Model_Observer {
25
  Mage::helper('lensync/data')->log('## Error cron import : import is already started ##');
26
  } else {
27
  Mage::helper('lensync/data')->log('## Start cron import ##');
28
-
29
- if(Mage::getStoreConfig('lensync/performances/debug'))
30
  Mage::helper('lensync/data')->log('WARNING ! Debug mode is activated');
31
-
32
  $result_new = 0;
33
  $result_update = 0;
34
  $lengow_groups = array();
35
-
36
- $store_collection = Mage::getResourceModel('core/store_collection')
37
- ->addFieldToFilter('is_active', 1);
38
  // Import different view if is different
39
- foreach($store_collection as $store) {
40
  try {
41
- if(!$store->getId())
42
  continue;
43
-
44
- Mage::helper('lensync/data')->log('Start cron import in store ' . $store->getName() . ' (' . $store->getId() . ')');
45
-
 
46
  $lensync_config = Mage::getModel('lensync/config', array('store' => $store));
47
  // if store is enabled -> stop import
48
- if(!$lensync_config->get('orders/active_store')) {
49
- Mage::helper('lensync/data')->log('Stop cron import - Store ' . $store->getName() . '(' . $store->getId() . ') is disabled');
 
 
50
  continue;
51
  }
52
- // get login informations
53
- $error_import = false;
54
- $lentracker_config = Mage::getModel('lentracker/config', array('store' => $store));
55
- $id_lengow_customer = $lentracker_config->get('general/login');
56
- $id_lengow_group = $this->_cleanGroup($lentracker_config->get('general/group'));
57
- $api_token_lengow = $lentracker_config->get('general/api_key');
58
- // if ID Customer or group are empty -> stop import for this store
59
- if (empty($id_lengow_customer) || !is_numeric($id_lengow_customer) || empty($id_lengow_group)) {
60
- $message = 'id customer or id group is empty. Please make sure it is saved in your plugin configuration';
61
- Mage::helper('lensync/data')->log('Stop cron import in store ' . $store->getName() . '(' . $store->getId() . ') : ' . $message);
62
- $error_import = true;
63
- }
64
- // check if group was already imported
65
- $new_id_lengow_group = false;
66
- $id_groups = explode(',', $id_lengow_group);
67
- foreach ($id_groups as $id_group) {
68
- if (is_numeric($id_group) && !in_array($id_group, $lengow_groups)) {
69
- $lengow_groups[] = $id_group;
70
- $new_id_lengow_group .= !$new_id_lengow_group ? $id_group : ','.$id_group;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
  }
73
- if (!$error_import && $new_id_lengow_group) {
74
- $days = $lensync_config->get('orders/period');
75
- $args = array(
76
- 'dateFrom' => date('Y-m-d', strtotime(date('Y-m-d') . '-' . $days . 'days')),
77
- 'dateTo' => date('Y-m-d'),
78
- 'config' => $lensync_config,
79
- 'idCustomer' => $id_lengow_customer,
80
- 'idGroup' => $new_id_lengow_group,
81
- 'apiToken' => $api_token_lengow,
82
- );
83
- $import = Mage::getModel('lensync/import', $args);
84
- $result = $import->exec();
85
- $result_new += $result['new'];
86
- $result_update += $result['update'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  }
88
- } catch(Exception $e) {
89
- Mage::helper('lensync/data')->log('Error ' . $e->getMessage() . '');
90
  }
91
  }
92
- if($result_new > 0)
93
- Mage::helper('lensync/data')->log(Mage::helper('lensync')->__('%d orders are imported', $result_new));
94
- if($result_update > 0)
95
- Mage::helper('lensync/data')->log(Mage::helper('lensync')->__('%d orders are updated', $result_update));
96
- if($result_new == 0 && $result_update == 0)
97
- Mage::helper('lensync/data')->log(Mage::helper('lensync')->__('No order available to import'));
 
 
 
 
 
 
 
 
 
98
  Mage::helper('lensync/data')->log('## End cron import ##');
99
  Mage::getSingleton('lensync/config')->importSetEnd();
100
  }
101
  }
 
102
  }
103
 
104
- /**
105
  * Sending a call WSDL for a new order shipment
106
  */
107
  public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
108
  {
109
  $shipment = $observer->getEvent()->getShipment();
110
  $order = $shipment->getOrder();
111
- if($order->getData('from_lengow') == 1) {
112
- $marketplace = Mage::getModel('lensync/marketplace');
113
- $marketplace->set($order->getMarketplaceLengow());
114
- if ($order->getState() == Mage::getSingleton('lensync/order')->getOrderState('processing')) {
115
- Mage::helper('lensync')->log('WSDL : send tracking to ' . $order->getData('marketplace_lengow') . ' - ' . $order->getData('feed_id_lengow'), $order->getData('order_id_lengow'));
116
- $marketplace->wsdl('shipped', $order->getData('feed_id_lengow'), $order, $shipment);
117
- }
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  return $this;
120
  }
121
 
122
- // /**
123
- // * Sending a call WSDL for a new tracking
124
- // */
125
- // public function salesOrderShipmentTrackSaveAfter(Varien_Event_Observer $observer) {
126
- // $track = $observer->getEvent()->getTrack();
127
- // $shipment = $track->getShipment();
128
- // $order = $shipment->getOrder();
129
- // if($order->getData('from_lengow') == 1) {
130
- // $marketplace = Mage::getModel('lensync/marketplace');
131
- // $marketplace->set($order->getMarketplaceLengow());
132
- // if ($order->getState() == Mage::getSingleton('lensync/order')->getOrderState('shipped')) {
133
- // Mage::helper('lensync')->log('WSDL : send tracking to ' . $order->getData('marketplace_lengow') . ' - ' . $order->getData('feed_id_lengow'), $order->getData('order_id_lengow'));
134
- // $marketplace->wsdl('shipped', $order->getData('feed_id_lengow'), $order, $shipment);
135
- // }
136
- // }
137
- // return $this;
138
- // }
139
-
140
- /**
141
- * Sending a call for a cancellation of order
142
  */
143
- public function salesOrderPaymentCancel(Varien_Event_Observer $observer)
144
  {
145
- $payment = $observer->getEvent()->getPayment();
146
- $order = $payment->getOrder();
147
- if($order->getData('from_lengow') == 1) {
148
- $marketplace = Mage::getModel('lensync/marketplace');
149
- $marketplace->set($order->getMarketplaceLengow());
150
- if ($order->getState() == Mage::getSingleton('lensync/order')->getOrderState('processing')) {
151
- Mage::helper('lensync')->log('WSDL : send cancel to ' . $order->getData('marketplace_lengow') . ' - ' . $order->getData('feed_id_lengow'), $order->getData('order_id_lengow'));
152
- $marketplace->wsdl('refuse', $order->getData('feed_id_lengow'), $order);
153
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
  return $this;
156
  }
157
 
158
- public function salesOrderSaveCommitAfter(Varien_Event_Observer $observer)
 
 
 
159
  {
160
- $order = $observer->getEvent();
161
- if($order->getData('from_lengow') == 1) {
162
- $marketplace = Mage::getModel('sync/marketplace');
163
- $marketplace->set($order->getMarketplaceLengow());
164
- if ($order->getState() == self::STATE_COMPLETE && $order->getState() == Mage::getSingleton('lensync/order')->getOrderState('processing')) {
165
- Mage::helper('lensync')->log('WSDL : send cancel to ' . $order->getData('marketplace_lengow') . ' - ' . $order->getData('feed_id_lengow'), $order->getData('order_id_lengow'));
166
- $marketplace->wsdl('shipped', $order->getData('feed_id_lengow'), $order);
167
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
  return $this;
170
- }
171
 
172
  /**
173
  * Clean group id
@@ -178,5 +371,4 @@ class Lengow_Sync_Model_Observer {
178
  {
179
  return trim(str_replace(array("\r\n", ';', '-', '|', ' '), ',', $data), ',');
180
  }
181
-
182
- }
1
  <?php
2
+
3
  /**
4
  * Lengow sync model observer
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Observer
13
+ {
14
 
15
+ protected $_alreadyShipped = array();
16
+
17
+ protected $_alreadyShippedV2 = array();
18
+
19
+ protected $_alreadyChecked = array();
20
+
21
+ public function import($observer = null)
22
  {
23
+ if (Mage::getStoreConfig('lensync/performances/active_cron')) {
24
  // update marketplace file
25
  Mage::helper('lensync/data')->updateMarketplaceXML();
26
  // clean old log (20 days)
30
  Mage::helper('lensync/data')->log('## Error cron import : import is already started ##');
31
  } else {
32
  Mage::helper('lensync/data')->log('## Start cron import ##');
33
+ if (Mage::getStoreConfig('lensync/performances/debug')) {
 
34
  Mage::helper('lensync/data')->log('WARNING ! Debug mode is activated');
35
+ }
36
  $result_new = 0;
37
  $result_update = 0;
38
  $lengow_groups = array();
39
+ $lengow_id_accounts = array();
40
+ $store_collection = Mage::getResourceModel('core/store_collection')->addFieldToFilter('is_active', 1);
 
41
  // Import different view if is different
42
+ foreach ($store_collection as $store) {
43
  try {
44
+ if (!$store->getId()) {
45
  continue;
46
+ }
47
+ Mage::helper('lensync/data')->log(
48
+ 'Start cron import in store '.$store->getName().' ('.$store->getId().')'
49
+ );
50
  $lensync_config = Mage::getModel('lensync/config', array('store' => $store));
51
  // if store is enabled -> stop import
52
+ if (!$lensync_config->get('orders/active_store')) {
53
+ Mage::helper('lensync/data')->log(
54
+ 'Stop cron import - Store '.$store->getName().'('.$store->getId().') is disabled'
55
+ );
56
  continue;
57
  }
58
+ // start v2 import process
59
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
60
+ // get login informations
61
+ $error_import = false;
62
+ $lentracker_config = Mage::getModel('lentracker/config', array('store' => $store));
63
+ $id_lengow_customer = $lentracker_config->get('general/login');
64
+ $id_lengow_group = $this->_cleanGroup($lentracker_config->get('general/group'));
65
+ $api_token_lengow = $lentracker_config->get('general/api_key');
66
+ unset($lentracker_config);
67
+ // if ID Customer, ID Group or token API are empty -> stop import
68
+ if (empty($id_lengow_customer)
69
+ || !is_numeric($id_lengow_customer)
70
+ || empty($id_lengow_group)
71
+ || empty($api_token_lengow)
72
+ ) {
73
+ $store_name = $store->getName().'('.$store->getId().').';
74
+ $message = 'Please checks your plugin configuration. ID customer, ID group or token API is empty in store ';
75
+ Mage::helper('lensync/data')->log($message.$store_name);
76
+ $error_import = true;
77
+ }
78
+ // check if group was already imported
79
+ $new_id_lengow_group = false;
80
+ $id_groups = explode(',', $id_lengow_group);
81
+ foreach ($id_groups as $id_group) {
82
+ if (is_numeric($id_group) && !in_array($id_group, $lengow_groups)) {
83
+ $lengow_groups[] = $id_group;
84
+ $new_id_lengow_group .= !$new_id_lengow_group ? $id_group : ','.$id_group;
85
+ }
86
+ }
87
+ if (!$new_id_lengow_group) {
88
+ Mage::helper('lensync/data')->log(
89
+ 'ID group '.$id_lengow_group.' is already used by another store'
90
+ );
91
+ }
92
+ if (!$error_import && $new_id_lengow_group) {
93
+ $days = $lensync_config->get('orders/period');
94
+ $args = array(
95
+ 'dateFrom' => date('Y-m-d', strtotime(date('Y-m-d').'-'.$days.'days')),
96
+ 'dateTo' => date('Y-m-d'),
97
+ 'config' => $lensync_config,
98
+ 'idCustomer' => $id_lengow_customer,
99
+ 'idGroup' => $new_id_lengow_group,
100
+ 'apiToken' => $api_token_lengow,
101
+ );
102
+ $import = Mage::getModel('lensync/importv2', $args);
103
+ $result = $import->exec();
104
+ $result_new += $result['new'];
105
+ $result_update += $result['update'];
106
  }
107
  }
108
+ // start v3 import process
109
+ if ((int)Mage::getStoreConfig('lentracker/general/version3')) {
110
+ $error_import = false;
111
+ $lentracker_config = Mage::getModel('lentracker/config', array('store' => $store));
112
+ $id_account = (integer)$lentracker_config->get('general/account_id');
113
+ $access_token = $lentracker_config->get('general/access_token');
114
+ $secret = $lentracker_config->get('general/secret');
115
+ // if ID Account, Access Token or Secret are empty -> stop import
116
+ if (empty($id_account)
117
+ || !is_numeric($id_account)
118
+ || empty($access_token)
119
+ || empty($secret)
120
+ ) {
121
+ $store_name = $store->getName().'('.$store->getId().').';
122
+ $message = 'Please checks your plugin configuration. ID account, access token or secret is empty in store ';
123
+ Mage::helper('lensync/data')->log($message.$store_name);
124
+ $error_import = true;
125
+ }
126
+ // check if id_account was already imported
127
+ $new_id_account = false;
128
+ if (is_numeric($id_account) && !in_array($id_account, $lengow_id_accounts)) {
129
+ $lengow_id_accounts[] = $id_account;
130
+ $new_id_account = $id_account;
131
+ } else {
132
+ Mage::helper('lensync/data')->log(
133
+ 'ID account '.$id_account.' is already used by another store'
134
+ );
135
+ }
136
+ // star import for actual store
137
+ if (!$error_import && $new_id_account) {
138
+ $days = $lensync_config->get('orders/period');
139
+ $args = array(
140
+ 'dateFrom' => date('c', strtotime(date('Y-m-d').'-'.$days.'days')),
141
+ 'dateTo' => date('c'),
142
+ 'config' => $lensync_config,
143
+ 'idAccount' => $new_id_account,
144
+ 'accessToken' => $access_token,
145
+ 'secret' => $secret,
146
+ );
147
+ $import = Mage::getModel('lensync/import', $args);
148
+ $result = $import->exec();
149
+ $result_new += $result['new'];
150
+ $result_update += $result['update'];
151
+ }
152
  }
153
+ } catch (Exception $e) {
154
+ Mage::helper('lensync/data')->log('Error '.$e->getMessage());
155
  }
156
  }
157
+ if ($result_new > 0) {
158
+ Mage::helper('lensync/data')->log(
159
+ Mage::helper('lensync')->__('%d orders are imported', $result_new)
160
+ );
161
+ }
162
+ if ($result_update > 0) {
163
+ Mage::helper('lensync/data')->log(
164
+ Mage::helper('lensync')->__('%d orders are updated', $result_update)
165
+ );
166
+ }
167
+ if ($result_new == 0 && $result_update == 0) {
168
+ Mage::helper('lensync/data')->log(
169
+ Mage::helper('lensync')->__('No order available to import')
170
+ );
171
+ }
172
  Mage::helper('lensync/data')->log('## End cron import ##');
173
  Mage::getSingleton('lensync/config')->importSetEnd();
174
  }
175
  }
176
+ return $this;
177
  }
178
 
179
+ /**
180
  * Sending a call WSDL for a new order shipment
181
  */
182
  public function salesOrderShipmentSaveAfter(Varien_Event_Observer $observer)
183
  {
184
  $shipment = $observer->getEvent()->getShipment();
185
  $order = $shipment->getOrder();
186
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
187
+ if ($order->getData('from_lengow') == 1
188
+ && !array_key_exists($order->getData('order_id_lengow'), $this->_alreadyShippedV2)
189
+ && $order->getData('feed_id_lengow') != 0
190
+ ) {
191
+ $marketplace = Mage::getModel('lensync/marketplacev2');
192
+ $marketplace->set($order->getMarketplaceLengow());
193
+ if ($order->getState() == Mage::getSingleton('lensync/orderv2')->getOrderState('processing')) {
194
+ Mage::helper('lensync')->log(
195
+ 'WSDL : send tracking to '.$order->getData('marketplace_lengow').' - '.$order->getData('feed_id_lengow'),
196
+ $order->getData('order_id_lengow')
197
+ );
198
+ $marketplace->wsdl('shipped', $order->getData('feed_id_lengow'), $order, $shipment);
199
+ $this->_alreadyShippedV2[$order->getData('order_id_lengow')] = true;
200
+ }
201
+ }
202
+ }
203
+ if ((int)Mage::getStoreConfig('lentracker/general/version3')) {
204
+ if ($order->getData('from_lengow') == 1
205
+ && ($order->getData('export_finish_lengow') == 1 || is_null($order->getData('export_finish_lengow')))
206
+ && $order->getState() == Mage::getSingleton('lensync/order')->getOrderState('accepted')
207
+ && !array_key_exists($order->getData('order_id_lengow'), $this->_alreadyShipped)
208
+ ) {
209
+ $store = $order->getStore();
210
+ $connector = Mage::helper('lensync/data')->getConnectorByStore($store);
211
+ if ($connector) {
212
+ $account_id = (integer)Mage::getStoreConfig('lentracker/general/account_id', $store);
213
+ $args = array(
214
+ 'connector' => $connector,
215
+ 'accountId' => $account_id
216
+ );
217
+ $marketplace = Mage::getModel('lensync/marketplace', $args);
218
+ // Compatibility V2
219
+ if ($order->getData('feed_id_lengow') != 0 && !array_key_exists($order->getData('order_id_lengow'), $this->_alreadyChecked)) {
220
+ $order = $marketplace->checkAndChangeMarketplaceName($order);
221
+ $this->_alreadyChecked[$order->getData('order_id_lengow')] = true;
222
+ }
223
+ $marketplace->set($order->getData('marketplace_lengow'));
224
+ if ($marketplace->isLoaded()) {
225
+ Mage::helper('lensync/data')->log(
226
+ 'WSDL : send tracking to '.$order->getData('marketplace_lengow').' with account id '.$account_id,
227
+ $order->getData('order_id_lengow')
228
+ );
229
+ $marketplace->wsdl('ship', $order->getData('order_id_lengow'), $order, $shipment);
230
+ }
231
+ $this->_alreadyShipped[$order->getData('order_id_lengow')] = true;
232
+ } else {
233
+ Mage::helper('lensync')->log(
234
+ 'WSDL : call canceled - Account ID, Token access or Secret are not valid in store '.$store->getName().'('.$store->getId().')',
235
+ $order->getData('order_id_lengow')
236
+ );
237
+ }
238
+ }
239
+ }
240
  return $this;
241
  }
242
 
243
+ /**
244
+ * Sending a call WSDL for a new tracking
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  */
246
+ public function salesOrderShipmentTrackSaveAfter(Varien_Event_Observer $observer)
247
  {
248
+ $track = $observer->getEvent()->getTrack();
249
+ $shipment = $track->getShipment();
250
+ $order = $shipment->getOrder();
251
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
252
+ if ($order->getData('from_lengow') == 1
253
+ && !array_key_exists($order->getData('order_id_lengow'), $this->_alreadyShippedV2)
254
+ && $order->getData('feed_id_lengow') != 0
255
+ ) {
256
+ $marketplace = Mage::getModel('lensync/marketplacev2');
257
+ $marketplace->set($order->getMarketplaceLengow());
258
+ if ($order->getState() == Mage::getSingleton('lensync/orderv2')->getOrderState('shipped')) {
259
+ Mage::helper('lensync')->log(
260
+ 'WSDL : send tracking to '.$order->getData('marketplace_lengow').' - '.$order->getData('feed_id_lengow'),
261
+ $order->getData('order_id_lengow')
262
+ );
263
+ $marketplace->wsdl('shipped', $order->getData('feed_id_lengow'), $order, $shipment);
264
+ $this->_alreadyShippedV2[$order->getData('order_id_lengow')] = true;
265
+ }
266
+ }
267
+ }
268
+ if ((int)Mage::getStoreConfig('lentracker/general/version3')) {
269
+ if ($order->getData('from_lengow') == 1
270
+ && ($order->getData('export_finish_lengow') == 1 || is_null($order->getData('export_finish_lengow')))
271
+ && $order->getState() == Mage::getSingleton('lensync/order')->getOrderState('shipped')
272
+ && !array_key_exists($order->getData('order_id_lengow'), $this->_alreadyShipped)
273
+ ) {
274
+ $store = $order->getStore();
275
+ $connector = Mage::helper('lensync/data')->getConnectorByStore($store);
276
+ if ($connector) {
277
+ $account_id = (integer)Mage::getStoreConfig('lentracker/general/account_id', $store);
278
+ $args = array(
279
+ 'connector' => $connector,
280
+ 'accountId' => $account_id
281
+ );
282
+ $marketplace = Mage::getModel('lensync/marketplace', $args);
283
+ // Compatibility V2
284
+ if ($order->getData('feed_id_lengow') != 0 && !array_key_exists($order->getData('order_id_lengow'), $this->_alreadyChecked)) {
285
+ $order = $marketplace->checkAndChangeMarketplaceName($order);
286
+ $this->_alreadyChecked[$order->getData('order_id_lengow')] = true;
287
+ }
288
+ $marketplace->set($order->getData('marketplace_lengow'));
289
+ if ($marketplace->isLoaded()) {
290
+ Mage::helper('lensync/data')->log(
291
+ 'WSDL : send tracking to '.$order->getData('marketplace_lengow').' with account id '.$account_id,
292
+ $order->getData('order_id_lengow')
293
+ );
294
+ $marketplace->wsdl('ship', $order->getData('order_id_lengow'), $order, $shipment, $track);
295
+ }
296
+ $this->_alreadyShipped[$order->getData('order_id_lengow')] = true;
297
+ } else {
298
+ Mage::helper('lensync')->log(
299
+ 'WSDL : call canceled - Account ID, Token access or Secret are not valid in store '.$store->getName().'('.$store->getId().')',
300
+ $order->getData('order_id_lengow')
301
+ );
302
+ }
303
+ }
304
  }
305
  return $this;
306
  }
307
 
308
+ /**
309
+ * Sending a call for a cancellation of order
310
+ */
311
+ public function salesOrderPaymentCancel(Varien_Event_Observer $observer)
312
  {
313
+ $payment = $observer->getEvent()->getPayment();
314
+ $order = $payment->getOrder();
315
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
316
+ if ($order->getData('from_lengow') == 1) {
317
+ $marketplace = Mage::getModel('lensync/marketplacev2');
318
+ $marketplace->set($order->getMarketplaceLengow());
319
+ if ($order->getState() == Mage::getSingleton('lensync/orderv2')->getOrderState('processing')) {
320
+ Mage::helper('lensync')->log(
321
+ 'WSDL : send cancel to '.$order->getData('marketplace_lengow').' - '.$order->getData('feed_id_lengow'),
322
+ $order->getData('order_id_lengow')
323
+ );
324
+ $marketplace->wsdl('refuse', $order->getData('feed_id_lengow'), $order);
325
+ }
326
+ }
327
+ }
328
+ if ((int)Mage::getStoreConfig('lentracker/general/version3')) {
329
+ if ($order->getData('from_lengow') == 1
330
+ && $order->getData('export_finish_lengow') == 1
331
+ && $order->getState() == Mage::getSingleton('lensync/order')->getOrderState('accepted')
332
+ ) {
333
+ $store = $order->getStore();
334
+ $connector = Mage::helper('lensync/data')->getConnectorByStore($store);
335
+ if ($connector) {
336
+ $account_id = (integer)Mage::getStoreConfig('lentracker/general/account_id', $store);
337
+ $args = array(
338
+ 'connector' => $connector,
339
+ 'accountId' => $account_id
340
+ );
341
+ $marketplace = Mage::getModel('lensync/marketplace', $args);
342
+ // Compatibility V2
343
+ if ($order->getData('feed_id_lengow') != 0) {
344
+ $order = $marketplace->checkAndChangeMarketplaceName($order);
345
+ }
346
+ $marketplace->set($order->getData('marketplace_lengow'));
347
+ if ($marketplace->isLoaded()) {
348
+ Mage::helper('lensync')->log(
349
+ 'WSDL : send cancel to ' . $order->getData('marketplace_lengow').' with account id '.$account_id,
350
+ $order->getData('order_id_lengow')
351
+ );
352
+ $marketplace->wsdl('cancel', $order->getData('order_id_lengow'), $order);
353
+ }
354
+ } else {
355
+ Mage::helper('lensync')->log(
356
+ 'WSDL : call canceled - Account ID, Token access or Secret are not valid in store '.$store->getName().'('.$store->getId().')',
357
+ $order->getData('order_id_lengow')
358
+ );
359
+ }
360
+ }
361
  }
362
  return $this;
363
+ }
364
 
365
  /**
366
  * Clean group id
371
  {
372
  return trim(str_replace(array("\r\n", ';', '-', '|', ' '), ',', $data), ',');
373
  }
374
+ }
 
app/code/community/Lengow/Sync/Model/Order.php CHANGED
@@ -5,11 +5,12 @@
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
- * @copyright 2015 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
 
13
 
14
  protected $_countryCollection;
15
 
@@ -34,19 +35,112 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
34
  /**
35
  * is Already Imported
36
  *
37
- * @param integer $idLengow Lengow order id
38
- * @param integer $idFlux Id flux Lengow
39
- *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  * @return mixed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  */
42
- public function isAlreadyImported($idLengow, $idFlux)
43
  {
44
- $order_collection = $this->getCollection()
45
- ->addAttributeToFilter('order_id_lengow', $idLengow)
46
- ->addAttributeToFilter('feed_id_lengow', $idFlux)
47
- ->addAttributeToSelect('entity_id')
48
- ->getData();
49
- return isset($order_collection[0]['entity_id']) ? $order_collection[0]['entity_id'] : false;
50
  }
51
 
52
  /**
@@ -56,7 +150,7 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
56
  */
57
  public function getConfig()
58
  {
59
- if(is_null($this->_config)) {
60
  $this->_config = Mage::getSingleton('lensync/config');
61
  }
62
  return $this->_config;
@@ -71,66 +165,66 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
71
  */
72
  public function setConfig($config)
73
  {
74
- $this->_config = $config;
75
- return $this;
76
  }
77
 
78
  /**
79
  * Create invoice
80
  *
81
- * @param Mage_Sales_Model_Order $order
82
- *
83
  */
84
  public function toInvoice($order)
85
  {
86
  $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
87
- if($invoice) {
88
  $invoice->register();
89
  $invoice->getOrder()->setIsInProcess(true);
90
  $transactionSave = Mage::getModel('core/resource_transaction')
91
  ->addObject($invoice)
92
  ->addObject($invoice->getOrder());
93
  $transactionSave->save();
94
- $order->_hasInvoices = true;
95
  }
96
  }
97
 
98
  /**
99
  * Ship order
100
  *
101
- * @param Mage_Sales_Model_Order $order
102
- * @param string $carrier
103
- * @param string $title
104
- * @param string $tracking
105
- *
106
  */
107
  public function toShip($order, $carrier = null, $title = '', $tracking = '')
108
  {
109
- if($order->canShip()) {
110
  $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment();
111
- if($shipment) {
112
  $shipment->register();
113
  $shipment->getOrder()->setIsInProcess(true);
 
 
 
 
 
 
 
 
114
  $transactionSave = Mage::getModel('core/resource_transaction')
115
  ->addObject($shipment)
116
  ->addObject($shipment->getOrder());
117
  $transactionSave->save();
118
  $this->_hasShipments = true;
119
- // Add tracking information
120
- if($tracking) {
121
- $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipment->getIncrementId());
122
- $track = Mage::getModel('sales/order_shipment_track')
123
- ->setNumber($tracking)
124
- ->setCarrierCode($carrier)
125
- ->setTitle($title);
126
- $shipment->addTrack($track);
127
- }
128
  try {
129
  $shipment->save();
130
- if(isset($track))
131
- $track->save();
132
  } catch (Mage_Core_Exception $e) {
133
- Mage::helper('lensync/data')->log('ERROR create shipment : ' . $e->getMessage(), $order->getOrderIdLengow());
 
 
 
134
  }
135
  }
136
  }
@@ -139,12 +233,12 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
139
  /**
140
  * Cancel order
141
  *
142
- * @param Mage_Sales_Model_Order $order
143
- *
144
  */
145
  public function toCancel($order)
146
  {
147
- if($this->_canCancel && $order->canCancel()) {
148
  $order->cancel();
149
  $this->_isCanceled = true;
150
  }
@@ -154,21 +248,21 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
154
  * Refund order
155
  *
156
  * @param Mage_Sales_Model_Order
157
- *
158
  * @return Lengow_Sync_Model_Order
159
  */
160
  public function toRefund(Lengow_Sync_Model_Order $order)
161
  {
162
- if($this->_canRefund && $order->canCreditmemo()) {
163
  $invoice_id = $order->getInvoiceCollection()->getFirstItem()->getId();
164
- if(!$invoice_id) {
165
  return $this;
166
  }
167
  $invoice = Mage::getModel('sales/order_invoice')->load($invoice_id)->setOrder($order);
168
  $service = Mage::getModel('sales/service_order', $order);
169
  $creditmemo = $service->prepareInvoiceCreditmemo($invoice);
170
  $backToStock = array();
171
- foreach($order->getAllItems() as $item) {
172
  $backToStock[$item->getId()] = true;
173
  }
174
  // Process back to stock flags
@@ -197,17 +291,17 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
197
  /**
198
  * Retrieve country id based on country name
199
  *
200
- * @param string $country_name
201
- *
202
- * @return string
203
  */
204
  protected function _getCountryId($country_name)
205
  {
206
- if(is_null($this->_countryCollection)) {
207
  $this->_countryCollection = Mage::getResourceModel('directory/country_collection')->toOptionArray();
208
  }
209
- foreach($this->_countryCollection as $country) {
210
- if(strtolower($country['label']) == strtolower($country_name)) {
211
  return $country['value'];
212
  }
213
  }
@@ -216,23 +310,27 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
216
 
217
  /**
218
  * Get Magento equivalent to lengow order state
219
- *
220
- * @param string $lengow_status lengow state
221
  *
222
  * @return string
223
  */
224
- public function getOrderState($lengow_status)
225
  {
226
- switch ($lengow_status) {
227
  case 'new':
 
228
  return Mage_Sales_Model_Order::STATE_NEW;
229
  break;
230
- case 'processing':
 
231
  return Mage_Sales_Model_Order::STATE_PROCESSING;
232
  break;
233
  case 'shipped':
 
234
  return Mage_Sales_Model_Order::STATE_COMPLETE;
235
  break;
 
236
  case 'canceled':
237
  return Mage_Sales_Model_Order::STATE_CANCELED;
238
  break;
@@ -241,46 +339,65 @@ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order {
241
 
242
  /**
243
  * Update order state to marketplace state
244
- *
245
- * @param Mage_Sales_Model_Order $order Magento Order
246
- * @param string $lengow_status marketplace status
247
- * @param string $order_data order data
248
- *
249
- * @return bool true if order has been updated
250
  */
251
- public function updateState($order, $lengow_status, SimpleXMLelement $order_data)
252
  {
253
  $helper = Mage::helper('lensync/data');
254
  // Update order's status only if in process, shipped, or canceled
255
  if ($order->getState() != self::getOrderState($lengow_status) && $order->getData('from_lengow') == 1) {
256
- if ($order->getState() == self::getOrderState('new') && $lengow_status == 'processing') {
257
- // generate invoice
258
- $this->toInvoice($order);
259
- $helper->log('state updated to "processing" (Order ' . $order->getIncrementId() . ')', $order->getOrderIdLengow());
 
 
 
 
 
260
  return true;
261
- } elseif (($order->getState() == self::getOrderState('processing') || $order->getState() == self::getOrderState('new'))
262
- && $lengow_status == 'shipped') {
 
 
 
263
  // if order is new -> generate invoice
264
- if ($order->getState() == self::getOrderState('new'))
265
- $this->toInvoice($order);
 
 
266
  $this->toShip(
267
  $order,
268
- (string) $order_data->tracking_informations->tracking_carrier,
269
- (string) $order_data->tracking_informations->tracking_method,
270
- (string) $order_data->tracking_informations->tracking_number
 
 
 
 
271
  );
272
- $helper->log('state updated to "shipped" (Order ' . $order->getIncrementId() . ')', $order->getOrderIdLengow());
273
  return true;
274
- } else if (($order->getState() == self::getOrderState('processing') || $order->getState() == self::getOrderState('shipped'))
275
- && $lengow_status == 'canceled') {
276
- $this->toCancel($order);
277
- if ($this->_isCanceled) {
278
- $helper->log('state update to "canceled" (Order ' . $order->getIncrementId() . ')', $order->getOrderIdLengow());
 
 
 
 
 
 
 
279
  return true;
280
  }
281
- return false;
282
  }
283
  }
284
  return false;
285
  }
286
- }
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Order extends Mage_Sales_Model_Order
13
+ {
14
 
15
  protected $_countryCollection;
16
 
35
  /**
36
  * is Already Imported
37
  *
38
+ * @param string $lengow_id Lengow order id
39
+ * @param integer $delivery_address_id delivery address id
40
+ * @param string $marketplace marketplace name
41
+ * @param string $marketplace_legacy marketplace legacy name
42
+ *
43
+ * @return mixed
44
+ */
45
+ public function isAlreadyImported($lengow_id, $delivery_address_id, $marketplace, $marketplace_legacy)
46
+ {
47
+ // V2 compatibility
48
+ $in = is_null($marketplace_legacy) ? array($marketplace) : array($marketplace, strtolower($marketplace_legacy));
49
+
50
+ $results = $this->getCollection()
51
+ ->addAttributeToFilter('order_id_lengow', $lengow_id)
52
+ ->addAttributeToFilter('marketplace_lengow', array('in' => $in))
53
+ ->addAttributeToSelect('entity_id')
54
+ ->addAttributeToSelect('delivery_address_id_lengow')
55
+ ->addAttributeToSelect('feed_id_lengow')
56
+ ->getData();
57
+ if (count($results) == 0) {
58
+ return false;
59
+ }
60
+ foreach ($results as $result) {
61
+ if ($result['delivery_address_id_lengow'] == 0 && $result['feed_id_lengow'] != 0) {
62
+ return $result['entity_id'];
63
+ } elseif ($result['delivery_address_id_lengow'] == $delivery_address_id) {
64
+ return $result['entity_id'];
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+
70
+ /**
71
+ * Get Lengow ID with order ID Prestashop and delivery address ID
72
+ *
73
+ * @param integer $order_id magento order id
74
+ * @param string $delivery_address_id delivery address id
75
+ *
76
+ * @return mixed
77
+ */
78
+ public function getLengowIdFromLengowDeliveryAddress($order_id, $delivery_address_id)
79
+ {
80
+ $results = $this->getCollection()
81
+ ->addAttributeToFilter('entity_id', $order_id)
82
+ ->addAttributeToFilter('delivery_address_id_lengow', $delivery_address_id)
83
+ ->addAttributeToSelect('order_id_lengow')
84
+ ->getData();
85
+ if (count($results) > 0) {
86
+ return $results[0]['order_id_lengow'];
87
+ }
88
+ return false;
89
+ }
90
+
91
+ /**
92
+ * Get order line from Order
93
+ *
94
+ * @param integer $id_order
95
+ *
96
  * @return mixed
97
+ *
98
+ */
99
+ public function getOrderLineFromIdOrder($order_id)
100
+ {
101
+ $order_line_id = Mage::getModel('lensync/orderline')->getCollection()
102
+ ->addFieldToFilter('id_order', $order_id)
103
+ ->addFieldToSelect('id_order_line')
104
+ ->getData();
105
+ if (count($order_line_id) > 0) {
106
+ return $order_line_id;
107
+ }
108
+ return false;
109
+ }
110
+
111
+ /**
112
+ * Get order ids from lengow order ID
113
+ *
114
+ * @param string $lengow_id
115
+ * @param string $marketplace
116
+ *
117
+ * @return array
118
+ *
119
+ */
120
+ public function getOrderIdFromLengowOrder($lengow_id, $marketplace)
121
+ {
122
+ $orders = $this->getCollection()
123
+ ->addAttributeToFilter('order_id_lengow', $lengow_id)
124
+ ->addAttributeToFilter('marketplace_lengow', $marketplace)
125
+ ->addAttributeToSelect('entity_id')
126
+ ->getData();
127
+ return $orders;
128
+ }
129
+
130
+ /**
131
+ * Save order line in lengow orders line table
132
+ *
133
+ * @param Mage_Sales_Model_Order $order order imported
134
+ * @param string $order_line_id order line id
135
+ *
136
  */
137
+ public function addLengowOrderLine($order, $order_line_id)
138
  {
139
+ $orderLine = Mage::getModel('lensync/orderline');
140
+ $orderLine->addOrderLine(
141
+ (integer)$order->getId(),
142
+ (string)$order_line_id
143
+ );
 
144
  }
145
 
146
  /**
150
  */
151
  public function getConfig()
152
  {
153
+ if (is_null($this->_config)) {
154
  $this->_config = Mage::getSingleton('lensync/config');
155
  }
156
  return $this->_config;
165
  */
166
  public function setConfig($config)
167
  {
168
+ $this->_config = $config;
169
+ return $this;
170
  }
171
 
172
  /**
173
  * Create invoice
174
  *
175
+ * @param Mage_Sales_Model_Order
176
+ *
177
  */
178
  public function toInvoice($order)
179
  {
180
  $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
181
+ if ($invoice) {
182
  $invoice->register();
183
  $invoice->getOrder()->setIsInProcess(true);
184
  $transactionSave = Mage::getModel('core/resource_transaction')
185
  ->addObject($invoice)
186
  ->addObject($invoice->getOrder());
187
  $transactionSave->save();
188
+ $this->_hasInvoices = true;
189
  }
190
  }
191
 
192
  /**
193
  * Ship order
194
  *
195
+ * @param Mage_Sales_Model_Order $order
196
+ * @param string $carrier
197
+ * @param string $title
198
+ * @param string $tracking
199
+ *
200
  */
201
  public function toShip($order, $carrier = null, $title = '', $tracking = '')
202
  {
203
+ if ($order->canShip()) {
204
  $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment();
205
+ if ($shipment) {
206
  $shipment->register();
207
  $shipment->getOrder()->setIsInProcess(true);
208
+ // Add tracking information
209
+ if ($tracking) {
210
+ $track = Mage::getModel('sales/order_shipment_track')
211
+ ->setNumber($tracking)
212
+ ->setCarrierCode($carrier)
213
+ ->setTitle($title);
214
+ $shipment->addTrack($track);
215
+ }
216
  $transactionSave = Mage::getModel('core/resource_transaction')
217
  ->addObject($shipment)
218
  ->addObject($shipment->getOrder());
219
  $transactionSave->save();
220
  $this->_hasShipments = true;
 
 
 
 
 
 
 
 
 
221
  try {
222
  $shipment->save();
 
 
223
  } catch (Mage_Core_Exception $e) {
224
+ Mage::helper('lensync/data')->log(
225
+ 'ERROR create shipment : '.$e->getMessage(),
226
+ $order->getOrderIdLengow()
227
+ );
228
  }
229
  }
230
  }
233
  /**
234
  * Cancel order
235
  *
236
+ * @param Mage_Sales_Model_Order
237
+ *
238
  */
239
  public function toCancel($order)
240
  {
241
+ if ($this->_canCancel && $order->canCancel()) {
242
  $order->cancel();
243
  $this->_isCanceled = true;
244
  }
248
  * Refund order
249
  *
250
  * @param Mage_Sales_Model_Order
251
+ *
252
  * @return Lengow_Sync_Model_Order
253
  */
254
  public function toRefund(Lengow_Sync_Model_Order $order)
255
  {
256
+ if ($this->_canRefund && $order->canCreditmemo()) {
257
  $invoice_id = $order->getInvoiceCollection()->getFirstItem()->getId();
258
+ if (!$invoice_id) {
259
  return $this;
260
  }
261
  $invoice = Mage::getModel('sales/order_invoice')->load($invoice_id)->setOrder($order);
262
  $service = Mage::getModel('sales/service_order', $order);
263
  $creditmemo = $service->prepareInvoiceCreditmemo($invoice);
264
  $backToStock = array();
265
+ foreach ($order->getAllItems() as $item) {
266
  $backToStock[$item->getId()] = true;
267
  }
268
  // Process back to stock flags
291
  /**
292
  * Retrieve country id based on country name
293
  *
294
+ * @param string $country_name
295
+ *
296
+ * @return string
297
  */
298
  protected function _getCountryId($country_name)
299
  {
300
+ if (is_null($this->_countryCollection)) {
301
  $this->_countryCollection = Mage::getResourceModel('directory/country_collection')->toOptionArray();
302
  }
303
+ foreach ($this->_countryCollection as $country) {
304
+ if (strtolower($country['label']) == strtolower($country_name)) {
305
  return $country['value'];
306
  }
307
  }
310
 
311
  /**
312
  * Get Magento equivalent to lengow order state
313
+ *
314
+ * @param string $lengow lengow state
315
  *
316
  * @return string
317
  */
318
+ public function getOrderState($lengow)
319
  {
320
+ switch ($lengow) {
321
  case 'new':
322
+ case 'waiting_acceptance':
323
  return Mage_Sales_Model_Order::STATE_NEW;
324
  break;
325
+ case 'accepted':
326
+ case 'waiting_shipment':
327
  return Mage_Sales_Model_Order::STATE_PROCESSING;
328
  break;
329
  case 'shipped':
330
+ case 'closed':
331
  return Mage_Sales_Model_Order::STATE_COMPLETE;
332
  break;
333
+ case 'refused':
334
  case 'canceled':
335
  return Mage_Sales_Model_Order::STATE_CANCELED;
336
  break;
339
 
340
  /**
341
  * Update order state to marketplace state
342
+ *
343
+ * @param Mage_Sales_Model_Order $order Magento Order
344
+ * @param string $lengow_status marketplace status
345
+ * @param mixed $package package data
346
+ *
347
+ * @return bool true if order has been updated
348
  */
349
+ public function updateState($order, $lengow_status, $package)
350
  {
351
  $helper = Mage::helper('lensync/data');
352
  // Update order's status only if in process, shipped, or canceled
353
  if ($order->getState() != self::getOrderState($lengow_status) && $order->getData('from_lengow') == 1) {
354
+ if ($order->getState() == self::getOrderState('new')
355
+ && ($lengow_status == 'accepted' || $lengow_status == 'waiting_shipment')
356
+ ) {
357
+ // Generate invoice
358
+ $this->toInvoice($order);
359
+ $helper->log(
360
+ 'state updated to "processing" (Order '.$order->getIncrementId().')',
361
+ $order->getOrderIdLengow()
362
+ );
363
  return true;
364
+ } elseif (($order->getState() == self::getOrderState('accepted')
365
+ || $order->getState() == self::getOrderState('new')
366
+ )
367
+ && ($lengow_status == 'shipped' || $lengow_status == 'closed')
368
+ ) {
369
  // if order is new -> generate invoice
370
+ if ($order->getState() == self::getOrderState('new')) {
371
+ $this->toInvoice();
372
+ }
373
+ $trackings = $package->delivery->trackings;
374
  $this->toShip(
375
  $order,
376
+ (count($trackings) > 0 ? (string)$trackings[0]->carrier : null),
377
+ (count($trackings) > 0 ? (string)$trackings[0]->method : null),
378
+ (count($trackings) > 0 ? (string)$trackings[0]->number : null)
379
+ );
380
+ $helper->log(
381
+ 'state updated to "shipped" (Order '.$order->getIncrementId().')',
382
+ $order->getOrderIdLengow()
383
  );
 
384
  return true;
385
+ } else {
386
+ if (($order->getState() == self::getOrderState('new')
387
+ || $order->getState() == self::getOrderState('accepted')
388
+ || $order->getState() == self::getOrderState('shipped')
389
+ )
390
+ && ($lengow_status == 'canceled' || $lengow_status == 'refused')
391
+ ) {
392
+ $this->toCancel($order);
393
+ $helper->log(
394
+ 'state update to "canceled" (Order '.$order->getIncrementId().')',
395
+ $order->getOrderIdLengow()
396
+ );
397
  return true;
398
  }
 
399
  }
400
  }
401
  return false;
402
  }
403
+ }
app/code/community/Lengow/Sync/Model/Orderline.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow sync model orderline
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Model_Orderline extends Mage_Core_Model_Abstract
13
+ {
14
+
15
+ /**
16
+ * Constructor
17
+ */
18
+ protected function _construct()
19
+ {
20
+ parent::_construct();
21
+ $this->_init('lensync/orderline');
22
+ }
23
+
24
+ /**
25
+ * Save Order line
26
+ *
27
+ * @param integer $id_order
28
+ * @param string $id_order_line
29
+ *
30
+ */
31
+ public function addOrderLine($id_order, $id_order_line)
32
+ {
33
+ $this->setIdOrder($id_order);
34
+ $this->setIdOrderLine($id_order_line);
35
+ return $this->save();
36
+ }
37
+ }
app/code/community/Lengow/Sync/Model/Orderv2.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow sync model order
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Model_Orderv2 extends Mage_Sales_Model_Order
13
+ {
14
+
15
+ protected $_countryCollection;
16
+
17
+ protected $_config;
18
+
19
+ protected $_canInvoice = false;
20
+
21
+ protected $_canShip = false;
22
+
23
+ protected $_canCancel = false;
24
+
25
+ protected $_canRefund = false;
26
+
27
+ protected $_hasInvoices = false;
28
+
29
+ protected $_hasShipments = false;
30
+
31
+ protected $_isCanceled = false;
32
+
33
+ protected $_isRefunded = false;
34
+
35
+ /**
36
+ * is Already Imported
37
+ *
38
+ * @param integer $idLengow Lengow order id
39
+ * @param integer $idFlux Id flux Lengow
40
+ *
41
+ * @return mixed
42
+ */
43
+ public function isAlreadyImported($idLengow, $idFlux)
44
+ {
45
+ $order_collection = $this->getCollection()
46
+ ->addAttributeToFilter('order_id_lengow', $idLengow)
47
+ ->addAttributeToFilter('feed_id_lengow', $idFlux)
48
+ ->addAttributeToSelect('entity_id')
49
+ ->getData();
50
+ return isset($order_collection[0]['entity_id']) ? $order_collection[0]['entity_id'] : false;
51
+ }
52
+
53
+ /**
54
+ * Retrieve config singleton
55
+ *
56
+ * @return Lengow_Sync_Model_Config
57
+ */
58
+ public function getConfig()
59
+ {
60
+ if (is_null($this->_config)) {
61
+ $this->_config = Mage::getSingleton('lensync/config');
62
+ }
63
+ return $this->_config;
64
+ }
65
+
66
+ /**
67
+ * Set config
68
+ *
69
+ * @param Lengow_Sync_Model_Config $config
70
+ *
71
+ * @return Lengow_Sync_Model_Order
72
+ */
73
+ public function setConfig($config)
74
+ {
75
+ $this->_config = $config;
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Create invoice
81
+ *
82
+ * @param Mage_Sales_Model_Order $order
83
+ *
84
+ */
85
+ public function toInvoice($order)
86
+ {
87
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
88
+ if ($invoice) {
89
+ $invoice->register();
90
+ $invoice->getOrder()->setIsInProcess(true);
91
+ $transactionSave = Mage::getModel('core/resource_transaction')
92
+ ->addObject($invoice)
93
+ ->addObject($invoice->getOrder());
94
+ $transactionSave->save();
95
+ $order->_hasInvoices = true;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Ship order
101
+ *
102
+ * @param Mage_Sales_Model_Order $order
103
+ * @param string $carrier
104
+ * @param string $title
105
+ * @param string $tracking
106
+ *
107
+ */
108
+ public function toShip($order, $carrier = null, $title = '', $tracking = '')
109
+ {
110
+ if ($order->canShip()) {
111
+ $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment();
112
+ if ($shipment) {
113
+ $shipment->register();
114
+ $shipment->getOrder()->setIsInProcess(true);
115
+ $transactionSave = Mage::getModel('core/resource_transaction')
116
+ ->addObject($shipment)
117
+ ->addObject($shipment->getOrder());
118
+ $transactionSave->save();
119
+ $this->_hasShipments = true;
120
+ // Add tracking information
121
+ if ($tracking) {
122
+ $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipment->getIncrementId());
123
+ $track = Mage::getModel('sales/order_shipment_track')
124
+ ->setNumber($tracking)
125
+ ->setCarrierCode($carrier)
126
+ ->setTitle($title);
127
+ $shipment->addTrack($track);
128
+ }
129
+ try {
130
+ $shipment->save();
131
+ if (isset($track)) {
132
+ $track->save();
133
+ }
134
+ } catch (Mage_Core_Exception $e) {
135
+ Mage::helper('lensync/data')->log(
136
+ 'ERROR create shipment : '.$e->getMessage(),
137
+ $order->getOrderIdLengow()
138
+ );
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Cancel order
146
+ *
147
+ * @param Mage_Sales_Model_Order $order
148
+ *
149
+ */
150
+ public function toCancel($order)
151
+ {
152
+ if ($this->_canCancel && $order->canCancel()) {
153
+ $order->cancel();
154
+ $this->_isCanceled = true;
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Refund order
160
+ *
161
+ * @param Mage_Sales_Model_Order
162
+ *
163
+ * @return Lengow_Sync_Model_Order
164
+ */
165
+ public function toRefund(Lengow_Sync_Model_Order $order)
166
+ {
167
+ if ($this->_canRefund && $order->canCreditmemo()) {
168
+ $invoice_id = $order->getInvoiceCollection()->getFirstItem()->getId();
169
+ if (!$invoice_id) {
170
+ return $this;
171
+ }
172
+ $invoice = Mage::getModel('sales/order_invoice')->load($invoice_id)->setOrder($order);
173
+ $service = Mage::getModel('sales/service_order', $order);
174
+ $creditmemo = $service->prepareInvoiceCreditmemo($invoice);
175
+ $backToStock = array();
176
+ foreach ($order->getAllItems() as $item) {
177
+ $backToStock[$item->getId()] = true;
178
+ }
179
+ // Process back to stock flags
180
+ foreach ($creditmemo->getAllItems() as $creditmemoItem) {
181
+ $orderItem = $creditmemoItem->getOrderItem();
182
+ $parentId = $orderItem->getParentItemId();
183
+ if (Mage::helper('cataloginventory')->isAutoReturnEnabled()) {
184
+ $creditmemoItem->setBackToStock(true);
185
+ } else {
186
+ $creditmemoItem->setBackToStock(false);
187
+ }
188
+ }
189
+ $creditmemo->register();
190
+ $transactionSave = Mage::getModel('core/resource_transaction')
191
+ ->addObject($creditmemo)
192
+ ->addObject($creditmemo->getOrder());
193
+ if ($creditmemo->getInvoice()) {
194
+ $transactionSave->addObject($creditmemo->getInvoice());
195
+ }
196
+ $transactionSave->save();
197
+ $this->_isRefunded = true;
198
+ }
199
+ return $this;
200
+ }
201
+
202
+ /**
203
+ * Retrieve country id based on country name
204
+ *
205
+ * @param string $country_name
206
+ *
207
+ * @return string
208
+ */
209
+ protected function _getCountryId($country_name)
210
+ {
211
+ if (is_null($this->_countryCollection)) {
212
+ $this->_countryCollection = Mage::getResourceModel('directory/country_collection')->toOptionArray();
213
+ }
214
+ foreach ($this->_countryCollection as $country) {
215
+ if (strtolower($country['label']) == strtolower($country_name)) {
216
+ return $country['value'];
217
+ }
218
+ }
219
+ return $country_name;
220
+ }
221
+
222
+ /**
223
+ * Get Magento equivalent to lengow order state
224
+ *
225
+ * @param string $lengow_status lengow state
226
+ *
227
+ * @return string
228
+ */
229
+ public function getOrderState($lengow_status)
230
+ {
231
+ switch ($lengow_status) {
232
+ case 'new':
233
+ return Mage_Sales_Model_Order::STATE_NEW;
234
+ break;
235
+ case 'processing':
236
+ return Mage_Sales_Model_Order::STATE_PROCESSING;
237
+ break;
238
+ case 'shipped':
239
+ return Mage_Sales_Model_Order::STATE_COMPLETE;
240
+ break;
241
+ case 'canceled':
242
+ return Mage_Sales_Model_Order::STATE_CANCELED;
243
+ break;
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Update order state to marketplace state
249
+ *
250
+ * @param Mage_Sales_Model_Order $order Magento Order
251
+ * @param string $lengow_status marketplace status
252
+ * @param string $order_data order data
253
+ *
254
+ * @return bool true if order has been updated
255
+ */
256
+ public function updateState($order, $lengow_status, SimpleXMLelement $order_data)
257
+ {
258
+ $helper = Mage::helper('lensync/data');
259
+ // Update order's status only if in process, shipped, or canceled
260
+ if ($order->getState() != self::getOrderState($lengow_status) && $order->getData('from_lengow') == 1) {
261
+ if ($order->getState() == self::getOrderState('new') && $lengow_status == 'processing') {
262
+ // generate invoice
263
+ $this->toInvoice($order);
264
+ $helper->log(
265
+ 'state updated to "processing" (Order '.$order->getIncrementId().')',
266
+ $order->getOrderIdLengow()
267
+ );
268
+ return true;
269
+ } elseif (($order->getState() == self::getOrderState('processing') || $order->getState() == self::getOrderState('new'))
270
+ && $lengow_status == 'shipped'
271
+ ) {
272
+ // if order is new -> generate invoice
273
+ if ($order->getState() == self::getOrderState('new')) {
274
+ $this->toInvoice($order);
275
+ }
276
+ $this->toShip(
277
+ $order,
278
+ (string)$order_data->tracking_informations->tracking_carrier,
279
+ (string)$order_data->tracking_informations->tracking_method,
280
+ (string)$order_data->tracking_informations->tracking_number
281
+ );
282
+ $helper->log(
283
+ 'state updated to "shipped" (Order '.$order->getIncrementId().')',
284
+ $order->getOrderIdLengow()
285
+ );
286
+ return true;
287
+ } else {
288
+ if (($order->getState() == self::getOrderState('processing') || $order->getState() == self::getOrderState('shipped'))
289
+ && $lengow_status == 'canceled'
290
+ ) {
291
+ $this->toCancel($order);
292
+ if ($this->_isCanceled) {
293
+ $helper->log(
294
+ 'state update to "canceled" (Order '.$order->getIncrementId().')',
295
+ $order->getOrderIdLengow()
296
+ );
297
+ return true;
298
+ }
299
+ return false;
300
+ }
301
+ }
302
+ }
303
+ return false;
304
+ }
305
+ }
app/code/community/Lengow/Sync/Model/Payment/Method/Lengow.php CHANGED
@@ -1,16 +1,18 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml export controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Payment_Method_Lengow extends Mage_Payment_Model_Method_Abstract {
 
12
 
13
- protected $_code = 'lengow';
14
  protected $_infoBlockType = 'lensync/payment_info_purchaseorder';
15
 
16
  /**
@@ -19,7 +21,8 @@ class Lengow_Sync_Model_Payment_Method_Lengow extends Mage_Payment_Model_Method_
19
  * @param mixed $data
20
  * @return Profileolabs_Lengow_Model_Manageorders_Payment_Method_Purchaseorder
21
  */
22
- public function assignData($data) {
 
23
  if (!($data instanceof Varien_Object)) {
24
  $data = new Varien_Object($data);
25
  }
@@ -27,12 +30,13 @@ class Lengow_Sync_Model_Payment_Method_Lengow extends Mage_Payment_Model_Method_
27
  return $this;
28
  }
29
 
30
- /**
31
  * Check whether payment method can be used
32
  * @param Mage_Sales_Model_Quote
33
  * @return bool
34
  */
35
- public function isAvailable($quote = null) {
 
36
  return Mage::getSingleton('core/session')->getIsFromlengow();
37
- }
38
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync model payment method lengow
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Payment_Method_Lengow extends Mage_Payment_Model_Method_Abstract
13
+ {
14
 
15
+ protected $_code = 'lengow';
16
  protected $_infoBlockType = 'lensync/payment_info_purchaseorder';
17
 
18
  /**
21
  * @param mixed $data
22
  * @return Profileolabs_Lengow_Model_Manageorders_Payment_Method_Purchaseorder
23
  */
24
+ public function assignData($data)
25
+ {
26
  if (!($data instanceof Varien_Object)) {
27
  $data = new Varien_Object($data);
28
  }
30
  return $this;
31
  }
32
 
33
+ /**
34
  * Check whether payment method can be used
35
  * @param Mage_Sales_Model_Quote
36
  * @return bool
37
  */
38
+ public function isAvailable($quote = null)
39
+ {
40
  return Mage::getSingleton('core/session')->getIsFromlengow();
41
+ }
42
+ }
app/code/community/Lengow/Sync/Model/Quote.php CHANGED
@@ -5,138 +5,178 @@
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
- * @author Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
- * @copyright 2015 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Sync_Model_Quote extends Mage_Sales_Model_Quote {
 
13
 
14
  protected $_rowTotalLengow = array();
15
 
16
  /**
17
  * Add products from API to current quote
18
- *
19
- * @param SimpleXMLelement $products product list to be added
20
- * @param Lengow_Sync_Model_Marketplace $marketplace
21
- * @param String $id_lengow_order
22
- * @param boolean $priceIncludeTax
23
  *
24
  * @return Lengow_Sync_Model_Quote
25
  */
26
- public function addLengowProducts(SimpleXMLelement $products, Lengow_Sync_Model_Marketplace $marketplace, $id_lengow_order, $priceIncludeTax = true)
27
- {
 
 
 
 
28
  $order_lineid = '';
29
  $first = true;
30
  foreach ($products as $product_line) {
31
- if ($first || empty($order_lineid) || $order_lineid != (string) $product_line->order_lineid) {
32
  $first = false;
33
- $order_lineid = (string) $product_line->order_lineid;
34
  // check whether the product is canceled
35
- if (!empty($product_line->status)) {
36
- if ($marketplace->getStateLengow((string) $product_line->status) == 'canceled') {
37
- Mage::helper('lensync')->log('product ' . $product_line->sku . ' could not be added to cart - status: ' . $marketplace->getStateLengow((string) $product_line->status), $id_lengow_order);
38
- continue;
 
 
 
 
 
 
 
 
 
 
39
  }
40
- }
41
  $product = $this->_findProduct($product_line);
42
  if ($product) {
43
  // get unit price with tax
44
- $price = (float) $product_line->price_unit;
45
  // save total row Lengow for each product
46
- $this->_rowTotalLengow[(string) $product->getId()] = $price * $product_line->quantity;
47
  // if price not include tax -> get shipping cost without tax
48
  if (!$priceIncludeTax) {
49
- $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $this->getStore());
50
- $country_id = ($basedOn == 'shipping') ? $this->getShippingAddress()->getCountryId() : $this->getBillingAddress()->getCountryId();
 
 
 
 
 
51
  $taxCalculator = Mage::getModel('tax/calculation');
52
- $taxRequest = new Varien_Object();
53
  $taxRequest->setCountryId($country_id)
54
- ->setCustomerClassId($this->getCustomer()->getTaxClassId())
55
- ->setProductClassId($product->getTaxClassId());
56
- $tax_rate = $taxCalculator->getRate($taxRequest);
57
- $tax = (float) $taxCalculator->calcTaxAmount($price, $tax_rate, true);
58
  $price = $price - $tax;
59
  }
60
  $product->setPrice($price);
 
61
  $product->setFinalPrice($price);
62
- //option "import with product's title from Lengow"
63
- if (Mage::getStoreConfig('lensync/orders/title', $this->getStore()))
64
- $product->setName((string) $product_line->title);
 
65
  // add item to quote
66
  $quote_item = Mage::getModel('lensync/quote_item')
67
- ->setProduct($product)
68
- ->setQty((int) $product_line->quantity)
69
- ->setConvertedPrice($price);
70
  $this->addItem($quote_item);
71
  }
72
  }
73
  }
74
- return $this;
75
  }
76
 
77
  /**
78
  * Find product in Magento based on API data
79
- *
80
- * @param SimpleXMLelement $lengow_product product data
81
  *
82
- * @return Mage_Catalog_Model_Product product found to be added
 
 
83
  */
84
- protected function _findProduct(SimpleXMLelement $lengow_product)
85
  {
86
- $api_fields = array(
87
- 'sku',
88
- 'idLengow',
89
- 'idMP',
90
- 'ean',
91
  );
92
- $product_field = strtolower((string) $lengow_product->sku['field'][0]);
 
 
93
  $product_model = Mage::getModel('catalog/product');
94
  // search product foreach sku
95
  $i = 0;
96
  $found = false;
97
  $product = false;
98
- $count = count($api_fields);
99
- while(!$found && $i < $count) {
100
- // search with sku type field first
101
- $sku = (string) $lengow_product->{$api_fields[$i]};
102
  $i++;
103
- if (empty($sku))
104
  continue;
 
105
  // search by field if exists
106
- $attributeModel = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $product_field);
107
- if ($attributeModel->getAttributeId()) {
108
- $collection = Mage::getResourceModel('catalog/product_collection')
109
- ->setStoreId($this->getStore()->getStoreId())
110
- ->addAttributeToSelect($product_field)
111
- ->addAttributeToFilter($product_field, $sku)
112
- ->setPage(1,1)
113
- ->getData();
114
- if(is_array($collection) && count($collection) > 0) {
115
- $product = $product_model->load($collection[0]['entity_id']);
 
 
116
  }
117
  }
118
  // search by id or sku
119
  if (!$product || !$product->getId()) {
120
- if (preg_match('/^[0-9]*$/',$sku)) {
121
- $product = $product_model->load((integer) $sku);
122
- } else {
 
123
  $sku = str_replace('\_', '_', $sku);
124
  $product = $product_model->load($product_model->getIdBySku($sku));
125
  }
126
  }
127
- if ($product && $product->getId())
128
  $found = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
- if (!$found)
131
- throw new Exception('product ' . (string) $lengow_product->sku . ' could not be found.');
132
- elseif ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
133
- throw new Exception('product ' . (string) $lengow_product->sku . ' is a parent product.');
134
  return $product;
135
  }
136
-
137
  /**
138
  * Get row Total from Lengow
139
- *
140
  * @param string $product_id product id
141
  *
142
  * @return string
@@ -145,5 +185,4 @@ class Lengow_Sync_Model_Quote extends Mage_Sales_Model_Quote {
145
  {
146
  return $this->_rowTotalLengow[$product_id];
147
  }
148
-
149
  }
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Quote extends Mage_Sales_Model_Quote
13
+ {
14
 
15
  protected $_rowTotalLengow = array();
16
 
17
  /**
18
  * Add products from API to current quote
19
+ *
20
+ * @param mixed $products product list to be added
21
+ * @param Lengow_Sync_Model_Marketplace $marketplace
22
+ * @param string $id_lengow_order
23
+ * @param boolean $priceIncludeTax
24
  *
25
  * @return Lengow_Sync_Model_Quote
26
  */
27
+ public function addLengowProducts(
28
+ $products,
29
+ Lengow_Sync_Model_Marketplace $marketplace,
30
+ $id_lengow_order,
31
+ $priceIncludeTax = true
32
+ ) {
33
  $order_lineid = '';
34
  $first = true;
35
  foreach ($products as $product_line) {
36
+ if ($first || empty($order_lineid) || $order_lineid != (string)$product_line->marketplace_order_line_id) {
37
  $first = false;
38
+ $order_lineid = (string)$product_line->marketplace_order_line_id;
39
  // check whether the product is canceled
40
+ if ($product_line->marketplace_status != null) {
41
+ if ($marketplace->getStateLengow((string)$product_line->marketplace_status) == 'canceled'
42
+ || $marketplace->getStateLengow((string)$product_line->marketplace_status) == 'refused'
43
+ ) {
44
+ Mage::helper('lensync')->log(
45
+ 'product '.(!is_null($product_line->merchant_product_id->id)
46
+ ? (string)$product_line->merchant_product_id->id
47
+ : (string)$product_line->marketplace_product_id
48
+ )
49
+ .' could not be added to cart - status: '
50
+ .$marketplace->getStateLengow((string)$product_line->marketplace_status),
51
+ $id_lengow_order
52
+ );
53
+ continue;
54
  }
55
+ }
56
  $product = $this->_findProduct($product_line);
57
  if ($product) {
58
  // get unit price with tax
59
+ $price = (float)($product_line->amount / $product_line->quantity);
60
  // save total row Lengow for each product
61
+ $this->_rowTotalLengow[(string)$product->getId()] = (float)$product_line->amount;
62
  // if price not include tax -> get shipping cost without tax
63
  if (!$priceIncludeTax) {
64
+ $basedOn = Mage::getStoreConfig(
65
+ Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON,
66
+ $this->getStore()
67
+ );
68
+ $country_id = ($basedOn == 'shipping')
69
+ ? $this->getShippingAddress()->getCountryId()
70
+ : $this->getBillingAddress()->getCountryId();
71
  $taxCalculator = Mage::getModel('tax/calculation');
72
+ $taxRequest = new Varien_Object();
73
  $taxRequest->setCountryId($country_id)
74
+ ->setCustomerClassId($this->getCustomer()->getTaxClassId())
75
+ ->setProductClassId($product->getTaxClassId());
76
+ $tax_rate = (float)$taxCalculator->getRate($taxRequest);
77
+ $tax = (float)$taxCalculator->calcTaxAmount($price, $tax_rate, true);
78
  $price = $price - $tax;
79
  }
80
  $product->setPrice($price);
81
+ $product->setSpecialPrice($price);
82
  $product->setFinalPrice($price);
83
+ // option "import with product's title from Lengow"
84
+ if (Mage::getStoreConfig('lensync/orders/title', $this->getStore())) {
85
+ $product->setName((string)$product_line->title);
86
+ }
87
  // add item to quote
88
  $quote_item = Mage::getModel('lensync/quote_item')
89
+ ->setProduct($product)
90
+ ->setQty((int)$product_line->quantity)
91
+ ->setConvertedPrice($price);
92
  $this->addItem($quote_item);
93
  }
94
  }
95
  }
 
96
  }
97
 
98
  /**
99
  * Find product in Magento based on API data
 
 
100
  *
101
+ * @param mixed $lengow_product product data
102
+ *
103
+ * @return Mage_Catalog_Model_Product product found to be added
104
  */
105
+ protected function _findProduct($lengow_product)
106
  {
107
+ $id_fields = array(
108
+ $lengow_product->marketplace_product_id != null ? $lengow_product->marketplace_product_id : 0,
109
+ $lengow_product->merchant_product_id->id != null ? $lengow_product->merchant_product_id->id : 0
 
 
110
  );
111
+ $product_field = $lengow_product->merchant_product_id->field != null
112
+ ? strtolower((string)$lengow_product->merchant_product_id->field)
113
+ : false;
114
  $product_model = Mage::getModel('catalog/product');
115
  // search product foreach sku
116
  $i = 0;
117
  $found = false;
118
  $product = false;
119
+ $count = count($id_fields);
120
+ while (!$found && $i < $count) {
121
+ $sku = (string)$id_fields[$i];
 
122
  $i++;
123
+ if (!$sku) {
124
  continue;
125
+ }
126
  // search by field if exists
127
+ if ($product_field) {
128
+ $attributeModel = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $product_field);
129
+ if ($attributeModel->getAttributeId()) {
130
+ $collection = Mage::getResourceModel('catalog/product_collection')
131
+ ->setStoreId($this->getStore()->getStoreId())
132
+ ->addAttributeToSelect($product_field)
133
+ ->addAttributeToFilter($product_field, $sku)
134
+ ->setPage(1, 1)
135
+ ->getData();
136
+ if (is_array($collection) && count($collection) > 0) {
137
+ $product = $product_model->load($collection[0]['entity_id']);
138
+ }
139
  }
140
  }
141
  // search by id or sku
142
  if (!$product || !$product->getId()) {
143
+ if (preg_match('/^[0-9]*$/', $sku)) {
144
+ $product = $product_model->load((integer)$sku);
145
+ }
146
+ if (!$product || !$product->getId()) {
147
  $sku = str_replace('\_', '_', $sku);
148
  $product = $product_model->load($product_model->getIdBySku($sku));
149
  }
150
  }
151
+ if ($product && $product->getId()) {
152
  $found = true;
153
+ }
154
+ }
155
+ if (!$found) {
156
+ throw new Exception(
157
+ 'product '
158
+ .(!is_null($lengow_product->merchant_product_id->id)
159
+ ? (string)$lengow_product->merchant_product_id->id
160
+ : (string)$lengow_product->marketplace_product_id
161
+ )
162
+ .' could not be found.'
163
+ );
164
+ } elseif ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
165
+ throw new Exception(
166
+ 'product '
167
+ .(!is_null($lengow_product->merchant_product_id->id)
168
+ ? (string)$lengow_product->merchant_product_id->id
169
+ : (string)$lengow_product->marketplace_product_id
170
+ )
171
+ .' is a parent product.'
172
+ );
173
  }
 
 
 
 
174
  return $product;
175
  }
176
+
177
  /**
178
  * Get row Total from Lengow
179
+ *
180
  * @param string $product_id product id
181
  *
182
  * @return string
185
  {
186
  return $this->_rowTotalLengow[$product_id];
187
  }
 
188
  }
app/code/community/Lengow/Sync/Model/Quote/Item.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
- * Lengow sync model order
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Quote_Item extends Mage_Sales_Model_Quote_Item {
 
12
 
13
  /**
14
  * Specify item price (base calculation price and converted price will be refreshed too)
1
  <?php
2
+
3
  /**
4
+ * Lengow sync model quote item
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Quote_Item extends Mage_Sales_Model_Quote_Item
13
+ {
14
 
15
  /**
16
  * Specify item price (base calculation price and converted price will be refreshed too)
app/code/community/Lengow/Sync/Model/Quotev2.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Lengow sync model quote
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Benjamin Le Nevé <benjamin.le-neve@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
+ class Lengow_Sync_Model_Quotev2 extends Mage_Sales_Model_Quote
13
+ {
14
+
15
+ protected $_rowTotalLengow = array();
16
+
17
+ /**
18
+ * Add products from API to current quote
19
+ *
20
+ * @param SimpleXMLelement $products product list to be added
21
+ * @param Lengow_Sync_Model_Marketplace $marketplace
22
+ * @param String $id_lengow_order
23
+ * @param boolean $priceIncludeTax
24
+ *
25
+ * @return Lengow_Sync_Model_Quote
26
+ */
27
+ public function addLengowProducts(
28
+ SimpleXMLelement $products,
29
+ Lengow_Sync_Model_Marketplacev2 $marketplace,
30
+ $id_lengow_order,
31
+ $priceIncludeTax = true
32
+ ) {
33
+ $order_lineid = '';
34
+ $first = true;
35
+ foreach ($products as $product_line) {
36
+ if ($first || empty($order_lineid) || $order_lineid != (string)$product_line->order_lineid) {
37
+ $first = false;
38
+ $order_lineid = (string)$product_line->order_lineid;
39
+ // check whether the product is canceled
40
+ if (!empty($product_line->status)) {
41
+ if ($marketplace->getStateLengow((string)$product_line->status) == 'canceled') {
42
+ Mage::helper('lensync')->log(
43
+ 'product '.$product_line->sku.' could not be added to cart - status: '
44
+ .$marketplace->getStateLengow((string)$product_line->status),
45
+ $id_lengow_order
46
+ );
47
+ continue;
48
+ }
49
+ }
50
+ $product = $this->_findProduct($product_line);
51
+ if ($product) {
52
+ // get unit price with tax
53
+ $price = (float)$product_line->price_unit;
54
+ // save total row Lengow for each product
55
+ $this->_rowTotalLengow[(string)$product->getId()] = $price * $product_line->quantity;
56
+ // if price not include tax -> get shipping cost without tax
57
+ if (!$priceIncludeTax) {
58
+ $basedOn = Mage::getStoreConfig(
59
+ Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON,
60
+ $this->getStore()
61
+ );
62
+ $country_id = ($basedOn == 'shipping')
63
+ ? $this->getShippingAddress()->getCountryId()
64
+ : $this->getBillingAddress()->getCountryId();
65
+ $taxCalculator = Mage::getModel('tax/calculation');
66
+ $taxRequest = new Varien_Object();
67
+ $taxRequest->setCountryId($country_id)
68
+ ->setCustomerClassId($this->getCustomer()->getTaxClassId())
69
+ ->setProductClassId($product->getTaxClassId());
70
+ $tax_rate = $taxCalculator->getRate($taxRequest);
71
+ $tax = (float)$taxCalculator->calcTaxAmount($price, $tax_rate, true);
72
+ $price = $price - $tax;
73
+ }
74
+ $product->setPrice($price);
75
+ $product->setSpecialPrice($price);
76
+ $product->setFinalPrice($price);
77
+ //option "import with product's title from Lengow"
78
+ if (Mage::getStoreConfig('lensync/orders/title', $this->getStore())) {
79
+ $product->setName((string)$product_line->title);
80
+ }
81
+ // add item to quote
82
+ $quote_item = Mage::getModel('lensync/quote_item')
83
+ ->setProduct($product)
84
+ ->setQty((int)$product_line->quantity)
85
+ ->setConvertedPrice($price);
86
+ $this->addItem($quote_item);
87
+ }
88
+ }
89
+ }
90
+ return $this;
91
+ }
92
+
93
+ /**
94
+ * Find product in Magento based on API data
95
+ *
96
+ * @param SimpleXMLelement $lengow_product product data
97
+ *
98
+ * @return Mage_Catalog_Model_Product product found to be added
99
+ */
100
+ protected function _findProduct(SimpleXMLelement $lengow_product)
101
+ {
102
+ $api_fields = array(
103
+ 'sku',
104
+ 'idLengow',
105
+ 'idMP',
106
+ 'ean',
107
+ );
108
+ $product_field = strtolower((string)$lengow_product->sku['field'][0]);
109
+ $product_model = Mage::getModel('catalog/product');
110
+ // search product foreach sku
111
+ $i = 0;
112
+ $found = false;
113
+ $product = false;
114
+ $count = count($api_fields);
115
+ while (!$found && $i < $count) {
116
+ // search with sku type field first
117
+ $sku = (string)$lengow_product->{$api_fields[$i]};
118
+ $i++;
119
+ if (empty($sku)) {
120
+ continue;
121
+ }
122
+ // search by field if exists
123
+ $attributeModel = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $product_field);
124
+ if ($attributeModel->getAttributeId()) {
125
+ $collection = Mage::getResourceModel('catalog/product_collection')
126
+ ->setStoreId($this->getStore()->getStoreId())
127
+ ->addAttributeToSelect($product_field)
128
+ ->addAttributeToFilter($product_field, $sku)
129
+ ->setPage(1, 1)
130
+ ->getData();
131
+ if (is_array($collection) && count($collection) > 0) {
132
+ $product = $product_model->load($collection[0]['entity_id']);
133
+ }
134
+ }
135
+ // search by id or sku
136
+ if (!$product || !$product->getId()) {
137
+ if (preg_match('/^[0-9]*$/', $sku)) {
138
+ $product = $product_model->load((integer)$sku);
139
+ }
140
+ if (!$product || !$product->getId()) {
141
+ $sku = str_replace('\_', '_', $sku);
142
+ $product = $product_model->load($product_model->getIdBySku($sku));
143
+ }
144
+ }
145
+ if ($product && $product->getId()) {
146
+ $found = true;
147
+ }
148
+ }
149
+ if (!$found) {
150
+ throw new Exception('product '.(string)$lengow_product->sku.' could not be found.');
151
+ } elseif ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
152
+ throw new Exception('product '.(string)$lengow_product->sku.' is a parent product.');
153
+ }
154
+ return $product;
155
+ }
156
+
157
+ /**
158
+ * Get row Total from Lengow
159
+ *
160
+ * @param string $product_id product id
161
+ *
162
+ * @return string
163
+ */
164
+ public function getRowTotalLengow($product_id)
165
+ {
166
+ return $this->_rowTotalLengow[$product_id];
167
+ }
168
+ }
app/code/community/Lengow/Sync/Model/Shipping/Carrier/Lengow.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
  * Lengow sync model shipping carrier lengow
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Model_Shipping_Carrier_Lengow extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface {
 
12
 
13
  protected $_code = 'lengow';
14
  protected $_isFixed = true;
@@ -19,7 +21,8 @@ class Lengow_Sync_Model_Shipping_Carrier_Lengow extends Mage_Shipping_Model_Carr
19
  * @param Mage_Shipping_Model_Rate_Request $request
20
  * @return Mage_Shipping_Model_Rate_Result
21
  */
22
- public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
 
23
  if (!$this->isActive()) {
24
  return false;
25
  }
@@ -36,27 +39,31 @@ class Lengow_Sync_Model_Shipping_Carrier_Lengow extends Mage_Shipping_Model_Carr
36
  }
37
 
38
  /**
39
- * Processing additional validation to check is carrier applicable.
40
- *
41
- * @param Mage_Shipping_Model_Rate_Request $request
42
- * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
43
- */
44
- public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request) {
45
- if(Mage::getVersion() == '1.4.1.0')
46
- return $this->isActive();
 
 
47
  return parent::proccessAdditionalValidation($request);
48
  }
49
 
50
- public function getSession() {
 
51
  return Mage::getSingleton('checkout/session');
52
  }
53
 
54
- public function isActive() {
 
55
  return Mage::getSingleton('core/session')->getIsFromlengow();
56
  }
57
 
58
- public function getAllowedMethods() {
 
59
  return array('lengow' => $this->getConfigData('name'));
60
  }
61
-
62
  }
1
  <?php
2
+
3
  /**
4
  * Lengow sync model shipping carrier lengow
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_Shipping_Carrier_Lengow extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface
13
+ {
14
 
15
  protected $_code = 'lengow';
16
  protected $_isFixed = true;
21
  * @param Mage_Shipping_Model_Rate_Request $request
22
  * @return Mage_Shipping_Model_Rate_Result
23
  */
24
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
25
+ {
26
  if (!$this->isActive()) {
27
  return false;
28
  }
39
  }
40
 
41
  /**
42
+ * Processing additional validation to check is carrier applicable.
43
+ *
44
+ * @param Mage_Shipping_Model_Rate_Request $request
45
+ * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
46
+ */
47
+ public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
48
+ {
49
+ if (Mage::getVersion() == '1.4.1.0') {
50
+ return $this->isActive();
51
+ }
52
  return parent::proccessAdditionalValidation($request);
53
  }
54
 
55
+ public function getSession()
56
+ {
57
  return Mage::getSingleton('checkout/session');
58
  }
59
 
60
+ public function isActive()
61
+ {
62
  return Mage::getSingleton('core/session')->getIsFromlengow();
63
  }
64
 
65
+ public function getAllowedMethods()
66
+ {
67
  return array('lengow' => $this->getConfigData('name'));
68
  }
 
69
  }
app/code/community/Lengow/Sync/Model/System/Config/Source/Customer/Group.php CHANGED
@@ -1,32 +1,34 @@
1
  <?php
 
2
  /**
3
- * Lengow sync model systems config source customer group
4
- * group of customer
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
- * @author Ludovic Drin <ludovic@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Sync_Model_System_Config_Source_Customer_Group extends Mage_Core_Model_Config_Data {
 
13
 
14
- public function toOptionArray() {
 
15
  $collection = Mage::getModel('customer/group')->getCollection();
16
  $select = array();
17
- foreach ($collection as $group) { /* @var $group Mage_Customer_Model_Group */
18
  $select[$group->getCustomerGroupId()] = $group->getCustomerGroupCode();
19
  }
20
  return $select;
21
  }
22
-
23
- public function toSelectArray() {
 
24
  $collection = Mage::getModel('customer/group')->getCollection();
25
  $select = array();
26
  foreach ($collection as $group) {
27
- /* @var $group Mage_Customer_Model_Group */
28
  $select[$group->getCustomerGroupId()] = $group->getCustomerGroupCode();
29
  }
30
  return $select;
31
  }
32
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync model system config source customer group
 
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Model_System_Config_Source_Customer_Group extends Mage_Core_Model_Config_Data
13
+ {
14
 
15
+ public function toOptionArray()
16
+ {
17
  $collection = Mage::getModel('customer/group')->getCollection();
18
  $select = array();
19
+ foreach ($collection as $group) {
20
  $select[$group->getCustomerGroupId()] = $group->getCustomerGroupCode();
21
  }
22
  return $select;
23
  }
24
+
25
+ public function toSelectArray()
26
+ {
27
  $collection = Mage::getModel('customer/group')->getCollection();
28
  $select = array();
29
  foreach ($collection as $group) {
 
30
  $select[$group->getCustomerGroupId()] = $group->getCustomerGroupCode();
31
  }
32
  return $select;
33
  }
34
+ }
app/code/community/Lengow/Sync/Model/System/Config/Source/Shipping/Carrier.php CHANGED
@@ -1,24 +1,35 @@
1
  <?php
2
 
3
-
 
 
 
 
 
 
 
 
4
  class Lengow_Sync_Model_System_Config_Source_Shipping_Carrier extends Mage_Core_Model_Config_Data
5
  {
6
- public function toOptionArray() {
 
 
7
  $carriers = Mage::getModel('shipping/config')->getActiveCarriers();
8
  $select = array();
9
  foreach ($carriers as $code => $model) {
10
- $title = Mage::getStoreConfig('carriers/'.$code.'/title');
11
  $select[$code] = empty($title) ? $code : $title;
12
  }
13
  return $select;
14
  }
15
 
16
- public function toSelectArray() {
17
- $carriers = Mage::getModel('shipping/config')->getActiveCarriers();
 
18
  $select = array();
19
  foreach ($carriers as $code => $model) {
20
- $select[$code] = Mage::getStoreConfig('carriers/'.$code.'/title');;
21
  }
22
  return $select;
23
  }
24
- }
1
  <?php
2
 
3
+ /**
4
+ * Lengow sync model system config source shipping carrier
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
  class Lengow_Sync_Model_System_Config_Source_Shipping_Carrier extends Mage_Core_Model_Config_Data
13
  {
14
+
15
+ public function toOptionArray()
16
+ {
17
  $carriers = Mage::getModel('shipping/config')->getActiveCarriers();
18
  $select = array();
19
  foreach ($carriers as $code => $model) {
20
+ $title = Mage::getStoreConfig('carriers/' . $code . '/title');
21
  $select[$code] = empty($title) ? $code : $title;
22
  }
23
  return $select;
24
  }
25
 
26
+ public function toSelectArray()
27
+ {
28
+ $carriers = Mage::getModel('shipping/config')->getActiveCarriers();
29
  $select = array();
30
  foreach ($carriers as $code => $model) {
31
+ $select[$code] = Mage::getStoreConfig('carriers/' . $code . '/title');
32
  }
33
  return $select;
34
  }
35
+ }
app/code/community/Lengow/Sync/Model/System/Config/Source/Shipping/Method.php CHANGED
@@ -1,46 +1,61 @@
1
  <?php
2
 
3
-
 
 
 
 
 
 
 
 
4
  class Lengow_Sync_Model_System_Config_Source_Shipping_Method extends Mage_Core_Model_Config_Data
5
  {
6
- public function toOptionArray() {
 
 
7
  $store = Mage::getModel('core/store')
8
- ->load(Mage::getSingleton('adminhtml/config_data')->getStore());
9
 
10
  $carrier_code = Mage::getSingleton('lensync/config')
11
- ->setStore($store)
12
- ->get('orders/default_carrier');
13
- if (!$carrier_code)
14
  return array();
 
15
  $carrier = Mage::getModel('shipping/shipping')
16
- ->getCarrierByCode($carrier_code, $store->getId());
17
  $methods = $carrier->getAllowedMethods();
18
- if (count($methods) == 0 )
19
  return array();
 
20
 
21
  $select = array();
22
  $index = 0;
23
  foreach ($methods as $method) {
24
 
25
- $select[$carrier_code.'--'.Mage::helper('lensync/data')->cleanMethod($method)] = $method;
26
  }
27
  return $select;
28
  }
29
 
30
- public function toSelectArray() {
 
31
  $store = Mage::getModel('core/store')
32
- ->load(Mage::getSingleton('adminhtml/config_data')->getStore());
33
 
34
  $carrier_code = Mage::getSingleton('lensync/config')
35
- ->setStore($store)
36
- ->get('orders/default_carrier');
37
- if (!$carrier_code)
38
  return array();
 
39
  $carrier = Mage::getModel('shipping/shipping')
40
- ->getCarrierByCode($carrier_code, $store->getId());
41
  $methods = $carrier->getAllowedMethods();
42
- if (count($methods) == 0 )
43
  return array();
 
44
 
45
  $select = array();
46
  $index = 0;
1
  <?php
2
 
3
+ /**
4
+ * Lengow sync model system config source shipping method
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
  class Lengow_Sync_Model_System_Config_Source_Shipping_Method extends Mage_Core_Model_Config_Data
13
  {
14
+
15
+ public function toOptionArray()
16
+ {
17
  $store = Mage::getModel('core/store')
18
+ ->load(Mage::getSingleton('adminhtml/config_data')->getStore());
19
 
20
  $carrier_code = Mage::getSingleton('lensync/config')
21
+ ->setStore($store)
22
+ ->get('orders/default_carrier');
23
+ if (!$carrier_code) {
24
  return array();
25
+ }
26
  $carrier = Mage::getModel('shipping/shipping')
27
+ ->getCarrierByCode($carrier_code, $store->getId());
28
  $methods = $carrier->getAllowedMethods();
29
+ if (count($methods) == 0) {
30
  return array();
31
+ }
32
 
33
  $select = array();
34
  $index = 0;
35
  foreach ($methods as $method) {
36
 
37
+ $select[$carrier_code . '--' . Mage::helper('lensync/data')->cleanMethod($method)] = $method;
38
  }
39
  return $select;
40
  }
41
 
42
+ public function toSelectArray()
43
+ {
44
  $store = Mage::getModel('core/store')
45
+ ->load(Mage::getSingleton('adminhtml/config_data')->getStore());
46
 
47
  $carrier_code = Mage::getSingleton('lensync/config')
48
+ ->setStore($store)
49
+ ->get('orders/default_carrier');
50
+ if (!$carrier_code) {
51
  return array();
52
+ }
53
  $carrier = Mage::getModel('shipping/shipping')
54
+ ->getCarrierByCode($carrier_code, $store->getId());
55
  $methods = $carrier->getAllowedMethods();
56
+ if (count($methods) == 0) {
57
  return array();
58
+ }
59
 
60
  $select = array();
61
  $index = 0;
app/code/community/Lengow/Sync/controllers/Adminhtml/Lengow/DebugController.php CHANGED
@@ -1,19 +1,23 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml log controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Pierre Basile <pierre.basile@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Adminhtml_Lengow_DebugController extends Mage_Adminhtml_Controller_Action {
 
12
 
13
  //can access page without secret key
14
  public function preDispatch()
15
  {
16
- if ($this->getRequest()->getActionName() == 'index') Mage::getSingleton('adminhtml/url')->turnOffSecretKey();
 
 
17
  parent::preDispatch();
18
  }
19
 
@@ -31,5 +35,4 @@ class Lengow_Sync_Adminhtml_Lengow_DebugController extends Mage_Adminhtml_Contro
31
  $this->getResponse()->setBody($this->getLayout()->createBlock('lensync/adminhtml_cron_grid')->toHtml());
32
  return $this;
33
  }
34
-
35
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync adminhtml lengow debug controller
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Adminhtml_Lengow_DebugController extends Mage_Adminhtml_Controller_Action
13
+ {
14
 
15
  //can access page without secret key
16
  public function preDispatch()
17
  {
18
+ if ($this->getRequest()->getActionName() == 'index') {
19
+ Mage::getSingleton('adminhtml/url')->turnOffSecretKey();
20
+ }
21
  parent::preDispatch();
22
  }
23
 
35
  $this->getResponse()->setBody($this->getLayout()->createBlock('lensync/adminhtml_cron_grid')->toHtml());
36
  return $this;
37
  }
38
+ }
 
app/code/community/Lengow/Sync/controllers/Adminhtml/Lengow/LogController.php CHANGED
@@ -1,43 +1,47 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml log controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Adminhtml_Lengow_LogController extends Mage_Adminhtml_Controller_Action {
12
-
 
13
  protected function _initAction()
14
  {
15
  $this->loadLayout()
16
- ->_setActiveMenu('lengow/log')
17
- ->_addBreadcrumb(Mage::helper('lensync')->__('Lengow orders'), Mage::helper('lensync')->__('Lengow orders'));
 
18
  return $this;
19
  }
20
-
21
  public function indexAction()
22
  {
23
  $this->_initAction()
24
- ->renderLayout();
25
  return $this;
26
  }
27
-
28
  public function deleteAction()
29
  {
30
  $collection = Mage::getModel('lensync/log')->getCollection();
31
- foreach($collection as $log)
32
- $log->delete();
 
33
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('Log is empty'));
34
  $this->_redirect('*/*/index');
35
-
36
  }
37
-
38
  public function gridAction()
39
  {
40
- $this->getResponse()->setBody($this->getLayout()->createBlock('lensync/adminhtml_log_grid')->toHtml());
41
  return $this;
42
  }
43
 
@@ -45,5 +49,4 @@ class Lengow_Sync_Adminhtml_Lengow_LogController extends Mage_Adminhtml_Controll
45
  {
46
  return Mage::getSingleton('admin/session')->isAllowed('lengow/log');
47
  }
48
-
49
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync adminhtml lengow log controller
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Adminhtml_Lengow_LogController extends Mage_Adminhtml_Controller_Action
13
+ {
14
+
15
  protected function _initAction()
16
  {
17
  $this->loadLayout()
18
+ ->_setActiveMenu('lengow/log')
19
+ ->_addBreadcrumb(Mage::helper('lensync')->__('Lengow orders'),
20
+ Mage::helper('lensync')->__('Lengow orders'));
21
  return $this;
22
  }
23
+
24
  public function indexAction()
25
  {
26
  $this->_initAction()
27
+ ->renderLayout();
28
  return $this;
29
  }
30
+
31
  public function deleteAction()
32
  {
33
  $collection = Mage::getModel('lensync/log')->getCollection();
34
+ foreach ($collection as $log) {
35
+ $log->delete();
36
+ }
37
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('Log is empty'));
38
  $this->_redirect('*/*/index');
39
+
40
  }
41
+
42
  public function gridAction()
43
  {
44
+ $this->getResponse()->setBody($this->getLayout()->createBlock('lensync/adminhtml_log_grid')->toHtml());
45
  return $this;
46
  }
47
 
49
  {
50
  return Mage::getSingleton('admin/session')->isAllowed('lengow/log');
51
  }
52
+ }
 
app/code/community/Lengow/Sync/controllers/Adminhtml/Lengow/OrderController.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
- * Lengow adminhtml sync order controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com> & Benjamin Le Nevé <benjamin.le-neve@lengow.com>
8
- * @copyright 2015 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_Adminhtml_Lengow_OrderController extends Mage_Adminhtml_Controller_Action {
 
12
 
13
  /**
14
  * Init Lengow orders menu
@@ -16,24 +18,29 @@ class Lengow_Sync_Adminhtml_Lengow_OrderController extends Mage_Adminhtml_Contro
16
  protected function _initAction()
17
  {
18
  $this->loadLayout()
19
- ->_setActiveMenu('lengow/order')
20
- ->_addBreadcrumb(Mage::helper('lensync')->__('Lengow manage orders'), Mage::helper('lensync')->__('Lengow orders'));
 
 
 
21
  return $this;
22
  }
23
 
24
  /**
25
  * Render the layout
26
  */
27
- public function indexAction() {
 
28
  $this->_initAction()
29
- ->renderLayout();
30
  return $this;
31
  }
32
 
33
  /**
34
  * Create the order grid
35
  */
36
- public function gridAction() {
 
37
  $this->getResponse()->setBody(
38
  $this->getLayout()->createBlock('lensync/adminhtml_order_grid')->toHtml()
39
  );
@@ -45,8 +52,8 @@ class Lengow_Sync_Adminhtml_Lengow_OrderController extends Mage_Adminhtml_Contro
45
  */
46
  public function exportCsvAction()
47
  {
48
- $filename = 'orders_lengow.csv';
49
- $grid = $this->getLayout()->createBlock('lensync/adminhtml_order_grid');
50
  $this->_prepareDownloadResponse($filename, $grid->getCsvFile());
51
  }
52
 
@@ -55,8 +62,8 @@ class Lengow_Sync_Adminhtml_Lengow_OrderController extends Mage_Adminhtml_Contro
55
  */
56
  public function exportExcelAction()
57
  {
58
- $filename = 'orders_lengow.xml';
59
- $grid = $this->getLayout()->createBlock('lensync/adminhtml_order_grid');
60
  $this->_prepareDownloadResponse($filename, $grid->getExcelFile($filename));
61
  }
62
 
@@ -76,98 +83,152 @@ class Lengow_Sync_Adminhtml_Lengow_OrderController extends Mage_Adminhtml_Contro
76
  $this->_redirect('*/*/index');
77
  } else {
78
  Mage::helper('lensync/data')->log('## Start manual import ##');
79
-
80
- if(Mage::getStoreConfig('lensync/performances/debug'))
81
  Mage::helper('lensync/data')->log('WARNING ! Debug mode is activated');
82
-
83
  $store_count = 0;
84
  $store_disabled = 0;
85
  $result_new = 0;
86
  $result_update = 0;
87
  $lengow_groups = array();
88
-
89
- $store_collection = Mage::getResourceModel('core/store_collection')
90
- ->addFieldToFilter('is_active', 1);
91
-
92
- foreach($store_collection as $store) {
93
  try {
94
- if(!$store->getId())
95
  continue;
96
-
97
  $store_count++;
98
- Mage::helper('lensync/data')->log('Start manual import in store ' . $store->getName() . ' (' . $store->getId() . ')');
99
-
 
100
  $lensync_config = Mage::getModel('lensync/config', array('store' => $store));
101
  // if store is enabled -> stop import
102
- if(!$lensync_config->get('orders/active_store')) {
103
- Mage::helper('lensync/data')->log('Stop manual import - Store ' . $store->getName() . '(' . $store->getId() . ') is disabled');
 
 
104
  $store_disabled++;
105
  continue;
106
  }
107
- // get login informations
108
- $error_import = false;
109
- $lentracker_config = Mage::getModel('lentracker/config', array('store' => $store));
110
- $id_lengow_customer = $lentracker_config->get('general/login');
111
- $id_lengow_group = $this->_cleanGroup($lentracker_config->get('general/group'));
112
- $api_token_lengow = $lentracker_config->get('general/api_key');
113
- // if ID Customer or token API are empty -> stop import
114
- if (empty($id_lengow_customer) || !is_numeric($id_lengow_customer) || empty($api_token_lengow)) {
115
- $message = 'Please checks your plugin configuration. ID customer or token API is empty';
116
- $this->_getSession()->addError(Mage::helper('lensync')->__($message));
117
- Mage::helper('lensync/data')->log($message);
118
- break;
119
- }
120
- // if ID group is empty -> stop import for current store
121
- if (empty($id_lengow_group)) {
122
- $message = 'ID group is empty. Please make sure it is saved in your plugin configuration';
123
- Mage::helper('lensync/data')->log('Stop manual import in store ' . $store->getName() . '(' . $store->getId() . ') : ' . $message);
124
- $error_import = true;
125
- }
126
- // check if group was already imported
127
- $new_id_lengow_group = false;
128
- $id_groups = explode(',', $id_lengow_group);
129
- foreach ($id_groups as $id_group) {
130
- if (is_numeric($id_group) && !in_array($id_group, $lengow_groups)) {
131
- $lengow_groups[] = $id_group;
132
- $new_id_lengow_group .= !$new_id_lengow_group ? $id_group : ','.$id_group;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
  }
135
- // start import for current store
136
- if (!$error_import && $new_id_lengow_group) {
137
- $days = $lensync_config->get('orders/period');
138
- $args = array(
139
- 'dateFrom' => date('Y-m-d', strtotime(date('Y-m-d') . '-' . $days . 'days')),
140
- 'dateTo' => date('Y-m-d'),
141
- 'config' => $lensync_config,
142
- 'idCustomer' => $id_lengow_customer,
143
- 'idGroup' => $new_id_lengow_group,
144
- 'apiToken' => $api_token_lengow,
145
- );
146
- $import = Mage::getModel('lensync/import', $args);
147
- $result = $import->exec();
148
- $result_new += $result['new'];
149
- $result_update += $result['update'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  }
151
- } catch(Exception $e) {
152
  $this->_getSession()->addError($e->getMessage());
153
- Mage::helper('lensync/data')->log('Error ' . $e->getMessage() . '');
154
  }
155
  }
156
- if($result_new > 0) {
157
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('%d orders are imported', $result_new));
158
- Mage::helper('lensync/data')->log($result_new . ' orders are imported');
159
  }
160
- if($result_update > 0) {
161
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('%d orders are updated', $result_update));
162
- Mage::helper('lensync/data')->log($result_update . ' orders are updated');
163
  }
164
- if($result_new == 0 && $result_update == 0) {
165
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('No order available to import'));
166
  Mage::helper('lensync/data')->log('No order available to import');
167
  }
168
  if ($store_count == $store_disabled) {
169
- $this->_getSession()->addError(Mage::helper('lensync')->__('Please checks your plugin configuration. No store enabled to import'));
170
- Mage::helper('lensync/data')->log('Please checks your plugin configuration. No store enabled to import');
 
 
 
 
171
  }
172
  Mage::helper('lensync/data')->log('## End manual import ##');
173
  Mage::getSingleton('lensync/config')->importSetEnd();
@@ -189,5 +250,4 @@ class Lengow_Sync_Adminhtml_Lengow_OrderController extends Mage_Adminhtml_Contro
189
  {
190
  return Mage::getSingleton('admin/session')->isAllowed('lengow/sync');
191
  }
192
-
193
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync adminhtml lengow order controller
5
  *
6
  * @category Lengow
7
  * @package Lengow_Sync
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_Adminhtml_Lengow_OrderController extends Mage_Adminhtml_Controller_Action
13
+ {
14
 
15
  /**
16
  * Init Lengow orders menu
18
  protected function _initAction()
19
  {
20
  $this->loadLayout()
21
+ ->_setActiveMenu('lengow/order')
22
+ ->_addBreadcrumb(
23
+ Mage::helper('lensync')->__('Lengow manage orders'),
24
+ Mage::helper('lensync')->__('Lengow orders')
25
+ );
26
  return $this;
27
  }
28
 
29
  /**
30
  * Render the layout
31
  */
32
+ public function indexAction()
33
+ {
34
  $this->_initAction()
35
+ ->renderLayout();
36
  return $this;
37
  }
38
 
39
  /**
40
  * Create the order grid
41
  */
42
+ public function gridAction()
43
+ {
44
  $this->getResponse()->setBody(
45
  $this->getLayout()->createBlock('lensync/adminhtml_order_grid')->toHtml()
46
  );
52
  */
53
  public function exportCsvAction()
54
  {
55
+ $filename = 'orders_lengow.csv';
56
+ $grid = $this->getLayout()->createBlock('lensync/adminhtml_order_grid');
57
  $this->_prepareDownloadResponse($filename, $grid->getCsvFile());
58
  }
59
 
62
  */
63
  public function exportExcelAction()
64
  {
65
+ $filename = 'orders_lengow.xml';
66
+ $grid = $this->getLayout()->createBlock('lensync/adminhtml_order_grid');
67
  $this->_prepareDownloadResponse($filename, $grid->getExcelFile($filename));
68
  }
69
 
83
  $this->_redirect('*/*/index');
84
  } else {
85
  Mage::helper('lensync/data')->log('## Start manual import ##');
86
+ if (Mage::getStoreConfig('lensync/performances/debug')) {
 
87
  Mage::helper('lensync/data')->log('WARNING ! Debug mode is activated');
88
+ }
89
  $store_count = 0;
90
  $store_disabled = 0;
91
  $result_new = 0;
92
  $result_update = 0;
93
  $lengow_groups = array();
94
+ $lengow_id_accounts = array();
95
+ $store_collection = Mage::getResourceModel('core/store_collection')->addFieldToFilter('is_active', 1);
96
+ foreach ($store_collection as $store) {
 
 
97
  try {
98
+ if (!$store->getId()) {
99
  continue;
100
+ }
101
  $store_count++;
102
+ Mage::helper('lensync/data')->log(
103
+ 'Start manual import in store '.$store->getName().' ('.$store->getId().')'
104
+ );
105
  $lensync_config = Mage::getModel('lensync/config', array('store' => $store));
106
  // if store is enabled -> stop import
107
+ if (!$lensync_config->get('orders/active_store')) {
108
+ Mage::helper('lensync/data')->log(
109
+ 'Stop manual import - Store '.$store->getName().'('.$store->getId().') is disabled'
110
+ );
111
  $store_disabled++;
112
  continue;
113
  }
114
+ // start v2 import process
115
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
116
+ // get login informations
117
+ $error_import = false;
118
+ $lentracker_config = Mage::getModel('lentracker/config', array('store' => $store));
119
+ $id_lengow_customer = $lentracker_config->get('general/login');
120
+ $id_lengow_group = $this->_cleanGroup($lentracker_config->get('general/group'));
121
+ $api_token_lengow = $lentracker_config->get('general/api_key');
122
+ unset($lentracker_config);
123
+ // if ID Customer, ID Group or token API are empty -> stop import
124
+ if (empty($id_lengow_customer)
125
+ || !is_numeric($id_lengow_customer)
126
+ || empty($id_lengow_group)
127
+ || empty($api_token_lengow)
128
+ ) {
129
+ $store_name = $store->getName().'('.$store->getId().').';
130
+ $message = 'Please checks your plugin configuration. ID customer, ID group or token API is empty in store ';
131
+ Mage::helper('lensync/data')->log($message.$store_name);
132
+ $error_import = true;
133
+ }
134
+ // check if group was already imported
135
+ $new_id_lengow_group = false;
136
+ $id_groups = explode(',', $id_lengow_group);
137
+ foreach ($id_groups as $id_group) {
138
+ if (is_numeric($id_group) && !in_array($id_group, $lengow_groups)) {
139
+ $lengow_groups[] = $id_group;
140
+ $new_id_lengow_group.= !$new_id_lengow_group ? $id_group : ','.$id_group;
141
+ }
142
+ }
143
+ if (!$new_id_lengow_group) {
144
+ Mage::helper('lensync/data')->log(
145
+ 'ID group '.$id_lengow_group.' is already used by another store'
146
+ );
147
+ }
148
+ // start import for current store
149
+ if (!$error_import && $new_id_lengow_group) {
150
+ $days = $lensync_config->get('orders/period');
151
+ $args = array(
152
+ 'dateFrom' => date('Y-m-d', strtotime(date('Y-m-d').'-'.$days.'days')),
153
+ 'dateTo' => date('Y-m-d'),
154
+ 'config' => $lensync_config,
155
+ 'idCustomer' => $id_lengow_customer,
156
+ 'idGroup' => $new_id_lengow_group,
157
+ 'apiToken' => $api_token_lengow,
158
+ );
159
+ $import = Mage::getModel('lensync/importv2', $args);
160
+ $result = $import->exec();
161
+ $result_new += $result['new'];
162
+ $result_update += $result['update'];
163
  }
164
  }
165
+ // start v3 import process
166
+ if ((int)Mage::getStoreConfig('lentracker/general/version3')) {
167
+ // get login informations
168
+ $error_import = false;
169
+ $lentracker_config = Mage::getModel('lentracker/config', array('store' => $store));
170
+ $id_account = (integer)$lentracker_config->get('general/account_id');
171
+ $access_token = $lentracker_config->get('general/access_token');
172
+ $secret = $lentracker_config->get('general/secret');
173
+ unset($lentracker_config);
174
+ // if ID Account, Access Token or Secret are empty -> stop import for this store
175
+ if (empty($id_account) || !is_numeric($id_account) || empty($access_token) || empty($secret)) {
176
+ $store_name = $store->getName().'('.$store->getId().').';
177
+ $message = 'Please checks your plugin configuration. ID account, access token or secret is empty in store ';
178
+ Mage::helper('lensync/data')->log($message.$store_name);
179
+ $error_import = true;
180
+ }
181
+ // check if id_account was already imported
182
+ $new_id_account = false;
183
+ if (is_numeric($id_account) && !in_array($id_account, $lengow_id_accounts)) {
184
+ $lengow_id_accounts[] = $id_account;
185
+ $new_id_account = $id_account;
186
+ } else {
187
+ Mage::helper('lensync/data')->log(
188
+ 'ID account '.$id_account.' is already used by another store'
189
+ );
190
+ }
191
+ // star import for actual store
192
+ if (!$error_import && $new_id_account) {
193
+ $days = $lensync_config->get('orders/period');
194
+ $args = array(
195
+ 'dateFrom' => date('c', strtotime(date('Y-m-d').'-'.$days.'days')),
196
+ 'dateTo' => date('c'),
197
+ 'config' => $lensync_config,
198
+ 'idAccount' => $new_id_account,
199
+ 'accessToken' => $access_token,
200
+ 'secret' => $secret,
201
+ );
202
+ $import = Mage::getModel('lensync/import', $args);
203
+ $result = $import->exec();
204
+ $result_new += $result['new'];
205
+ $result_update += $result['update'];
206
+ }
207
  }
208
+ } catch (Exception $e) {
209
  $this->_getSession()->addError($e->getMessage());
210
+ Mage::helper('lensync/data')->log('Error '.$e->getMessage());
211
  }
212
  }
213
+ if ($result_new > 0) {
214
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('%d orders are imported', $result_new));
215
+ Mage::helper('lensync/data')->log($result_new.' orders are imported');
216
  }
217
+ if ($result_update > 0) {
218
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('%d orders are updated', $result_update));
219
+ Mage::helper('lensync/data')->log($result_update.' orders are updated');
220
  }
221
+ if ($result_new == 0 && $result_update == 0) {
222
  $this->_getSession()->addSuccess(Mage::helper('lensync')->__('No order available to import'));
223
  Mage::helper('lensync/data')->log('No order available to import');
224
  }
225
  if ($store_count == $store_disabled) {
226
+ $this->_getSession()->addError(Mage::helper('lensync')->__(
227
+ 'Please checks your plugin configuration. No store enabled to import'
228
+ ));
229
+ Mage::helper('lensync/data')->log(
230
+ 'Please checks your plugin configuration. No store enabled to import'
231
+ );
232
  }
233
  Mage::helper('lensync/data')->log('## End manual import ##');
234
  Mage::getSingleton('lensync/config')->importSetEnd();
250
  {
251
  return Mage::getSingleton('admin/session')->isAllowed('lengow/sync');
252
  }
253
+ }
 
app/code/community/Lengow/Sync/controllers/ApiController.php CHANGED
@@ -1,29 +1,34 @@
1
  <?php
 
2
  /**
3
- * Lengow export controller
4
  *
5
  * @category Lengow
6
  * @package Lengow_Export
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Sync_ApiController extends Mage_Core_Controller_Front_Action {
 
12
 
13
- public function indexAction() {
 
14
  echo 'Please specify an action';
15
  }
16
 
17
- public function checkAction() {
 
18
  $_helper_export = Mage::helper('lenexport/security');
19
  $_helper_api = Mage::helper('lensync/api');
20
- if($_helper_export->checkIp()) {
21
- $return = array('magento_version' => Mage::getVersion(),
22
- 'lengow_version' => $_helper_api->getVersion());
 
 
23
  echo Mage::helper('core')->jsonEncode($return);
24
  } else {
25
  echo 'Unauthorised ip : ' . $_SERVER['REMOTE_ADDR'];
26
  }
27
- }
28
-
29
  }
1
  <?php
2
+
3
  /**
4
+ * Lengow sync api controller
5
  *
6
  * @category Lengow
7
  * @package Lengow_Export
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Sync_ApiController extends Mage_Core_Controller_Front_Action
13
+ {
14
 
15
+ public function indexAction()
16
+ {
17
  echo 'Please specify an action';
18
  }
19
 
20
+ public function checkAction()
21
+ {
22
  $_helper_export = Mage::helper('lenexport/security');
23
  $_helper_api = Mage::helper('lensync/api');
24
+ if ($_helper_export->checkIp()) {
25
+ $return = array(
26
+ 'magento_version' => Mage::getVersion(),
27
+ 'lengow_version' => $_helper_api->getVersion()
28
+ );
29
  echo Mage::helper('core')->jsonEncode($return);
30
  } else {
31
  echo 'Unauthorised ip : ' . $_SERVER['REMOTE_ADDR'];
32
  }
33
+ }
 
34
  }
app/code/community/Lengow/Sync/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Lengow_Sync>
5
- <version>2.1.2</version>
6
  </Lengow_Sync>
7
  </modules>
8
  <admin>
@@ -35,6 +35,9 @@
35
  <log>
36
  <table>lengow_log</table>
37
  </log>
 
 
 
38
  </entities>
39
  </sync_mysql4>
40
  </models>
@@ -78,14 +81,14 @@
78
  </lengow_shipment_save_after>
79
  </observers>
80
  </sales_order_shipment_save_after>
81
- <!-- <sales_order_shipment_track_save_after>
82
  <observers>
83
  <lengow_shipment_track_save_after>
84
  <class>Lengow_Sync_Model_Observer</class>
85
  <method>salesOrderShipmentTrackSaveAfter</method>
86
  </lengow_shipment_track_save_after>
87
  </observers>
88
- </sales_order_shipment_track_save_after> -->
89
  <sales_order_payment_cancel>
90
  <observers>
91
  <lengow_payment_cancel>
@@ -94,16 +97,50 @@
94
  </lengow_payment_cancel>
95
  </observers>
96
  </sales_order_payment_cancel>
97
- <sales_order_save_commit_after>
98
- <observers>
99
- <lengow_order_save_commit_after>
100
- <class>Lengow_Sync_Model_Observer</class>
101
- <method>salesOrderSaveCommitAfter</method>
102
- </lengow_order_save_commit_after>
103
- </observers>
104
- </sales_order_save_commit_after>
105
  </events>
106
  <fieldsets>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  <lengow_convert_billing_address>
108
  <billing_society>
109
  <to_customer>company</to_customer>
@@ -218,7 +255,7 @@
218
  <title>Manage Orders</title>
219
  </sync>
220
  <log translate="title" module="lensync">
221
- <title>Manage Logs</title>
222
  </log>
223
  </children>
224
  </lengow>
@@ -248,7 +285,6 @@
248
  <processing_fee>1</processing_fee>
249
  <customer_group>0</customer_group>
250
  <title>0</title>
251
- <!-- <pending>0</pending> -->
252
  <split_name>0</split_name>
253
  <default_shipping>lengow_lengow</default_shipping>
254
  <fake_email>0</fake_email>
@@ -289,4 +325,11 @@
289
  </lengow>
290
  </carriers>
291
  </default>
 
 
 
 
 
 
 
292
  </config>
2
  <config>
3
  <modules>
4
  <Lengow_Sync>
5
+ <version>2.2.4</version>
6
  </Lengow_Sync>
7
  </modules>
8
  <admin>
35
  <log>
36
  <table>lengow_log</table>
37
  </log>
38
+ <orderline>
39
+ <table>lengow_order_line</table>
40
+ </orderline>
41
  </entities>
42
  </sync_mysql4>
43
  </models>
81
  </lengow_shipment_save_after>
82
  </observers>
83
  </sales_order_shipment_save_after>
84
+ <sales_order_shipment_track_save_after>
85
  <observers>
86
  <lengow_shipment_track_save_after>
87
  <class>Lengow_Sync_Model_Observer</class>
88
  <method>salesOrderShipmentTrackSaveAfter</method>
89
  </lengow_shipment_track_save_after>
90
  </observers>
91
+ </sales_order_shipment_track_save_after>
92
  <sales_order_payment_cancel>
93
  <observers>
94
  <lengow_payment_cancel>
97
  </lengow_payment_cancel>
98
  </observers>
99
  </sales_order_payment_cancel>
 
 
 
 
 
 
 
 
100
  </events>
101
  <fieldsets>
102
+ <lengow_convert_address>
103
+ <company>
104
+ <to_customer>company</to_customer>
105
+ <to_billing_address>company</to_billing_address>
106
+ <to_shipping_address>company</to_shipping_address>
107
+ </company>
108
+ <last_name>
109
+ <to_customer>lastname</to_customer>
110
+ <to_billing_address>lastname</to_billing_address>
111
+ <to_shipping_address>lastname</to_shipping_address>
112
+ </last_name>
113
+ <first_name>
114
+ <to_customer>firstname</to_customer>
115
+ <to_billing_address>firstname</to_billing_address>
116
+ <to_shipping_address>firstname</to_shipping_address>
117
+ </first_name>
118
+ <email>
119
+ <to_customer>email</to_customer>
120
+ <to_billing_address>email</to_billing_address>
121
+ <to_shipping_address>email</to_shipping_address>
122
+ </email>
123
+ <phone_home>
124
+ <to_billing_address>telephone</to_billing_address>
125
+ <to_shipping_address>telephone</to_shipping_address>
126
+ </phone_home>
127
+ <address>
128
+ <to_billing_address>street_full</to_billing_address>
129
+ <to_shipping_address>street_full</to_shipping_address>
130
+ </address>
131
+ <zipcode>
132
+ <to_billing_address>postcode</to_billing_address>
133
+ <to_shipping_address>postcode</to_shipping_address>
134
+ </zipcode>
135
+ <city>
136
+ <to_billing_address>city</to_billing_address>
137
+ <to_shipping_address>city</to_shipping_address>
138
+ </city>
139
+ <common_country_iso_a2>
140
+ <to_billing_address>country_id</to_billing_address>
141
+ <to_shipping_address>country_id</to_shipping_address>
142
+ </common_country_iso_a2>
143
+ </lengow_convert_address>
144
  <lengow_convert_billing_address>
145
  <billing_society>
146
  <to_customer>company</to_customer>
255
  <title>Manage Orders</title>
256
  </sync>
257
  <log translate="title" module="lensync">
258
+ <title>Logs</title>
259
  </log>
260
  </children>
261
  </lengow>
285
  <processing_fee>1</processing_fee>
286
  <customer_group>0</customer_group>
287
  <title>0</title>
 
288
  <split_name>0</split_name>
289
  <default_shipping>lengow_lengow</default_shipping>
290
  <fake_email>0</fake_email>
325
  </lengow>
326
  </carriers>
327
  </default>
328
+ <phpunit>
329
+ <suite>
330
+ <modules>
331
+ <Lengow_Sync/>
332
+ </modules>
333
+ </suite>
334
+ </phpunit>
335
  </config>
app/code/community/Lengow/Sync/etc/marketplaces.xml CHANGED
@@ -133,7 +133,7 @@
133
  <state name="closed">
134
  <lengow>shipped</lengow>
135
  </state>
136
- <state name="CLOSED">
137
  <lengow>shipped</lengow>
138
  </state>
139
  <state name="CANCELLED">
@@ -214,11 +214,11 @@
214
  </state>
215
  </states>
216
  <additional_params>
217
- <param usedby="shipped" require="carrier">
218
  <type>tracking</type>
219
  <name>colis_idTracking</name>
220
  </param>
221
- <param usedby="shipped" require="tracking">
222
  <type>carrier</type>
223
  <name>transporteur</name>
224
  </param>
@@ -1385,32 +1385,6 @@
1385
  <param usedby="shipped" require="tracking">
1386
  <type>carrier</type>
1387
  <name>Transporteur</name>
1388
- <accepted_values>
1389
- <value label="La Poste" default="true">LAPOSTE</value>
1390
- <value label="DHL">DHL</value>
1391
- <value label="Fedex">FEDEX</value>
1392
- <value label="GLS">GLS</value>
1393
- <value label="UPS">UPS</value>
1394
- <value label="TAT Express">TAT</value>
1395
- <value label="TNT">TNT</value>
1396
- <value label="Mondial Relay">MONDIALRELAY</value>
1397
- <value label="SERNAM">SERNAM</value>
1398
- <value label="Geodis Calberson">GEODISCALBERSON</value>
1399
- <value label="France Express">FRANCEEXPRESS</value>
1400
- <value label="SDEN">FRANCSDENEEXPRESS</value>
1401
- <value label="CHRONOPOST">Chronopost</value>
1402
- <value label="TATEX">TATEX</value>
1403
- <value label="SCHENKER JOYAU">SCHENKER_JOYAU</value>
1404
- <value label="Relais colis">Relais_colis</value>
1405
- <value label="Gefco">Gefco</value>
1406
- <value label="MORY">MORY</value>
1407
- <value label="Heppner">Heppner</value>
1408
- <value label="Exapaq">Exapaq</value>
1409
- <value label="Mazet">Mazet</value>
1410
- <value label="SIC EXPRESS">SICEXPRESS</value>
1411
- <value label="TMB">TMB</value>
1412
- <value label="DPD">DPD</value>
1413
- </accepted_values>
1414
  </param>
1415
  <param usedby="shipped">
1416
  <type>tracking_url</type>
@@ -1422,10 +1396,14 @@
1422
  <carrier code='STD'>standard</carrier>
1423
  <carrier code='TRK'>suivi</carrier>
1424
  <carrier code='REG'>recommande</carrier>
1425
- <carrier code='COL'>colissimo</carrier>
1426
  <carrier code='RCO'>relaiscolis</carrier>
1427
  <carrier code='REL'>mondialrelay</carrier>
1428
  <carrier code='MAG'>inshop</carrier>
 
 
 
 
 
1429
  </carriers>
1430
  </marketplace>
1431
  <marketplace name="moncornerdeco">
@@ -1524,7 +1502,7 @@
1524
  <value label="SIC EXPRESS">SICEXPRESS</value>
1525
  <value label="TMB">TMB</value>
1526
  <value label="DPD">DPD</value>
1527
- </accepted_values>
1528
  </param>
1529
  <param usedby="shipped">
1530
  <type>tracking_url</type>
@@ -1628,7 +1606,7 @@
1628
  <value label="SIC EXPRESS">SICEXPRESS</value>
1629
  <value label="TMB">TMB</value>
1630
  <value label="DPD">DPD</value>
1631
- </accepted_values>
1632
  </param>
1633
  <param usedby="shipped">
1634
  <type>tracking_url</type>
@@ -1732,7 +1710,7 @@
1732
  <value label="SIC EXPRESS">SICEXPRESS</value>
1733
  <value label="TMB">TMB</value>
1734
  <value label="DPD">DPD</value>
1735
- </accepted_values>
1736
  </param>
1737
  <param usedby="shipped">
1738
  <type>tracking_url</type>
@@ -1836,7 +1814,7 @@
1836
  <value label="SIC EXPRESS">SICEXPRESS</value>
1837
  <value label="TMB">TMB</value>
1838
  <value label="DPD">DPD</value>
1839
- </accepted_values>
1840
  </param>
1841
  <param usedby="shipped">
1842
  <type>tracking_url</type>
@@ -1940,7 +1918,7 @@
1940
  <value label="SIC EXPRESS">SICEXPRESS</value>
1941
  <value label="TMB">TMB</value>
1942
  <value label="DPD">DPD</value>
1943
- </accepted_values>
1944
  </param>
1945
  <param usedby="shipped">
1946
  <type>tracking_url</type>
@@ -2044,7 +2022,7 @@
2044
  <value label="SIC EXPRESS">SICEXPRESS</value>
2045
  <value label="TMB">TMB</value>
2046
  <value label="DPD">DPD</value>
2047
- </accepted_values>
2048
  </param>
2049
  <param usedby="shipped">
2050
  <type>tracking_url</type>
@@ -2052,7 +2030,7 @@
2052
  </param>
2053
  </additional_params>
2054
  </marketplace>
2055
- <marketplace name="laredoute">
2056
  <api>https://wsdl.lengow.com/wsdl/laredoute/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
2057
  <apibyline>https://wsdl.lengow.com/wsdl/laredoute/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QTY_TO_REFUND#/#FDP#/#ACTION#.xml</apibyline>
2058
  <states>
@@ -2072,6 +2050,9 @@
2072
  <action type="shipped">shippedOrder</action>
2073
  <action type="refund">refundOrder</action>
2074
  <action type="refundLine" usedbyline="true">refundOrder</action>
 
 
 
2075
  </actions>
2076
  <lengow>processing</lengow>
2077
  </state>
@@ -2088,6 +2069,21 @@
2088
  <state name="Refunded">
2089
  <lengow>canceled</lengow>
2090
  </state>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2091
  <state name="Cancelled">
2092
  <lengow>canceled</lengow>
2093
  </state>
@@ -2273,7 +2269,11 @@
2273
  </param>
2274
  <param usedby="shipped">
2275
  <type>carrier</type>
2276
- <name>Transporteur</name>
 
 
 
 
2277
  </param>
2278
  </additional_params>
2279
  </marketplace>
@@ -2450,9 +2450,22 @@
2450
  <type>carrier</type>
2451
  <name>carrier_name</name>
2452
  </param>
 
 
 
 
 
 
 
 
 
 
 
 
 
2453
  <param usedby="shipped">
2454
  <type>tracking_url</type>
2455
- <name>carrier_url</name>
2456
  </param>
2457
  </additional_params>
2458
  </marketplace>
@@ -2521,9 +2534,21 @@
2521
  <type>carrier</type>
2522
  <name>carrier_name</name>
2523
  </param>
 
 
 
 
 
 
 
 
 
 
 
 
2524
  <param usedby="shipped">
2525
  <type>tracking_url</type>
2526
- <name>carrier_url</name>
2527
  </param>
2528
  </additional_params>
2529
  </marketplace>
@@ -2592,9 +2617,28 @@
2592
  <type>carrier</type>
2593
  <name>carrier_name</name>
2594
  </param>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2595
  <param usedby="shipped">
2596
  <type>tracking_url</type>
2597
- <name>carrier_url</name>
2598
  </param>
2599
  </additional_params>
2600
  </marketplace>
@@ -2662,15 +2706,25 @@
2662
  <param usedby="shipped">
2663
  <type>carrier</type>
2664
  <name>carrier_name</name>
 
 
 
 
2665
  <accepted_values>
2666
  <value label="MRW" default="true">MRW</value>
2667
  <value label="UPS">UPS</value>
 
 
 
 
 
2668
  <value label="ASM">ASM</value>
2669
- </accepted_values>
 
2670
  </param>
2671
  <param usedby="shipped">
2672
  <type>tracking_url</type>
2673
- <name>carrier_url</name>
2674
  </param>
2675
  </additional_params>
2676
  </marketplace>
@@ -2735,19 +2789,23 @@
2735
  <type>tracking</type>
2736
  <name>tracking_number</name>
2737
  </param>
2738
- <param usedby="shipped">
2739
  <type>carrier</type>
2740
  <name>carrier_name</name>
 
 
 
 
2741
  <accepted_values>
2742
  <value label="Colissimo" default="true">1</value>
2743
  <value label="La Poste">2</value>
2744
  <value label="Fedex">3</value>
2745
  <value label="UPS">4</value>
2746
- </accepted_values>
2747
  </param>
2748
  <param usedby="shipped">
2749
  <type>tracking_url</type>
2750
- <name>carrier_url</name>
2751
  </param>
2752
  </additional_params>
2753
  </marketplace>
@@ -2814,17 +2872,13 @@
2814
  </param>
2815
  <param usedby="shipped">
2816
  <type>carrier</type>
2817
- <name>carrier_name</name>
2818
  <accepted_values>
2819
  <value label="Colissimo" default="true">1</value>
2820
  <value label="TNT">2</value>
2821
  <value label="Mondial Relay">3</value>
2822
  <value label="DHL">4</value>
2823
- </accepted_values>
2824
- </param>
2825
- <param usedby="shipped">
2826
- <type>tracking_url</type>
2827
- <name>carrier_url</name>
2828
  </param>
2829
  </additional_params>
2830
  </marketplace>
@@ -2893,9 +2947,17 @@
2893
  <type>carrier</type>
2894
  <name>carrier_name</name>
2895
  </param>
 
 
 
 
 
 
 
 
2896
  <param usedby="shipped">
2897
  <type>tracking_url</type>
2898
- <name>carrier_url</name>
2899
  </param>
2900
  </additional_params>
2901
  </marketplace>
@@ -2963,16 +3025,24 @@
2963
  <param usedby="shipped">
2964
  <type>carrier</type>
2965
  <name>carrier_name</name>
 
 
 
 
2966
  <accepted_values>
2967
- <value label="Colissimo" default="true">1</value>
2968
- <value label="TNT">2</value>
2969
- <value label="Mondial Relay">3</value>
2970
- <value label="DHL">4</value>
2971
- </accepted_values>
 
 
 
 
2972
  </param>
2973
  <param usedby="shipped">
2974
  <type>tracking_url</type>
2975
- <name>carrier_url</name>
2976
  </param>
2977
  </additional_params>
2978
  </marketplace>
@@ -3037,13 +3107,23 @@
3037
  <type>tracking</type>
3038
  <name>tracking_number</name>
3039
  </param>
 
 
 
 
 
 
 
 
 
 
3040
  <param usedby="shipped">
3041
  <type>carrier</type>
3042
  <name>carrier_name</name>
3043
  </param>
3044
  <param usedby="shipped">
3045
  <type>tracking_url</type>
3046
- <name>carrier_url</name>
3047
  </param>
3048
  </additional_params>
3049
  </marketplace>
@@ -3112,9 +3192,20 @@
3112
  <type>carrier</type>
3113
  <name>carrier_name</name>
3114
  </param>
 
 
 
 
 
 
 
 
 
 
 
3115
  <param usedby="shipped">
3116
  <type>tracking_url</type>
3117
- <name>carrier_url</name>
3118
  </param>
3119
  </additional_params>
3120
  </marketplace>
@@ -3180,7 +3271,7 @@
3180
  <value label="Divers" default="true">1</value>
3181
  <value label="Colissimo">2</value>
3182
  <value label="Lettre Max">3</value>
3183
- </accepted_values>
3184
  </param>
3185
  </additional_params>
3186
  </marketplace>
@@ -3321,12 +3412,12 @@
3321
  </param>
3322
  <param usedby="shipped">
3323
  <type>tracking_url</type>
3324
- <name>carrier_url</name>
3325
  </param>
3326
  </additional_params>
3327
  </marketplace>
3328
  <marketplace name="rakuten_de">
3329
- <api>https://wsdl.lengow.com/wsdl/rakutende/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3330
  <states>
3331
  <state name="pending">
3332
  <lengow>new</lengow>
@@ -3347,9 +3438,23 @@
3347
  <lengow>canceled</lengow>
3348
  </state>
3349
  </states>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3350
  </marketplace>
3351
  <marketplace name="rakuten_es">
3352
- <api>https://wsdl.lengow.com/wsdl/rakutenes/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3353
  <states>
3354
  <state name="Unfixed">
3355
  <lengow>new</lengow>
@@ -3382,7 +3487,7 @@
3382
  </states>
3383
  </marketplace>
3384
  <marketplace name="rakuten_uk">
3385
- <api>https://wsdl.lengow.com/wsdl/rakutenuk/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3386
  <states>
3387
  <state name="Unfixed">
3388
  <lengow>new</lengow>
@@ -3415,47 +3520,47 @@
3415
  </states>
3416
  </marketplace>
3417
  <marketplace name="spartoo">
3418
- <api>https://wsdl.lengow.com/wsdl/spartoo/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3419
- <states>
3420
- <state name="0">
3421
- <lengow>new</lengow>
3422
- </state>
3423
- <state name="1">
3424
- <actions>
3425
- <action type="accept">processing</action>
3426
- <action type="cancel">canceled</action>
3427
- <action type="refund">refund</action>
3428
- </actions>
3429
- <lengow>new</lengow>
3430
- </state>
3431
- <state name="11">
3432
- <lengow>new</lengow>
3433
- <actions>
3434
- <action type="accept">processing</action>
3435
- <action type="cancel">canceled</action>
3436
- <action type="refund">refund</action>
3437
- </actions>
3438
- </state>
3439
- <state name="2">
3440
- <actions>
3441
- <action type="shipped" method="post">shipped</action>
3442
- <action type="cancel">canceled</action>
3443
- <action type="refund">refund</action>
3444
- </actions>
3445
- <lengow>processing</lengow>
3446
- </state>
3447
- <state name="3">
3448
- <lengow>shipped</lengow>
3449
- </state>
3450
- <state name="4">
3451
- <lengow>canceled</lengow>
3452
- </state>
3453
- <state name="41">
3454
- <lengow>canceled</lengow>
3455
- </state>
3456
- <state name="48">
3457
- <lengow>canceled</lengow>
3458
- </state>
3459
  </states>
3460
  <additional_params>
3461
  <param usedby="shipped">
@@ -3465,33 +3570,33 @@
3465
  </additional_params>
3466
  </marketplace>
3467
  <marketplace name="zalando">
3468
- <api>https://wsdl.lengow.com/wsdl/zalando/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3469
- <states>
3470
- <state name="New">
3471
- <lengow>new</lengow>
3472
- </state>
3473
- <state name="Approved">
3474
- <actions>
3475
- <action type="shipped" method="post">shipped</action>
3476
- <action type="cancel" method="post">canceled</action>
3477
- </actions>
3478
- <lengow>processing</lengow>
3479
- </state>
3480
- <state name="SHIPPED">
3481
- <actions>
3482
- <action type="returned" method="post">returned</action>
3483
- </actions>
3484
- <lengow>shipped</lengow>
3485
- </state>
3486
- <state name="RETURNED">
3487
- <lengow>canceled</lengow>
3488
- </state>
3489
- <state name="ZALANDO_CANCELED">
3490
- <lengow>canceled</lengow>
3491
- </state>
3492
- <state name="NO_INVENTORY_CANCELED">
3493
- <lengow>canceled</lengow>
3494
- </state>
3495
  </states>
3496
  <additional_params>
3497
  <param usedby="shipped cancel refund returned">
@@ -3529,45 +3634,45 @@
3529
  </additional_params>
3530
  </marketplace>
3531
  <marketplace name="placedumariage">
3532
- <states>
3533
- <state name="partielle">
3534
- <lengow>new</lengow>
3535
- </state>
3536
- <state name="complète">
3537
- <lengow>new</lengow>
3538
- </state>
3539
- <state name="expédiée">
3540
- <lengow>shipped</lengow>
3541
- </state>
3542
- <state name="annulée">
3543
- <lengow>canceled</lengow>
3544
- </state>
3545
- </states>
3546
  </marketplace>
3547
  <marketplace name="home24_de">
3548
- <api>https://wsdl.lengow.com/wsdl/home24_de/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3549
- <apibyline>https://wsdl.lengow.com/wsdl/home24_de/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3550
- <states>
3551
- <state name="new">
3552
- <lengow>new</lengow>
3553
- <actions>
3554
- <action type="accept" method="post">processing</action>
3555
- <action type="refuse" method="post">canceled</action>
3556
- </actions>
3557
- </state>
3558
- <state name="processing">
3559
- <lengow>processing</lengow>
3560
- <actions>
3561
- <action type="shipped" method="post">shipped</action>
3562
- <action type="refuse" method="post">canceled</action>
3563
- </actions>
3564
- </state>
3565
- <state name="shipped">
3566
- <lengow>shipped</lengow>
3567
- </state>
3568
- <state name="canceled">
3569
- <lengow>canceled</lengow>
3570
- </state>
3571
  </states>
3572
  <additional_params>
3573
  <param usedby="accept">
@@ -3602,32 +3707,32 @@
3602
  <type>carrier</type>
3603
  <name>carrier_name</name>
3604
  </param>
3605
- </additional_params>
3606
  </marketplace>
3607
  <marketplace name="home24_fr">
3608
- <api>https://wsdl.lengow.com/wsdl/home24_fr/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3609
- <apibyline>https://wsdl.lengow.com/wsdl/home24_fr/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3610
- <states>
3611
- <state name="new">
3612
- <lengow>new</lengow>
3613
- <actions>
3614
- <action type="accept" method="post">processing</action>
3615
- <action type="refuse" method="post">canceled</action>
3616
- </actions>
3617
- </state>
3618
- <state name="processing">
3619
- <lengow>processing</lengow>
3620
- <actions>
3621
- <action type="shipped" method="post">shipped</action>
3622
- <action type="refuse" method="post">canceled</action>
3623
- </actions>
3624
- </state>
3625
- <state name="shipped">
3626
- <lengow>shipped</lengow>
3627
- </state>
3628
- <state name="canceled">
3629
- <lengow>canceled</lengow>
3630
- </state>
3631
  </states>
3632
  <additional_params>
3633
  <param usedby="accept">
@@ -3665,29 +3770,29 @@
3665
  </additional_params>
3666
  </marketplace>
3667
  <marketplace name="home24_nl">
3668
- <api>https://wsdl.lengow.com/wsdl/home24_nl/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3669
- <apibyline>https://wsdl.lengow.com/wsdl/home24_nl/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3670
- <states>
3671
- <state name="new">
3672
- <lengow>new</lengow>
3673
- <actions>
3674
- <action type="accept" method="post">processing</action>
3675
- <action type="refuse" method="post">canceled</action>
3676
- </actions>
3677
- </state>
3678
- <state name="processing">
3679
- <lengow>processing</lengow>
3680
- <actions>
3681
- <action type="shipped" method="post">shipped</action>
3682
- <action type="refuse" method="post">canceled</action>
3683
- </actions>
3684
- </state>
3685
- <state name="shipped">
3686
- <lengow>shipped</lengow>
3687
- </state>
3688
- <state name="canceled">
3689
- <lengow>canceled</lengow>
3690
- </state>
3691
  </states>
3692
  <additional_params>
3693
  <param usedby="accept">
@@ -3725,29 +3830,29 @@
3725
  </additional_params>
3726
  </marketplace>
3727
  <marketplace name="home24_at">
3728
- <api>https://wsdl.lengow.com/wsdl/home24_at/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3729
- <apibyline>https://wsdl.lengow.com/wsdl/home24_at/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3730
- <states>
3731
- <state name="new">
3732
- <lengow>new</lengow>
3733
- <actions>
3734
- <action type="accept" method="post">processing</action>
3735
- <action type="refuse" method="post">canceled</action>
3736
- </actions>
3737
- </state>
3738
- <state name="processing">
3739
- <lengow>processing</lengow>
3740
- <actions>
3741
- <action type="shipped" method="post">shipped</action>
3742
- <action type="refuse" method="post">canceled</action>
3743
- </actions>
3744
- </state>
3745
- <state name="shipped">
3746
- <lengow>shipped</lengow>
3747
- </state>
3748
- <state name="canceled">
3749
- <lengow>canceled</lengow>
3750
- </state>
3751
  </states>
3752
  <additional_params>
3753
  <param usedby="accept">
@@ -3785,43 +3890,43 @@
3785
  </additional_params>
3786
  </marketplace>
3787
  <marketplace name="home24_bede">
3788
- <api>https://wsdl.lengow.com/wsdl/home24_bede/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3789
- <apibyline>https://wsdl.lengow.com/wsdl/home24_bede/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3790
- <states>
3791
- <state name="new">
3792
- <lengow>new</lengow>
3793
- <actions>
3794
- <action type="accept" method="post">processing</action>
3795
- <action type="refuse" method="post">canceled</action>
3796
- </actions>
3797
- </state>
3798
- <state name="processing">
3799
- <lengow>processing</lengow>
3800
- <actions>
3801
- <action type="shipped" method="post">shipped</action>
3802
- <action type="refuse" method="post">canceled</action>
3803
- </actions>
3804
- </state>
3805
- <state name="shipped">
3806
- <lengow>shipped</lengow>
3807
- </state>
3808
- <state name="canceled">
3809
- <lengow>canceled</lengow>
3810
- </state>
3811
- </states>
3812
- <additional_params>
3813
- <param usedby="accept">
3814
- <type>date_shipped</type>
3815
- <name>date_shipped</name>
3816
- </param>
3817
- <param usedby="accept">
3818
- <type>date_delivered</type>
3819
- <name>date_delivered</name>
3820
- </param>
3821
- <param usedby="shipped cancel refund returned">
3822
- <type>action</type>
3823
- <name>action</name>
3824
- </param>
3825
  <param usedby="shipped cancel refund returned">
3826
  <type>sku</type>
3827
  <name>sku</name>
@@ -3845,29 +3950,29 @@
3845
  </additional_params>
3846
  </marketplace>
3847
  <marketplace name="home24_befr">
3848
- <api>https://wsdl.lengow.com/wsdl/home24_befr/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3849
- <apibyline>https://wsdl.lengow.com/wsdl/home24_befr/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3850
- <states>
3851
- <state name="new">
3852
- <lengow>new</lengow>
3853
- <actions>
3854
- <action type="accept" method="post">processing</action>
3855
- <action type="refuse" method="post">canceled</action>
3856
- </actions>
3857
- </state>
3858
- <state name="processing">
3859
- <lengow>processing</lengow>
3860
- <actions>
3861
- <action type="shipped" method="post">shipped</action>
3862
- <action type="refuse" method="post">canceled</action>
3863
- </actions>
3864
- </state>
3865
- <state name="shipped">
3866
- <lengow>shipped</lengow>
3867
- </state>
3868
- <state name="canceled">
3869
- <lengow>canceled</lengow>
3870
- </state>
3871
  </states>
3872
  <additional_params>
3873
  <param usedby="accept">
@@ -3905,29 +4010,29 @@
3905
  </additional_params>
3906
  </marketplace>
3907
  <marketplace name="home24_it">
3908
- <api>https://wsdl.lengow.com/wsdl/home24_it/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3909
- <apibyline>https://wsdl.lengow.com/wsdl/home24_it/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3910
- <states>
3911
- <state name="new">
3912
- <lengow>new</lengow>
3913
- <actions>
3914
- <action type="accept" method="post">processing</action>
3915
- <action type="refuse" method="post">canceled</action>
3916
- </actions>
3917
- </state>
3918
- <state name="processing">
3919
- <lengow>processing</lengow>
3920
- <actions>
3921
- <action type="shipped" method="post">shipped</action>
3922
- <action type="refuse" method="post">canceled</action>
3923
- </actions>
3924
- </state>
3925
- <state name="shipped">
3926
- <lengow>shipped</lengow>
3927
- </state>
3928
- <state name="canceled">
3929
- <lengow>canceled</lengow>
3930
- </state>
3931
  </states>
3932
  <additional_params>
3933
  <param usedby="accept">
@@ -3965,29 +4070,29 @@
3965
  </additional_params>
3966
  </marketplace>
3967
  <marketplace name="home24_chde">
3968
- <api>https://wsdl.lengow.com/wsdl/home24_chde/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3969
- <apibyline>https://wsdl.lengow.com/wsdl/home24_chde/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3970
- <states>
3971
- <state name="new">
3972
- <lengow>new</lengow>
3973
- <actions>
3974
- <action type="accept" method="post">processing</action>
3975
- <action type="refuse" method="post">canceled</action>
3976
- </actions>
3977
- </state>
3978
- <state name="processing">
3979
- <lengow>processing</lengow>
3980
- <actions>
3981
- <action type="shipped" method="post">shipped</action>
3982
- <action type="refuse" method="post">canceled</action>
3983
- </actions>
3984
- </state>
3985
- <state name="shipped">
3986
- <lengow>shipped</lengow>
3987
- </state>
3988
- <state name="canceled">
3989
- <lengow>canceled</lengow>
3990
- </state>
3991
  </states>
3992
  <additional_params>
3993
  <param usedby="accept">
@@ -4025,29 +4130,29 @@
4025
  </additional_params>
4026
  </marketplace>
4027
  <marketplace name="home24_chfr">
4028
- <api>https://wsdl.lengow.com/wsdl/home24_chfr/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4029
- <apibyline>https://wsdl.lengow.com/wsdl/home24_chfr/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
4030
- <states>
4031
- <state name="new">
4032
- <lengow>new</lengow>
4033
- <actions>
4034
- <action type="accept" method="post">processing</action>
4035
- <action type="refuse" method="post">canceled</action>
4036
- </actions>
4037
- </state>
4038
- <state name="processing">
4039
- <lengow>processing</lengow>
4040
- <actions>
4041
- <action type="shipped" method="post">shipped</action>
4042
- <action type="refuse" method="post">canceled</action>
4043
- </actions>
4044
- </state>
4045
- <state name="shipped">
4046
- <lengow>shipped</lengow>
4047
- </state>
4048
- <state name="canceled">
4049
- <lengow>canceled</lengow>
4050
- </state>
4051
  </states>
4052
  <additional_params>
4053
  <param usedby="accept">
@@ -4085,23 +4190,1700 @@
4085
  </additional_params>
4086
  </marketplace>
4087
  <marketplace name="ricardo">
4088
- <api>https://wsdl.lengow.com/wsdl/ricardo/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4089
- <states>
4090
- <state name="new">
4091
- <lengow>new</lengow>
4092
- </state>
4093
- <state name="processing">
4094
- <lengow>processing</lengow>
4095
- <actions>
4096
- <action type="shipped" method="post">ship</action>
4097
- </actions>
4098
- </state>
4099
- <state name="shipped">
4100
- <lengow>shipped</lengow>
4101
- </state>
4102
- <state name="canceled">
4103
- <lengow>canceled</lengow>
4104
- </state>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4105
  </states>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4106
  </marketplace>
4107
  </marketplaces>
133
  <state name="closed">
134
  <lengow>shipped</lengow>
135
  </state>
136
+ <state name="CLOSED">
137
  <lengow>shipped</lengow>
138
  </state>
139
  <state name="CANCELLED">
214
  </state>
215
  </states>
216
  <additional_params>
217
+ <param usedby="shipped">
218
  <type>tracking</type>
219
  <name>colis_idTracking</name>
220
  </param>
221
+ <param usedby="shipped">
222
  <type>carrier</type>
223
  <name>transporteur</name>
224
  </param>
1385
  <param usedby="shipped" require="tracking">
1386
  <type>carrier</type>
1387
  <name>Transporteur</name>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1388
  </param>
1389
  <param usedby="shipped">
1390
  <type>tracking_url</type>
1396
  <carrier code='STD'>standard</carrier>
1397
  <carrier code='TRK'>suivi</carrier>
1398
  <carrier code='REG'>recommande</carrier>
 
1399
  <carrier code='RCO'>relaiscolis</carrier>
1400
  <carrier code='REL'>mondialrelay</carrier>
1401
  <carrier code='MAG'>inshop</carrier>
1402
+ <carrier code='LV1'>BigParcelEco</carrier>
1403
+ <carrier code='LV2'>BigParcelStandard</carrier>
1404
+ <carrier code='LV3'>BigParcelComfort</carrier>
1405
+ <carrier code='EXP'>Express</carrier>
1406
+ <carrier code='FST'>Fast</carrier>
1407
  </carriers>
1408
  </marketplace>
1409
  <marketplace name="moncornerdeco">
1502
  <value label="SIC EXPRESS">SICEXPRESS</value>
1503
  <value label="TMB">TMB</value>
1504
  <value label="DPD">DPD</value>
1505
+ </accepted_values>
1506
  </param>
1507
  <param usedby="shipped">
1508
  <type>tracking_url</type>
1606
  <value label="SIC EXPRESS">SICEXPRESS</value>
1607
  <value label="TMB">TMB</value>
1608
  <value label="DPD">DPD</value>
1609
+ </accepted_values>
1610
  </param>
1611
  <param usedby="shipped">
1612
  <type>tracking_url</type>
1710
  <value label="SIC EXPRESS">SICEXPRESS</value>
1711
  <value label="TMB">TMB</value>
1712
  <value label="DPD">DPD</value>
1713
+ </accepted_values>
1714
  </param>
1715
  <param usedby="shipped">
1716
  <type>tracking_url</type>
1814
  <value label="SIC EXPRESS">SICEXPRESS</value>
1815
  <value label="TMB">TMB</value>
1816
  <value label="DPD">DPD</value>
1817
+ </accepted_values>
1818
  </param>
1819
  <param usedby="shipped">
1820
  <type>tracking_url</type>
1918
  <value label="SIC EXPRESS">SICEXPRESS</value>
1919
  <value label="TMB">TMB</value>
1920
  <value label="DPD">DPD</value>
1921
+ </accepted_values>
1922
  </param>
1923
  <param usedby="shipped">
1924
  <type>tracking_url</type>
2022
  <value label="SIC EXPRESS">SICEXPRESS</value>
2023
  <value label="TMB">TMB</value>
2024
  <value label="DPD">DPD</value>
2025
+ </accepted_values>
2026
  </param>
2027
  <param usedby="shipped">
2028
  <type>tracking_url</type>
2030
  </param>
2031
  </additional_params>
2032
  </marketplace>
2033
+ <marketplace name="laredoute">
2034
  <api>https://wsdl.lengow.com/wsdl/laredoute/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
2035
  <apibyline>https://wsdl.lengow.com/wsdl/laredoute/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QTY_TO_REFUND#/#FDP#/#ACTION#.xml</apibyline>
2036
  <states>
2050
  <action type="shipped">shippedOrder</action>
2051
  <action type="refund">refundOrder</action>
2052
  <action type="refundLine" usedbyline="true">refundOrder</action>
2053
+ <action type="cancel">OutOfStock</action>
2054
+ <action type="cancelLine" usedbyline="true">OutOfStock</action>
2055
+ <action type="shippedLine" usedbyline="true">shippedOrder</action>
2056
  </actions>
2057
  <lengow>processing</lengow>
2058
  </state>
2069
  <state name="Refunded">
2070
  <lengow>canceled</lengow>
2071
  </state>
2072
+ <state name="Paid">
2073
+ <lengow>shipped</lengow>
2074
+ </state>
2075
+ <state name="Refunding">
2076
+ <lengow>canceled</lengow>
2077
+ </state>
2078
+ <state name="ToApprove">
2079
+ <lengow>shipped</lengow>
2080
+ </state>
2081
+ <state name="OutOfStock">
2082
+ <lengow>canceled</lengow>
2083
+ </state>
2084
+ <state name="RefundRefused">
2085
+ <lengow>shipped</lengow>
2086
+ </state>
2087
  <state name="Cancelled">
2088
  <lengow>canceled</lengow>
2089
  </state>
2269
  </param>
2270
  <param usedby="shipped">
2271
  <type>carrier</type>
2272
+ <name>TransporteurColis</name>
2273
+ </param>
2274
+ <param usedby="shipped">
2275
+ <type>tracking_url</type>
2276
+ <name>TrackingUrl</name>
2277
  </param>
2278
  </additional_params>
2279
  </marketplace>
2450
  <type>carrier</type>
2451
  <name>carrier_name</name>
2452
  </param>
2453
+ <param usedby="shipped">
2454
+ <type>carrier_code</type>
2455
+ <name>carrier_code</name>
2456
+ <accepted_values>
2457
+ <value label="Colissimo" default="true">colissimo</value>
2458
+ <value label="Chronopost">chronopost</value>
2459
+ <value label="UPS">ups</value>
2460
+ <value label="GLS">gls</value>
2461
+ <value label="Gefco">gefco</value>
2462
+ <value label="DPD">dpd</value>
2463
+ <value label="DHL France">dhl</value>
2464
+ </accepted_values>
2465
+ </param>
2466
  <param usedby="shipped">
2467
  <type>tracking_url</type>
2468
+ <name>tracking_url</name>
2469
  </param>
2470
  </additional_params>
2471
  </marketplace>
2534
  <type>carrier</type>
2535
  <name>carrier_name</name>
2536
  </param>
2537
+ <param usedby="shipped">
2538
+ <type>carrier_code</type>
2539
+ <name>carrier_code</name>
2540
+ <accepted_values>
2541
+ <value label="Socolissimo">T1</value>
2542
+ <value label="Mondial Relay LD1">T2</value>
2543
+ <value label="Calberson">T3</value>
2544
+ <value label="Relais Colis">T4</value>
2545
+ <value label="Chronopost">T5</value>
2546
+ <value label="GLS">T6</value>
2547
+ </accepted_values>
2548
+ </param>
2549
  <param usedby="shipped">
2550
  <type>tracking_url</type>
2551
+ <name>tracking_url</name>
2552
  </param>
2553
  </additional_params>
2554
  </marketplace>
2617
  <type>carrier</type>
2618
  <name>carrier_name</name>
2619
  </param>
2620
+ <param usedby="shipped">
2621
+ <type>carrier_code</type>
2622
+ <name>carrier_code</name>
2623
+ <accepted_values>
2624
+ <value label="La Poste - Colissimo" default="true">COLISSIMO</value>
2625
+ <value label="La Poste - Lettre Max">LAPOSTE</value>
2626
+ <value label="Chonopost">CHRONOPOST</value>
2627
+ <value label="Colis Privé">COLISPRIVE</value>
2628
+ <value label="UPS">UPS</value>
2629
+ <value label="DHL">DHL</value>
2630
+ <value label="TNT">TNT</value>
2631
+ <value label="Fedex">FEDEX</value>
2632
+ <value label="DPD UK">DPD</value>
2633
+ <value label="DPD DE">DPDDE</value>
2634
+ <value label="Exapaq">EXAPAQ</value>
2635
+ <value label="Elite Express">ELITEEXPRESS</value>
2636
+ <value label="Post Luxembourg">POSTLU</value>
2637
+ </accepted_values>
2638
+ </param>
2639
  <param usedby="shipped">
2640
  <type>tracking_url</type>
2641
+ <name>tracking_url</name>
2642
  </param>
2643
  </additional_params>
2644
  </marketplace>
2706
  <param usedby="shipped">
2707
  <type>carrier</type>
2708
  <name>carrier_name</name>
2709
+ </param>
2710
+ <param usedby="shipped">
2711
+ <type>carrier_code</type>
2712
+ <name>carrier_code</name>
2713
  <accepted_values>
2714
  <value label="MRW" default="true">MRW</value>
2715
  <value label="UPS">UPS</value>
2716
+ <value label="SEUR">SEUR</value>
2717
+ <value label="DHL">DHL</value>
2718
+ <value label="ENVIALIA">ENVIALIA</value>
2719
+ <value label="CORREOS">CORREOS</value>
2720
+ <value label="CHRONO EXPRESS">CHRONO EXPRESS</value>
2721
  <value label="ASM">ASM</value>
2722
+ <value label="DEUTSCHE POST">DEUTSCHE POST</value>
2723
+ </accepted_values>
2724
  </param>
2725
  <param usedby="shipped">
2726
  <type>tracking_url</type>
2727
+ <name>tracking_url</name>
2728
  </param>
2729
  </additional_params>
2730
  </marketplace>
2789
  <type>tracking</type>
2790
  <name>tracking_number</name>
2791
  </param>
2792
+ <param usedby="shipped">
2793
  <type>carrier</type>
2794
  <name>carrier_name</name>
2795
+ </param>
2796
+ <param usedby="shipped">
2797
+ <type>carrier_code</type>
2798
+ <name>carrier_code</name>
2799
  <accepted_values>
2800
  <value label="Colissimo" default="true">1</value>
2801
  <value label="La Poste">2</value>
2802
  <value label="Fedex">3</value>
2803
  <value label="UPS">4</value>
2804
+ </accepted_values>
2805
  </param>
2806
  <param usedby="shipped">
2807
  <type>tracking_url</type>
2808
+ <name>tracking_url</name>
2809
  </param>
2810
  </additional_params>
2811
  </marketplace>
2872
  </param>
2873
  <param usedby="shipped">
2874
  <type>carrier</type>
2875
+ <name>carrier_code</name>
2876
  <accepted_values>
2877
  <value label="Colissimo" default="true">1</value>
2878
  <value label="TNT">2</value>
2879
  <value label="Mondial Relay">3</value>
2880
  <value label="DHL">4</value>
2881
+ </accepted_values>
 
 
 
 
2882
  </param>
2883
  </additional_params>
2884
  </marketplace>
2947
  <type>carrier</type>
2948
  <name>carrier_name</name>
2949
  </param>
2950
+ <param usedby="shipped">
2951
+ <type>carrier_code</type>
2952
+ <name>carrier_code</name>
2953
+ <accepted_values>
2954
+ <value label="Colissimo" default="true">Colissimo</value>
2955
+ <value label="La Poste">LAPOSTE</value>
2956
+ </accepted_values>
2957
+ </param>
2958
  <param usedby="shipped">
2959
  <type>tracking_url</type>
2960
+ <name>tracking_url</name>
2961
  </param>
2962
  </additional_params>
2963
  </marketplace>
3025
  <param usedby="shipped">
3026
  <type>carrier</type>
3027
  <name>carrier_name</name>
3028
+ </param>
3029
+ <param usedby="shipped">
3030
+ <type>carrier_code</type>
3031
+ <name>carrier_code</name>
3032
  <accepted_values>
3033
+ <value label="MRW">MRW</value>
3034
+ <value label="UPS">UPS</value>
3035
+ <value label="SEUR">SEUR</value>
3036
+ <value label="DHL">DHL</value>
3037
+ <value label="ENVIALIA">ENVIALIA</value>
3038
+ <value label="CORREOS">CORREOS</value>
3039
+ <value label="CHRONO EXPRESS">CHRONO EXPRESS</value>
3040
+ <value label="ASM">ASM</value>
3041
+ </accepted_values>
3042
  </param>
3043
  <param usedby="shipped">
3044
  <type>tracking_url</type>
3045
+ <name>tracking_url</name>
3046
  </param>
3047
  </additional_params>
3048
  </marketplace>
3107
  <type>tracking</type>
3108
  <name>tracking_number</name>
3109
  </param>
3110
+ <param usedby="shipped">
3111
+ <type>carrier_code</type>
3112
+ <name>carrier_code</name>
3113
+ <accepted_values>
3114
+ <value label="Chronospost" default="true">CHRONOPOST</value>
3115
+ <value label="DHL">DHL</value>
3116
+ <value label="TNT">TNT</value>
3117
+ <value label="Colissimo">COLISSIMO</value>
3118
+ </accepted_values>
3119
+ </param>
3120
  <param usedby="shipped">
3121
  <type>carrier</type>
3122
  <name>carrier_name</name>
3123
  </param>
3124
  <param usedby="shipped">
3125
  <type>tracking_url</type>
3126
+ <name>tracking_url</name>
3127
  </param>
3128
  </additional_params>
3129
  </marketplace>
3192
  <type>carrier</type>
3193
  <name>carrier_name</name>
3194
  </param>
3195
+ <param usedby="shipped">
3196
+ <type>carrier_code</type>
3197
+ <name>carrier_code</name>
3198
+ <accepted_values>
3199
+ <value label="Colissimo" default="true">CO</value>
3200
+ <value label="Chronopost">CHR</value>
3201
+ <value label="Courrier suivi">COS</value>
3202
+ <value label="GLS">Group</value>
3203
+ <value label="UPS">UPS</value>
3204
+ </accepted_values>
3205
+ </param>
3206
  <param usedby="shipped">
3207
  <type>tracking_url</type>
3208
+ <name>tracking_url</name>
3209
  </param>
3210
  </additional_params>
3211
  </marketplace>
3271
  <value label="Divers" default="true">1</value>
3272
  <value label="Colissimo">2</value>
3273
  <value label="Lettre Max">3</value>
3274
+ </accepted_values>
3275
  </param>
3276
  </additional_params>
3277
  </marketplace>
3412
  </param>
3413
  <param usedby="shipped">
3414
  <type>tracking_url</type>
3415
+ <name>tracking_url</name>
3416
  </param>
3417
  </additional_params>
3418
  </marketplace>
3419
  <marketplace name="rakuten_de">
3420
+ <api>https://wsdl.lengow.com/wsdl/rakutende/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3421
  <states>
3422
  <state name="pending">
3423
  <lengow>new</lengow>
3438
  <lengow>canceled</lengow>
3439
  </state>
3440
  </states>
3441
+ <additional_params>
3442
+ <param usedby="shipped">
3443
+ <type>tracking</type>
3444
+ <name>tracking_number</name>
3445
+ </param>
3446
+ <param usedby="shipped">
3447
+ <type>carrier</type>
3448
+ <name>carrier</name>
3449
+ </param>
3450
+ <param usedby="shipped">
3451
+ <type>tracking_url</type>
3452
+ <name>tracking_url</name>
3453
+ </param>
3454
+ </additional_params>
3455
  </marketplace>
3456
  <marketplace name="rakuten_es">
3457
+ <api>https://wsdl.lengow.com/wsdl/rakutenes/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3458
  <states>
3459
  <state name="Unfixed">
3460
  <lengow>new</lengow>
3487
  </states>
3488
  </marketplace>
3489
  <marketplace name="rakuten_uk">
3490
+ <api>https://wsdl.lengow.com/wsdl/rakutenuk/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3491
  <states>
3492
  <state name="Unfixed">
3493
  <lengow>new</lengow>
3520
  </states>
3521
  </marketplace>
3522
  <marketplace name="spartoo">
3523
+ <api>https://wsdl.lengow.com/wsdl/spartoo/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3524
+ <states>
3525
+ <state name="0">
3526
+ <lengow>new</lengow>
3527
+ </state>
3528
+ <state name="1">
3529
+ <actions>
3530
+ <action type="accept">processing</action>
3531
+ <action type="refuse">canceled</action>
3532
+ <action type="refund">refund</action>
3533
+ </actions>
3534
+ <lengow>new</lengow>
3535
+ </state>
3536
+ <state name="11">
3537
+ <lengow>new</lengow>
3538
+ <actions>
3539
+ <action type="accept">processing</action>
3540
+ <action type="refuse">canceled</action>
3541
+ <action type="refund">refund</action>
3542
+ </actions>
3543
+ </state>
3544
+ <state name="2">
3545
+ <actions>
3546
+ <action type="shipped" method="post">shipped</action>
3547
+ <action type="refuse">canceled</action>
3548
+ <action type="refund">refund</action>
3549
+ </actions>
3550
+ <lengow>processing</lengow>
3551
+ </state>
3552
+ <state name="3">
3553
+ <lengow>shipped</lengow>
3554
+ </state>
3555
+ <state name="4">
3556
+ <lengow>canceled</lengow>
3557
+ </state>
3558
+ <state name="41">
3559
+ <lengow>canceled</lengow>
3560
+ </state>
3561
+ <state name="48">
3562
+ <lengow>canceled</lengow>
3563
+ </state>
3564
  </states>
3565
  <additional_params>
3566
  <param usedby="shipped">
3570
  </additional_params>
3571
  </marketplace>
3572
  <marketplace name="zalando">
3573
+ <api>https://wsdl.lengow.com/wsdl/zalando/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3574
+ <states>
3575
+ <state name="New">
3576
+ <lengow>new</lengow>
3577
+ </state>
3578
+ <state name="Approved">
3579
+ <actions>
3580
+ <action type="shipped" method="post">shipped</action>
3581
+ <action type="cancel" method="post">canceled</action>
3582
+ </actions>
3583
+ <lengow>processing</lengow>
3584
+ </state>
3585
+ <state name="SHIPPED">
3586
+ <actions>
3587
+ <action type="returned" method="post">returned</action>
3588
+ </actions>
3589
+ <lengow>shipped</lengow>
3590
+ </state>
3591
+ <state name="RETURNED">
3592
+ <lengow>canceled</lengow>
3593
+ </state>
3594
+ <state name="ZALANDO_CANCELED">
3595
+ <lengow>canceled</lengow>
3596
+ </state>
3597
+ <state name="NO_INVENTORY_CANCELED">
3598
+ <lengow>canceled</lengow>
3599
+ </state>
3600
  </states>
3601
  <additional_params>
3602
  <param usedby="shipped cancel refund returned">
3634
  </additional_params>
3635
  </marketplace>
3636
  <marketplace name="placedumariage">
3637
+ <states>
3638
+ <state name="partielle">
3639
+ <lengow>new</lengow>
3640
+ </state>
3641
+ <state name="complète">
3642
+ <lengow>new</lengow>
3643
+ </state>
3644
+ <state name="expédiée">
3645
+ <lengow>shipped</lengow>
3646
+ </state>
3647
+ <state name="annulée">
3648
+ <lengow>canceled</lengow>
3649
+ </state>
3650
+ </states>
3651
  </marketplace>
3652
  <marketplace name="home24_de">
3653
+ <api>https://wsdl.lengow.com/wsdl/home24_de/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3654
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_de/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3655
+ <states>
3656
+ <state name="new">
3657
+ <lengow>new</lengow>
3658
+ <actions>
3659
+ <action type="accept" method="post">processing</action>
3660
+ <action type="refuse" method="post">canceled</action>
3661
+ </actions>
3662
+ </state>
3663
+ <state name="processing">
3664
+ <lengow>processing</lengow>
3665
+ <actions>
3666
+ <action type="shipped" method="post">shipped</action>
3667
+ <action type="refuse" method="post">canceled</action>
3668
+ </actions>
3669
+ </state>
3670
+ <state name="shipped">
3671
+ <lengow>shipped</lengow>
3672
+ </state>
3673
+ <state name="canceled">
3674
+ <lengow>canceled</lengow>
3675
+ </state>
3676
  </states>
3677
  <additional_params>
3678
  <param usedby="accept">
3707
  <type>carrier</type>
3708
  <name>carrier_name</name>
3709
  </param>
3710
+ </additional_params>
3711
  </marketplace>
3712
  <marketplace name="home24_fr">
3713
+ <api>https://wsdl.lengow.com/wsdl/home24_fr/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3714
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_fr/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3715
+ <states>
3716
+ <state name="new">
3717
+ <lengow>new</lengow>
3718
+ <actions>
3719
+ <action type="accept" method="post">processing</action>
3720
+ <action type="refuse" method="post">canceled</action>
3721
+ </actions>
3722
+ </state>
3723
+ <state name="processing">
3724
+ <lengow>processing</lengow>
3725
+ <actions>
3726
+ <action type="shipped" method="post">shipped</action>
3727
+ <action type="refuse" method="post">canceled</action>
3728
+ </actions>
3729
+ </state>
3730
+ <state name="shipped">
3731
+ <lengow>shipped</lengow>
3732
+ </state>
3733
+ <state name="canceled">
3734
+ <lengow>canceled</lengow>
3735
+ </state>
3736
  </states>
3737
  <additional_params>
3738
  <param usedby="accept">
3770
  </additional_params>
3771
  </marketplace>
3772
  <marketplace name="home24_nl">
3773
+ <api>https://wsdl.lengow.com/wsdl/home24_nl/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3774
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_nl/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3775
+ <states>
3776
+ <state name="new">
3777
+ <lengow>new</lengow>
3778
+ <actions>
3779
+ <action type="accept" method="post">processing</action>
3780
+ <action type="refuse" method="post">canceled</action>
3781
+ </actions>
3782
+ </state>
3783
+ <state name="processing">
3784
+ <lengow>processing</lengow>
3785
+ <actions>
3786
+ <action type="shipped" method="post">shipped</action>
3787
+ <action type="refuse" method="post">canceled</action>
3788
+ </actions>
3789
+ </state>
3790
+ <state name="shipped">
3791
+ <lengow>shipped</lengow>
3792
+ </state>
3793
+ <state name="canceled">
3794
+ <lengow>canceled</lengow>
3795
+ </state>
3796
  </states>
3797
  <additional_params>
3798
  <param usedby="accept">
3830
  </additional_params>
3831
  </marketplace>
3832
  <marketplace name="home24_at">
3833
+ <api>https://wsdl.lengow.com/wsdl/home24_at/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3834
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_at/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3835
+ <states>
3836
+ <state name="new">
3837
+ <lengow>new</lengow>
3838
+ <actions>
3839
+ <action type="accept" method="post">processing</action>
3840
+ <action type="refuse" method="post">canceled</action>
3841
+ </actions>
3842
+ </state>
3843
+ <state name="processing">
3844
+ <lengow>processing</lengow>
3845
+ <actions>
3846
+ <action type="shipped" method="post">shipped</action>
3847
+ <action type="refuse" method="post">canceled</action>
3848
+ </actions>
3849
+ </state>
3850
+ <state name="shipped">
3851
+ <lengow>shipped</lengow>
3852
+ </state>
3853
+ <state name="canceled">
3854
+ <lengow>canceled</lengow>
3855
+ </state>
3856
  </states>
3857
  <additional_params>
3858
  <param usedby="accept">
3890
  </additional_params>
3891
  </marketplace>
3892
  <marketplace name="home24_bede">
3893
+ <api>https://wsdl.lengow.com/wsdl/home24_bede/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3894
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_bede/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3895
+ <states>
3896
+ <state name="new">
3897
+ <lengow>new</lengow>
3898
+ <actions>
3899
+ <action type="accept" method="post">processing</action>
3900
+ <action type="refuse" method="post">canceled</action>
3901
+ </actions>
3902
+ </state>
3903
+ <state name="processing">
3904
+ <lengow>processing</lengow>
3905
+ <actions>
3906
+ <action type="shipped" method="post">shipped</action>
3907
+ <action type="refuse" method="post">canceled</action>
3908
+ </actions>
3909
+ </state>
3910
+ <state name="shipped">
3911
+ <lengow>shipped</lengow>
3912
+ </state>
3913
+ <state name="canceled">
3914
+ <lengow>canceled</lengow>
3915
+ </state>
3916
+ </states>
3917
+ <additional_params>
3918
+ <param usedby="accept">
3919
+ <type>date_shipped</type>
3920
+ <name>date_shipped</name>
3921
+ </param>
3922
+ <param usedby="accept">
3923
+ <type>date_delivered</type>
3924
+ <name>date_delivered</name>
3925
+ </param>
3926
+ <param usedby="shipped cancel refund returned">
3927
+ <type>action</type>
3928
+ <name>action</name>
3929
+ </param>
3930
  <param usedby="shipped cancel refund returned">
3931
  <type>sku</type>
3932
  <name>sku</name>
3950
  </additional_params>
3951
  </marketplace>
3952
  <marketplace name="home24_befr">
3953
+ <api>https://wsdl.lengow.com/wsdl/home24_befr/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
3954
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_befr/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
3955
+ <states>
3956
+ <state name="new">
3957
+ <lengow>new</lengow>
3958
+ <actions>
3959
+ <action type="accept" method="post">processing</action>
3960
+ <action type="refuse" method="post">canceled</action>
3961
+ </actions>
3962
+ </state>
3963
+ <state name="processing">
3964
+ <lengow>processing</lengow>
3965
+ <actions>
3966
+ <action type="shipped" method="post">shipped</action>
3967
+ <action type="refuse" method="post">canceled</action>
3968
+ </actions>
3969
+ </state>
3970
+ <state name="shipped">
3971
+ <lengow>shipped</lengow>
3972
+ </state>
3973
+ <state name="canceled">
3974
+ <lengow>canceled</lengow>
3975
+ </state>
3976
  </states>
3977
  <additional_params>
3978
  <param usedby="accept">
4010
  </additional_params>
4011
  </marketplace>
4012
  <marketplace name="home24_it">
4013
+ <api>https://wsdl.lengow.com/wsdl/home24_it/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4014
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_it/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
4015
+ <states>
4016
+ <state name="new">
4017
+ <lengow>new</lengow>
4018
+ <actions>
4019
+ <action type="accept" method="post">processing</action>
4020
+ <action type="refuse" method="post">canceled</action>
4021
+ </actions>
4022
+ </state>
4023
+ <state name="processing">
4024
+ <lengow>processing</lengow>
4025
+ <actions>
4026
+ <action type="shipped" method="post">shipped</action>
4027
+ <action type="refuse" method="post">canceled</action>
4028
+ </actions>
4029
+ </state>
4030
+ <state name="shipped">
4031
+ <lengow>shipped</lengow>
4032
+ </state>
4033
+ <state name="canceled">
4034
+ <lengow>canceled</lengow>
4035
+ </state>
4036
  </states>
4037
  <additional_params>
4038
  <param usedby="accept">
4070
  </additional_params>
4071
  </marketplace>
4072
  <marketplace name="home24_chde">
4073
+ <api>https://wsdl.lengow.com/wsdl/home24_chde/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4074
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_chde/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
4075
+ <states>
4076
+ <state name="new">
4077
+ <lengow>new</lengow>
4078
+ <actions>
4079
+ <action type="accept" method="post">processing</action>
4080
+ <action type="refuse" method="post">canceled</action>
4081
+ </actions>
4082
+ </state>
4083
+ <state name="processing">
4084
+ <lengow>processing</lengow>
4085
+ <actions>
4086
+ <action type="shipped" method="post">shipped</action>
4087
+ <action type="refuse" method="post">canceled</action>
4088
+ </actions>
4089
+ </state>
4090
+ <state name="shipped">
4091
+ <lengow>shipped</lengow>
4092
+ </state>
4093
+ <state name="canceled">
4094
+ <lengow>canceled</lengow>
4095
+ </state>
4096
  </states>
4097
  <additional_params>
4098
  <param usedby="accept">
4130
  </additional_params>
4131
  </marketplace>
4132
  <marketplace name="home24_chfr">
4133
+ <api>https://wsdl.lengow.com/wsdl/home24_chfr/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4134
+ <apibyline>https://wsdl.lengow.com/wsdl/home24_chfr/#ID_FLUX#/#ORDER_ID#/#ORDER_LINE_ID#/#QUANTITY#/action_lines.xml</apibyline>
4135
+ <states>
4136
+ <state name="new">
4137
+ <lengow>new</lengow>
4138
+ <actions>
4139
+ <action type="accept" method="post">processing</action>
4140
+ <action type="refuse" method="post">canceled</action>
4141
+ </actions>
4142
+ </state>
4143
+ <state name="processing">
4144
+ <lengow>processing</lengow>
4145
+ <actions>
4146
+ <action type="shipped" method="post">shipped</action>
4147
+ <action type="refuse" method="post">canceled</action>
4148
+ </actions>
4149
+ </state>
4150
+ <state name="shipped">
4151
+ <lengow>shipped</lengow>
4152
+ </state>
4153
+ <state name="canceled">
4154
+ <lengow>canceled</lengow>
4155
+ </state>
4156
  </states>
4157
  <additional_params>
4158
  <param usedby="accept">
4190
  </additional_params>
4191
  </marketplace>
4192
  <marketplace name="ricardo">
4193
+ <api>https://wsdl.lengow.com/wsdl/ricardo/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4194
+ <states>
4195
+ <state name="new">
4196
+ <lengow>new</lengow>
4197
+ <actions>
4198
+ <action type="accept">acceptOrder</action>
4199
+ <action type="refuse">refuseOrder</action>
4200
+ </actions>
4201
+ </state>
4202
+ <state name="processing">
4203
+ <lengow>processing</lengow>
4204
+ <actions>
4205
+ <action type="shipped" method="post">ship</action>
4206
+ </actions>
4207
+ </state>
4208
+ <state name="shipped">
4209
+ <lengow>shipped</lengow>
4210
+ </state>
4211
+ <state name="canceled">
4212
+ <lengow>canceled</lengow>
4213
+ </state>
4214
+ </states>
4215
+ </marketplace>
4216
+ <marketplace name="oclio">
4217
+ <api>https://wsdl.lengow.com/wsdl/oclio/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4218
+ <states>
4219
+ <state name="RECEIVED">
4220
+ <lengow>shipped</lengow>
4221
+ </state>
4222
+ <state name="STAGING">
4223
+ <lengow>new</lengow>
4224
+ </state>
4225
+ <state name="WAITING_ACCEPTANCE">
4226
+ <lengow>new</lengow>
4227
+ <actions>
4228
+ <action type="accept">accept</action>
4229
+ <action type="refuse">canceled</action>
4230
+ </actions>
4231
+ </state>
4232
+ <state name="WAITING_DEBIT">
4233
+ <lengow>new</lengow>
4234
+ </state>
4235
+ <state name="WAITING_DEBIT_PAYMENT">
4236
+ <lengow>new</lengow>
4237
+ </state>
4238
+ <state name="SHIPPING">
4239
+ <lengow>processing</lengow>
4240
+ <actions>
4241
+ <action type="shipped">shipped</action>
4242
+ </actions>
4243
+ </state>
4244
+ <state name="RECEIVED">
4245
+ <lengow>shipped</lengow>
4246
+ </state>
4247
+ <state name="SHIPPED">
4248
+ <lengow>shipped</lengow>
4249
+ </state>
4250
+ <state name="CANCELED">
4251
+ <lengow>canceled</lengow>
4252
+ </state>
4253
+ <state name="CLOSED">
4254
+ <lengow>shipped</lengow>
4255
+ </state>
4256
+ <state name="REFUSED">
4257
+ <lengow>canceled</lengow>
4258
+ </state>
4259
+ <state name="INCIDENT_OPEN">
4260
+ <lengow>processing</lengow>
4261
+ </state>
4262
+ <state name="INCIDENT_CLOSED">
4263
+ <lengow>processing</lengow>
4264
+ </state>
4265
+ <state name="WAITING_REFUND">
4266
+ <lengow>processing</lengow>
4267
+ </state>
4268
+ <state name="WAITING_REFUND_PAYMENT">
4269
+ <lengow>processing</lengow>
4270
+ </state>
4271
+ <state name="REFUNDED">
4272
+ <lengow>canceled</lengow>
4273
+ </state>
4274
+ </states>
4275
+ <additional_params>
4276
+ <param usedby="shipped">
4277
+ <type>tracking</type>
4278
+ <name>tracking_number</name>
4279
+ </param>
4280
+ <param usedby="shipped">
4281
+ <type>carrier</type>
4282
+ <name>carrier_name</name>
4283
+ <accepted_values>
4284
+ <value label="Colissimo" default="true">Colissimo</value>
4285
+ <value label="Chronopost">Chronopost</value>
4286
+ <value label="DHL">DHL</value>
4287
+ <value label="La Poste">La Poste</value>
4288
+ <value label="La Poste Lettre MAX">La Poste Lettre MAX</value>
4289
+ <value label="Fedex">Fedex</value>
4290
+ <value label="TNT">TNT</value>
4291
+ <value label="UPS">UPS</value>
4292
+ </accepted_values>
4293
+ </param>
4294
+ </additional_params>
4295
+ </marketplace>
4296
+ <marketplace name="thebeautyst" realname="TheBeautyst" idshopbot="2049">
4297
+ <api>https://wsdl.lengow.com/wsdl/thebeautyst/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4298
+ <states>
4299
+ <state name="RECEIVED">
4300
+ <lengow>shipped</lengow>
4301
+ </state>
4302
+ <state name="STAGING">
4303
+ <lengow>new</lengow>
4304
+ </state>
4305
+ <state name="WAITING_ACCEPTANCE">
4306
+ <lengow>new</lengow>
4307
+ <actions>
4308
+ <action type="accept">accept</action>
4309
+ <action type="refuse">canceled</action>
4310
+ </actions>
4311
+ </state>
4312
+ <state name="WAITING_DEBIT">
4313
+ <lengow>new</lengow>
4314
+ </state>
4315
+ <state name="WAITING_DEBIT_PAYMENT">
4316
+ <lengow>new</lengow>
4317
+ </state>
4318
+ <state name="SHIPPING">
4319
+ <lengow>processing</lengow>
4320
+ <actions>
4321
+ <action type="shipped">shipped</action>
4322
+ </actions>
4323
+ </state>
4324
+ <state name="RECEIVED">
4325
+ <lengow>shipped</lengow>
4326
+ </state>
4327
+ <state name="SHIPPED">
4328
+ <lengow>shipped</lengow>
4329
+ </state>
4330
+ <state name="CANCELED">
4331
+ <lengow>canceled</lengow>
4332
+ </state>
4333
+ <state name="CLOSED">
4334
+ <lengow>shipped</lengow>
4335
+ </state>
4336
+ <state name="REFUSED">
4337
+ <lengow>canceled</lengow>
4338
+ </state>
4339
+ <state name="INCIDENT_OPEN">
4340
+ <lengow>processing</lengow>
4341
+ </state>
4342
+ <state name="INCIDENT_CLOSED">
4343
+ <lengow>processing</lengow>
4344
+ </state>
4345
+ <state name="WAITING_REFUND">
4346
+ <lengow>processing</lengow>
4347
+ </state>
4348
+ <state name="WAITING_REFUND_PAYMENT">
4349
+ <lengow>processing</lengow>
4350
+ </state>
4351
+ <state name="REFUNDED">
4352
+ <lengow>canceled</lengow>
4353
+ </state>
4354
  </states>
4355
+ <additional_params>
4356
+ <param usedby="shipped">
4357
+ <type>tracking</type>
4358
+ <name>tracking_number</name>
4359
+ </param>
4360
+ <param usedby="shipped">
4361
+ <type>carrier</type>
4362
+ <name>carrier_name</name>
4363
+ </param>
4364
+ <param usedby="shipped">
4365
+ <type>carrier_code</type>
4366
+ <name>carrier_code</name>
4367
+ <accepted_values>
4368
+ <value label="Colissimo" default="true">colissimo</value>
4369
+ <value label="DHL">dhl</value>
4370
+ <value label="Chronopost">chronopost</value>
4371
+ <value label="B Post">bpost</value>
4372
+ <value label="Exapaq">exapaq</value>
4373
+ <value label="Lettre suivie">lettresuivie</value>
4374
+ <value label="Paquet prio">paquetprio</value>
4375
+ <value label="Colis privé">colisprive</value>
4376
+ <value label="GLS">GLS</value>
4377
+ <value label="Royal Mail">royalmail</value>
4378
+ <value label="UPS">UPS</value>
4379
+ <value label="Priority Mail">prioritymail</value>
4380
+ <value label="USPS">usps</value>
4381
+ <value label="Lettre Max">LETTREMAX</value>
4382
+ <value label="Hermes">HERMES</value>
4383
+ <value label="FEDEX">FEDEX</value>
4384
+ </accepted_values>
4385
+ </param>
4386
+ <param usedby="shipped">
4387
+ <type>tracking_url</type>
4388
+ <name>tracking_url</name>
4389
+ </param>
4390
+ </additional_params>
4391
+ </marketplace>
4392
+ <marketplace name="boulanger" realname="Boulanger" idshopbot="1791">
4393
+ <api>https://wsdl.lengow.com/wsdl/boulanger/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4394
+ <states>
4395
+ <state name="RECEIVED">
4396
+ <lengow>shipped</lengow>
4397
+ </state>
4398
+ <state name="STAGING">
4399
+ <lengow>new</lengow>
4400
+ </state>
4401
+ <state name="WAITING_ACCEPTANCE">
4402
+ <lengow>new</lengow>
4403
+ <actions>
4404
+ <action type="accept">accept</action>
4405
+ <action type="refuse">canceled</action>
4406
+ </actions>
4407
+ </state>
4408
+ <state name="WAITING_DEBIT">
4409
+ <lengow>new</lengow>
4410
+ </state>
4411
+ <state name="WAITING_DEBIT_PAYMENT">
4412
+ <lengow>new</lengow>
4413
+ </state>
4414
+ <state name="SHIPPING">
4415
+ <lengow>processing</lengow>
4416
+ <actions>
4417
+ <action type="shipped">shipped</action>
4418
+ </actions>
4419
+ </state>
4420
+ <state name="RECEIVED">
4421
+ <lengow>shipped</lengow>
4422
+ </state>
4423
+ <state name="SHIPPED">
4424
+ <lengow>shipped</lengow>
4425
+ </state>
4426
+ <state name="CANCELED">
4427
+ <lengow>canceled</lengow>
4428
+ </state>
4429
+ <state name="CLOSED">
4430
+ <lengow>shipped</lengow>
4431
+ </state>
4432
+ <state name="REFUSED">
4433
+ <lengow>canceled</lengow>
4434
+ </state>
4435
+ <state name="INCIDENT_OPEN">
4436
+ <lengow>processing</lengow>
4437
+ </state>
4438
+ <state name="INCIDENT_CLOSED">
4439
+ <lengow>processing</lengow>
4440
+ </state>
4441
+ <state name="WAITING_REFUND">
4442
+ <lengow>processing</lengow>
4443
+ </state>
4444
+ <state name="WAITING_REFUND_PAYMENT">
4445
+ <lengow>processing</lengow>
4446
+ </state>
4447
+ <state name="REFUNDED">
4448
+ <lengow>canceled</lengow>
4449
+ </state>
4450
+ </states>
4451
+ <additional_params>
4452
+ <param usedby="shipped">
4453
+ <type>tracking</type>
4454
+ <name>tracking_number</name>
4455
+ </param>
4456
+ <param usedby="shipped">
4457
+ <type>carrier</type>
4458
+ <name>carrier_name</name>
4459
+ </param>
4460
+ <param usedby="shipped">
4461
+ <type>tracking_url</type>
4462
+ <name>tracking_url</name>
4463
+ </param>
4464
+ </additional_params>
4465
+ </marketplace>
4466
+ <marketplace name="beslist" realname="Beslist" idshopbot="915">
4467
+ <api>https://wsdl.lengow.com/wsdl/beslist/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4468
+ <states name="shipped">
4469
+ <lengow>shipped</lengow>
4470
+ </states>
4471
+ <states name="new">
4472
+ <lengow>new</lengow>
4473
+ <actions>
4474
+ <action type="shipped">shipped</action>
4475
+ </actions>
4476
+ </states>
4477
+ <states name="processing">
4478
+ <lengow>processing</lengow>
4479
+ <actions>
4480
+ <action type="shipped">shipped</action>
4481
+ </actions>
4482
+ </states>
4483
+ <additional_params>
4484
+ <param usedby="shipped">
4485
+ <type>tracking</type>
4486
+ <name>tracking_number</name>
4487
+ </param>
4488
+ <param usedby="shipped">
4489
+ <type>carrier</type>
4490
+ <name>carrier_name</name>
4491
+ </param>
4492
+ <param usedby="shipped">
4493
+ <type>tracking_url</type>
4494
+ <name>tracking_url</name>
4495
+ </param>
4496
+ </additional_params>
4497
+ </marketplace>
4498
+ <marketplace name="macway" realname="MacWay" idshopbot="2107">
4499
+ <api>https://wsdl.lengow.com/wsdl/macway/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4500
+ <states>
4501
+ <state name="RECEIVED">
4502
+ <lengow>shipped</lengow>
4503
+ </state>
4504
+ <state name="STAGING">
4505
+ <lengow>new</lengow>
4506
+ </state>
4507
+ <state name="WAITING_ACCEPTANCE">
4508
+ <lengow>new</lengow>
4509
+ <actions>
4510
+ <action type="accept">accept</action>
4511
+ <action type="refuse">canceled</action>
4512
+ </actions>
4513
+ </state>
4514
+ <state name="WAITING_DEBIT">
4515
+ <lengow>new</lengow>
4516
+ </state>
4517
+ <state name="WAITING_DEBIT_PAYMENT">
4518
+ <lengow>new</lengow>
4519
+ </state>
4520
+ <state name="SHIPPING">
4521
+ <lengow>processing</lengow>
4522
+ <actions>
4523
+ <action type="shipped">shipped</action>
4524
+ </actions>
4525
+ </state>
4526
+ <state name="RECEIVED">
4527
+ <lengow>shipped</lengow>
4528
+ </state>
4529
+ <state name="SHIPPED">
4530
+ <lengow>shipped</lengow>
4531
+ </state>
4532
+ <state name="CANCELED">
4533
+ <lengow>canceled</lengow>
4534
+ </state>
4535
+ <state name="CLOSED">
4536
+ <lengow>shipped</lengow>
4537
+ </state>
4538
+ <state name="REFUSED">
4539
+ <lengow>canceled</lengow>
4540
+ </state>
4541
+ <state name="INCIDENT_OPEN">
4542
+ <lengow>processing</lengow>
4543
+ </state>
4544
+ <state name="INCIDENT_CLOSED">
4545
+ <lengow>processing</lengow>
4546
+ </state>
4547
+ <state name="WAITING_REFUND">
4548
+ <lengow>processing</lengow>
4549
+ </state>
4550
+ <state name="WAITING_REFUND_PAYMENT">
4551
+ <lengow>processing</lengow>
4552
+ </state>
4553
+ <state name="REFUNDED">
4554
+ <lengow>canceled</lengow>
4555
+ </state>
4556
+ </states>
4557
+ <additional_params>
4558
+ <param usedby="shipped">
4559
+ <type>tracking</type>
4560
+ <name>tracking_number</name>
4561
+ </param>
4562
+ <param usedby="shipped">
4563
+ <type>carrier</type>
4564
+ <name>carrier_name</name>
4565
+ </param>
4566
+ <param usedby="shipped">
4567
+ <type>tracking_url</type>
4568
+ <name>tracking_url</name>
4569
+ </param>
4570
+ </additional_params>
4571
+ </marketplace>
4572
+ <marketplace name="fyndiq" realname="Fyndiq" idshopbot="2087">
4573
+ <api>https://wsdl.lengow.com/wsdl/fyndiq/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4574
+ <states>
4575
+ <state name="new">
4576
+ <lengow>processing</lengow>
4577
+ <actions>
4578
+ <action type="shipped">ship</action>
4579
+ </actions>
4580
+ </state>
4581
+
4582
+ <state name="sent">
4583
+ <lengow>shipped</lengow>
4584
+ </state>
4585
+ </states>
4586
+ <additional_params>
4587
+ <param usedby="shipped">
4588
+ <type>tracking</type>
4589
+ <name>tracking_number</name>
4590
+ </param>
4591
+ <param usedby="shipped">
4592
+ <type>carrier_code</type>
4593
+ <name>carrier_code</name>
4594
+ <accepted_values>
4595
+ <value label="PostNord">PostNord</value>
4596
+ <value label="Schenker">Schenker</value>
4597
+ <value label="DHL">DHL</value>
4598
+ <value label="Bring">Bring</value>
4599
+ <value label="Deutsche Post">Deutsche Post</value>
4600
+ <value label="DPD">DPD</value>
4601
+ <value label="GLS">GLS</value>
4602
+ <value label="UPS">UPS</value>
4603
+ <value label="Hermes">Hermes</value>
4604
+
4605
+ </accepted_values>
4606
+ </param>
4607
+ </additional_params>
4608
+ </marketplace>
4609
+ <marketplace name="hitmeister" realname="Hitmeister" idshopbot="1051">
4610
+ <api>https://wsdl.lengow.com/wsdl/hitmeister/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4611
+ <states>
4612
+ <state name="received">
4613
+ <lengow>shipped</lengow>
4614
+ </state>
4615
+ <state name="sent">
4616
+ <lengow>shipped</lengow>
4617
+ </state>
4618
+ <state name="cancelled">
4619
+ <lengow>canceled</lengow>
4620
+ </state>
4621
+ <state name="sent_and_autopaid">
4622
+ <lengow>shipped</lengow>
4623
+ </state>
4624
+ <state name="returned">
4625
+ <lengow>canceled</lengow>
4626
+ </state>
4627
+ <state name="need_to_be_sent">
4628
+ <lengow>processing</lengow>
4629
+ <actions>
4630
+ <action type="shipped">ship</action>
4631
+ <action type="cancel">cancel</action>
4632
+ </actions>
4633
+ </state>
4634
+ </states>
4635
+ <additional_params>
4636
+ <param usedby="shipped">
4637
+ <type>tracking</type>
4638
+ <name>tracking_number</name>
4639
+ </param>
4640
+ <param usedby="shipped">
4641
+ <type>carrier</type>
4642
+ <name>carrier_code</name>
4643
+ <accepted_values>
4644
+ <value label="Computeruniverse">Computeruniverse</value>
4645
+ <value label="DHL">DHL</value>
4646
+ <value label="DHL 2 MH">DHL 2 MH</value>
4647
+ <value label="DHL Freight">DHL Freight</value>
4648
+ <value label="dtl">dtl</value>
4649
+ <value label="DPD">DPD</value>
4650
+ <value label="Deutsche Post">Deutsche Post</value>
4651
+ <value label="Dachser">Dachser</value>
4652
+ <value label="Emons">Emons</value>
4653
+ <value label="Fedex">Fedex</value>
4654
+ <value label="GLS">GLS</value>
4655
+ <value label="GEL">GEL</value>
4656
+ <value label="Hermes">Hermes</value>
4657
+ <value label="Hermes 2 MH">Hermes 2 MH</value>
4658
+ <value label="Hellmann">Hellmann</value>
4659
+ <value label="Iloxx">Iloxx</value>
4660
+ <value label="Kuehne &amp; Nagel">Kuehne &amp; Nagel</value>
4661
+ <value label="Rhenus">Rhenus</value>
4662
+ <value label="Other">Other</value>
4663
+ <value label="Schenker">Schenker</value>
4664
+ <value label="Spedition Guettler">Spedition Guettler</value>
4665
+ <value label="TNT">TNT</value>
4666
+ <value label="trans-o-flex">trans-o-flex</value>
4667
+ <value label="UPS">UPS</value>
4668
+ </accepted_values>
4669
+ </param>
4670
+ <param usedby="cancel">
4671
+ <type>reason</type>
4672
+ <name>reason</name>
4673
+ <accepted_values>
4674
+ <value label="GeneralAdjustment">GeneralAdjustment</value>
4675
+ <value label="BuyerCancelled">BuyerCancelled</value>
4676
+ <value label="CustomerExchange">CustomerExchange</value>
4677
+ <value label="CustomerReturn">CustomerReturn</value>
4678
+ <value label="ShippingAddressUndeliverable">ShippingAddressUndeliverable</value>
4679
+ <value label="WrongCatalogData">WrongCatalogData</value>
4680
+ <value label="MerchandiseNotReceived">MerchandiseNotReceived</value>
4681
+ <value label="NoInventory">NoInventory</value>
4682
+ <value label="WrongPrice">WrongPrice</value>
4683
+ <value label="UndeliverableRegion">UndeliverableRegion</value>
4684
+ </accepted_values>
4685
+ </param>
4686
+ </additional_params>
4687
+ </marketplace>
4688
+ <marketplace name="outiz">
4689
+ <api>https://wsdl.lengow.com/wsdl/outiz/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4690
+ <states>
4691
+ <state name="STAGING">
4692
+ <lengow>new</lengow>
4693
+ </state>
4694
+ <state name="WAITING_ACCEPTANCE">
4695
+ <lengow>new</lengow>
4696
+ <actions>
4697
+ <action type="accept">accept</action>
4698
+ <action type="refuse">canceled</action>
4699
+ </actions>
4700
+ </state>
4701
+ <state name="WAITING_DEBIT">
4702
+ <lengow>new</lengow>
4703
+ </state>
4704
+ <state name="WAITING_DEBIT_PAYMENT">
4705
+ <lengow>new</lengow>
4706
+ </state>
4707
+ <state name="SHIPPING">
4708
+ <lengow>processing</lengow>
4709
+ <actions>
4710
+ <action type="shipped">shipped</action>
4711
+ </actions>
4712
+ </state>
4713
+ <state name="RECEIVED">
4714
+ <lengow>shipped</lengow>
4715
+ </state>
4716
+ <state name="SHIPPED">
4717
+ <lengow>shipped</lengow>
4718
+ </state>
4719
+ <state name="CANCELED">
4720
+ <lengow>canceled</lengow>
4721
+ </state>
4722
+ <state name="CLOSED">
4723
+ <lengow>shipped</lengow>
4724
+ </state>
4725
+ <state name="REFUSED">
4726
+ <lengow>canceled</lengow>
4727
+ </state>
4728
+ <state name="INCIDENT_OPEN">
4729
+ <lengow>processing</lengow>
4730
+ </state>
4731
+ <state name="INCIDENT_CLOSED">
4732
+ <lengow>processing</lengow>
4733
+ </state>
4734
+ <state name="WAITING_REFUND">
4735
+ <lengow>processing</lengow>
4736
+ </state>
4737
+ <state name="WAITING_REFUND_PAYMENT">
4738
+ <lengow>processing</lengow>
4739
+ </state>
4740
+ <state name="REFUNDED">
4741
+ <lengow>canceled</lengow>
4742
+ </state>
4743
+ </states>
4744
+ <additional_params>
4745
+ <param usedby="shipped">
4746
+ <type>tracking</type>
4747
+ <name>tracking_number</name>
4748
+ </param>
4749
+ <param usedby="shipped">
4750
+ <type>carrier</type>
4751
+ <name>carrier_name</name>
4752
+ </param>
4753
+ <param usedby="shipped">
4754
+ <type>carrier_code</type>
4755
+ <name>carrier_code</name>
4756
+ <accepted_values>
4757
+ <value label="CHRONOPOST" default="true">chr</value>
4758
+ <value label="CIBLEX">cib</value>
4759
+ <value label="COLIPOSTE PARTICULIER (Colissimo, Colissimo International)">cpart</value>
4760
+ <value label="COLIPOSTE PRO">cpro</value>
4761
+ <value label="COURRIER SUIVI, LETTRE MAX, LETTRE SUIVIE, LETTRE RECOMMANDEE">cos</value>
4762
+ <value label="DHL">dhl</value>
4763
+ <value label="DPD">dpd</value>
4764
+ <value label="EXAPAQ">exa</value>
4765
+ <value label="FEDEX">fed</value>
4766
+ <value label="GEFCO">gef</value>
4767
+ <value label="GLS">gls</value>
4768
+ <value label="SCHENKER">sch</value>
4769
+ <value label="UPS">ups</value>
4770
+ </accepted_values>
4771
+ </param>
4772
+ <param usedby="shipped">
4773
+ <type>tracking_url</type>
4774
+ <name>tracking_url</name>
4775
+ </param>
4776
+ </additional_params>
4777
+ </marketplace>
4778
+ <marketplace name="atlasformen">
4779
+ <api>https://wsdl.lengow.com/wsdl/atlasformen/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4780
+ <states>
4781
+ <state name="STAGING">
4782
+ <lengow>new</lengow>
4783
+ </state>
4784
+ <state name="WAITING_ACCEPTANCE">
4785
+ <lengow>new</lengow>
4786
+ <actions>
4787
+ <action type="accept">accept</action>
4788
+ <action type="refuse">canceled</action>
4789
+ </actions>
4790
+ </state>
4791
+ <state name="WAITING_DEBIT">
4792
+ <lengow>new</lengow>
4793
+ </state>
4794
+ <state name="WAITING_DEBIT_PAYMENT">
4795
+ <lengow>new</lengow>
4796
+ </state>
4797
+ <state name="SHIPPING">
4798
+ <lengow>processing</lengow>
4799
+ <actions>
4800
+ <action type="shipped">shipped</action>
4801
+ </actions>
4802
+ </state>
4803
+ <state name="RECEIVED">
4804
+ <lengow>shipped</lengow>
4805
+ </state>
4806
+ <state name="SHIPPED">
4807
+ <lengow>shipped</lengow>
4808
+ </state>
4809
+ <state name="CANCELED">
4810
+ <lengow>canceled</lengow>
4811
+ </state>
4812
+ <state name="CLOSED">
4813
+ <lengow>shipped</lengow>
4814
+ </state>
4815
+ <state name="REFUSED">
4816
+ <lengow>canceled</lengow>
4817
+ </state>
4818
+ <state name="INCIDENT_OPEN">
4819
+ <lengow>processing</lengow>
4820
+ </state>
4821
+ <state name="INCIDENT_CLOSED">
4822
+ <lengow>processing</lengow>
4823
+ </state>
4824
+ <state name="WAITING_REFUND">
4825
+ <lengow>processing</lengow>
4826
+ </state>
4827
+ <state name="WAITING_REFUND_PAYMENT">
4828
+ <lengow>processing</lengow>
4829
+ </state>
4830
+ <state name="REFUNDED">
4831
+ <lengow>canceled</lengow>
4832
+ </state>
4833
+ </states>
4834
+ <additional_params>
4835
+ <param usedby="shipped">
4836
+ <type>tracking</type>
4837
+ <name>tracking_number</name>
4838
+ </param>
4839
+ <param usedby="shipped">
4840
+ <type>carrier</type>
4841
+ <name>carrier_name</name>
4842
+ </param>
4843
+ <param usedby="shipped">
4844
+ <type>carrier_code</type>
4845
+ <name>carrier_code</name>
4846
+ <accepted_values>
4847
+ <value label="Colissimo" default="true">colissimo</value>
4848
+ </accepted_values>
4849
+ </param>
4850
+ <param usedby="shipped">
4851
+ <type>tracking_url</type>
4852
+ <name>tracking_url</name>
4853
+ </param>
4854
+ </additional_params>
4855
+ </marketplace>
4856
+ <marketplace name="carrefour_es">
4857
+ <api>https://wsdl.lengow.com/wsdl/carrefour_es/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4858
+ <states>
4859
+ <state name="STAGING">
4860
+ <lengow>new</lengow>
4861
+ </state>
4862
+ <state name="WAITING_ACCEPTANCE">
4863
+ <lengow>new</lengow>
4864
+ <actions>
4865
+ <action type="accept">accept</action>
4866
+ <action type="refuse">canceled</action>
4867
+ </actions>
4868
+ </state>
4869
+ <state name="WAITING_DEBIT">
4870
+ <lengow>new</lengow>
4871
+ </state>
4872
+ <state name="WAITING_DEBIT_PAYMENT">
4873
+ <lengow>new</lengow>
4874
+ </state>
4875
+ <state name="SHIPPING">
4876
+ <lengow>processing</lengow>
4877
+ <actions>
4878
+ <action type="shipped">shipped</action>
4879
+ </actions>
4880
+ </state>
4881
+ <state name="RECEIVED">
4882
+ <lengow>shipped</lengow>
4883
+ </state>
4884
+ <state name="SHIPPED">
4885
+ <lengow>shipped</lengow>
4886
+ </state>
4887
+ <state name="CANCELED">
4888
+ <lengow>canceled</lengow>
4889
+ </state>
4890
+ <state name="CLOSED">
4891
+ <lengow>shipped</lengow>
4892
+ </state>
4893
+ <state name="REFUSED">
4894
+ <lengow>canceled</lengow>
4895
+ </state>
4896
+ <state name="INCIDENT_OPEN">
4897
+ <lengow>processing</lengow>
4898
+ </state>
4899
+ <state name="INCIDENT_CLOSED">
4900
+ <lengow>processing</lengow>
4901
+ </state>
4902
+ <state name="WAITING_REFUND">
4903
+ <lengow>processing</lengow>
4904
+ </state>
4905
+ <state name="WAITING_REFUND_PAYMENT">
4906
+ <lengow>processing</lengow>
4907
+ </state>
4908
+ <state name="REFUNDED">
4909
+ <lengow>canceled</lengow>
4910
+ </state>
4911
+ </states>
4912
+ <additional_params>
4913
+ <param usedby="shipped">
4914
+ <type>tracking</type>
4915
+ <name>tracking_number</name>
4916
+ </param>
4917
+ <param usedby="shipped">
4918
+ <type>carrier</type>
4919
+ <name>carrier_name</name>
4920
+ </param>
4921
+ <param usedby="shipped">
4922
+ <type>carrier_code</type>
4923
+ <name>carrier_code</name>
4924
+ <accepted_values>
4925
+ <value label="Seur" default="true">seur</value>
4926
+ <value label="Nacex">nacex</value>
4927
+ <value label="MRW">mrw</value>
4928
+ <value label="Correos">correos</value>
4929
+ <value label="DHL">dhl</value>
4930
+ <value label="UPS">ups</value>
4931
+ <value label="Envilia">envilia</value>
4932
+ <value label="ASM">asm</value>
4933
+ </accepted_values>
4934
+ </param>
4935
+ <param usedby="shipped">
4936
+ <type>tracking_url</type>
4937
+ <name>tracking_url</name>
4938
+ </param>
4939
+ </additional_params>
4940
+ </marketplace>
4941
+ <marketplace name="wish" idshopbot="2103" realname="Wish.com">
4942
+ <api>https://wsdl.lengow.com/wsdl/wish/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
4943
+ <states>
4944
+ <state name="APPROVED">
4945
+ <lengow>processing</lengow>
4946
+ <actions>
4947
+ <action type="shipped">ship</action>
4948
+ <action type="refuse">refuse</action>
4949
+ </actions>
4950
+ </state>
4951
+ <state name="SHIPPED">
4952
+ <lengow>shipped</lengow>
4953
+ </state>
4954
+ <state name="REFUNDED">
4955
+ <lengow>canceled</lengow>
4956
+ </state>
4957
+ <state name="REQUIRE_REVIEW">
4958
+ <lengow>processing</lengow>
4959
+ </state>
4960
+ </states>
4961
+ <additional_params>
4962
+ <param usedby="shipped">
4963
+ <type>tracking</type>
4964
+ <name>tracking_number</name>
4965
+ </param>
4966
+ <param usedby="shipped">
4967
+ <type>carrier_code</type>
4968
+ <name>carrier_code</name>
4969
+ <accepted_values>
4970
+ <value label="Colissimo" default="True">Colissimo</value>
4971
+ <value label="USPS">USPS</value>
4972
+ <value label="FedEx">FedEx</value>
4973
+ <value label="DHL">DHL</value>
4974
+ <value label="UPS">UPS</value>
4975
+ <value label="OnTrac">OnTrac</value>
4976
+ <value label="FlytExpress">FlytExpress</value>
4977
+ <value label="CanadaPost">CanadaPost</value>
4978
+ <value label="HongKongPost">HongKongPost</value>
4979
+ <value label="ChinaAirPost">ChinaAirPost</value>
4980
+ <value label="SingaporePost">SingaporePost</value>
4981
+ <value label="IsraelPost">IsraelPost</value>
4982
+ <value label="TurkishPost">TurkishPost</value>
4983
+ <value label="EMS (China)">EMS (China)</value>
4984
+ <value label="SwissPost">SwissPost</value>
4985
+ <value label="IndiaPost">IndiaPost</value>
4986
+ <value label="BPost">BPost</value>
4987
+ <value label="IndonesiaPost">IndonesiaPost</value>
4988
+ <value label="ThailandThaiPost">ThailandThaiPost</value>
4989
+ <value label="UPSMailInnovations">UPSMailInnovations</value>
4990
+ <value label="TNT">TNT</value>
4991
+ <value label="DPD">DPD</value>
4992
+ <value label="Aramex">Aramex</value>
4993
+ <value label="DHLGlobalMail">DHLGlobalMail</value>
4994
+ <value label="Purolator">Purolator</value>
4995
+ <value label="DirectLink">DirectLink</value>
4996
+ <value label="YRC">YRC</value>
4997
+ <value label="UPSFreight">UPSFreight</value>
4998
+ <value label="AsendiaUSA">AsendiaUSA</value>
4999
+ <value label="Evergreen">Evergreen</value>
5000
+ <value label="LaserShip">LaserShip</value>
5001
+ <value label="Estes">Estes</value>
5002
+ <value label="ABF">ABF</value>
5003
+ <value label="RLCarriers">RLCarriers</value>
5004
+ <value label="RoyalMail">RoyalMail</value>
5005
+ <value label="ParcelForce">ParcelForce</value>
5006
+ <value label="FedExUK">FedExUK</value>
5007
+ <value label="DPDUK">DPDUK</value>
5008
+ <value label="TNTUK">TNTUK</value>
5009
+ <value label="UKMail">UKMail</value>
5010
+ <value label="InterlinkExpress">InterlinkExpress</value>
5011
+ <value label="YODEL">YODEL</value>
5012
+ <value label="Hermes">Hermes</value>
5013
+ <value label="CityLink">CityLink</value>
5014
+ <value label="FastwayIreland">FastwayIreland</value>
5015
+ <value label="DeutschePost">DeutschePost</value>
5016
+ <value label="DHLGermany">DHLGermany</value>
5017
+ <value label="HermesGermany">HermesGermany</value>
5018
+ <value label="DPDGermany">DPDGermany</value>
5019
+ <value label="AustrianPost">AustrianPost</value>
5020
+ <value label="CorreosDeEspana">CorreosDeEspana</value>
5021
+ <value label="NACEXSpain">NACEXSpain</value>
5022
+ <value label="MRW">MRW</value>
5023
+ <value label="SpanishSeur">SpanishSeur</value>
5024
+ <value label="InternationalSeur">InternationalSeur</value>
5025
+ <value label="PortugalCTT">PortugalCTT</value>
5026
+ <value label="ChronopostPortugal">ChronopostPortugal</value>
5027
+ <value label="PortugalSeur">PortugalSeur</value>
5028
+ <value label="LaPosteColissimo">LaPosteColissimo</value>
5029
+ <value label="ChronopostFrance">ChronopostFrance</value>
5030
+ <value label="PostNL">PostNL</value>
5031
+ <value label="DHLNetherlands">DHLNetherlands</value>
5032
+ <value label="Selektvracht">Selektvracht</value>
5033
+ <value label="GLS">GLS</value>
5034
+ <value label="DeltecCourier">DeltecCourier</value>
5035
+ <value label="DHLBenelux">DHLBenelux</value>
5036
+ <value label="AnPost">AnPost</value>
5037
+ <value label="ItellaPosti">ItellaPosti</value>
5038
+ <value label="PostenNorge">PostenNorge</value>
5039
+ <value label="SwedenPosten">SwedenPosten</value>
5040
+ <value label="ItalySDA">ItalySDA</value>
5041
+ <value label="PosteItalianePaccocelere">PosteItalianePaccocelere</value>
5042
+ <value label="PosteItaliane">PosteItaliane</value>
5043
+ <value label="DanmarkPost">DanmarkPost</value>
5044
+ <value label="TNTItaly">TNTItaly</value>
5045
+ <value label="RussianPost">RussianPost</value>
5046
+ <value label="NovaPoshta">NovaPoshta</value>
5047
+ <value label="DHLPoland">DHLPoland</value>
5048
+ <value label="PocztaPolska">PocztaPolska</value>
5049
+ <value label="DPDPoland">DPDPoland</value>
5050
+ <value label="Siodemka">Siodemka</value>
5051
+ <value label="OPEK">OPEK</value>
5052
+ <value label="UkrPoshta">UkrPoshta</value>
5053
+ <value label="CeskaPosta">CeskaPosta</value>
5054
+ <value label="EltaCourier">EltaCourier</value>
5055
+ <value label="PTTPosta">PTTPosta</value>
5056
+ <value label="KuehneNagel">KuehneNagel</value>
5057
+ <value label="4PX">4PX</value>
5058
+ <value label="SFExpress">SFExpress</value>
5059
+ <value label="DHLGlobalMailAsia">DHLGlobalMailAsia</value>
5060
+ <value label="TAQBINHongKong">TAQBINHongKong</value>
5061
+ <value label="TGX">TGX</value>
5062
+ <value label="SingaporeSpeedpost">SingaporeSpeedpost</value>
5063
+ <value label="TAQBINSingapore">TAQBINSingapore</value>
5064
+ <value label="Bluedart">Bluedart</value>
5065
+ <value label="Safexpress">Safexpress</value>
5066
+ <value label="RedExpress">RedExpress</value>
5067
+ <value label="FirstFlightCouriers">FirstFlightCouriers</value>
5068
+ <value label="GatiKWE">GatiKWE</value>
5069
+ <value label="JapanPost">JapanPost</value>
5070
+ <value label="Sagawa">Sagawa</value>
5071
+ <value label="TaiwanPost">TaiwanPost</value>
5072
+ <value label="MalaysiaPost">MalaysiaPost</value>
5073
+ <value label="MalaysiaPostPosDaftar">MalaysiaPostPosDaftar</value>
5074
+ <value label="SkynetMalaysia">SkynetMalaysia</value>
5075
+ <value label="CambodiaPost">CambodiaPost</value>
5076
+ <value label="KoreaPost">KoreaPost</value>
5077
+ <value label="AustraliaPost">AustraliaPost</value>
5078
+ <value label="TollPriority">TollPriority</value>
5079
+ <value label="TollGlobalExpress">TollGlobalExpress</value>
5080
+ <value label="TNTAustralia">TNTAustralia</value>
5081
+ <value label="StarTrackAustralia">StarTrackAustralia</value>
5082
+ <value label="NewZealandPost">NewZealandPost</value>
5083
+ <value label="BrazilCorreios">BrazilCorreios</value>
5084
+ <value label="FlashCourier">FlashCourier</value>
5085
+ <value label="SouthAfricanPostOffice">SouthAfricanPostOffice</value>
5086
+ <value label="FastwaySouthAfrica">FastwaySouthAfrica</value>
5087
+ <value label="CorreosChile">CorreosChile</value>
5088
+ <value label="SaudiPost">SaudiPost</value>
5089
+ <value label="NiPost">NiPost</value>
5090
+ <value label="CorreoArgentino">CorreoArgentino</value>
5091
+ <value label="OCAArgentina">OCAArgentina</value>
5092
+ <value label="CorreosDeMexico">CorreosDeMexico</value>
5093
+ <value label="Estafeta">Estafeta</value>
5094
+ <value label="MexicoSendaExpress">MexicoSendaExpress</value>
5095
+ <value label="MexicoRedpack">MexicoRedpack</value>
5096
+ <value label="MexicoMultipack">MexicoMultipack</value>
5097
+ <value label="MexicoAeroFlash">MexicoAeroFlash</value>
5098
+ <value label="CyprusPost">CyprusPost</value>
5099
+ <value label="SkynetWorldwideExpress">SkynetWorldwideExpress</value>
5100
+ <value label="APCLogistics">APCLogistics</value>
5101
+ <value label="IParcel">IParcel</value>
5102
+ <value label="TAQBINMalaysia">TAQBINMalaysia</value>
5103
+ <value label="HrvatskaPosta">HrvatskaPosta</value>
5104
+ <value label="RomaniaPost">RomaniaPost</value>
5105
+ <value label="TAQBINJapan">TAQBINJapan</value>
5106
+ <value label="RedExpressWaybill">RedExpressWaybill</value>
5107
+ <value label="CourierPost">CourierPost</value>
5108
+ <value label="ProfessionalCouriers">ProfessionalCouriers</value>
5109
+ <value label="GoJaVAS">GoJaVAS</value>
5110
+ <value label="CJGLS">CJGLS</value>
5111
+ <value label="ECFirstClass">ECFirstClass</value>
5112
+ <value label="BulgarianPosts">BulgarianPosts</value>
5113
+ <value label="PostNLInternational">PostNLInternational</value>
5114
+ <value label="FastwayAustralia">FastwayAustralia</value>
5115
+ <value label="KerryLogistics">KerryLogistics</value>
5116
+ <value label="DTDCIndia">DTDCIndia</value>
5117
+ <value label="StarTrackExpress">StarTrackExpress</value>
5118
+ <value label="GDEX">GDEX</value>
5119
+ <value label="JNE">JNE</value>
5120
+ <value label="RPXIndonesia">RPXIndonesia</value>
5121
+ <value label="GLSItaly">GLSItaly</value>
5122
+ <value label="DPDIreland">DPDIreland</value>
5123
+ <value label="FirstLogistics">FirstLogistics</value>
5124
+ <value label="BRTBartolini">BRTBartolini</value>
5125
+ <value label="Belpost">Belpost</value>
5126
+ <value label="Xend">Xend</value>
5127
+ <value label="_2GO">_2GO</value>
5128
+ <value label="PostNordLogistics">PostNordLogistics</value>
5129
+ <value label="ACSCourier">ACSCourier</value>
5130
+ <value label="AIR21">AIR21</value>
5131
+ <value label="LBCExpress">LBCExpress</value>
5132
+ <value label="ArrowXL">ArrowXL</value>
5133
+ <value label="VietnamPostEMS">VietnamPostEMS</value>
5134
+ <value label="ViettelPost">ViettelPost</value>
5135
+ <value label="VietnamPost">VietnamPost</value>
5136
+ <value label="PayPalPackage">PayPalPackage</value>
5137
+ <value label="LithuaniaPost">LithuaniaPost</value>
5138
+ <value label="CouriersPlease">CouriersPlease</value>
5139
+ <value label="PostNLInternational3S">PostNLInternational3S</value>
5140
+ <value label="ColisPrive">ColisPrive</value>
5141
+ <value label="ASM">ASM</value>
5142
+ <value label="AustrianPostRegistered">AustrianPostRegistered</value>
5143
+ <value label="AuPostChina">AuPostChina</value>
5144
+ <value label="TNTPostItaly">TNTPostItaly</value>
5145
+ <value label="Tiki">Tiki</value>
5146
+ <value label="XDPExpress">XDPExpress</value>
5147
+ <value label="GLSNetherlands">GLSNetherlands</value>
5148
+ <value label="RedurSpain">RedurSpain</value>
5149
+ <value label="TNTFrance">TNTFrance</value>
5150
+ <value label="JamExpress">JamExpress</value>
5151
+ <value label="Wahana">Wahana</value>
5152
+ <value label="CollectPlus">CollectPlus</value>
5153
+ <value label="DynamicLogistics">DynamicLogistics</value>
5154
+ <value label="IndiaPostInternational">IndiaPostInternational</value>
5155
+ <value label="IsraelPostDomestic">IsraelPostDomestic</value>
5156
+ <value label="BPostInternational">BPostInternational</value>
5157
+ <value label="DX">DX</value>
5158
+ <value label="CityLinkExpress">CityLinkExpress</value>
5159
+ <value label="WeDoLogisitics">WeDoLogisitics</value>
5160
+ <value label="GeodisCalbersonFrance">GeodisCalbersonFrance</value>
5161
+ <value label="PosIndonesiaDomestic">PosIndonesiaDomestic</value>
5162
+ <value label="STOExpress">STOExpress</value>
5163
+ <value label="TollIPEC">TollIPEC</value>
5164
+ <value label="JCEX">JCEX</value>
5165
+ <value label="Delhivery">Delhivery</value>
5166
+ <value label="DHLParcelNL">DHLParcelNL</value>
5167
+ <value label="Greyhound">Greyhound</value>
5168
+ <value label="Yanwen">Yanwen</value>
5169
+ <value label="RPXOnline">RPXOnline</value>
5170
+ <value label="PostService">PostService</value>
5171
+ <value label="GenikiTaxydromiki">GenikiTaxydromiki</value>
5172
+ <value label="SkynetWorldwideExpressUK">SkynetWorldwideExpressUK</value>
5173
+ <value label="GHN">GHN</value>
5174
+ <value label="Envialia">Envialia</value>
5175
+ <value label="Chukou1">Chukou1</value>
5176
+ <value label="EPacket">EPacket</value>
5177
+ <value label="RAF">RAF</value>
5178
+ <value label="YundaExpress">YundaExpress</value>
5179
+ <value label="SpecialisedFreight">SpecialisedFreight</value>
5180
+ <value label="TrakPak">TrakPak</value>
5181
+ <value label="EquickChina">EquickChina</value>
5182
+ <value label="DPESouthAfrica">DPESouthAfrica</value>
5183
+ <value label="EmiratesPost">EmiratesPost</value>
5184
+ <value label="DPEXChina">DPEXChina</value>
5185
+ <value label="Qxpress">Qxpress</value>
5186
+ <value label="CourierPlus">CourierPlus</value>
5187
+ <value label="CourierIT">CourierIT</value>
5188
+ <value label="BestExpress">BestExpress</value>
5189
+ <value label="CityLinkInternational">CityLinkInternational</value>
5190
+ <value label="DHL2MannHandling">DHL2MannHandling</value>
5191
+ <value label="DBSchenkerSweden">DBSchenkerSweden</value>
5192
+ <value label="_4SquareGroup">_4SquareGroup</value>
5193
+ <value label="XpressBees">XpressBees</value>
5194
+ <value label="Dotzot">Dotzot</value>
5195
+ <value label="EcomExpress">EcomExpress</value>
5196
+ <value label="Mypostonline">Mypostonline</value>
5197
+ <value label="Panther">Panther</value>
5198
+ <value label="TNTClickItaly">TNTClickItaly</value>
5199
+ <value label="YodelInternational">YodelInternational</value>
5200
+ <value label="BOXC">BOXC</value>
5201
+ <value label="EMPSExpress">EMPSExpress</value>
5202
+ <value label="Post56">Post56</value>
5203
+ <value label="SREKorea">SREKorea</value>
5204
+ <value label="ChinaPost-WishPost">ChinaPost-WishPost</value>
5205
+ <value label="DHLSpainDomestic">DHLSpainDomestic</value>
5206
+ <value label="TransMission">TransMission</value>
5207
+ <value label="MagyarPosta">MagyarPosta</value>
5208
+ <value label="Exapaq">Exapaq</value>
5209
+ <value label="PostaPlus">PostaPlus</value>
5210
+ <value label="TeliwaySICExpress">TeliwaySICExpress</value>
5211
+ <value label="Packlink">Packlink</value>
5212
+ <value label="CNEExpress">CNEExpress</value>
5213
+ <value label="MyHermesUK">MyHermesUK</value>
5214
+ <value label="CanparCourier">CanparCourier</value>
5215
+ <value label="RAM">RAM</value>
5216
+ <value label="DHLExpress">DHLExpress</value>
5217
+ <value label="PanduLogistics">PanduLogistics</value>
5218
+ <value label="SpeedexCourier">SpeedexCourier</value>
5219
+ <value label="SpeedCourier">SpeedCourier</value>
5220
+ <value label="AsendiaGermany">AsendiaGermany</value>
5221
+ <value label="DMMNetwork">DMMNetwork</value>
5222
+ <value label="SGTCorriereEspresso">SGTCorriereEspresso</value>
5223
+ <value label="NationwideExpress">NationwideExpress</value>
5224
+ <value label="GlobegisticsInc">GlobegisticsInc</value>
5225
+ <value label="DACHSER">DACHSER</value>
5226
+ <value label="Ecargo">Ecargo</value>
5227
+ <value label="DawnWing">DawnWing</value>
5228
+ <value label="CorreosExpress">CorreosExpress</value>
5229
+ <value label="FERCAM">FERCAM</value>
5230
+ <value label="JayonExpress">JayonExpress</value>
5231
+ <value label="DSV">DSV</value>
5232
+ <value label="SFInternational">SFInternational</value>
5233
+ <value label="ABXExpress">ABXExpress</value>
5234
+ <value label="KangarooWorldwideExpress">KangarooWorldwideExpress</value>
5235
+ <value label="ZJSExpress">ZJSExpress</value>
5236
+ <value label="Spreadel">Spreadel</value>
5237
+ <value label="AsendiaUK">AsendiaUK</value>
5238
+ <value label="APCOvernight">APCOvernight</value>
5239
+ <value label="BertTransport">BertTransport</value>
5240
+ <value label="DelivreeKing">DelivreeKing</value>
5241
+ <value label="CBLLogistics">CBLLogistics</value>
5242
+ <value label="Newgistics">Newgistics</value>
5243
+ <value label="EasyMail">EasyMail</value>
5244
+ <value label="LogisticWorldwideExpress">LogisticWorldwideExpress</value>
5245
+ <value label="FastrakServices">FastrakServices</value>
5246
+ <value label="Delcart">Delcart</value>
5247
+ <value label="FastwayNewZealand">FastwayNewZealand</value>
5248
+ <value label="NanjingWoyuan">NanjingWoyuan</value>
5249
+ <value label="UBILogisticsAustralia">UBILogisticsAustralia</value>
5250
+ <value label="YunExpress">YunExpress</value>
5251
+ <value label="HomedirectLogistics">HomedirectLogistics</value>
5252
+ <value label="TuffnellsParcelsExpress">TuffnellsParcelsExpress</value>
5253
+ <value label="NinjaVan">NinjaVan</value>
5254
+ <value label="AirpakExpress">AirpakExpress</value>
5255
+ <value label="BondsCouriers">BondsCouriers</value>
5256
+ <value label="Nightline">Nightline</value>
5257
+ <value label="JetShipWorldwide">JetShipWorldwide</value>
5258
+ <value label="IMXMail">IMXMail</value>
5259
+ <value label="NorskGlobal">NorskGlobal</value>
5260
+ <value label="NhansSolutions">NhansSolutions</value>
5261
+ <value label="CuckooExpress">CuckooExpress</value>
5262
+ <value label="BosniaandHerzegovinaPost">BosniaandHerzegovinaPost</value>
5263
+ <value label="ColombiaPostalService">ColombiaPostalService</value>
5264
+ <value label="Maxcellent">Maxcellent</value>
5265
+ <value label="ParcelPost">ParcelPost</value>
5266
+ <value label="GoFly">GoFly</value>
5267
+ <value label="PostSerbia">PostSerbia</value>
5268
+ <value label="RZYExpress">RZYExpress</value>
5269
+ <value label="RRDonnelley">RRDonnelley</value>
5270
+ <value label="SingParcelService">SingParcelService</value>
5271
+ <value label="CosmeticsNow">CosmeticsNow</value>
5272
+ <value label="OneWorldExpress">OneWorldExpress</value>
5273
+ <value label="Cainiao">Cainiao</value>
5274
+ <value label="SloveniaPost">SloveniaPost</value>
5275
+ <value label="EasternExpress">EasternExpress</value>
5276
+ <value label="CPacket">CPacket</value>
5277
+ <value label="SFCService">SFCService</value>
5278
+ </accepted_values>
5279
+ </param>
5280
+ </additional_params>
5281
+ </marketplace>
5282
+ <marketplace name="allyouneed">
5283
+ <api>https://wsdl.lengow.com/wsdl/allyouneed/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5284
+ <states>
5285
+ <state name="new">
5286
+ <actions>
5287
+ <action type="shipped">acceptOrder</action>
5288
+ <action type="refund">refundOrder</action>
5289
+ <action type="cancel">cancel</action>
5290
+ </actions>
5291
+ <lengow>new</lengow>
5292
+ </state>
5293
+ <state name="OPEN">
5294
+ <actions>
5295
+ <action type="shipped">acceptOrder</action>
5296
+ <action type="refund">refundOrder</action>
5297
+ <action type="cancel">cancel</action>
5298
+ </actions>
5299
+ <lengow>new</lengow>
5300
+ </state>
5301
+ <state name="SHIPPED">
5302
+ <lengow>shipped</lengow>
5303
+ </state>
5304
+ <state name="CANCELED">
5305
+ <lengow>canceled</lengow>
5306
+ </state>
5307
+ </states>
5308
+ <additional_params>
5309
+ <param usedby="shipped">
5310
+ <type>tracking</type>
5311
+ <name>tracking_number</name>
5312
+ </param>
5313
+ <param usedby="shipped">
5314
+ <type>carrier</type>
5315
+ <name>carrier_code</name>
5316
+ </param>
5317
+ <param usedby="cancel">
5318
+ <type>reason</type>
5319
+ <name>reason</name>
5320
+ </param>
5321
+ <param usedby="refund">
5322
+ <type>refund_reason</type>
5323
+ <name>refund_reason</name>
5324
+ <accepted_values>
5325
+ <value label="Look_in_comment" default="True">LOOK_IN_COMMENT</value>
5326
+ <value label="Used">USED</value>
5327
+ <value label="Damaged">DAMAGED</value>
5328
+ </accepted_values>
5329
+ </param>
5330
+ <param usedby="refund">
5331
+ <type>reduction_amount</type>
5332
+ <name>reduction_amount</name>
5333
+ </param>
5334
+ <param usedby="refund">
5335
+ <type>delivery_amount</type>
5336
+ <name>delivery_amount</name>
5337
+ </param>
5338
+ <param usedby="refund">
5339
+ <type>comment</type>
5340
+ <name>comment</name>
5341
+ </param>
5342
+ </additional_params>
5343
+ </marketplace>
5344
+ <marketplace name="cdon_se">
5345
+ <api>https://wsdl.lengow.com/wsdl/cdon_se/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5346
+ <states>
5347
+ <state name="Pending">
5348
+ <lengow>new</lengow>
5349
+ <actions>
5350
+ <action type="shipped">ship</action>
5351
+ <action type="refund">refuse</action>
5352
+ <action type="cancel">cancel</action>
5353
+ </actions>
5354
+ </state>
5355
+ <state name="Delivered">
5356
+ <lengow>shipped</lengow>
5357
+ </state>
5358
+ <state name="Returned">
5359
+ <lengow>canceled</lengow>
5360
+ </state>
5361
+ <state name="Cancelled">
5362
+ <lengow>canceled</lengow>
5363
+ </state>
5364
+ <state name="Invoiced">
5365
+ <lengow>processing</lengow>
5366
+ </state>
5367
+ </states>
5368
+ <additional_params>
5369
+ <param usedby="shipped">
5370
+ <type>tracking</type>
5371
+ <name>tracking_number</name>
5372
+ </param>
5373
+ <param usedby="shipped">
5374
+ <type>carrier</type>
5375
+ <name>carrier_code</name>
5376
+ </param>
5377
+ </additional_params>
5378
+ </marketplace>
5379
+ <marketplace name="cdon_dk">
5380
+ <api>https://wsdl.lengow.com/wsdl/cdon_dk/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5381
+ <states>
5382
+ <state name="Pending">
5383
+ <lengow>new</lengow>
5384
+ <actions>
5385
+ <action type="shipped">ship</action>
5386
+ <action type="refund">refuse</action>
5387
+ <action type="cancel">cancel</action>
5388
+ </actions>
5389
+ </state>
5390
+ <state name="Delivered">
5391
+ <lengow>shipped</lengow>
5392
+ </state>
5393
+ <state name="Returned">
5394
+ <lengow>canceled</lengow>
5395
+ </state>
5396
+ <state name="Cancelled">
5397
+ <lengow>canceled</lengow>
5398
+ </state>
5399
+ <state name="Invoiced">
5400
+ <lengow>processing</lengow>
5401
+ </state>
5402
+ </states>
5403
+ <additional_params>
5404
+ <param usedby="shipped">
5405
+ <type>tracking</type>
5406
+ <name>tracking_number</name>
5407
+ </param>
5408
+ <param usedby="shipped">
5409
+ <type>carrier</type>
5410
+ <name>carrier_code</name>
5411
+ </param>
5412
+ </additional_params>
5413
+ </marketplace>
5414
+ <marketplace name="cdon_no">
5415
+ <api>https://wsdl.lengow.com/wsdl/cdon_no/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5416
+ <states>
5417
+ <state name="Pending">
5418
+ <lengow>new</lengow>
5419
+ <actions>
5420
+ <action type="shipped">ship</action>
5421
+ <action type="refund">refuse</action>
5422
+ <action type="cancel">cancel</action>
5423
+ </actions>
5424
+ </state>
5425
+ <state name="Delivered">
5426
+ <lengow>shipped</lengow>
5427
+ </state>
5428
+ <state name="Returned">
5429
+ <lengow>canceled</lengow>
5430
+ </state>
5431
+ <state name="Cancelled">
5432
+ <lengow>canceled</lengow>
5433
+ </state>
5434
+ <state name="Invoiced">
5435
+ <lengow>processing</lengow>
5436
+ </state>
5437
+ </states>
5438
+ <additional_params>
5439
+ <param usedby="shipped">
5440
+ <type>tracking</type>
5441
+ <name>tracking_number</name>
5442
+ </param>
5443
+ <param usedby="shipped">
5444
+ <type>carrier</type>
5445
+ <name>carrier_code</name>
5446
+ </param>
5447
+ </additional_params>
5448
+ </marketplace>
5449
+ <marketplace name="cdon_fi">
5450
+ <api>https://wsdl.lengow.com/wsdl/cdon_fi/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5451
+ <states>
5452
+ <state name="Pending">
5453
+ <lengow>new</lengow>
5454
+ <actions>
5455
+ <action type="shipped">ship</action>
5456
+ <action type="refund">refuse</action>
5457
+ <action type="cancel">cancel</action>
5458
+ </actions>
5459
+ </state>
5460
+ <state name="Delivered">
5461
+ <lengow>shipped</lengow>
5462
+ </state>
5463
+ <state name="Returned">
5464
+ <lengow>canceled</lengow>
5465
+ </state>
5466
+ <state name="Cancelled">
5467
+ <lengow>canceled</lengow>
5468
+ </state>
5469
+ <state name="Invoiced">
5470
+ <lengow>processing</lengow>
5471
+ </state>
5472
+ </states>
5473
+ <additional_params>
5474
+ <param usedby="shipped">
5475
+ <type>tracking</type>
5476
+ <name>tracking_number</name>
5477
+ </param>
5478
+ <param usedby="shipped">
5479
+ <type>carrier</type>
5480
+ <name>carrier_code</name>
5481
+ </param>
5482
+ </additional_params>
5483
+ </marketplace>
5484
+ <marketplace name="bol">
5485
+ <api>https://wsdl.lengow.com/wsdl/bol/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5486
+ <states>
5487
+ <state name="new">
5488
+ <actions>
5489
+ <action type="shipped">acceptOrder</action>
5490
+ <action type="refund">refundOrder</action>
5491
+ <action type="cancel">cancel</action>
5492
+ </actions>
5493
+ <lengow>new</lengow>
5494
+ </state>
5495
+ <state name="processing">
5496
+ <actions>
5497
+ <action type="shipped">acceptOrder</action>
5498
+ <action type="refund">refundOrder</action>
5499
+ <action type="cancel">cancel</action>
5500
+ </actions>
5501
+ <lengow>processing</lengow>
5502
+ </state>
5503
+ <state name="shipped">
5504
+ <actions>
5505
+ <action type="refund">refundOrder</action>
5506
+ </actions>
5507
+ <lengow>shipped</lengow>
5508
+ </state>
5509
+ <state name="canceled">
5510
+ <lengow>canceled</lengow>
5511
+ </state>
5512
+ <state name="returned">
5513
+ <lengow>canceled</lengow>
5514
+ </state>
5515
+ </states>
5516
+ <additional_params>
5517
+ <param usedby="shipped">
5518
+ <type>tracking</type>
5519
+ <name>tracking_number</name>
5520
+ </param>
5521
+ <param usedby="shipped">
5522
+ <type>carrier</type>
5523
+ <name>carrier_code</name>
5524
+ </param>
5525
+ <param usedby="shipped">
5526
+ <type>ship_date</type>
5527
+ <name>ship_date</name>
5528
+ </param>
5529
+ <param usedby="shipped">
5530
+ <type>expected_delivery_date</type>
5531
+ <name>expected_delivery_date</name>
5532
+ </param>
5533
+ <param usedby="cancel">
5534
+ <type>reason</type>
5535
+ <name>reason</name>
5536
+ <accepted_values>
5537
+ <value label="OUT_OF_STOCK" default="True">OUT_OF_STOCK</value>
5538
+ <value label="REQUESTED_BY_CUSTOMER">REQUESTED_BY_CUSTOMER</value>
5539
+ <value label="BAD_CONDITION">BAD_CONDITION</value>
5540
+ <value label="HIGHER_SHIPCOST">HIGHER_SHIPCOST</value>
5541
+ <value label="INCORRECT_PRICE">INCORRECT_PRICE</value>
5542
+ <value label="NOT_AVAIL_IN_TIME">NOT_AVAIL_IN_TIME</value>
5543
+ <value label="NO_BOL_GUARANTEE">NO_BOL_GUARANTEE</value>
5544
+ <value label="ORDERED_TWICE">ORDERED_TWICE</value>
5545
+ <value label="RETAIN_ITEM">RETAIN_ITEM</value>
5546
+ <value label="TECH_ISSUE">TECH_ISSUE</value>
5547
+ <value label="UNFINDABLE_ITEM">UNFINDABLE_ITEM</value>
5548
+ <value label="OTHER">OTHER</value>
5549
+ </accepted_values>
5550
+ </param>
5551
+ <param usedby="refund">
5552
+ <type>status_reason</type>
5553
+ <name>status_reason</name>
5554
+ <accepted_values>
5555
+ <value label="PRODUCT_RECEIVED" default="True">PRODUCT_RECEIVED</value>
5556
+ <value label="REPAIRED_OR_EXCHANGED">REPAIRED_OR_EXCHANGED</value>
5557
+ <value label="FAILS_TO_MATCH_RETURN_CONDITIONS">FAILS_TO_MATCH_RETURN_CONDITIONS</value>
5558
+ <value label="CUSTOMER_KEEPS_PRODUCT">CUSTOMER_KEEPS_PRODUCT</value>
5559
+ </accepted_values>
5560
+ </param>
5561
+ </additional_params>
5562
+ </marketplace>
5563
+ <marketplace name="teeps">
5564
+ <api>https://wsdl.lengow.com/wsdl/teeps/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5565
+ <states>
5566
+ <state name="Initial">
5567
+ <lengow>new</lengow>
5568
+ </state>
5569
+ <state name="Expired">
5570
+ <lengow>processing</lengow>
5571
+ </state>
5572
+ <state name="Ongoing">
5573
+ <lengow>pending</lengow>
5574
+ </state>
5575
+ <state name="Valid">
5576
+ <lengow>pending</lengow>
5577
+ </state>
5578
+ <state name="Direct Payment">
5579
+ <lengow>processing</lengow>
5580
+ </state>
5581
+ <state name="Pending Payment">
5582
+ <lengow>pending</lengow>
5583
+ </state>
5584
+ <state name="Pending Payment Paypal">
5585
+ <lengow>pending</lengow>
5586
+ </state>
5587
+ <state name="Pending Payment Bank Wire">
5588
+ <lengow>pending</lengow>
5589
+ </state>
5590
+ <state name="Not authorized">
5591
+ <lengow>canceled</lengow>
5592
+ </state>
5593
+ <state name="Authorization cancelled">
5594
+ <lengow>canceled</lengow>
5595
+ </state>
5596
+ <state name="Authorized (?)">
5597
+ <lengow>processing</lengow>
5598
+ </state>
5599
+ <state name="Payment Authorized">
5600
+ <lengow>pending</lengow>
5601
+ </state>
5602
+ <state name="Partially Confirmed">
5603
+ <lengow>processing</lengow>
5604
+ </state>
5605
+ <state name="Paid">
5606
+ <lengow>pending</lengow>
5607
+ </state>
5608
+ <state name="Confirmed">
5609
+ <lengow>pending</lengow>
5610
+ </state>
5611
+ <state name="Sent">
5612
+ <lengow>shipped</lengow>
5613
+ <actions>
5614
+ <action type="shipped">shipped</action>
5615
+ </actions>
5616
+ </state>
5617
+ <state name="Received">
5618
+ <lengow>complete</lengow>
5619
+ </state>
5620
+ <state name="Finalized">
5621
+ <lengow>complete</lengow>
5622
+ </state>
5623
+ <state name="Return in progress">
5624
+ <lengow>processing</lengow>
5625
+ </state>
5626
+ <state name="Partially Returned">
5627
+ <lengow>processing</lengow>
5628
+ </state>
5629
+ <state name="Returned">
5630
+ <lengow>processing</lengow>
5631
+ </state>
5632
+ <state name="Pending Payment Cheque">
5633
+ <lengow>pending</lengow>
5634
+ </state>
5635
+ <state name="Payment partial failure">
5636
+ <lengow>processing</lengow>
5637
+ </state>
5638
+ <state name="Payment failure">
5639
+ <lengow>processing</lengow>
5640
+ </state>
5641
+ <state name="Cancelled">
5642
+ <lengow>canceled</lengow>
5643
+ </state>
5644
+ <state name="Deleted">
5645
+ <lengow>canceled</lengow>
5646
+ </state>
5647
+ </states>
5648
+ <additional_params>
5649
+ <param usedby="shipped">
5650
+ <type>carrier_name</type>
5651
+ <name>carrier_name</name>
5652
+ <accepted_values>
5653
+ <value label="Chronopost" default="true">chronopost</value>
5654
+ <value label="Lapostecourriersuivi" default="true">lapostecourriersuivi</value>
5655
+ <value label="Chronorelais" default="true">chronorelais</value>
5656
+ <value label="Colissimo" default="true">colissimo</value>
5657
+ <value label="Ups" default="true">ups</value>
5658
+ <value label="Fedex" default="true">fedex</value>
5659
+ <value label="Dhl" default="true">dhl</value>
5660
+ <value label="Usps" default="true">usps</value>
5661
+ <value label="Tnt" default="true">tnt</value>
5662
+ <value label="Parcelforce" default="true">parcelforce</value>
5663
+ <value label="Exapaq" default="true">exapaq</value>
5664
+ <value label="Gls" default="true">gls</value>
5665
+ </accepted_values>
5666
+ </param>
5667
+ <param usedby="shipped">
5668
+ <type>tracking</type>
5669
+ <name>tracking_number</name>
5670
+ </param>
5671
+ </additional_params>
5672
+ </marketplace>
5673
+ <marketplace name="eprice">
5674
+ <api>https://wsdl.lengow.com/wsdl/eprice/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5675
+ <states>
5676
+ <state name="STAGING">
5677
+ <lengow>new</lengow>
5678
+ </state>
5679
+ <state name="WAITING_ACCEPTANCE">
5680
+ <lengow>new</lengow>
5681
+ <actions>
5682
+ <action type="accept">accept</action>
5683
+ <action type="refuse">canceled</action>
5684
+ </actions>
5685
+ </state>
5686
+ <state name="WAITING_DEBIT">
5687
+ <lengow>new</lengow>
5688
+ </state>
5689
+ <state name="WAITING_DEBIT_PAYMENT">
5690
+ <lengow>new</lengow>
5691
+ </state>
5692
+ <state name="SHIPPING">
5693
+ <lengow>processing</lengow>
5694
+ <actions>
5695
+ <action type="shipped">shipped</action>
5696
+ </actions>
5697
+ </state>
5698
+ <state name="RECEIVED">
5699
+ <lengow>shipped</lengow>
5700
+ </state>
5701
+ <state name="SHIPPED">
5702
+ <lengow>shipped</lengow>
5703
+ </state>
5704
+ <state name="CANCELED">
5705
+ <lengow>canceled</lengow>
5706
+ </state>
5707
+ <state name="CLOSED">
5708
+ <lengow>shipped</lengow>
5709
+ </state>
5710
+ <state name="REFUSED">
5711
+ <lengow>canceled</lengow>
5712
+ </state>
5713
+ <state name="INCIDENT_OPEN">
5714
+ <lengow>processing</lengow>
5715
+ </state>
5716
+ <state name="INCIDENT_CLOSED">
5717
+ <lengow>processing</lengow>
5718
+ </state>
5719
+ <state name="WAITING_REFUND">
5720
+ <lengow>processing</lengow>
5721
+ </state>
5722
+ <state name="WAITING_REFUND_PAYMENT">
5723
+ <lengow>processing</lengow>
5724
+ </state>
5725
+ <state name="REFUNDED">
5726
+ <lengow>canceled</lengow>
5727
+ </state>
5728
+ </states>
5729
+ <additional_params>
5730
+ <param usedby="shipped">
5731
+ <type>tracking</type>
5732
+ <name>tracking_number</name>
5733
+ </param>
5734
+ <param usedby="shipped">
5735
+ <type>carrier</type>
5736
+ <name>carrier_name</name>
5737
+ </param>
5738
+ <param usedby="shipped">
5739
+ <type>carrier_code</type>
5740
+ <name>carrier_code</name>
5741
+ <accepted_values>
5742
+ <value label="SDA" default="true">sda</value>
5743
+ <value label="TNT">tnt</value>
5744
+ <value label="GLS">gls</value>
5745
+ <value label="FEDEX">fedex</value>
5746
+ <value label="DHL">dhl</value>
5747
+ <value label="BRT">brt</value>
5748
+ </accepted_values>
5749
+ </param>
5750
+ <param usedby="shipped">
5751
+ <type>tracking_url</type>
5752
+ <name>tracking_url</name>
5753
+ </param>
5754
+ </additional_params>
5755
+ </marketplace>
5756
+ <marketplace name="harveynichols" realname="Harvey Nichols" idshopbot="2293">
5757
+ <api>https://wsdl.lengow.com/wsdl/harveynichols/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5758
+ <states>
5759
+ <state name="STAGING">
5760
+ <lengow>new</lengow>
5761
+ </state>
5762
+ <state name="WAITING_ACCEPTANCE">
5763
+ <lengow>new</lengow>
5764
+ <actions>
5765
+ <action type="accept">accept</action>
5766
+ <action type="refuse">canceled</action>
5767
+ </actions>
5768
+ </state>
5769
+ <state name="WAITING_DEBIT">
5770
+ <lengow>new</lengow>
5771
+ </state>
5772
+ <state name="WAITING_DEBIT_PAYMENT">
5773
+ <lengow>new</lengow>
5774
+ </state>
5775
+ <state name="SHIPPING">
5776
+ <lengow>processing</lengow>
5777
+ <actions>
5778
+ <action type="shipped">shipped</action>
5779
+ </actions>
5780
+ </state>
5781
+ <state name="RECEIVED">
5782
+ <lengow>shipped</lengow>
5783
+ </state>
5784
+ <state name="SHIPPED">
5785
+ <lengow>shipped</lengow>
5786
+ </state>
5787
+ <state name="CANCELED">
5788
+ <lengow>canceled</lengow>
5789
+ </state>
5790
+ <state name="CLOSED">
5791
+ <lengow>shipped</lengow>
5792
+ </state>
5793
+ <state name="REFUSED">
5794
+ <lengow>canceled</lengow>
5795
+ </state>
5796
+ <state name="INCIDENT_OPEN">
5797
+ <lengow>processing</lengow>
5798
+ </state>
5799
+ <state name="INCIDENT_CLOSED">
5800
+ <lengow>processing</lengow>
5801
+ </state>
5802
+ <state name="WAITING_REFUND">
5803
+ <lengow>processing</lengow>
5804
+ </state>
5805
+ <state name="WAITING_REFUND_PAYMENT">
5806
+ <lengow>processing</lengow>
5807
+ </state>
5808
+ <state name="REFUNDED">
5809
+ <lengow>canceled</lengow>
5810
+ </state>
5811
+ </states>
5812
+ <additional_params>
5813
+ <param usedby="shipped">
5814
+ <type>tracking</type>
5815
+ <name>tracking_number</name>
5816
+ </param>
5817
+ <param usedby="shipped">
5818
+ <type>carrier</type>
5819
+ <name>carrier_code</name>
5820
+ <accepted_values>
5821
+ <value label="Fed Ex" default="true">FEDEX</value>
5822
+ <value label="UPS">UPS</value>
5823
+ <value label="Interlink">IL</value>
5824
+ <value label="DHL">DHL</value>
5825
+ <value label="Royal Mail">RM</value>
5826
+ <value label="DPD">DPD</value>
5827
+ <value label="TNT">TNT</value>
5828
+ <value label="Parcelforce">PF</value>
5829
+ </accepted_values>
5830
+ </param>
5831
+ <param usedby="shipped">
5832
+ <type>carrier_name</type>
5833
+ <name>carrier_name</name>
5834
+ </param>
5835
+ <param usedby="shipped">
5836
+ <type>tracking_url</type>
5837
+ <name>tracking_url</name>
5838
+ </param>
5839
+ </additional_params>
5840
+ </marketplace>
5841
+ <marketplace name="idealo_de">
5842
+ <api>https://wsdl.lengow.com/wsdl/idealo_de/#ID_FLUX#/#ORDER_ID#/#ACTION#.xml</api>
5843
+ <states>
5844
+ <state name="PROCESSING">
5845
+ <lengow>processing</lengow>
5846
+ <actions>
5847
+ <action type="shipped">shipped</action>
5848
+ <action type="cancel">cancel</action>
5849
+ </actions>
5850
+ </state>
5851
+ <state name="shipped">
5852
+ <lengow>shipped</lengow>
5853
+ </state>
5854
+ <state name="canceled">
5855
+ <lengow>canceled</lengow>
5856
+ </state>
5857
+ </states>
5858
+ <additional_params>
5859
+ <param usedby="shipped">
5860
+ <type>tracking</type>
5861
+ <name>tracking_number</name>
5862
+ </param>
5863
+ <param usedby="shipped">
5864
+ <type>carrier</type>
5865
+ <name>carrier_name</name>
5866
+ <accepted_values>
5867
+ <value label="Cargo">Cargo</value>
5868
+ <value label="Hermes">Hermes</value>
5869
+ <value label="DHL">DHL</value>
5870
+ <value label="eparcel">eparcel</value>
5871
+ <value label="primeMail">primeMail</value>
5872
+ <value label="paket.ag">paket.ag</value>
5873
+ <value label="GLS">GLS</value>
5874
+ <value label="FedEx">FedEx</value>
5875
+ <value label="GdSK">GdSK</value>
5876
+ <value label="TOMBA">TOMBA</value>
5877
+ <value label="iloxx">iloxx</value>
5878
+ <value label="Der Courier">Der Courier</value>
5879
+ <value label="GO!">GO!</value>
5880
+ <value label="Noxxs Logistic">Noxxs Logistic</value>
5881
+ <value label="DPD">DPD</value>
5882
+ <value label="UPS">UPS</value>
5883
+ <value label="Midway">Midway</value>
5884
+ <value label="Deutsche Post">Deutsche Post</value>
5885
+ </accepted_values>
5886
+ </param>
5887
+ </additional_params>
5888
  </marketplace>
5889
  </marketplaces>
app/code/community/Lengow/Sync/etc/system.xml CHANGED
@@ -79,16 +79,6 @@
79
  <show_in_store>1</show_in_store>
80
  <source_model>adminhtml/system_config_source_yesno</source_model>
81
  </title>
82
- <!--<pending>
83
- <label>Import order in pending payment</label>
84
- <comment>Import an order in pendinf payment (like check or money order)</comment>
85
- <frontend_type>select</frontend_type>
86
- <sort_order>50</sort_order>
87
- <show_in_default>1</show_in_default>
88
- <show_in_website>1</show_in_website>
89
- <show_in_store>1</show_in_store>
90
- <source_model>adminhtml/system_config_source_yesno</source_model>
91
- </pending>-->
92
  <split_name>
93
  <label>Split name</label>
94
  <comment>If one of the name fields is empty, the non-empty field will be split to fill the empty name field</comment>
79
  <show_in_store>1</show_in_store>
80
  <source_model>adminhtml/system_config_source_yesno</source_model>
81
  </title>
 
 
 
 
 
 
 
 
 
 
82
  <split_name>
83
  <label>Split name</label>
84
  <comment>If one of the name fields is empty, the non-empty field will be split to fill the empty name field</comment>
app/code/community/Lengow/Sync/etc/wsdl.xml DELETED
@@ -1,34 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
3
- xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
4
- name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
5
- <types>
6
- <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
7
- <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
8
- <complexType name="salesOrderEntity">
9
- <all>
10
- <element name="order_id_lengow" type="xsd:string" minOccurs="0" />
11
- <element name="fees_lengow" type="xsd:string" minOccurs="0" />
12
- <element name="feed_id_lengow" type="xsd:string" minOccurs="0" />
13
- <element name="message_lengow" type="xsd:string" minOccurs="0" />
14
- <element name="marketplace_lengow" type="xsd:string" minOccurs="0" />
15
- <element name="total_paid_lengow" type="xsd:string" minOccurs="0" />
16
- <element name="carrier_lengow" type="xsd:string" minOccurs="0" />
17
- <element name="carrier_method_lengow" type="xsd:string" minOccurs="0" />
18
- </all>
19
- </complexType>
20
- <complexType name="salesOrderListEntity">
21
- <all>
22
- <element name="order_id_lengow" type="xsd:string" minOccurs="0" />
23
- <element name="fees_lengow" type="xsd:string" minOccurs="0" />
24
- <element name="feed_id_lengow" type="xsd:string" minOccurs="0" />
25
- <element name="message_lengow" type="xsd:string" minOccurs="0" />
26
- <element name="marketplace_lengow" type="xsd:string" minOccurs="0" />
27
- <element name="total_paid_lengow" type="xsd:string" minOccurs="0" />
28
- <element name="carrier_lengow" type="xsd:string" minOccurs="0" />
29
- <element name="carrier_method_lengow" type="xsd:string" minOccurs="0" />
30
- </all>
31
- </complexType>
32
- </schema>
33
- </types>
34
- </definitions>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-install-2.0.0.0.php CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * @category Lengow
5
  * @package Lengow_Sync
6
- * @author Romain Le Polh <romain@lengow.com>
7
  * @copyright 2013 Lengow SAS
8
  */
9
 
@@ -173,7 +173,7 @@ if(!$attribute){
173
  'unique' => 0,
174
  'used_in_product_listing' => 1
175
  ));
176
- }else{
177
  $installer->updateAttribute('catalog_product','lengow_product','default_value', 0);
178
  $installer->updateAttribute('catalog_product','lengow_product','is_global', Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE);
179
  }
3
  /**
4
  * @category Lengow
5
  * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
  * @copyright 2013 Lengow SAS
8
  */
9
 
173
  'unique' => 0,
174
  'used_in_product_listing' => 1
175
  ));
176
+ } else {
177
  $installer->updateAttribute('catalog_product','lengow_product','default_value', 0);
178
  $installer->updateAttribute('catalog_product','lengow_product','is_global', Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE);
179
  }
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.0.0.0-2.0.0.1.php CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * @category Lengow
5
  * @package Lengow_Sync
6
- * @author Ludovic DRIN <romain@lengow.com>
7
  * @copyright 2013 Lengow SAS
8
  */
9
 
@@ -12,8 +12,7 @@ $installer->startSetup();
12
 
13
  /*
14
  * Add order infos
15
- * - Carrier - text
16
- * - Carrier method - text
17
  */
18
  $order_entity_id = $installer->getEntityTypeId('order');
19
 
3
  /**
4
  * @category Lengow
5
  * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
  * @copyright 2013 Lengow SAS
8
  */
9
 
12
 
13
  /*
14
  * Add order infos
15
+ * - carrier - string
 
16
  */
17
  $order_entity_id = $installer->getEntityTypeId('order');
18
 
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.0.2-2.1.0.php CHANGED
@@ -3,8 +3,8 @@
3
  /**
4
  * @category Lengow
5
  * @package Lengow_Sync
6
- * @author Benjamin Le Nevé <benjamin.le-neve@lengow.com>
7
- * @copyright 2015 Lengow SAS
8
  */
9
 
10
  $installer = $this;
3
  /**
4
  * @category Lengow
5
  * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
+ * @copyright 2016 Lengow SAS
8
  */
9
 
10
  $installer = $this;
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.1.2-2.2.0.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Lengow
5
+ * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
+ * @copyright 2016 Lengow SAS
8
+ */
9
+
10
+ $installer = $this;
11
+ $installer->startSetup();
12
+
13
+ /*
14
+ * Add order infos
15
+ * export_finish_lengow - boolean
16
+ *
17
+ */
18
+ $order_entity_id = $installer->getEntityTypeId('order');
19
+
20
+ $list_attribute[] = array(
21
+ 'name' => 'export_finish_lengow',
22
+ 'label' => 'Export finish lengow',
23
+ 'type' => 'int',
24
+ 'input' => 'select',
25
+ 'source' => 'eav/entity_attribute_source_boolean',
26
+ 'default' => 1,
27
+ 'grid' => false,
28
+ );
29
+
30
+ $list_attribute[] = array(
31
+ 'name' => 'delivery_address_id_lengow',
32
+ 'label' => 'Delivery address id lengow',
33
+ 'type' => 'int',
34
+ 'input' => 'text',
35
+ 'source' => '',
36
+ 'default' => 0,
37
+ 'grid' => false,
38
+ );
39
+
40
+ foreach ($list_attribute as $attr) {
41
+ $order_attribute = $installer->getAttribute($order_entity_id, $attr['name']);
42
+ if (!$order_attribute) {
43
+ $installer->addAttribute('order', $attr['name'], array(
44
+ 'name' => $attr['name'],
45
+ 'label' => $attr['label'],
46
+ 'type' => $attr['type'],
47
+ 'visible' => true,
48
+ 'required' => false,
49
+ 'unique' => false,
50
+ 'filterable' => 1,
51
+ 'sort_order' => 700,
52
+ 'default' => $attr['default'],
53
+ 'input' => $attr['input'],
54
+ 'source' => $attr['source'],
55
+ 'grid' => $attr['grid'],
56
+ ));
57
+ }
58
+ $usedInForms = array(
59
+ 'adminhtml_order',
60
+ );
61
+ }
62
+
63
+ $installer->run(
64
+ "CREATE TABLE IF NOT EXISTS `{$this->getTable('lengow_order_line')}` (
65
+ `id` int(11) NOT NULL auto_increment,
66
+ `id_order` int(11) NOT NULL,
67
+ `id_order_line` text NOT NULL,
68
+ PRIMARY KEY (`id`)
69
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
70
+ );
71
+
72
+ $installer->endSetup();
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.0-2.2.1.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Lengow
5
+ * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
+ * @copyright 2016 Lengow SAS
8
+ */
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.1-2.2.2.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Lengow
5
+ * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
+ * @copyright 2016 Lengow SAS
8
+ */
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.2-2.2.3.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Lengow
5
+ * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
+ * @copyright 2016 Lengow SAS
8
+ */
app/code/community/Lengow/Sync/sql/lengow_setup/mysql4-upgrade-2.2.3-2.2.4.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Lengow
5
+ * @package Lengow_Sync
6
+ * @author Team Connector <team-connector@lengow.com>
7
+ * @copyright 2016 Lengow SAS
8
+ */
app/code/community/Lengow/Tracker/Block/Adminhtml/System/Config/Check.php CHANGED
@@ -1,40 +1,27 @@
1
  <?php
2
-
3
- /**
4
- * Copyright 2013 Lengow.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
7
- * not use this file except in compliance with the License. You may obtain
8
- * a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- * License for the specific language governing permissions and limitations
16
- * under the License.
17
- */
18
-
19
-
20
  /**
21
- * Lengow_Tracker_Block_Adminhtml_System_Config_Check
22
  *
23
- * @author Ludovic Drin <ludovic@lengow.com>
24
- * @copyright 2014 Lengow SAS
 
 
 
25
  */
26
-
27
  class Lengow_Tracker_Block_Adminhtml_System_Config_Check extends Mage_Adminhtml_Block_Template implements Varien_Data_Form_Element_Renderer_Interface {
28
 
29
  protected $_element;
30
 
31
- protected function _construct() {
 
32
  $this->setTemplate('widget/form/renderer/fieldset.phtml');
33
  }
34
 
35
- public function getElement() {
 
36
  return $this->_element;
37
  }
 
38
  /**
39
  * Generate html for button
40
  *
@@ -42,7 +29,8 @@ class Lengow_Tracker_Block_Adminhtml_System_Config_Check extends Mage_Adminhtml_
42
  * @return string $html
43
  * @see Mage_Adminhtml_Block_System_Config_Form_Field::_getElementHtml()
44
  */
45
- public function render(Varien_Data_Form_Element_Abstract $element) {
 
46
  $html = $this->getLayout()->createBlock('lentracker/adminhtml_system_config_check_point', 'lengow_checkpoint')
47
  ->toHtml();
48
  $element->setHtmlContent($html);
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /**
3
+ * Lengow tracker block adminhtml system config check
4
  *
5
+ * @category Lengow
6
+ * @package Lengow_Tracker
7
+ * @author Team Connector <team-connector@lengow.com>
8
+ * @copyright 2016 Lengow SAS
9
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
 
11
  class Lengow_Tracker_Block_Adminhtml_System_Config_Check extends Mage_Adminhtml_Block_Template implements Varien_Data_Form_Element_Renderer_Interface {
12
 
13
  protected $_element;
14
 
15
+ protected function _construct()
16
+ {
17
  $this->setTemplate('widget/form/renderer/fieldset.phtml');
18
  }
19
 
20
+ public function getElement()
21
+ {
22
  return $this->_element;
23
  }
24
+
25
  /**
26
  * Generate html for button
27
  *
29
  * @return string $html
30
  * @see Mage_Adminhtml_Block_System_Config_Form_Field::_getElementHtml()
31
  */
32
+ public function render(Varien_Data_Form_Element_Abstract $element)
33
+ {
34
  $html = $this->getLayout()->createBlock('lentracker/adminhtml_system_config_check_point', 'lengow_checkpoint')
35
  ->toHtml();
36
  $element->setHtmlContent($html);
app/code/community/Lengow/Tracker/Block/Tag/Capsule.php CHANGED
@@ -3,11 +3,14 @@
3
  /**
4
  * Lengow_Tracker Tracking Block Capsule
5
  *
6
- * @category Lengow
7
- * @package Lengow_Tracker
8
- * @author Romain Le Polh <romain@lengow.com>
 
 
9
  */
10
- class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
 
11
 
12
  protected $_data = array();
13
 
@@ -27,128 +30,148 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
27
  static private $_IDS_PRODUCTS_CART = '';
28
  static private $_ID_CATEGORY = '';
29
 
30
- public function __construct() {
 
31
  $this->setData('config_model', Mage::getSingleton('lentracker/config'));
32
  $this->setData('capsule_model', Mage::getSingleton('lentracker/capsule'));
33
  $this->setData('id_client', $this->getData('config_model')->get('general/login'));
34
-
35
  // explode group id => force 1 group only
36
  $id_groups = $this->getData('config_model')->get('general/group');
37
- $id_groups = explode(',', $id_groups);
38
  $this->setData('id_group', $id_groups[0]);
39
-
40
  $this->setData('current_view', Mage::app()->getRequest()->getActionName());
41
  }
42
 
43
- protected function _prepareLayout() {
 
44
  parent::_prepareLayout();
45
-
46
- // Page type
47
- $current_module = Mage::app()->getFrontController()->getRequest()->getModuleName();
48
- $current_controller = Mage::app()->getFrontController()->getRequest()->getControllerName();
49
- $current_action = '';
50
-
51
- if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
52
- self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_HOMEPAGE;
53
- } else if ($current_module == 'catalog') {
54
- if ($current_controller == 'category')
55
- self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE_LIST;
56
- else if ($current_controller == 'product')
57
- self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE;
58
- } else if ($current_module == 'checkout') {
59
-
60
- $current_action = Mage::app()->getRequest()->getActionName();
61
-
62
- if ($current_action == 'success')
63
- self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE_CONFIRMATION;
64
- else if ($current_controller == 'cart')
65
- self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE_CART;
66
- else if ($current_controller == 'onepage')
67
- self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE;
68
- }
69
-
70
- // Order total
71
- if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CART ||
 
 
 
 
 
 
 
 
72
  self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_PAYMENT ||
73
- $current_module == 'checkout' && $current_action != 'success') {
74
- $quote = Mage::getModel('checkout/cart')->getQuote();
75
- self::$_ORDER_TOTAL = round($quote->getGrandTotal(), 2);
76
- } else if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
77
- $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
78
- $order = Mage::getModel('sales/order')->load($order_id);
79
- self::$_ORDER_TOTAL = round($order->getGrandTotal(), 2);
80
- }
81
-
82
- // Order id - Lead / Payment / Confirmation
83
- if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
84
- self::$_ID_ORDER = Mage::getSingleton('checkout/session')->getLastRealOrderId();
85
- }
86
-
87
- // Ids Products - Page / Listpage / Basket / Payment / Confirmation
88
- if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CART ||
 
89
  self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_PAYMENT ||
90
- $current_module == 'checkout' && $current_action != 'success') {
91
- // Get current quote
92
- $quote = Mage::getModel('checkout/cart')->getQuote();
93
- self::$_IDS_PRODUCTS = $this->getData('capsule_model')->getIdsProducts($quote);
94
- } else if(self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_LIST) {
95
- self::$_IDS_PRODUCTS = $this->_getCurrentProductsIds();
96
- } else if(self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE) {
97
- self::$_IDS_PRODUCTS = $this->_getCurrentProductId();
98
- } else if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
99
- // Get last order
100
- $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
101
- $order = Mage::getModel('sales/order')->load($order_id);
102
- self::$_IDS_PRODUCTS = $this->getData('capsule_model')->getIdsProducts($order);
103
- }
104
-
105
- // List product in basket - Basket - Confirmation
106
- if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CART ||
107
- $current_module == 'checkout' && $current_action != 'success') {
108
- $quote = Mage::getModel('checkout/cart')->getQuote();
109
- self::$_IDS_PRODUCTS_CART = $this->getData('capsule_model')->getProductsCart($quote);
110
- } else if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
111
- $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
112
- $order = Mage::getModel('sales/order')->load($order_id);
113
- self::$_IDS_PRODUCTS_CART = $this->getData('capsule_model')->getProductsCart($order);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  }
115
-
116
- // Id categorie
117
- if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_LIST)
118
- self::$_ID_CATEGORY = Mage::registry('current_category')->getName();
119
-
120
- // Use SSL
121
- if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
122
- self::$_USE_SSL = true;
123
-
124
- // Assign data
125
- $this->setData('type_page', self::$_CURRENT_PAGE_TYPE);
126
- $this->setData('id_order', self::$_ID_ORDER);
127
- $this->setData('order_total', self::$_ORDER_TOTAL);
128
- $this->setData('id_category', self::$_ID_CATEGORY);
129
- $this->setData('ids_products', self::$_IDS_PRODUCTS);
130
- $this->setData('list_products', self::$_IDS_PRODUCTS_CART);
131
- $this->setData('use_ssl', self::$_USE_SSL == true ? 'true' : 'false');
132
- $this->setData('controller', $current_controller);
133
- $this->setData('module', $current_module);
134
- $this->setData('current_action', $current_action);
135
-
136
- $this->setTemplate('lengow/tracker/tagcapsule.phtml');
137
  return $this;
138
  }
139
 
140
- protected function _getCurrentProductId() {
 
141
  $config = Mage::getModel('lentracker/config');
142
- if($product = Mage::registry('product'))
143
  return $product->getData($config->get('tag/identifiant'));
 
144
  return '';
145
  }
146
 
147
- protected function _getCurrentProductsIds($implode = true) {
 
148
  $config = Mage::getModel('lentracker/config');
149
  $ids = array();
150
  $products = $this->_getProductCollection()->getData();
151
- if($products) {
152
  foreach ($products as $product) {
153
  $ids[] = $product[$config->get('tag/identifiant')];
154
  }
@@ -161,14 +184,14 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
161
  *
162
  * @return Mage_Eav_Model_Entity_Collection_Abstract
163
  */
164
- protected function _getProductCollection() {
 
165
  if (is_null($this->_productCollection)) {
166
  $layer = $this->getLayer();
167
  /* @var $layer Mage_Catalog_Model_Layer */
168
  if ($this->getShowRootCategory()) {
169
  $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
170
  }
171
-
172
  // if this is a product view page
173
  if (Mage::registry('product')) {
174
  // get collection of categories this product is associated with
@@ -181,7 +204,6 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
181
  $this->setCategoryId(current($categories->getIterator()));
182
  }
183
  }
184
-
185
  $origCategory = null;
186
  if ($this->getCategoryId()) {
187
  $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
@@ -192,9 +214,7 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
192
  }
193
  }
194
  $this->_productCollection = $layer->getProductCollection();
195
-
196
  $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
197
-
198
  if ($origCategory) {
199
  $layer->setCurrentCategory($origCategory);
200
  }
@@ -202,12 +222,14 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
202
  return $this->_productCollection;
203
  }
204
 
205
- protected function _beforeToHtml() {
206
- if(self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_LIST) {
 
207
  $config = Mage::getModel('lentracker/config');
 
208
  $_list = $this->getLayout()->getBlock('product_list');
209
  $_products = $_list->getLoadedProductCollection();
210
- if($_products) {
211
  foreach ($_products as $product) {
212
  $ids[] = $product[$config->get('tag/identifiant')];
213
  }
@@ -222,7 +244,8 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
222
  *
223
  * @return Mage_Catalog_Model_Layer
224
  */
225
- public function getLayer() {
 
226
  $layer = Mage::registry('current_layer');
227
  if ($layer) {
228
  return $layer;
@@ -236,7 +259,8 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
236
  * @param Mage_Catalog_Model_Category $category
237
  * @return Mage_Catalog_Block_Product_List
238
  */
239
- public function prepareSortableFieldsByCategory($category) {
 
240
  if (!$this->getAvailableOrders()) {
241
  $this->setAvailableOrders($category->getAvailableSortByOptions());
242
  }
@@ -254,4 +278,14 @@ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template {
254
 
255
  return $this;
256
  }
257
- }
 
 
 
 
 
 
 
 
 
 
3
  /**
4
  * Lengow_Tracker Tracking Block Capsule
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Tracker_Block_Tag_Capsule extends Mage_Core_Block_Template
13
+ {
14
 
15
  protected $_data = array();
16
 
30
  static private $_IDS_PRODUCTS_CART = '';
31
  static private $_ID_CATEGORY = '';
32
 
33
+ public function __construct()
34
+ {
35
  $this->setData('config_model', Mage::getSingleton('lentracker/config'));
36
  $this->setData('capsule_model', Mage::getSingleton('lentracker/capsule'));
37
  $this->setData('id_client', $this->getData('config_model')->get('general/login'));
 
38
  // explode group id => force 1 group only
39
  $id_groups = $this->getData('config_model')->get('general/group');
40
+ $id_groups = explode(',', $this->_cleanGroup($id_groups));
41
  $this->setData('id_group', $id_groups[0]);
 
42
  $this->setData('current_view', Mage::app()->getRequest()->getActionName());
43
  }
44
 
45
+ protected function _prepareLayout()
46
+ {
47
  parent::_prepareLayout();
48
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
49
+ // Page type
50
+ $current_module = Mage::app()->getFrontController()->getRequest()->getModuleName();
51
+ $current_controller = Mage::app()->getFrontController()->getRequest()->getControllerName();
52
+ $current_action = '';
53
+ if (Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
54
+ self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_HOMEPAGE;
55
+ } else {
56
+ if ($current_module == 'catalog') {
57
+ if ($current_controller == 'category') {
58
+ self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE_LIST;
59
+ } else {
60
+ if ($current_controller == 'product') {
61
+ self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE;
62
+ }
63
+ }
64
+ } else {
65
+ if ($current_module == 'checkout') {
66
+ $current_action = Mage::app()->getRequest()->getActionName();
67
+ if ($current_action == 'success') {
68
+ self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE_CONFIRMATION;
69
+ } else {
70
+ if ($current_controller == 'cart') {
71
+ self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE_CART;
72
+ } else {
73
+ if ($current_controller == 'onepage') {
74
+ self::$_CURRENT_PAGE_TYPE = self::LENGOW_TRACK_PAGE;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ // Order total
82
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CART ||
83
  self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_PAYMENT ||
84
+ $current_module == 'checkout' && $current_action != 'success'
85
+ ) {
86
+ $quote = Mage::getModel('checkout/cart')->getQuote();
87
+ self::$_ORDER_TOTAL = round($quote->getGrandTotal(), 2);
88
+ } else {
89
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
90
+ $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
91
+ $order = Mage::getModel('sales/order')->load($order_id);
92
+ self::$_ORDER_TOTAL = round($order->getGrandTotal(), 2);
93
+ }
94
+ }
95
+ // Order id - Lead / Payment / Confirmation
96
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
97
+ self::$_ID_ORDER = Mage::getSingleton('checkout/session')->getLastRealOrderId();
98
+ }
99
+ // Ids Products - Page / Listpage / Basket / Payment / Confirmation
100
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CART ||
101
  self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_PAYMENT ||
102
+ $current_module == 'checkout' && $current_action != 'success'
103
+ ) {
104
+ // Get current quote
105
+ $quote = Mage::getModel('checkout/cart')->getQuote();
106
+ self::$_IDS_PRODUCTS = $this->getData('capsule_model')->getIdsProductsV2($quote);
107
+ } else {
108
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_LIST) {
109
+ self::$_IDS_PRODUCTS = $this->_getCurrentProductsIds();
110
+ } else {
111
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE) {
112
+ self::$_IDS_PRODUCTS = $this->_getCurrentProductId();
113
+ } else {
114
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
115
+ // Get last order
116
+ $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
117
+ $order = Mage::getModel('sales/order')->load($order_id);
118
+ self::$_IDS_PRODUCTS = $this->getData('capsule_model')->getIdsProductsV2($order);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ // List product in basket - Basket - Confirmation
124
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CART ||
125
+ $current_module == 'checkout' && $current_action != 'success'
126
+ ) {
127
+ $quote = Mage::getModel('checkout/cart')->getQuote();
128
+ self::$_IDS_PRODUCTS_CART = $this->getData('capsule_model')->getProductsCart($quote);
129
+ } else {
130
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_CONFIRMATION) {
131
+ $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
132
+ $order = Mage::getModel('sales/order')->load($order_id);
133
+ self::$_IDS_PRODUCTS_CART = $this->getData('capsule_model')->getProductsCart($order);
134
+ }
135
+ }
136
+ // Id categorie
137
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_LIST) {
138
+ self::$_ID_CATEGORY = Mage::registry('current_category')->getName();
139
+ }
140
+ // Use SSL
141
+ if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
142
+ self::$_USE_SSL = true;
143
+ }
144
+ // Assign data
145
+ $this->setData('type_page', self::$_CURRENT_PAGE_TYPE);
146
+ $this->setData('id_order', self::$_ID_ORDER);
147
+ $this->setData('order_total', self::$_ORDER_TOTAL);
148
+ $this->setData('id_category', self::$_ID_CATEGORY);
149
+ $this->setData('ids_products', self::$_IDS_PRODUCTS);
150
+ $this->setData('list_products', self::$_IDS_PRODUCTS_CART);
151
+ $this->setData('use_ssl', self::$_USE_SSL == true ? 'true' : 'false');
152
+ $this->setData('controller', $current_controller);
153
+ $this->setData('module', $current_module);
154
+ $this->setData('current_action', $current_action);
155
+ $this->setTemplate('lengow/tracker/tagcapsule.phtml');
156
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  return $this;
158
  }
159
 
160
+ protected function _getCurrentProductId()
161
+ {
162
  $config = Mage::getModel('lentracker/config');
163
+ if ($product = Mage::registry('product')) {
164
  return $product->getData($config->get('tag/identifiant'));
165
+ }
166
  return '';
167
  }
168
 
169
+ protected function _getCurrentProductsIds($implode = true)
170
+ {
171
  $config = Mage::getModel('lentracker/config');
172
  $ids = array();
173
  $products = $this->_getProductCollection()->getData();
174
+ if ($products) {
175
  foreach ($products as $product) {
176
  $ids[] = $product[$config->get('tag/identifiant')];
177
  }
184
  *
185
  * @return Mage_Eav_Model_Entity_Collection_Abstract
186
  */
187
+ protected function _getProductCollection()
188
+ {
189
  if (is_null($this->_productCollection)) {
190
  $layer = $this->getLayer();
191
  /* @var $layer Mage_Catalog_Model_Layer */
192
  if ($this->getShowRootCategory()) {
193
  $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
194
  }
 
195
  // if this is a product view page
196
  if (Mage::registry('product')) {
197
  // get collection of categories this product is associated with
204
  $this->setCategoryId(current($categories->getIterator()));
205
  }
206
  }
 
207
  $origCategory = null;
208
  if ($this->getCategoryId()) {
209
  $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
214
  }
215
  }
216
  $this->_productCollection = $layer->getProductCollection();
 
217
  $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
 
218
  if ($origCategory) {
219
  $layer->setCurrentCategory($origCategory);
220
  }
222
  return $this->_productCollection;
223
  }
224
 
225
+ protected function _beforeToHtml()
226
+ {
227
+ if (self::$_CURRENT_PAGE_TYPE == self::LENGOW_TRACK_PAGE_LIST) {
228
  $config = Mage::getModel('lentracker/config');
229
+ $ids = array();
230
  $_list = $this->getLayout()->getBlock('product_list');
231
  $_products = $_list->getLoadedProductCollection();
232
+ if ($_products) {
233
  foreach ($_products as $product) {
234
  $ids[] = $product[$config->get('tag/identifiant')];
235
  }
244
  *
245
  * @return Mage_Catalog_Model_Layer
246
  */
247
+ public function getLayer()
248
+ {
249
  $layer = Mage::registry('current_layer');
250
  if ($layer) {
251
  return $layer;
259
  * @param Mage_Catalog_Model_Category $category
260
  * @return Mage_Catalog_Block_Product_List
261
  */
262
+ public function prepareSortableFieldsByCategory($category)
263
+ {
264
  if (!$this->getAvailableOrders()) {
265
  $this->setAvailableOrders($category->getAvailableSortByOptions());
266
  }
278
 
279
  return $this;
280
  }
281
+
282
+ /**
283
+ * Clean group id
284
+ *
285
+ * @param string $data
286
+ */
287
+ private function _cleanGroup($data)
288
+ {
289
+ return trim(str_replace(array("\r\n", ';', '-', '|', ' '), ',', $data), ',');
290
+ }
291
+ }
app/code/community/Lengow/Tracker/Block/Tag/Simple.php CHANGED
@@ -3,34 +3,60 @@
3
  /**
4
  * Lengow_Tracker Tracking Block Simple
5
  *
6
- * @category Lengow
7
- * @package Lengow_Tracker
8
- * @author Romain Le Polh <romain@lengow.com>
 
 
9
  */
 
 
10
 
11
- class Lengow_Tracker_Block_Tag_Simple extends Mage_Core_Block_Template {
12
-
13
- protected $_config_model;
14
-
15
- public function __construct() {
16
- $this->_config_model = Mage::getSingleton('lentracker/config');
17
- $this->setData('id_client', $this->_config_model->get('general/login'));
18
- $this->setData('id_group', $this->_config_model->get('general/group'));
19
  }
20
-
21
- protected function _prepareLayout() {
 
22
  parent::_prepareLayout();
23
- $tracker_model = Mage::getSingleton('lentracker/tracker');
24
- if(Mage::app()->getRequest()->getActionName() == 'success') {
25
  $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
26
- $order = Mage::getModel('sales/order')->load($order_id);
27
- $this->setData('mode_paiement', $order->getPayment()->getMethodInstance()->getCode());
28
- $this->setData('id_order', $order_id);
29
- $this->setData('total_paid', $order->getGrandTotal());
30
- $this->setData('ids_products', $tracker_model->getIdsProducts($order));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  $this->setTemplate('lengow/tracker/simpletag.phtml');
32
  }
33
  return $this;
34
  }
35
-
36
- }
3
  /**
4
  * Lengow_Tracker Tracking Block Simple
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Tracker_Block_Tag_Simple extends Mage_Core_Block_Template
13
+ {
14
 
15
+ protected $_tracker_model;
16
+
17
+ public function __construct()
18
+ {
19
+ $this->_tracker_model = Mage::getSingleton('lentracker/tracker');
 
 
 
20
  }
21
+
22
+ protected function _prepareLayout()
23
+ {
24
  parent::_prepareLayout();
25
+ if (Mage::app()->getRequest()->getActionName() == 'success') {
 
26
  $order_id = Mage::getSingleton('checkout/session')->getLastOrderId();
27
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
28
+ $order = Mage::getModel('sales/order')->load($order_id);
29
+ $this->setData(
30
+ 'id_client',
31
+ Mage::getStoreConfig('lentracker/general/login', Mage::app()->getStore())
32
+ );
33
+ // explode group id => force 1 group only
34
+ $id_groups = Mage::getStoreConfig('lentracker/general/group', Mage::app()->getStore());
35
+ $id_groups = explode(',', $id_groups);
36
+ $this->setData('id_group', $id_groups[0]);
37
+ $this->setData('mode_paiement', $order->getPayment()->getMethodInstance()->getCode());
38
+ $this->setData('id_order', $order_id);
39
+ $this->setData('total_paid', $order->getGrandTotal());
40
+ $this->setData('ids_products', $this->_tracker_model->getIdsProductsV2($order));
41
+ }
42
+ if ((int)Mage::getStoreConfig('lentracker/general/version3')) {
43
+ $order = Mage::getModel('sales/order')->load($order_id);
44
+ $this->setData(
45
+ 'account_id',
46
+ Mage::getStoreConfig('lentracker/general/account_id', Mage::app()->getStore())
47
+ );
48
+ $cart = $this->_tracker_model->getIdsProducts($order);
49
+ $this->setData('order_ref', $order_id);
50
+ $this->setData('amount', $order->getGrandTotal());
51
+ $this->setData('currency', $order->getOrderCurrencyCode());
52
+ $this->setData('payment_method', $order->getPayment()->getMethodInstance()->getCode());
53
+ $this->setData('cart', htmlspecialchars($cart));
54
+ $this->setData('cart_number', $order->getQuoteId());
55
+ $this->setData('newbiz', 1);
56
+ $this->setData('valid', 1);
57
+ }
58
  $this->setTemplate('lengow/tracker/simpletag.phtml');
59
  }
60
  return $this;
61
  }
62
+ }
 
app/code/community/Lengow/Tracker/Block/Tracker.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
2
 
3
  /**
4
- * Lengow_Tracker Tracking Block
5
  *
6
- * @category Lengow
7
- * @package Lengow_Tracker
8
- * @author Romain Le Polh <romain@lengow.com>
 
 
9
  */
10
-
11
- class Lengow_Tracker_Block_Tracker extends Mage_Core_Block_Template {
12
 
13
  const URI_TAG_CAPSULE = 'https://tracking.lengow.com/tagcapsule.js';
14
  const BLOCK_SIMPLE = 'lentracker/tag_simple';
@@ -18,23 +20,25 @@ class Lengow_Tracker_Block_Tracker extends Mage_Core_Block_Template {
18
  protected $_id_group;
19
  protected $_tag;
20
 
21
- protected function _construct() {
 
22
  $config_model = Mage::getSingleton('lentracker/config');
23
-
24
  $this->_id_client = $config_model->get('general/login');
25
  $this->_id_group = $config_model->get('general/group');
26
  $this->_tag = $config_model->get('tag/type');
27
-
 
 
28
  }
29
 
30
  protected function _prepareLayout()
31
  {
32
  parent::_prepareLayout();
33
- if($this->_tag == 'tagcapsule')
34
  $this->setChild('tracker', $this->getLayout()->createBlock(self::BLOCK_CAPSULE, 'tag_capsule'));
35
- elseif($this->_tag == 'simpletag')
36
  $this->setChild('tracker', $this->getLayout()->createBlock(self::BLOCK_SIMPLE, 'simple_tag'));
37
-
38
  return $this;
39
  }
40
 
@@ -43,36 +47,33 @@ class Lengow_Tracker_Block_Tracker extends Mage_Core_Block_Template {
43
  *
44
  * @return string
45
  */
46
- protected function _toHtml() {
 
47
  return parent::_toHtml();
48
  }
49
 
50
-
51
-
52
-
53
  /**
54
  * Retrieve Page Type
55
  *
56
  * @return string
57
  */
58
- public function getPage() {
 
59
  if (!$this->hasData('page')) {
60
-
61
  $this->setPage('page'); //by default
62
-
63
  $handles = $this->getLayout()->getUpdate()->getHandles();
64
-
65
- if (in_array('cms_index_index', $handles))
66
  $this->setPage('homepage');
67
-
68
- if (in_array('checkout_onepage_success', $handles))
69
  $this->setPage('confirmation');
70
-
71
- if (in_array('catalog_category_view', $handles))
72
  $this->setPage('listepage');
73
-
74
- if (in_array('checkout_cart_index', $handles))
75
  $this->setPage('basket');
 
76
  }
77
  return $this->getData('page');
78
  }
@@ -82,7 +83,8 @@ class Lengow_Tracker_Block_Tracker extends Mage_Core_Block_Template {
82
  *
83
  * @return string
84
  */
85
- public function useSSL() {
 
86
  if (!$this->hasData('use_ssl')) {
87
  $this->setUseSsl(Mage::getStoreConfig('lengow_export/general/ssl_tagcapsule'));
88
  }
1
  <?php
2
 
3
  /**
4
+ * Lengow tracker block tracker
5
  *
6
+ * @category Lengow
7
+ * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Tracker_Block_Tracker extends Mage_Core_Block_Template
13
+ {
14
 
15
  const URI_TAG_CAPSULE = 'https://tracking.lengow.com/tagcapsule.js';
16
  const BLOCK_SIMPLE = 'lentracker/tag_simple';
20
  protected $_id_group;
21
  protected $_tag;
22
 
23
+ protected function _construct()
24
+ {
25
  $config_model = Mage::getSingleton('lentracker/config');
 
26
  $this->_id_client = $config_model->get('general/login');
27
  $this->_id_group = $config_model->get('general/group');
28
  $this->_tag = $config_model->get('tag/type');
29
+ if ((int)Mage::getStoreConfig('lentracker/general/version2') == 0 && $this->_tag == 'tagcapsule') {
30
+ $this->_tag = 'simpletag';
31
+ }
32
  }
33
 
34
  protected function _prepareLayout()
35
  {
36
  parent::_prepareLayout();
37
+ if ($this->_tag == 'tagcapsule') {
38
  $this->setChild('tracker', $this->getLayout()->createBlock(self::BLOCK_CAPSULE, 'tag_capsule'));
39
+ } elseif ($this->_tag == 'simpletag') {
40
  $this->setChild('tracker', $this->getLayout()->createBlock(self::BLOCK_SIMPLE, 'simple_tag'));
41
+ }
42
  return $this;
43
  }
44
 
47
  *
48
  * @return string
49
  */
50
+ protected function _toHtml()
51
+ {
52
  return parent::_toHtml();
53
  }
54
 
 
 
 
55
  /**
56
  * Retrieve Page Type
57
  *
58
  * @return string
59
  */
60
+ public function getPage()
61
+ {
62
  if (!$this->hasData('page')) {
 
63
  $this->setPage('page'); //by default
 
64
  $handles = $this->getLayout()->getUpdate()->getHandles();
65
+ if (in_array('cms_index_index', $handles)) {
 
66
  $this->setPage('homepage');
67
+ }
68
+ if (in_array('checkout_onepage_success', $handles)) {
69
  $this->setPage('confirmation');
70
+ }
71
+ if (in_array('catalog_category_view', $handles)) {
72
  $this->setPage('listepage');
73
+ }
74
+ if (in_array('checkout_cart_index', $handles)) {
75
  $this->setPage('basket');
76
+ }
77
  }
78
  return $this->getData('page');
79
  }
83
  *
84
  * @return string
85
  */
86
+ public function useSSL()
87
+ {
88
  if (!$this->hasData('use_ssl')) {
89
  $this->setUseSsl(Mage::getStoreConfig('lengow_export/general/ssl_tagcapsule'));
90
  }
app/code/community/Lengow/Tracker/Helper/Check.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
2
  /**
3
- * Lengow sync helper data
4
  *
5
  * @category Lengow
6
  * @package Lengow_Tracker
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2014 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
- class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract {
 
12
 
13
  const PLUGIN_NAME = 'magento';
14
 
@@ -21,7 +23,7 @@ class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract {
21
  public function getVersion()
22
  {
23
  $this->updatePluginsVersion();
24
- return (string) Mage::getConfig()->getNode()->modules->Lengow_Tracker->version;
25
  }
26
 
27
  public function getLastVersion()
@@ -29,10 +31,11 @@ class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract {
29
  $this->_loadDom();
30
  // Compare version
31
  $object = $this->_dom->xpath('/plugins/plugin[@name=\'' . self::PLUGIN_NAME . '\']');
32
- if(!empty($object))
33
  return $object[0]->version;
34
- else
35
  return 'NULL';
 
36
  }
37
 
38
 
@@ -44,7 +47,7 @@ class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract {
44
  public static function updatePluginsVersion()
45
  {
46
  $mp_update = Mage::getModel('lentracker/config')->get('hidden/last_synchro');
47
- if (!$mp_update || !$mp_update == '0000-00-00' ||$mp_update != date('Y-m-d')) {
48
  $sep = DS;
49
  if ($xml = fopen(self::LENGOW_PLUGINS_VERSION, 'r')) {
50
  $handle = fopen(Mage::getModuleDir('etc', 'Lengow_Tracker') . DS . self::URI_TAG_CAPSULE . '', 'w');
@@ -62,14 +65,15 @@ class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract {
62
  */
63
  public function checkPluginVersion($current_version = null)
64
  {
65
- if($current_version == null)
66
  return false;
 
67
  $this->_loadDom();
68
  // Compare version
69
  $object = $this->_dom->xpath('/plugins/plugin[@name=\'' . self::PLUGIN_NAME . '\']');
70
- if(!empty($object)) {
71
  $plugin = $object[0];
72
- if(version_compare($current_version, $plugin->version, '<')) {
73
  return false;
74
  } else {
75
  return true;
@@ -85,8 +89,9 @@ class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract {
85
 
86
  private function _loadDom()
87
  {
88
- if(!$this->_dom)
89
- $this->_dom = simplexml_load_file(Mage::getModuleDir('etc', 'Lengow_Tracker') . DS . self::URI_TAG_CAPSULE );
 
90
  }
91
 
92
  /**
@@ -98,5 +103,4 @@ class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract {
98
  {
99
  return (Mage::getVersion() < '1.5.0.0') ? false : true;
100
  }
101
-
102
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow tracker helper check
5
  *
6
  * @category Lengow
7
  * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Tracker_Helper_Check extends Mage_Core_Helper_Abstract
13
+ {
14
 
15
  const PLUGIN_NAME = 'magento';
16
 
23
  public function getVersion()
24
  {
25
  $this->updatePluginsVersion();
26
+ return (string)Mage::getConfig()->getNode()->modules->Lengow_Tracker->version;
27
  }
28
 
29
  public function getLastVersion()
31
  $this->_loadDom();
32
  // Compare version
33
  $object = $this->_dom->xpath('/plugins/plugin[@name=\'' . self::PLUGIN_NAME . '\']');
34
+ if (!empty($object)) {
35
  return $object[0]->version;
36
+ } else {
37
  return 'NULL';
38
+ }
39
  }
40
 
41
 
47
  public static function updatePluginsVersion()
48
  {
49
  $mp_update = Mage::getModel('lentracker/config')->get('hidden/last_synchro');
50
+ if (!$mp_update || !$mp_update == '0000-00-00' || $mp_update != date('Y-m-d')) {
51
  $sep = DS;
52
  if ($xml = fopen(self::LENGOW_PLUGINS_VERSION, 'r')) {
53
  $handle = fopen(Mage::getModuleDir('etc', 'Lengow_Tracker') . DS . self::URI_TAG_CAPSULE . '', 'w');
65
  */
66
  public function checkPluginVersion($current_version = null)
67
  {
68
+ if ($current_version == null) {
69
  return false;
70
+ }
71
  $this->_loadDom();
72
  // Compare version
73
  $object = $this->_dom->xpath('/plugins/plugin[@name=\'' . self::PLUGIN_NAME . '\']');
74
+ if (!empty($object)) {
75
  $plugin = $object[0];
76
+ if (version_compare($current_version, $plugin->version, '<')) {
77
  return false;
78
  } else {
79
  return true;
89
 
90
  private function _loadDom()
91
  {
92
+ if (!$this->_dom) {
93
+ $this->_dom = simplexml_load_file(Mage::getModuleDir('etc', 'Lengow_Tracker') . DS . self::URI_TAG_CAPSULE);
94
+ }
95
  }
96
 
97
  /**
103
  {
104
  return (Mage::getVersion() < '1.5.0.0') ? false : true;
105
  }
106
+ }
 
app/code/community/Lengow/Tracker/Helper/Data.php CHANGED
@@ -1,13 +1,14 @@
1
  <?php
 
2
  /**
3
- * Lengow sync helper data
4
  *
5
  * @category Lengow
6
- * @package Lengow_Sync
7
- * @author Ludovic Drin <ludovic@lengow.com>
8
- * @copyright 2013 Lengow SAS
9
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
10
  */
11
  class Lengow_Tracker_Helper_Data extends Mage_Core_Helper_Abstract {
12
 
13
- }
1
  <?php
2
+
3
  /**
4
+ * Lengow tracker helper data
5
  *
6
  * @category Lengow
7
+ * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Tracker_Helper_Data extends Mage_Core_Helper_Abstract {
13
 
14
+ }
app/code/community/Lengow/Tracker/Model/Capsule.php CHANGED
@@ -1,35 +1,38 @@
1
  <?php
2
 
3
  /**
4
- * Lengow tracker model tracker
5
  *
6
  * @category Lengow
7
  * @package Lengow_Tracker
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Tracker_Model_Capsule extends Lengow_Tracker_Model_Tracker {
13
 
14
  /**
15
  * Return product quote or order
16
- *
17
  * @param $quote Order or Quote
 
18
  * @return string i(n)=(id_product_n)&p(n)=(unit_price_n)&q(n)=(quantity_n)
19
  */
20
- public function getProductsCart($quote) {
21
- if($quote instanceof Mage_Sales_Model_Quote || $quote instanceof Mage_Sales_Model_Order) {
 
22
  $quote_items = $quote->getAllVisibleItems();
23
  $list_products = array();
24
  $i = 1;
25
- foreach($quote_items as $item) {
26
- if($item->hasProduct())
27
  $product = $item->getProduct();
28
- else
29
  $product = Mage::getModel('catalog/product')->load($item->getProductId());
30
- $str = 'i' . $i . '=' . $product->getData($this->_getIdentifier());
31
- $str .= '&p' . $i . '=' . $item->getPrice();
32
- $str .= '&q' . $i . '=' . ($item->getQty() > 0 ? $item->getQty() : (integer) $item->getQtyOrdered());
 
33
  $list_products[] = $str;
34
  $i++;
35
  }
@@ -37,5 +40,4 @@ class Lengow_Tracker_Model_Capsule extends Lengow_Tracker_Model_Tracker {
37
  }
38
  return;
39
  }
40
-
41
- }
1
  <?php
2
 
3
  /**
4
+ * Lengow tracker model capsule
5
  *
6
  * @category Lengow
7
  * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Tracker_Model_Capsule extends Lengow_Tracker_Model_Tracker {
13
 
14
  /**
15
  * Return product quote or order
16
+ *
17
  * @param $quote Order or Quote
18
+ *
19
  * @return string i(n)=(id_product_n)&p(n)=(unit_price_n)&q(n)=(quantity_n)
20
  */
21
+ public function getProductsCart($quote)
22
+ {
23
+ if ($quote instanceof Mage_Sales_Model_Quote || $quote instanceof Mage_Sales_Model_Order) {
24
  $quote_items = $quote->getAllVisibleItems();
25
  $list_products = array();
26
  $i = 1;
27
+ foreach ($quote_items as $item) {
28
+ if ($item->hasProduct()) {
29
  $product = $item->getProduct();
30
+ } else {
31
  $product = Mage::getModel('catalog/product')->load($item->getProductId());
32
+ }
33
+ $str = 'i'.$i.'='.$product->getData($this->_getIdentifier());
34
+ $str.= '&p'.$i.'='.$item->getPrice();
35
+ $str.= '&q'.$i.'='.($item->getQty() > 0 ? $item->getQty() : (integer) $item->getQtyOrdered());
36
  $list_products[] = $str;
37
  $i++;
38
  }
40
  }
41
  return;
42
  }
43
+ }
 
app/code/community/Lengow/Tracker/Model/Config.php CHANGED
@@ -1,23 +1,24 @@
1
  <?php
2
 
3
  /**
4
- * Lengow export model config
5
  *
6
  * @category Lengow
7
  * @package Lengow_Tracker
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Tracker_Model_Config extends Varien_Object {
13
 
14
  protected $store;
15
 
16
- public function __construct($args = null)
17
  {
18
  parent::__construct();
19
- if (isset($args['store']))
20
  $this->setStore($args['store']);
 
21
  }
22
 
23
  public function setStore($store)
@@ -31,11 +32,13 @@ class Lengow_Tracker_Model_Config extends Varien_Object {
31
  return $this->store;
32
  }
33
 
34
- public function get($key) {
35
- if (is_null($this->store))
 
36
  $id_store = null;
37
- else
38
  $id_store = $this->store->getId();
39
- return Mage::getStoreConfig('lentracker/' . $key, $id_store);
 
40
  }
41
- }
1
  <?php
2
 
3
  /**
4
+ * Lengow tracker model config
5
  *
6
  * @category Lengow
7
  * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
  class Lengow_Tracker_Model_Config extends Varien_Object {
13
 
14
  protected $store;
15
 
16
+ public function __construct($args = null)
17
  {
18
  parent::__construct();
19
+ if (isset($args['store'])) {
20
  $this->setStore($args['store']);
21
+ }
22
  }
23
 
24
  public function setStore($store)
32
  return $this->store;
33
  }
34
 
35
+ public function get($key)
36
+ {
37
+ if (is_null($this->store)) {
38
  $id_store = null;
39
+ } else {
40
  $id_store = $this->store->getId();
41
+ }
42
+ return Mage::getStoreConfig('lentracker/'.$key, $id_store);
43
  }
44
+ }
app/code/community/Lengow/Tracker/Model/System/Config/Source/Identifiant.php CHANGED
@@ -1,12 +1,21 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
3
  class Lengow_Tracker_Model_System_Config_Source_Identifiant extends Mage_Core_Model_Config_Data {
4
 
5
- public function toOptionArray() {
 
6
  return array(
7
  array('value' => 'sku', 'label' => Mage::helper('adminhtml')->__('Sku')),
8
  array('value' => 'entity_id', 'label' => Mage::helper('adminhtml')->__('ID product')),
9
  );
10
  }
11
-
12
- }
1
  <?php
2
 
3
+ /**
4
+ * Lengow tracker model system config source identifiant
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
  class Lengow_Tracker_Model_System_Config_Source_Identifiant extends Mage_Core_Model_Config_Data {
13
 
14
+ public function toOptionArray()
15
+ {
16
  return array(
17
  array('value' => 'sku', 'label' => Mage::helper('adminhtml')->__('Sku')),
18
  array('value' => 'entity_id', 'label' => Mage::helper('adminhtml')->__('ID product')),
19
  );
20
  }
21
+ }
 
app/code/community/Lengow/Tracker/Model/System/Config/Source/Tracker.php CHANGED
@@ -1,13 +1,29 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
3
  class Lengow_Tracker_Model_System_Config_Source_Tracker extends Mage_Core_Model_Config_Data {
4
 
5
- public function toOptionArray() {
6
- return array(
7
- array('value' => 'none', 'label' => Mage::helper('adminhtml')->__('Aucun')),
8
- array('value' => 'simpletag', 'label' => Mage::helper('adminhtml')->__('SimpleTag')),
9
- array('value' => 'tagcapsule', 'label' => Mage::helper('adminhtml')->__('TagCapsule')),
10
- );
 
 
 
 
 
 
 
 
11
  }
12
-
13
- }
1
  <?php
2
 
3
+ /**
4
+ * Lengow tracker model system config source tracker
5
+ *
6
+ * @category Lengow
7
+ * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
+ */
12
  class Lengow_Tracker_Model_System_Config_Source_Tracker extends Mage_Core_Model_Config_Data {
13
 
14
+ public function toOptionArray()
15
+ {
16
+ if ((int)Mage::getStoreConfig('lentracker/general/version2')) {
17
+ return array(
18
+ array('value' => 'none', 'label' => Mage::helper('adminhtml')->__('Aucun')),
19
+ array('value' => 'simpletag', 'label' => Mage::helper('adminhtml')->__('SimpleTag')),
20
+ array('value' => 'tagcapsule', 'label' => Mage::helper('adminhtml')->__('TagCapsule')),
21
+ );
22
+ } else {
23
+ return array(
24
+ array('value' => 'none', 'label' => Mage::helper('adminhtml')->__('Aucun')),
25
+ array('value' => 'simpletag', 'label' => Mage::helper('adminhtml')->__('SimpleTag'))
26
+ );
27
+ }
28
  }
29
+ }
 
app/code/community/Lengow/Tracker/Model/Tracker.php CHANGED
@@ -1,31 +1,64 @@
1
  <?php
2
 
3
  /**
4
- * Lengow tracker model tracker
5
  *
6
  * @category Lengow
7
- * @package Lengow_Export
8
- * @author Romain Le Polh <romain@lengow.com>
9
- * @copyright 2013 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
- class Lengow_Tracker_Model_Tracker extends Varien_Object {
13
-
14
  /**
15
  * Return list of order's items id
16
  *
17
  * @param $order Mage_Sales_Model_Order
18
  * @return string
19
  */
20
- public function getIdsProducts($quote) {
21
- if($quote instanceof Mage_Sales_Model_Order || $quote instanceof Mage_Sales_Model_Quote) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  $quote_items = $quote->getAllVisibleItems();
23
  $ids = array();
24
- foreach($quote_items as $item) {
25
- if($item->hasProduct())
26
  $product = $item->getProduct();
27
- else
28
  $product = Mage::getModel('catalog/product')->load($item->getProductId());
 
29
  $ids[] = $product->getData($this->_getIdentifier());
30
  }
31
  return implode('|', $ids);
@@ -39,10 +72,9 @@ class Lengow_Tracker_Model_Tracker extends Varien_Object {
39
  * @param $order Mage_Sales_Model_Order
40
  * @return string
41
  */
42
- protected function _getIdentifier() {
 
43
  $config = Mage::getModel('lentracker/config');
44
  return $config->get('tag/identifiant');
45
  }
46
-
47
-
48
- }
1
  <?php
2
 
3
  /**
4
+ * Lengow tracker block tracker
5
  *
6
  * @category Lengow
7
+ * @package Lengow_Tracker
8
+ * @author Team Connector <team-connector@lengow.com>
9
+ * @copyright 2016 Lengow SAS
10
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
11
  */
12
+ class Lengow_Tracker_Model_Tracker extends Varien_Object
13
+ {
14
  /**
15
  * Return list of order's items id
16
  *
17
  * @param $order Mage_Sales_Model_Order
18
  * @return string
19
  */
20
+ public function getIdsProducts($quote)
21
+ {
22
+ if ($quote instanceof Mage_Sales_Model_Order || $quote instanceof Mage_Sales_Model_Quote) {
23
+ $quote_items = $quote->getAllVisibleItems();
24
+ $products_cart = array();
25
+ foreach ($quote_items as $item) {
26
+ if ($item->hasProduct()) {
27
+ $product = $item->getProduct();
28
+ } else {
29
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
30
+ }
31
+ $quantity = (int) $item->getQtyOrdered();
32
+ $price = round((float)$item->getRowTotalInclTax() / $quantity, 2);
33
+ $product_datas = array(
34
+ 'product_id' => $product->getData($this->_getIdentifier()),
35
+ 'price' => $price,
36
+ 'quantity' => $quantity
37
+ );
38
+ $products_cart[] = $product_datas;
39
+ }
40
+ return json_encode($products_cart);
41
+ }
42
+ return false;
43
+ }
44
+
45
+ /**
46
+ * Return list of order's items id for v2 version
47
+ *
48
+ * @param $order Mage_Sales_Model_Order
49
+ * @return string
50
+ */
51
+ public function getIdsProductsV2($quote)
52
+ {
53
+ if ($quote instanceof Mage_Sales_Model_Order || $quote instanceof Mage_Sales_Model_Quote) {
54
  $quote_items = $quote->getAllVisibleItems();
55
  $ids = array();
56
+ foreach ($quote_items as $item) {
57
+ if ($item->hasProduct()) {
58
  $product = $item->getProduct();
59
+ } else {
60
  $product = Mage::getModel('catalog/product')->load($item->getProductId());
61
+ }
62
  $ids[] = $product->getData($this->_getIdentifier());
63
  }
64
  return implode('|', $ids);
72
  * @param $order Mage_Sales_Model_Order
73
  * @return string
74
  */
75
+ protected function _getIdentifier()
76
+ {
77
  $config = Mage::getModel('lentracker/config');
78
  return $config->get('tag/identifiant');
79
  }
80
+ }
 
 
app/code/community/Lengow/Tracker/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Lengow_Tracker>
5
- <version>2.1.2</version>
6
  </Lengow_Tracker>
7
  </modules>
8
  <global>
@@ -101,6 +101,10 @@
101
  </adminhtml>
102
  <default>
103
  <lentracker>
 
 
 
 
104
  <tag>
105
  <identifiant>sku</identifiant>
106
  </tag>
2
  <config>
3
  <modules>
4
  <Lengow_Tracker>
5
+ <version>2.2.4</version>
6
  </Lengow_Tracker>
7
  </modules>
8
  <global>
101
  </adminhtml>
102
  <default>
103
  <lentracker>
104
+ <general>
105
+ <version2>1</version2>
106
+ <version3>0</version3>
107
+ </general>
108
  <tag>
109
  <identifiant>sku</identifiant>
110
  </tag>
app/code/community/Lengow/Tracker/etc/plugins.xml CHANGED
@@ -1,12 +1,12 @@
1
  <?xml version="1.0" encoding="UTF-8" ?>
2
  <plugins>
3
  <plugin name="prestashop">
4
- <version>2.0.5</version>
5
- <release_date>2014-04-08</release_date>
6
  </plugin>
7
  <plugin name="magento">
8
- <version>2.0.2</version>
9
- <release_date>2014-04-25</release_date>
10
  </plugin>
11
  <plugin name="woomcommerce">
12
  <version>1.0.0.0</version>
1
  <?xml version="1.0" encoding="UTF-8" ?>
2
  <plugins>
3
  <plugin name="prestashop">
4
+ <version>2.1.1</version>
5
+ <release_date>2015-12-31</release_date>
6
  </plugin>
7
  <plugin name="magento">
8
+ <version>2.1.2</version>
9
+ <release_date>2015-12-21</release_date>
10
  </plugin>
11
  <plugin name="woomcommerce">
12
  <version>1.0.0.0</version>
app/code/community/Lengow/Tracker/etc/system.xml CHANGED
@@ -28,37 +28,90 @@
28
  <general translate="label, comment">
29
  <label>Lengow API</label>
30
  <show_in_default>1</show_in_default>
31
- <show_in_website>1</show_in_website>
32
  <show_in_store>1</show_in_store>
33
  <sort_order>1</sort_order>
34
  <fields>
 
 
 
 
 
 
 
 
 
 
35
  <login>
36
  <label>Customer ID</label>
37
  <comment>Your Customer ID of Lengow</comment>
38
  <frontend_type>text</frontend_type>
39
- <sort_order>3</sort_order>
40
  <show_in_default>1</show_in_default>
41
  <show_in_website>0</show_in_website>
42
  <show_in_store>0</show_in_store>
 
43
  </login>
44
  <group>
45
  <label>Group ID</label>
46
  <comment>Your Group ID of Lengow</comment>
47
  <frontend_type>text</frontend_type>
48
- <sort_order>5</sort_order>
49
- <show_in_default>0</show_in_default>
50
  <show_in_website>0</show_in_website>
51
  <show_in_store>1</show_in_store>
 
52
  </group>
53
  <api_key>
54
  <label>Token API</label>
55
- <comment>You can find credentials on your Lengow Dashboard</comment>
56
  <frontend_type>text</frontend_type>
57
- <sort_order>20</sort_order>
58
  <show_in_default>1</show_in_default>
59
  <show_in_website>0</show_in_website>
60
  <show_in_store>0</show_in_store>
 
61
  </api_key>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  </fields>
63
  </general>
64
  <tag translate="label, comment">
28
  <general translate="label, comment">
29
  <label>Lengow API</label>
30
  <show_in_default>1</show_in_default>
31
+ <show_in_website>0</show_in_website>
32
  <show_in_store>1</show_in_store>
33
  <sort_order>1</sort_order>
34
  <fields>
35
+ <version2>
36
+ <label>Compatibility with the old version of the Lengow platform</label>
37
+ <comment>Activate this option if you have the old version of the Lengow platform</comment>
38
+ <frontend_type>select</frontend_type>
39
+ <sort_order>1</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>0</show_in_website>
42
+ <show_in_store>0</show_in_store>
43
+ <source_model>adminhtml/system_config_source_yesno</source_model>
44
+ </version2>
45
  <login>
46
  <label>Customer ID</label>
47
  <comment>Your Customer ID of Lengow</comment>
48
  <frontend_type>text</frontend_type>
49
+ <sort_order>2</sort_order>
50
  <show_in_default>1</show_in_default>
51
  <show_in_website>0</show_in_website>
52
  <show_in_store>0</show_in_store>
53
+ <depends><version2>1</version2></depends>
54
  </login>
55
  <group>
56
  <label>Group ID</label>
57
  <comment>Your Group ID of Lengow</comment>
58
  <frontend_type>text</frontend_type>
59
+ <sort_order>3</sort_order>
60
+ <show_in_default>1</show_in_default>
61
  <show_in_website>0</show_in_website>
62
  <show_in_store>1</show_in_store>
63
+ <depends><version2>1</version2></depends>
64
  </group>
65
  <api_key>
66
  <label>Token API</label>
67
+ <comment>Your Token API of Lengow</comment>
68
  <frontend_type>text</frontend_type>
69
+ <sort_order>4</sort_order>
70
  <show_in_default>1</show_in_default>
71
  <show_in_website>0</show_in_website>
72
  <show_in_store>0</show_in_store>
73
+ <depends><version2>1</version2></depends>
74
  </api_key>
75
+ <version3>
76
+ <label>Compatibility with the new version of the Lengow platform</label>
77
+ <comment>Activate this option if you have the new version of the Lengow platform</comment>
78
+ <frontend_type>select</frontend_type>
79
+ <sort_order>5</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>0</show_in_website>
82
+ <show_in_store>0</show_in_store>
83
+ <source_model>adminhtml/system_config_source_yesno</source_model>
84
+ </version3>
85
+ <account_id>
86
+ <label>Account ID</label>
87
+ <comment>Your Account ID of Lengow</comment>
88
+ <frontend_type>text</frontend_type>
89
+ <sort_order>6</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>0</show_in_website>
92
+ <show_in_store>1</show_in_store>
93
+ <depends><version3>1</version3></depends>
94
+ </account_id>
95
+ <access_token>
96
+ <label>Access token</label>
97
+ <comment>Your Access Token of Lengow</comment>
98
+ <frontend_type>text</frontend_type>
99
+ <sort_order>7</sort_order>
100
+ <show_in_default>1</show_in_default>
101
+ <show_in_website>0</show_in_website>
102
+ <show_in_store>1</show_in_store>
103
+ <depends><version3>1</version3></depends>
104
+ </access_token>
105
+ <secret>
106
+ <label>Secret</label>
107
+ <comment>Your Secret Token of Lengow</comment>
108
+ <frontend_type>text</frontend_type>
109
+ <sort_order>8</sort_order>
110
+ <show_in_default>1</show_in_default>
111
+ <show_in_website>0</show_in_website>
112
+ <show_in_store>1</show_in_store>
113
+ <depends><version3>1</version3></depends>
114
+ </secret>
115
  </fields>
116
  </general>
117
  <tag translate="label, comment">
app/design/adminhtml/default/default/layout/lengow.xml CHANGED
@@ -23,7 +23,7 @@
23
  <block type="lensync/adminhtml_log" name="manageorders.log.grid.container"></block>
24
  </reference>
25
  </adminhtml_lengow_log_index>
26
-
27
  <adminhtml_lengow_debug_index>
28
  <reference name="head">
29
  <action method="setTitle" translate="title">
@@ -34,8 +34,8 @@
34
  <block type="lensync/adminhtml_cron" name="cron.grid" template="lengow/debug/index.phtml"></block>
35
  </reference>
36
  </adminhtml_lengow_debug_index>
37
-
38
- <adminhtml_lengow_export_index>
39
  <reference name="head">
40
  <action method="setTitle" translate="title">
41
  <title>Lengow Manage Products</title>
@@ -50,30 +50,7 @@
50
  </block>
51
  </block>
52
  </reference>
53
- </adminhtml_lengow_export_index>
54
-
55
- <adminhtml_lengow_feed_index>
56
- <reference name="head">
57
- <action method="setTitle" translate="title">
58
- <title>Lengow Manage Feed</title>
59
- </action>
60
- <action method="addJs"><script>prototype/tooltip.js</script></action>
61
- <action method="addJs"><script>scriptaculous/scriptaculous.js</script></action>
62
- <action method="addItem">
63
- <type>js_css</type>
64
- <name>prototype/windows/themes/default.css</name>
65
- </action>
66
- </reference>
67
- <reference name="content">
68
- <block type="lenfeed/adminhtml_feed" name="feed.grid" template="lengow/feed/grid.phtml">
69
- <block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">
70
- <action method="setUseConfirm">
71
- <params>0</params>
72
- </action>
73
- </block>
74
- </block>
75
- </reference>
76
- </adminhtml_lengow_feed_index>
77
 
78
  <adminhtml_sales_order_view>
79
  <reference name="sales_order_tabs">
23
  <block type="lensync/adminhtml_log" name="manageorders.log.grid.container"></block>
24
  </reference>
25
  </adminhtml_lengow_log_index>
26
+
27
  <adminhtml_lengow_debug_index>
28
  <reference name="head">
29
  <action method="setTitle" translate="title">
34
  <block type="lensync/adminhtml_cron" name="cron.grid" template="lengow/debug/index.phtml"></block>
35
  </reference>
36
  </adminhtml_lengow_debug_index>
37
+
38
+ <adminhtml_lengow_product_index>
39
  <reference name="head">
40
  <action method="setTitle" translate="title">
41
  <title>Lengow Manage Products</title>
50
  </block>
51
  </block>
52
  </reference>
53
+ </adminhtml_lengow_product_index>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  <adminhtml_sales_order_view>
56
  <reference name="sales_order_tabs">
app/design/adminhtml/default/default/template/lengow/dashboard/charts.phtml DELETED
@@ -1,86 +0,0 @@
1
- <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
2
- <script type="text/javascript">
3
- $.noConflict();
4
- ;jQuery(document).ready(function($) {
5
- function lengowLoadStats(key) {
6
- var ctx = $("#lengow-stats").get(0).getContext("2d");
7
- var data = {
8
- labels: data_stats[key].evolution_libelle,
9
- datasets: [
10
- {
11
- fillColor: "rgba(151,187,205,0.5)",
12
- strokeColor: "rgba(151,187,205,1)",
13
- pointColor: "rgba(151,187,205,1)",
14
- pointStrokeColor: "#fff",
15
- data: data_stats[key].evolution_values
16
- }
17
- ]
18
- };
19
- new Chart(ctx).Line(data);
20
- }
21
- // admin dashboard
22
- $('#table-feeds').hide();
23
- $('#lengow-info').hide();
24
- var lengowAPI = 'https://solution.lengow.com/routine/PrestaShop/dashboard_plugin_v2.php?token=<?php echo $this->getData('api_key'); ?>&idClient=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>&callback=?',
25
- table_feeds = '',
26
- select = '',
27
- data_stats = {};
28
- $.getJSON(lengowAPI, function(json) {
29
- if (json.return == 'ok') {
30
- data_stats = json.stats;
31
- $('#lengow-load').hide();
32
- $.each(json.feeds, function(key, val){
33
- table_feeds += '<tr>'
34
- + '<td>' + json.feeds[key].id + '</td>'
35
- + '<td>' + json.feeds[key].type + '</td>'
36
- + '<td>' + json.feeds[key].diffuseur + '</td>'
37
- + '<td>' + json.feeds[key].nom + '</td>'
38
- + '<td>' + json.feeds[key].nbProduit + '</td>'
39
- + '<td>' + json.feeds[key].nbProduitActif + '</td>'
40
- + '</th>';
41
- });
42
- select = '<select name="lengow-change" id="lengow-change">';
43
- $.each(json.stats, function(key, val){
44
- select += '<option value="' + key + '">' + json.stats[key].name + '</option>';
45
- });
46
- select += '</select>';
47
- $('#table-feeds tbody').html(table_feeds);
48
- $('#table-feeds').show();
49
- $('#lengow-info').show();
50
- $('#lengow-change-select').html(select);
51
- $('#lengow-root').html('<canvas id="lengow-stats" width="587" height="400"></canvas>');
52
- $('#lengow-change').change(function() {
53
- var selected = $('#lengow-change').val();
54
- lengowLoadStats(selected);
55
- });
56
- lengowLoadStats(0);
57
- }
58
- });
59
- });
60
- </script>
61
- <div style="margin: 20px;">
62
-
63
- <div id="lengow-load"><?php echo Mage::helper('lendashboard')->__('Dashboard Lengow'); ?></div>
64
-
65
- <div class="switcher a-right" style="padding:5px 10px;" id="lengow-change-select"></div>
66
-
67
- <div id="lengow-info">
68
- <div id="lengow-root"></div>
69
- </div>
70
-
71
- <br />
72
- <table id="table-feeds">
73
- <thead>
74
- <tr>
75
- <th><span><?php echo Mage::helper('lendashboard')->__('ID'); ?></span></th>
76
- <th><span><?php echo Mage::helper('lendashboard')->__('Type'); ?></span></th>
77
- <th><span><?php echo Mage::helper('lendashboard')->__('Supplier'); ?></span></th>
78
- <th><span><?php echo Mage::helper('lendashboard')->__('Name'); ?></span></th>
79
- <th><span><?php echo Mage::helper('lendashboard')->__('Products'); ?></span></th>
80
- <th><span><?php echo Mage::helper('lendashboard')->__('Enable\'s products'); ?></span></th>
81
- </tr>
82
- </thead>
83
- <tbody></tbody>
84
- </table>
85
-
86
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/adminhtml/default/default/template/lengow/debug/index.phtml CHANGED
@@ -10,9 +10,8 @@
10
  </div>
11
 
12
  <?php
13
- $lenfeedConfig = Mage::getSingleton('lenfeed/config');
14
- $helperSecurity = Mage::helper('lenexport/security');
15
- $helperCheck = Mage::helper('lentracker/check');
16
  ?>
17
 
18
  <div>
@@ -26,113 +25,121 @@
26
  <td><?php echo $this->__('Magento version') ?></td>
27
  <td><?php echo Mage::getVersion(); ?></td>
28
  <?php
29
- if ($helperCheck->checkValidMagentoVersion()) {
30
- echo '<td class="lengow-debug-green">' . $this->__('Yes') . '</td>';
31
- } else {
32
- echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
33
- }
34
  ?>
35
  </tr>
36
  <tr>
37
  <td><?php echo $this->__('Plugin version'); ?></td>
38
  <td><?php echo Mage::helper('lensync/api')->getVersion(); ?></td>
39
  <?php
40
- if ($helperCheck->checkPluginVersion($helperCheck->getVersion())) {
41
- echo '<td class="lengow-debug-green">' . $this->__('Yes') . '</td>';
42
- } else {
43
- echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
44
- }
45
  ?>
46
  </tr>
47
- <tr>
48
- <td><?php echo $this->__('Server IP'); ?></td>
49
- <td colspan="2"><?php echo $_SERVER["SERVER_ADDR"]; ?></td>
50
- </tr>
 
 
51
  <tr>
52
  <td><?php echo $this->__('Ip authorised to export') ?></td>
53
  <?php
54
- $validIP = Mage::getStoreConfig('lenexport/performances/valid_ip');
55
- echo '<td class="a-right"><input type="text" value="' . $validIP . '"></td>';
56
- if ($helperSecurity->checkValidAuthorizedIP($validIP)) {
57
- echo '<td class="lengow-debug-green">' . $this->__('Yes') . '</td>';
58
- } else {
59
- echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
60
- }
61
  ?>
62
  </tr>
63
  <tr>
64
- <td><?php echo $this->__('Customer ID'); ?></td>
65
- <td colspan="2"><?php echo $lenfeedConfig->get('lentracker/general/login'); ?></td>
66
- </tr>
67
- <tr>
68
- <td><?php echo $this->__('Token API'); ?></td>
69
- <td colspan="2"><?php echo $lenfeedConfig->get('lentracker/general/api_key'); ?></td>
70
  </tr>
 
 
 
 
 
 
 
 
 
 
71
  <tr>
72
  <td><?php echo $this->__('Save feed on file') ?></td>
73
  <?php
74
- if (Mage::getStoreConfig('lenexport/performances/usesavefile')) {
75
- echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
76
- } else {
77
- echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
78
- }
79
  ?>
80
  </tr>
81
  <tr>
82
  <td><?php echo $this->__('Active cron') ?></td>
83
  <?php
84
- if (Mage::getStoreConfig('lenexport/performances/active_cron')) {
85
- echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
86
- } else {
87
- echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
88
- }
89
  ?>
90
  </tr>
91
  <tr>
92
  <td><?php echo $this->__('Auto import') ?></td>
93
  <?php
94
- if (Mage::getStoreConfig('lensync/performances/active_cron')) {
95
- echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
96
- } else {
97
- echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
98
- }
99
  ?>
100
  </tr>
101
  <tr>
102
  <td><?php echo $this->__('Debug mode') ?></td>
103
  <?php
104
- if (Mage::getStoreConfig('lensync/performances/debug')) {
105
- echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
106
- } else {
107
- echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
108
- }
109
  ?>
110
  </tr>
111
  <tr>
112
  <td><?php echo $this->__('The rights of import.flag file') ?></td>
113
  <?php
114
- $file_path = Mage::getBaseDir('media') . DS . 'lengow' . DS . 'import.flag';
115
- echo '<td colspan="2">' . substr(sprintf('%o', fileperms($file_path)), -4) . '</td>';
116
  ?>
117
  </tr>
118
  <tr>
119
  <td><?php echo $this->__('The rights of plugin.xml file') ?></td>
120
  <?php
121
- $file_path = Mage::getModuleDir('etc', 'Lengow_Tracker') . DS . 'plugins.xml';
122
- echo '<td colspan="2">' . substr(sprintf('%o', fileperms($file_path)), -4) . '</td>';
123
  ?>
124
  </tr>
125
  <tr>
126
  <td><?php echo $this->__('Write permission from media folder') ?></td>
127
  <?php
128
- $file_path = Mage::getBaseDir('media') . DS . 'lengow' . DS .'test.txt';
129
- $file = fopen($file_path, "w+");
130
- if($file == false) {
131
- echo '<td class="lengow-debug-red" colspan="2">' . $this->__('No') . '</td>';
132
- } else {
133
- echo '<td class="lengow-debug-green" colspan="2">' . $this->__('Yes') . '</td>';
134
- unlink($file_path);
135
- }
136
  ?>
137
  </tr>
138
  </table>
@@ -163,16 +170,39 @@
163
  } else {
164
  echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
165
  }
166
- echo '</tr>';
167
- echo '<tr>';
168
- echo '<td>' . $this->__('Group ID') . '</td>';
169
- echo '<td>' . Mage::getStoreConfig('lentracker/general/group', $store) . '</td>';
170
- echo '</tr>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  echo '<tr>';
172
  echo '<td>' . $this->__('Feed Url') . '</td>';
173
- $urlFeed = Mage::getUrl('lengow/feed', array('store' => $store->getId(), '_current' => false)) ;
174
- echo '<td><input type="text" class="lengow-feed-input" value="'.$urlFeed.'" READONLY>
175
- - <a href="'.$urlFeed.'">'.$this->__('View feed').'</a></td>';
 
176
  echo '</tr>';
177
  echo '</table><br/>';
178
  }
@@ -181,17 +211,17 @@
181
  ?>
182
  </div>
183
  </td>
184
- <td style="width:550px">
185
  <h2><?php echo $this->__('Content folder media'); ?></h2>
186
  <div class="grid">
187
- <?php
188
  foreach (Mage::app()->getWebsites() as $website) {
189
  foreach ($website->getGroups() as $group) {
190
  $stores = $group->getStores();
191
  foreach ($stores as $store) {
192
  $folder_path = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store->getCode() . DS;
193
- $folder_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'lengow' . DS . $store->getCode() . DS;
194
- $files = array_diff(scandir($folder_path), array('..', '.'));
195
  echo '<table class="data">';
196
  echo '<tr><td colspan="3" class="lengow-debug-store">' . $this->__('Store') . ' : ' . $store->getName() . ' (' . $store->getId() . ')</td></tr>';
197
  echo '<tr><td>' . $this->__('Path folder') . '</td><td colspan="2">' . $folder_path . '</td></tr>';
@@ -199,14 +229,14 @@
199
  if (count($files) > 0) {
200
  date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
201
  foreach ($files as $file) {
202
- echo '<tr><td>'.$file.'</td>';
203
- echo '<td>'.date("F d Y H:i:s", filectime($folder_path.$file)).'</td>';
204
- echo '<td><a href="' . $folder_url.$file . '" target="_blank">' . $this->__('View file') . '</a></td></tr>';
205
  }
206
  } else {
207
  echo '<tr><td colspan="3" class="lengow-debug-red">' . $this->__('No file exported') . '</td></tr>';
208
  }
209
- echo '</table><br/>';
210
  }
211
  }
212
  }
@@ -219,4 +249,4 @@
219
  <h2><?php echo $this->__('Viewing cron jobs'); ?></h2>
220
  <?php echo $this->getGridHtml() ?>
221
  </div>
222
- </div>
10
  </div>
11
 
12
  <?php
13
+ $helperSecurity = Mage::helper('lenexport/security');
14
+ $helperCheck = Mage::helper('lentracker/check');
 
15
  ?>
16
 
17
  <div>
25
  <td><?php echo $this->__('Magento version') ?></td>
26
  <td><?php echo Mage::getVersion(); ?></td>
27
  <?php
28
+ if ($helperCheck->checkValidMagentoVersion()) {
29
+ echo '<td class="lengow-debug-green">' . $this->__('Yes') . '</td>';
30
+ } else {
31
+ echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
32
+ }
33
  ?>
34
  </tr>
35
  <tr>
36
  <td><?php echo $this->__('Plugin version'); ?></td>
37
  <td><?php echo Mage::helper('lensync/api')->getVersion(); ?></td>
38
  <?php
39
+ if ($helperCheck->checkPluginVersion($helperCheck->getVersion())) {
40
+ echo '<td class="lengow-debug-green">' . $this->__('Yes') . '</td>';
41
+ } else {
42
+ echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
43
+ }
44
  ?>
45
  </tr>
46
+ <?php if (!(int)Mage::getStoreConfig('lentracker/general/version3')) { ?>
47
+ <tr>
48
+ <td><?php echo $this->__('Server IP'); ?></td>
49
+ <td colspan="2"><?php echo $_SERVER["SERVER_ADDR"]; ?></td>
50
+ </tr>
51
+ <?php } ?>
52
  <tr>
53
  <td><?php echo $this->__('Ip authorised to export') ?></td>
54
  <?php
55
+ $validIP = Mage::getStoreConfig('lenexport/performances/valid_ip');
56
+ echo '<td class="a-right"><input type="text" value="' . $validIP . '"></td>';
57
+ if ($helperSecurity->checkValidAuthorizedIP($validIP)) {
58
+ echo '<td class="lengow-debug-green">' . $this->__('Yes') . '</td>';
59
+ } else {
60
+ echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
61
+ }
62
  ?>
63
  </tr>
64
  <tr>
65
+ <td><?php echo $this->__('Server IP'); ?></td>
66
+ <td colspan="2"><?php echo $_SERVER["SERVER_ADDR"]; ?></td>
 
 
 
 
67
  </tr>
68
+ <?php if (!(int)Mage::getStoreConfig('lentracker/general/version3')) { ?>
69
+ <tr>
70
+ <td><?php echo $this->__('Customer ID'); ?></td>
71
+ <td colspan="2"><?php echo Mage::getStoreConfig('lentracker/general/login'); ?></td>
72
+ </tr>
73
+ <tr>
74
+ <td><?php echo $this->__('Token API'); ?></td>
75
+ <td colspan="2"><?php echo Mage::getStoreConfig('lentracker/general/api_key'); ?></td>
76
+ </tr>
77
+ <?php } ?>
78
  <tr>
79
  <td><?php echo $this->__('Save feed on file') ?></td>
80
  <?php
81
+ if (Mage::getStoreConfig('lenexport/performances/usesavefile')) {
82
+ echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
83
+ } else {
84
+ echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
85
+ }
86
  ?>
87
  </tr>
88
  <tr>
89
  <td><?php echo $this->__('Active cron') ?></td>
90
  <?php
91
+ if (Mage::getStoreConfig('lenexport/performances/active_cron')) {
92
+ echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
93
+ } else {
94
+ echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
95
+ }
96
  ?>
97
  </tr>
98
  <tr>
99
  <td><?php echo $this->__('Auto import') ?></td>
100
  <?php
101
+ if (Mage::getStoreConfig('lensync/performances/active_cron')) {
102
+ echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
103
+ } else {
104
+ echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
105
+ }
106
  ?>
107
  </tr>
108
  <tr>
109
  <td><?php echo $this->__('Debug mode') ?></td>
110
  <?php
111
+ if (Mage::getStoreConfig('lensync/performances/debug')) {
112
+ echo '<td colspan="2" class="lengow-debug-green">' . $this->__('Enabled') . '</td>';
113
+ } else {
114
+ echo '<td colspan="2" class="lengow-debug-red">' . $this->__('Disabled') . '</td>';
115
+ }
116
  ?>
117
  </tr>
118
  <tr>
119
  <td><?php echo $this->__('The rights of import.flag file') ?></td>
120
  <?php
121
+ $file_path = Mage::getBaseDir('media') . DS . 'lengow' . DS . 'import.flag';
122
+ echo '<td colspan="2">' . substr(sprintf('%o', fileperms($file_path)), -4) . '</td>';
123
  ?>
124
  </tr>
125
  <tr>
126
  <td><?php echo $this->__('The rights of plugin.xml file') ?></td>
127
  <?php
128
+ $file_path = Mage::getModuleDir('etc', 'Lengow_Tracker') . DS . 'plugins.xml';
129
+ echo '<td colspan="2">' . substr(sprintf('%o', fileperms($file_path)), -4) . '</td>';
130
  ?>
131
  </tr>
132
  <tr>
133
  <td><?php echo $this->__('Write permission from media folder') ?></td>
134
  <?php
135
+ $file_path = Mage::getBaseDir('media') . DS . 'lengow' . DS . 'test.txt';
136
+ $file = fopen($file_path, "w+");
137
+ if ($file == false) {
138
+ echo '<td class="lengow-debug-red" colspan="2">' . $this->__('No') . '</td>';
139
+ } else {
140
+ echo '<td class="lengow-debug-green" colspan="2">' . $this->__('Yes') . '</td>';
141
+ unlink($file_path);
142
+ }
143
  ?>
144
  </tr>
145
  </table>
170
  } else {
171
  echo '<td class="lengow-debug-red">' . $this->__('No') . '</td>';
172
  }
173
+ if (!(int)Mage::getStoreConfig('lentracker/general/version3')) {
174
+ echo '</tr>';
175
+ echo '<tr>';
176
+ echo '<td>' . $this->__('Group ID') . '</td>';
177
+ echo '<td>' . Mage::getStoreConfig('lentracker/general/group', $store) . '</td>';
178
+ echo '</tr>';
179
+ } else {
180
+
181
+ echo '<tr>';
182
+ echo '<td>' . $this->__('Account ID') . '</td>';
183
+ echo '<td>' . Mage::getStoreConfig('lentracker/general/account_id',
184
+ $store) . '</td>';
185
+ echo '</tr>';
186
+ echo '<tr>';
187
+ echo '<td>' . $this->__('Access Token') . '</td>';
188
+ echo '<td>' . Mage::getStoreConfig('lentracker/general/access_token',
189
+ $store) . '</td>';
190
+ echo '</tr>';
191
+ echo '<tr>';
192
+ echo '<td>' . $this->__('Secret') . '</td>';
193
+ echo '<td>' . Mage::getStoreConfig('lentracker/general/secret', $store) . '</td>';
194
+ echo '</tr>';
195
+ echo '<tr>';
196
+ echo '<td>' . $this->__('Marketplace') . '</td>';
197
+ echo '<td>' . Mage::getStoreConfig('lensync/orders/marketplace', $store) . '</td>';
198
+ echo '</tr>';
199
+ }
200
  echo '<tr>';
201
  echo '<td>' . $this->__('Feed Url') . '</td>';
202
+ $urlFeed = Mage::getUrl('lengow/feed',
203
+ array('store' => $store->getId(), '_current' => false));
204
+ echo '<td><input type="text" class="lengow-feed-input" value="' . $urlFeed . '" READONLY>
205
+ - <a href="' . $urlFeed . '" target="_blank">' . $this->__('View feed') . '</a></td>';
206
  echo '</tr>';
207
  echo '</table><br/>';
208
  }
211
  ?>
212
  </div>
213
  </td>
214
+ <td style="width:550px">
215
  <h2><?php echo $this->__('Content folder media'); ?></h2>
216
  <div class="grid">
217
+ <?php
218
  foreach (Mage::app()->getWebsites() as $website) {
219
  foreach ($website->getGroups() as $group) {
220
  $stores = $group->getStores();
221
  foreach ($stores as $store) {
222
  $folder_path = Mage::getBaseDir('media') . DS . 'lengow' . DS . $store->getCode() . DS;
223
+ $folder_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'lengow' . DS . $store->getCode() . DS;
224
+ $files = @array_diff(scandir($folder_path), array('..', '.'));
225
  echo '<table class="data">';
226
  echo '<tr><td colspan="3" class="lengow-debug-store">' . $this->__('Store') . ' : ' . $store->getName() . ' (' . $store->getId() . ')</td></tr>';
227
  echo '<tr><td>' . $this->__('Path folder') . '</td><td colspan="2">' . $folder_path . '</td></tr>';
229
  if (count($files) > 0) {
230
  date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
231
  foreach ($files as $file) {
232
+ echo '<tr><td>' . $file . '</td>';
233
+ echo '<td>' . date("F d Y H:i:s", filectime($folder_path . $file)) . '</td>';
234
+ echo '<td><a href="' . $folder_url . $file . '" target="_blank">' . $this->__('View file') . '</a></td></tr>';
235
  }
236
  } else {
237
  echo '<tr><td colspan="3" class="lengow-debug-red">' . $this->__('No file exported') . '</td></tr>';
238
  }
239
+ echo '</table><br/>';
240
  }
241
  }
242
  }
249
  <h2><?php echo $this->__('Viewing cron jobs'); ?></h2>
250
  <?php echo $this->getGridHtml() ?>
251
  </div>
252
+ </div>
app/design/adminhtml/default/default/template/lengow/feed/grid.phtml DELETED
@@ -1,61 +0,0 @@
1
- <?php
2
- /**
3
- * @var $this Lengow_Feed_Block_Adminhtml_Feed
4
- * @see Lengow_Feed
5
- */
6
- ?>
7
- <div class="content-header">
8
- <table cellspacing="0">
9
- <tr>
10
- <td style="width:50%;">
11
- <h3 class="icon-head head-products">
12
- <?php echo Mage::helper('lenfeed')->__('Feeds management') ?>
13
- </h3>
14
- </td>
15
- <td class="a-right">
16
- <?php echo $this->getButtonsHtml() ?>
17
- </td>
18
- </tr>
19
- </table>
20
- </div>
21
- <?php if (!$this->isSingleStoreMode()): ?>
22
- <?php echo $this->getChildHtml('store_switcher'); ?>
23
- <?php endif; ?>
24
- <?php
25
- $_store_id = $this->getRequest()->getParam('store');
26
- $args = array();
27
- if(!empty($_store_id))
28
- $args['store'] = $_store_id;
29
- ?>
30
- <div>
31
- <form method="post" id="form_grid_feed" action="<?php echo $this->getUrl('*/*/migrate', $args); ?>">
32
- <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
33
- <?php echo $this->getGridHtml() ?>
34
- </form>
35
- </div>
36
- <style>
37
- .tooltip {
38
- color: #000;
39
- background: #fff;
40
- border: 2px solid #ea7601;
41
- padding: 10px;
42
- overflow: visible;
43
- }
44
- .tooltip .toolbar {
45
- background: #0F6788;
46
- font: italic 17px Georgia, serif;
47
- }
48
- .tooltip .title { padding: 5px; }
49
- .tooltip .content {
50
- background: dodgerblue;
51
- font: 11px Arial, Helvetica, sans-serif;
52
- padding: 5px;
53
- }
54
- </style>
55
- <script type="text/javascript">
56
- document.observe("dom:loaded", function() {
57
- $$('.popup-link').each(function(element) {
58
- new Tooltip(element, element.readAttribute('data-link'));
59
- })
60
- });
61
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/frontend/base/default/layout/lengow.xml CHANGED
@@ -5,14 +5,9 @@
5
  <block type="lentracker/tracker" name="lengow_tracker" template="lengow/tracker/tag.phtml" />
6
  </reference>
7
  </default>
8
-
9
  <checkout_onepage_index translate="label">
10
  <reference name="head">
11
- <action method="addItem">
12
- <type>skin_js</type>
13
- <name>lengow/js/tracker.js</name>
14
- </action>
15
  </reference>
16
  </checkout_onepage_index>
17
-
18
  </layout>
5
  <block type="lentracker/tracker" name="lengow_tracker" template="lengow/tracker/tag.phtml" />
6
  </reference>
7
  </default>
 
8
  <checkout_onepage_index translate="label">
9
  <reference name="head">
10
+ <action method="addItem"><type>skin_js</type><name>lengow/js/tracker.js</name></action>
 
 
 
11
  </reference>
12
  </checkout_onepage_index>
 
13
  </layout>
app/design/frontend/base/default/template/lengow/tracker/simpletag.phtml CHANGED
@@ -1,4 +1,19 @@
1
  <!-- Tag_Lengow -->
2
- <img src="https://tracking.lengow.com/lead.php?idClient=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>&price=<?php echo $this->getData('total_paid'); ?>&idCommande=<?php echo $this->getData('id_order'); ?>&modePaiement=<?php echo $this->getData('mode_paiement'); ?>&listingProduit=<?php echo $this->getData('ids_products'); ?>" alt="" style="width: 1px; height: 1px; border: none;" />
3
- <img src="https://tracking.lengow.com/leadValidation.php?idClient=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>&idCommande=<?php echo $this->getData('id_order'); ?>" alt="" style="width: 1px; height: 1px; border: none;" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  <!-- /Tag_Lengow -->
1
  <!-- Tag_Lengow -->
2
+ <?php if ((int)Mage::getStoreConfig('lentracker/general/version2')) { ?>
3
+ <img
4
+ src="https://tracking.lengow.com/lead.php?idClient=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>&price=<?php echo $this->getData('total_paid'); ?>&idCommande=<?php echo $this->getData('id_order'); ?>&modePaiement=<?php echo $this->getData('mode_paiement'); ?>&listingProduit=<?php echo $this->getData('ids_products'); ?>"
5
+ alt="" style="width: 1px; height: 1px; border: none;"/>
6
+ <img
7
+ src="https://tracking.lengow.com/leadValidation.php?idClient=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>&idCommande=<?php echo $this->getData('id_order'); ?>"
8
+ alt="" style="width: 1px; height: 1px; border: none;"/>
9
+
10
+ <?php } ?>
11
+ <?php if ((int)Mage::getStoreConfig('lentracker/general/version3')) { ?>
12
+ <img
13
+ src="https://trk.lgw.io/lead?account_id=<?php echo $this->getData('account_id'); ?>&order_ref=<?php echo $this->getData('order_ref'); ?>&amount=<?php echo $this->getData('amount'); ?>&currency=<?php echo $this->getData('currency'); ?>&payment_method=<?php echo $this->getData('payment_method'); ?>&cart=<?php echo $this->getData('cart'); ?>&cart_number=<?php echo $this->getData('cart_number'); ?>&newbiz=<?php echo $this->getData('newbiz'); ?>"
14
+ alt="" style="width: 1px; height: 1px; border: none;"/>
15
+ <img
16
+ src="https://trk.lgw.io/validation?account_id=<?php echo $this->getData('account_id'); ?>&order_ref=<?php echo $this->getData('order_ref'); ?>&payment_method=<?php echo $this->getData('payment_method'); ?>&valid=<?php echo $this->getData('valid'); ?>"
17
+ alt="" style="width: 1px; height: 1px; border: none;"/>
18
+ <?php } ?>
19
  <!-- /Tag_Lengow -->
app/design/frontend/base/default/template/lengow/tracker/tagcapsule.phtml CHANGED
@@ -11,7 +11,8 @@ if ($this->getData('controller') == 'onepage' && $this->getData('current_action'
11
  ssl = '<?php echo $this->getData('use_ssl'); ?>';
12
  id_categorie = '<?php echo $this->getData('id_category'); ?>'; // #ID CATEGORIE EN COURS#
13
  </script>
14
- <script type="text/javascript" src="https://tracking.lengow.com/tagcapsule.js?lengow_id=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>"></script>
 
15
  <?php
16
  }
17
  ?>
@@ -26,6 +27,6 @@ if ($this->getData('controller') == 'onepage' && $this->getData('current_action'
26
  var id_categorie = '<?php echo $this->getData('id_category'); ?>'; // #ID CATEGORIE EN COURS#
27
  </script>
28
  </div>
29
- <script id="url_script" type="text/javascript" src="https://tracking.lengow.com/tagcapsule.js?lengow_id=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>"></script>
30
-
31
  <!-- /Tag_Lengow -->
11
  ssl = '<?php echo $this->getData('use_ssl'); ?>';
12
  id_categorie = '<?php echo $this->getData('id_category'); ?>'; // #ID CATEGORIE EN COURS#
13
  </script>
14
+ <script type="text/javascript"
15
+ src="https://tracking.lengow.com/tagcapsule.js?lengow_id=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>"></script>
16
  <?php
17
  }
18
  ?>
27
  var id_categorie = '<?php echo $this->getData('id_category'); ?>'; // #ID CATEGORIE EN COURS#
28
  </script>
29
  </div>
30
+ <script id="url_script" type="text/javascript"
31
+ src="https://tracking.lengow.com/tagcapsule.js?lengow_id=<?php echo $this->getData('id_client'); ?>&idGroup=<?php echo $this->getData('id_group'); ?>"></script>
32
  <!-- /Tag_Lengow -->
app/etc/modules/Lengow_Connector.xml CHANGED
@@ -2,7 +2,7 @@
2
  <!--
3
 
4
  /**
5
- * Copyright 2013 Lengow.
6
  *
7
  * Licensed under the Apache License, Version 2.0 (the "License"); you may
8
  * not use this file except in compliance with the License. You may obtain
@@ -19,7 +19,7 @@
19
 
20
  * @category Lengow
21
  * @package Lengow_All
22
- * @copyright Copyright (c) 2013 Lengow SAS (http://www.lengow.com)
23
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
24
  */
25
  -->
@@ -54,19 +54,5 @@
54
  <Mage_Sales />
55
  </depends>
56
  </Lengow_Tracker>
57
- <Lengow_Dashboard>
58
- <active>true</active>
59
- <codePool>community</codePool>
60
- <depends>
61
- <Mage_Adminhtml />
62
- </depends>
63
- </Lengow_Dashboard>
64
- <Lengow_Feed>
65
- <active>true</active>
66
- <codePool>community</codePool>
67
- <depends>
68
- <Mage_Adminhtml />
69
- </depends>
70
- </Lengow_Feed>
71
  </modules>
72
  </config>
2
  <!--
3
 
4
  /**
5
+ * Copyright 2015 Lengow.
6
  *
7
  * Licensed under the Apache License, Version 2.0 (the "License"); you may
8
  * not use this file except in compliance with the License. You may obtain
19
 
20
  * @category Lengow
21
  * @package Lengow_All
22
+ * @copyright Copyright (c) 2015 Lengow SAS (http://www.lengow.com)
23
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
24
  */
25
  -->
54
  <Mage_Sales />
55
  </depends>
56
  </Lengow_Tracker>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  </modules>
58
  </config>
app/locale/fr_FR/Lengow_Connector.csv CHANGED
@@ -1,6 +1,9 @@
1
  "Anglais","Français"
2
  "Export Configuration","Configuration de l'export"
3
  "Global","Global"
 
 
 
4
  "Ip authorised to export","Ip autorisée pour l'export"
5
  "Authorized acces to catalog export by IP, separated by ;","Autoriser l'accès de l'export du catalogue aux IPs séparées par des ;"
6
  "Export only selected product","Exporter uniquement les produits sélectionnés"
@@ -18,7 +21,8 @@
18
  "Default shipping cost if matching find","Coût par défaut de la livraison si aucune correspondance n'est trouvée"
19
  "Shipping method","Méthode de transport"
20
  "Default shipping method to calculate shipping cost","Méthode de transport par défaut pour calculer les frais d'envois"
21
- "Export default format","Format d'export par défaut"
 
22
  "Performances","Performances"
23
  "Save feed on file","Sauvegarder le flux dans un fichier"
24
  "Save the feed on a file","Sauvegarder votre flux dans un fichier"
@@ -31,7 +35,7 @@
31
  "Feed configuration","Gestion des flux"
32
  "Manage Orders","Gestion des commandes"
33
  "Import orders from x days","Importer les commandes depuis x jours"
34
- "Choose a number of days","Indiquer le nombre de jours "
35
  "Auto import","Import automatique"
36
  "Enable import every 30 minutes","Activer l'import automatique toutes les 30 min"
37
  "Debug mode","Mode debug"
@@ -44,6 +48,13 @@
44
  "Group ID","IdGroup"
45
  "Your Group ID of Lengow","Votre ID groupe Lengow"
46
  "Token API","Token API"
 
 
 
 
 
 
 
47
  "Tracker Type","Type de tracker"
48
  "Dashboard Lengow","Dashboard Lengow"
49
  "ID","ID"
@@ -86,27 +97,11 @@
86
  "Bundle","Packagé"
87
  "Grouped","Groupé"
88
  "Virtual","Virtuel"
89
- "Your feed is available here : %s","Votre flux est disponible ici : %s"
90
- "View feed","Voir le flux"
91
- "Feed ID","ID Flux"
92
- "Feed Name","Nom du flux"
93
- "Current Feed","Flux actuel"
94
- "Enabled store","Boutique activée"
95
- "Enable store to export","Active la boutique pour l'exportation"
96
- "Enable store to import","Active la boutique pour l'importation"
97
- "Export only selected product","Exporter seulement les produits sélectionnés"
98
- "Export product out of stock","Exporter les produits sans stock"
99
- "Product type to export","Type de produit à exporter"
100
- "Status of product to export","Statut des produits à exporter"
101
- "Format export","Format de l'export"
102
- "Action","Action"
103
- "Migrate all selected feeds","Migrer tous les flux"
104
- "Update success","Mise à jour réussi"
105
- "Error update feed %s","Erreur dans la mise à jour du flux %s"
106
  "Created at","Date création"
107
  "Message","Message"
108
  "Order #","Commande #"
109
  "Purchased From (Store)","Acheté sur (Magasin)"
 
110
  "Bill to Name","Nom (Fact.)"
111
  "Ship to Name","Nom (Livr.)"
112
  "G.T. (Base)","Montant total (Devise de base)"
@@ -137,6 +132,7 @@
137
  "%d orders are imported","%d commandes ont été importées"
138
  "%d orders are updated","%d commande ont été mises à jour"
139
  "No order available to import","Aucune commande n'est disponible à l'import"
 
140
  "Module's version","Version du module"
141
  "IP of your server","IP du serveur"
142
  "Your module is already updated","Votre module est bien à jour"
@@ -164,15 +160,13 @@
164
  "Auto export a new product on Lengow","Export automatique des nouveaux produits dans Lengow"
165
  "Choose Store View:","Sélectionner votre vue"
166
  "Import processing fee from Marketplace","Importer les frais de traitement des markeplaces"
167
- "Import the processing fee","Importer les frais de traitement"
168
  "Keep html for the selected fields","Garder l'HTML pour les champs sélectionnés"
169
  "Choose default shipping","Sélectionner le transporteur par défaut"
170
  "Default shipping method","La méthode de transport par défaut"
171
- "Use fictitious emails","Utilisation d'emails fictifs"
172
  "Use fictitious emails for customer creation","Utilisation d'emails fictifs pour la création de client"
 
173
  "Import is already started","Une importation est déjà en cours"
174
- "Please checks your plugin configuration. ID customer or token API is empty","Merci de vérifier votre configuration de plugin. L'ID client ou le token API est vide"
175
- "Please checks your plugin configuration. No store enabled to import","Merci de vérifier votre configuration de plugin. Aucune boutique active pour l'importation"
176
  "Debug","Debug"
177
  "Global information","Information globale"
178
  "Magento version","Version de Magento"
@@ -191,6 +185,7 @@
191
  "Path folder","Chemin du dossier"
192
  "File list","Liste de fichier"
193
  "View file","Voir le fichier"
 
194
  "Viewing cron jobs","Visualisation des tâches cron"
195
  "Update cron table","Mettre à jour la table cron"
196
  "Cron Configuration","Configuration du cron"
@@ -200,6 +195,8 @@
200
  "Finished at","Date de fin"
201
  "Optimize Export File","Flux d'export optimisé"
202
  "Beta feature: enable this option to get a faster export","Fonctionnalité en test : activez cette option pour profiter d'un export plus rapide"
203
- "Purchased On","Date d'achat"
204
- "You can find credentials on your Lengow Dashboard","Vous pouvez retrouver vos informations clients dans votre espace Lengow"
205
- "Manage Feeds","Gestion des flux"
 
 
1
  "Anglais","Français"
2
  "Export Configuration","Configuration de l'export"
3
  "Global","Global"
4
+ "Enabled store","Boutique activée"
5
+ "Enable store to export","Active la boutique pour l'exportation"
6
+ "Enable store to import","Active la boutique pour l'importation"
7
  "Ip authorised to export","Ip autorisée pour l'export"
8
  "Authorized acces to catalog export by IP, separated by ;","Autoriser l'accès de l'export du catalogue aux IPs séparées par des ;"
9
  "Export only selected product","Exporter uniquement les produits sélectionnés"
21
  "Default shipping cost if matching find","Coût par défaut de la livraison si aucune correspondance n'est trouvée"
22
  "Shipping method","Méthode de transport"
23
  "Default shipping method to calculate shipping cost","Méthode de transport par défaut pour calculer les frais d'envois"
24
+ "Data","Data"
25
+ "Format","Format"
26
  "Performances","Performances"
27
  "Save feed on file","Sauvegarder le flux dans un fichier"
28
  "Save the feed on a file","Sauvegarder votre flux dans un fichier"
35
  "Feed configuration","Gestion des flux"
36
  "Manage Orders","Gestion des commandes"
37
  "Import orders from x days","Importer les commandes depuis x jours"
38
+ "Choose a number of days","Indiquer le nombre de jours"
39
  "Auto import","Import automatique"
40
  "Enable import every 30 minutes","Activer l'import automatique toutes les 30 min"
41
  "Debug mode","Mode debug"
48
  "Group ID","IdGroup"
49
  "Your Group ID of Lengow","Votre ID groupe Lengow"
50
  "Token API","Token API"
51
+ "Your Token API of Lengow","Votre Token API Lengow"
52
+ "Account ID","ID compte"
53
+ "Your Account ID of Lengow","Votre ID compte Lengow"
54
+ "Access token","Token d'accès"
55
+ "Your Access Token of Lengow","Votre token d'accès Lengow"
56
+ "Secret","Secret"
57
+ "Your Secret Token of Lengow","Votre token secret Lengow"
58
  "Tracker Type","Type de tracker"
59
  "Dashboard Lengow","Dashboard Lengow"
60
  "ID","ID"
97
  "Bundle","Packagé"
98
  "Grouped","Groupé"
99
  "Virtual","Virtuel"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  "Created at","Date création"
101
  "Message","Message"
102
  "Order #","Commande #"
103
  "Purchased From (Store)","Acheté sur (Magasin)"
104
+ "Purchased On","Date d'achat"
105
  "Bill to Name","Nom (Fact.)"
106
  "Ship to Name","Nom (Livr.)"
107
  "G.T. (Base)","Montant total (Devise de base)"
132
  "%d orders are imported","%d commandes ont été importées"
133
  "%d orders are updated","%d commande ont été mises à jour"
134
  "No order available to import","Aucune commande n'est disponible à l'import"
135
+ "Please checks your plugin configuration. No store enabled to import","Merci de vérifier votre configuration de plugin. Aucune boutique active pour l'importation"
136
  "Module's version","Version du module"
137
  "IP of your server","IP du serveur"
138
  "Your module is already updated","Votre module est bien à jour"
160
  "Auto export a new product on Lengow","Export automatique des nouveaux produits dans Lengow"
161
  "Choose Store View:","Sélectionner votre vue"
162
  "Import processing fee from Marketplace","Importer les frais de traitement des markeplaces"
 
163
  "Keep html for the selected fields","Garder l'HTML pour les champs sélectionnés"
164
  "Choose default shipping","Sélectionner le transporteur par défaut"
165
  "Default shipping method","La méthode de transport par défaut"
166
+ "Use fictitious emails","Utilisation de d'emails fictifs"
167
  "Use fictitious emails for customer creation","Utilisation d'emails fictifs pour la création de client"
168
+ "Choice of marketplaces for import","Choix des marketplaces pour l'import"
169
  "Import is already started","Une importation est déjà en cours"
 
 
170
  "Debug","Debug"
171
  "Global information","Information globale"
172
  "Magento version","Version de Magento"
185
  "Path folder","Chemin du dossier"
186
  "File list","Liste de fichier"
187
  "View file","Voir le fichier"
188
+ "No file exported","Pas de fichier exporté"
189
  "Viewing cron jobs","Visualisation des tâches cron"
190
  "Update cron table","Mettre à jour la table cron"
191
  "Cron Configuration","Configuration du cron"
195
  "Finished at","Date de fin"
196
  "Optimize Export File","Flux d'export optimisé"
197
  "Beta feature: enable this option to get a faster export","Fonctionnalité en test : activez cette option pour profiter d'un export plus rapide"
198
+ "Export default format","Format d'export par défaut"
199
+ "Compatibility with the old version of the Lengow platform","Compatibilité avec l'ancienne version de la plateforme Lengow"
200
+ "Activate this option if you have the old version of the Lengow platform","Si vous avez accès à l'ancienne version de la plateforme Lengow, activez cette option"
201
+ "Compatibility with the new version of the Lengow platform","Compatibilité avec la nouvelle version de la plateforme Lengow"
202
+ "Activate this option if you have the new version of the Lengow platform","Si vous avez accès à la nouvelle version de la plateforme Lengow, activez cette option"
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Lengow_Export</name>
4
- <version>2.1.2</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -10,10 +10,10 @@
10
  <description>New module of Lengow.&#xD;
11
  Export your catalog, import your orders from all Marketplaces.</description>
12
  <notes>New version of Lengow's Connector</notes>
13
- <authors><author><name>Ludovic</name><user>ludo</user><email>ludovic@lengow.com</email></author><author><name>Romain</name><user>romain</user><email>romain@lengow.com</email></author><author><name>Mathieu</name><user>mathieu</user><email>mathieu.sabourin@lengow.com</email></author><author><name>Benjamin</name><user>benjamin</user><email>benjamin.le-neve@lengow.com</email></author></authors>
14
- <date>2015-12-18</date>
15
- <time>15:31:38</time>
16
- <contents><target name="magecommunity"><dir name="Lengow"><dir name="Dashboard"><dir name="Block"><dir name="Adminhtml"><dir name="Dashboard"><file name="Charts.php" hash="71641cf5b1ccd6267b5566a025dc96a4"/><file name="Diagrams.php" hash="0aeb53d09f0a83d03ce66825283b0046"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="7129af0e9ab390e0695f84865a02fdb5"/></dir><dir name="Model"><file name="Config.php" hash="7e0b019175b5ad29f0b70a6e43b5ebce"/></dir><dir name="etc"><file name="config.xml" hash="dd71373a31043cba10ccc224be5d2f98"/></dir></dir><dir name="Export"><dir name="Block"><dir name="Adminhtml"><dir name="Product"><file name="Grid.php" hash="9299bea84d78c5c852e0b8f6c05b17b6"/></dir><file name="Product.php" hash="e043c5abef03d0c46ccd51e49c868cf9"/></dir></dir><dir name="Helper"><file name="Data.php" hash="56be39f342b500f7a59c2a17c95527cd"/><file name="Security.php" hash="c8771b29a19c2ef12796a3affc837ae5"/></dir><dir name="Model"><dir name="Catalog"><file name="Product.php" hash="4b97758ec4e6b2f4d6a0cf51ac1721cb"/></dir><file name="Config.php" hash="fba4bed58d9c1a69d247b7cc7c0b6b64"/><dir name="Convert"><dir name="Parser"><file name="Product.php" hash="bc664380ca9d37256460613ecdbd8f92"/></dir></dir><dir name="Export"><dir name="Rewrite"><dir name="Catalog"><file name="Config.php" hash="e192cd30c6ed7e4cc370953c3ecd2367"/></dir></dir></dir><dir name="Feed"><file name="Abstract.php" hash="ed13409ab1c507b48b9460c8886bef8d"/><file name="Csv.php" hash="5958c0bdfc04dd33f59245fded2949d7"/><file name="Json.php" hash="4df743bce6647eea36d2677ab7f6a9a8"/><file name="Xml.php" hash="7c1a17b034a6b249da39ac9948227f88"/><file name="Yaml.php" hash="76070611f6a0b8eb6c63503ab4116c22"/></dir><file name="Generate.php" hash="544a0a21f81c25035fad0b285d9227d2"/><file name="Generateoptimize.php" hash="6b9576eb488e00384d33b810024b58a8"/><file name="Observer.php" hash="8cb4a5de53497658357410ccd49b1a5d"/><dir name="Product"><file name="Collection.php" hash="3c9c30d1b08dd8f291438358a4ee21fb"/></dir><dir name="Resource"><dir name="Catalog"><file name="Product.php" hash="b1daebdecf6504804fcab3085de51667"/></dir></dir><dir name="Shipping"><dir name="Carrier"><file name="Lengow.php" hash="685809c2367ec3509ecbf9f4d07f4661"/></dir></dir><dir name="Source"><file name="Attributes.php" hash="f8cae8fe1a7a15c7b4cd76503bffd053"/><file name="Types.php" hash="513868577816d51f6cc61e75ba43a938"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><file name="Apikey.php" hash="140ba6e9cce1204fe0e0c50cf81762ec"/></dir><dir name="Source"><dir name="Category"><file name="Level.php" hash="a1875080def0c89a2bb4b4088f57eac8"/></dir><file name="Format.php" hash="fd069f484cc3ae0d914fb7a965789d9f"/><file name="Getattributes.php" hash="d42c66b3f0ed0c21d5e824400c0b1dc5"/><file name="Images.php" hash="e6ec93f301599ea91d69a1f4847e240d"/><file name="Status.php" hash="449b2bf3c121c3a07aab6072aa629a90"/><file name="Types.php" hash="cab52d0a7e34ff4629ad17d0a2c96362"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Lengow"><file name="ExportController.php" hash="722a7c72d7cb9885e42531e2cfa719bc"/></dir></dir><file name="FeedController.php" hash="19fa16a8970e13c863f4da7018fdd837"/></dir><dir name="etc"><file name="config.xml" hash="18e5d0159c3dc2c41f103ddf9821dbbf"/><file name="system.xml" hash="5f7838932242b134766fd20385ac5547"/></dir></dir><dir name="Feed"><dir name="Block"><dir name="Adminhtml"><dir name="Feed"><file name="Grid.php" hash="74fcb8c472666b89d9ba550357102c38"/><dir name="Renderer"><file name="Migrate.php" hash="a6a1fd08b4269b052d8c9ed447589ae3"/><file name="Select.php" hash="78808e9061b7a5aa73c2273f18bc0746"/><file name="Url.php" hash="2a3c4fa22460806dda478a088a17ced7"/></dir></dir><file name="Feed.php" hash="30e2d20268eb24bbcc9554ba97e5149e"/></dir></dir><dir name="Helper"><file name="Data.php" hash="799d69122855da8c287b86e663f3562d"/></dir><dir name="Model"><file name="Config.php" hash="7487c73a3fe292614c9f4a2b66d8a664"/><file name="Feed.php" hash="9e7096ba72dcb071662842c681e50928"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Lengow"><file name="FeedController.php" hash="c808d1b5afc0aef6145ecb187d84b93b"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="d1fa57ae0a66c365e783a0aea0a233cb"/><file name="system.xml" hash="81e6692a37fead4aaa02a4e255ce8464"/></dir></dir><dir name="Sync"><dir name="Block"><dir name="Adminhtml"><dir name="Cron"><file name="Grid.php" hash="ac84c0ace4548928d5e7706a67eac7c1"/></dir><file name="Cron.php" hash="0be9b2a4d2b751d54a51bd1f1e5a15d3"/><file name="Import.php" hash="832bc82dde18ae4bc886933b28f41885"/><dir name="Log"><file name="Grid.php" hash="31416dda25b833416ef9dad2143b2d9f"/></dir><file name="Log.php" hash="e4032e885dbbdd0c3f4112efbc8ef5a2"/><dir name="Order"><file name="Grid.php" hash="313ea7fde1df56b36159e5d37a757ac9"/><file name="Tab.php" hash="405c887f100b259ba9750088b1c17b44"/></dir><file name="Order.php" hash="c5cecae61feb8dacd348124ba3a2ffef"/></dir><dir name="Payment"><dir name="Info"><file name="Purchaseorder.php" hash="ccf3a1c41c21d1ffd315819be1808fec"/></dir></dir></dir><dir name="Helper"><file name="Api.php" hash="e8846c81d34c1025579151c7372492fb"/><file name="Cron.php" hash="cf6c9289006e4bdea116e90ba8ec8d10"/><file name="Data.php" hash="d66a6bf80a4d4cb86aa793ad10e4aef3"/></dir><dir name="Model"><file name="Config.php" hash="938e26ef034db15e8a3d977b1a665e25"/><dir name="Connector"><file name="Exception.php" hash="de1fa1b69e24fe7b976c03f1ed1ca7f7"/></dir><file name="Connector.php" hash="544000640f47a5e12482138b1d920ce8"/><dir name="Customer"><file name="Customer.php" hash="2cb9388279a880b8bd602f4b026c9162"/></dir><file name="File.php" hash="d5c9e6af9ca7c7c6013430327b2019df"/><file name="Import.php" hash="1e019c7a66e5c84c68b65c1bd97a3998"/><file name="Log.php" hash="29e1e489b6d125fe64d91693f987a502"/><dir name="Marketplace"><file name="Exception.php" hash="bd7ab8db94e241d022cd6e467e8596ec"/></dir><file name="Marketplace.php" hash="19c8254e80a459b7304a75dc84afd280"/><dir name="Mysql4"><dir name="Log"><file name="Collection.php" hash="22e087b5cfee173440877dd0714fee55"/></dir><file name="Log.php" hash="ab90ef25ea4f6369f713325b6ba247e5"/></dir><file name="Observer.php" hash="9936599d8144bc4bb32886e7a099a8b3"/><file name="Order.php" hash="fd722ee55aa18db7f0d84cd80f00547e"/><dir name="Payment"><dir name="Method"><file name="Lengow.php" hash="34c96c7a150ee18598301f57dbc707bc"/></dir></dir><dir name="Quote"><file name="Item.php" hash="21408439544f076502b636dd6003877d"/></dir><file name="Quote.php" hash="6014d07add187c806711815bae806f92"/><dir name="Shipping"><dir name="Carrier"><file name="Lengow.php" hash="8340d3cef16fc86306d626a71d2e9ebc"/></dir></dir><dir name="System"><dir name="Config"><dir name="Source"><dir name="Customer"><file name="Group.php" hash="640638dcee398949ec4d0c1e2731005d"/></dir><dir name="Shipping"><file name="Carrier.php" hash="f83fd1e7fb5c2bd50d2ba983e24b6240"/><file name="Method.php" hash="8df07e95712559dad4b37bde3acf9f77"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Lengow"><file name="DebugController.php" hash="a0197d3783c806e97aed734378735014"/><file name="LogController.php" hash="6d643758cbd902fa32bc2f7468863655"/><file name="OrderController.php" hash="563070e0408429d0d788ca65fff83f4f"/></dir></dir><file name="ApiController.php" hash="3d62e46fd860b326f288c5869fbe3389"/></dir><dir name="etc"><file name="config.xml" hash="19d57bb45b5e6dcc18ab359bd9c818a3"/><file name="marketplaces.xml" hash="d71cd7ac07791fd82156243f2a573d83"/><file name="system.xml" hash="bd484e8b456802c5c894e52b4cbcd188"/><file name="wsdl.xml" hash="d299fecf68e9f795e26037be4f2115b3"/></dir><dir name="sql"><dir name="lengow_setup"><file name="mysql4-install-2.0.0.0.php" hash="6856dcca18117fb112e6523139fb47c5"/><file name="mysql4-upgrade-2.0.0.0-2.0.0.1.php" hash="92edfe3518259e1a11213cc80ccaeb34"/><file name="mysql4-upgrade-2.0.2-2.1.0.php" hash="187da13f6ae76378f1118bbf5acaf683"/></dir></dir></dir><dir name="Tracker"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Check"><file name="Point.php" hash="de29cb19427434c1713d2dae9c97900a"/></dir><file name="Check.php" hash="877fd7a030feff2ad8bc561a3785be5b"/></dir></dir></dir><dir name="Tag"><file name="Capsule.php" hash="d2ed189be29fd76f6ceb0b8d68f21efe"/><file name="Simple.php" hash="ff8fe8fa9767b75de69f5f8e2dfa6ba1"/></dir><file name="Tracker.php" hash="3bdb94f577a831310f8f12f854739906"/></dir><dir name="Helper"><file name="Check.php" hash="01f7145b0963867f78c29ec53e5ea5b7"/><file name="Data.php" hash="e526694354fe760f266bf925e5e4ac39"/></dir><dir name="Model"><file name="Capsule.php" hash="55504d0b6398f5a88b5977bf54f5b54b"/><file name="Config.php" hash="7848ae5ddc1f2617effa39e27b3e838e"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Identifiant.php" hash="51943c288cab9456c62a2130405b695b"/><file name="Tracker.php" hash="8fdc4f1d9f02300525aeb295e9cd3dfc"/></dir></dir></dir><file name="Tracker.php" hash="4c740aa3a311a93b8143a69fd1ea3221"/></dir><dir name="etc"><file name="config.xml" hash="67dc95e5e0b9434e4efafed5c3b21423"/><file name="plugins.xml" hash="e35408d7ea61c7ccc669cfb5b7bb8567"/><file name="system.xml" hash="ec32d45005f85f1bbc42ace04e1d82c6"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="lengow.xml" hash="359ec9ffc2b7f6785750ef0a760b7c6b"/></dir><dir name="template"><dir name="lengow"><dir name="check"><file name="point.phtml" hash="9791a2a673d45bb6db850ec802c63a71"/></dir><dir name="dashboard"><file name="charts.phtml" hash="51964c7bcace68d8f4ef23e314f07a8c"/></dir><dir name="debug"><file name="index.phtml" hash="23df3288336269a12024f13ed3ae0023"/></dir><dir name="export"><file name="product.phtml" hash="8c0c893621573c316bb7da14a3533224"/></dir><dir name="feed"><file name="grid.phtml" hash="b34e7f8ce18ce9605e88a5bc8b806442"/></dir><dir name="sales"><dir name="order"><dir name="tab"><file name="info.phtml" hash="fcaa52401ea83b17e52d0db2f8367b93"/></dir></dir><dir name="payment"><dir name="info"><file name="purchaseorder.phtml" hash="8e9e7a287ef57fe72023e28747fb0864"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="lengow.xml" hash="0e6a4eb11f6433d54474bfed8061d560"/></dir><dir name="template"><dir name="lengow"><dir name="tracker"><file name="simpletag.phtml" hash="3b73552b323d00bd053e1086e6f5ff45"/><file name="tag.phtml" hash="619f7bc6fe20c3dd6c1d82cdf12811b5"/><file name="tagcapsule.phtml" hash="2916e7693ef8ec9fcce5f5a8079d2beb"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="fr_FR"><file name="Lengow_Connector.csv" hash="5e5fca3304dd740615344a6cb8ee47ed"/></dir></target><target name="mageetc"><dir name="modules"><file name="Lengow_Connector.xml" hash="34b39beecc725740ea1e0bc8d339287a"/></dir></target><target name="magemedia"><dir name="lengow"><file name="import.flag" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="lengow"><dir name="css"><file name="admin.css" hash="45e6eca21d130d11c1e6fda8dae35f3d"/></dir><dir name="js"><file name="charts.min.js" hash="6806368c6a0bf73a5236b452fd5c2332"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="lengow"><dir name="js"><file name="tracker.js" hash="6402a4fbbb81a3b0587ec8c4c375e0a0"/></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Lengow_Export</name>
4
+ <version>2.2.4</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
10
  <description>New module of Lengow.&#xD;
11
  Export your catalog, import your orders from all Marketplaces.</description>
12
  <notes>New version of Lengow's Connector</notes>
13
+ <authors><author><name>Lengow</name><user>TeamConnector</user><email>team-connector@lengow.com</email></author></authors>
14
+ <date>2016-12-23</date>
15
+ <time>09:41:52</time>
16
+ <contents><target name="magecommunity"><dir name="Lengow"><dir name="Export"><dir name="Block"><dir name="Adminhtml"><dir name="Product"><file name="Grid.php" hash="fe8f74aa163c896abaf645ba2fb6c1f4"/></dir><file name="Product.php" hash="341a55c52bda11a3dd90d1982bf59346"/></dir></dir><dir name="Helper"><file name="Data.php" hash="d33f3b835d10435d0950ae4ff0ee85da"/><file name="Security.php" hash="ff8c75c3694f10757b9f0a43326109fa"/></dir><dir name="Model"><dir name="Catalog"><file name="Product.php" hash="d92e93142e8791c936bbb611ad7824d4"/></dir><file name="Config.php" hash="fe15873c2e704f7b7aa035960109a356"/><dir name="Convert"><dir name="Parser"><file name="Product.php" hash="64497fd3d454ec76534bdf99406b827f"/></dir></dir><dir name="Export"><dir name="Rewrite"><dir name="Catalog"><file name="Config.php" hash="28a6cbf10b098675ca4fdc6576a34d61"/></dir></dir></dir><dir name="Feed"><file name="Abstract.php" hash="0f27f3f1823bf16e377f1273dd1dbe5c"/><file name="Csv.php" hash="ba0d87e773bb9377a1f9dcd6fc1b65f0"/><file name="Json.php" hash="f985de46f8f9e914c4362022acf21bb5"/><file name="Xml.php" hash="ece414cac63ad3bbfabe0cdefff92c64"/><file name="Yaml.php" hash="ba448693d954393d2147a569085ee42a"/></dir><file name="Generate.php" hash="4508a8d0ee5656fd04b9a899c34108d6"/><file name="Generateoptimize.php" hash="8a337903214868c545ad1870349d8f5f"/><file name="Observer.php" hash="74969a89614ff1dd36b462833b73ea3f"/><dir name="Product"><file name="Collection.php" hash="43a3fd972637e7512dde16ae2b245304"/></dir><dir name="Resource"><dir name="Catalog"><file name="Product.php" hash="7962eb644c9d62bec4d522c1546c8cce"/></dir></dir><dir name="Shipping"><dir name="Carrier"><file name="Lengow.php" hash="8d24a5eb93f39c66029e4fb249c69362"/></dir></dir><dir name="Source"><file name="Attributes.php" hash="21824f801207670f32226e3ebbf855f3"/><file name="Types.php" hash="384f2e4873d7394a5a1eb9aede44285e"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><file name="Apikey.php" hash="a381a570a30c46a2ba17dc566b3e9be1"/></dir><dir name="Source"><dir name="Category"><file name="Level.php" hash="9dca6f562b1d03f4af6fb7b1cfe15bef"/></dir><file name="Format.php" hash="d85362458f4c1780bb4ebc197bbed67f"/><file name="Getattributes.php" hash="4a4d1629e63f561c394d1f2a10c6e57f"/><file name="Images.php" hash="bcdb42a554a807f139e615b640ea04de"/><file name="Status.php" hash="21fd130b3857257ce8fe2289727249ec"/><file name="Types.php" hash="32cc3b220a047f03be28669ab3d23ce7"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Lengow"><file name="ProductController.php" hash="eb3054f941fb5f54be334272fe2cdff9"/></dir></dir><file name="FeedController.php" hash="3e46215bdf7fbbbc3a26dfdb09143179"/></dir><dir name="etc"><file name="config.xml" hash="bccafc22b3fed39154ed4590a92dcc2b"/><file name="system.xml" hash="afd977bc892066a2336ef6caf13c9c07"/></dir></dir><dir name="Sync"><dir name="Block"><dir name="Adminhtml"><dir name="Cron"><file name="Grid.php" hash="dc0baa309fc3e69072454daa1c56fc09"/></dir><file name="Cron.php" hash="c1dd8c820206cdb9899215c5f8892a0d"/><file name="Import.php" hash="e7673f6b9d4cfa5c5bba59c069474f50"/><dir name="Log"><file name="Grid.php" hash="f86c9c1f19185b8e75e90202dcf75dbc"/></dir><file name="Log.php" hash="42524de866b929044776bb60dccc9314"/><dir name="Order"><file name="Grid.php" hash="d93bef9c878736d6b9ee1fdbc8867b9c"/><file name="Tab.php" hash="2c0d4e75b5ab2926905a44c474028f3f"/></dir><file name="Order.php" hash="4c73a6572f088af605661f4af8442ccf"/></dir><dir name="Payment"><dir name="Info"><file name="Purchaseorder.php" hash="5271f659c0ea36a13c7f50cf29292e5f"/></dir></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Hidden.php" hash="c7753eee1754a547fc62e5639ba129e7"/></dir></dir></dir></dir><dir name="Helper"><file name="Api.php" hash="a4d156a217f0a86dc46999198776f116"/><file name="Cron.php" hash="242b12edb0788d327117c62ecbe4a160"/><file name="Data.php" hash="f5ff4b6db5abe5a9e56b0671baf8bfe6"/></dir><dir name="Model"><file name="Config.php" hash="d2752407d2d40315d5c7d27610c5a512"/><dir name="Connector"><file name="Exception.php" hash="0404d1ba524212268de0a60959334474"/></dir><file name="Connector.php" hash="359a708b00bb6302162b86950080b8a8"/><file name="Connectorv2.php" hash="ce99fdf4bdd7efdbdb60a991060b7c16"/><dir name="Customer"><file name="Customer.php" hash="332e3e709637be031593f4ec6f3c426c"/><file name="Customerv2.php" hash="8025a54987095db2e0195d785425f3bb"/></dir><file name="File.php" hash="d3505554a6aebfd790a079c9e59e6da7"/><file name="Import.php" hash="06134a694c318a069120a83b4e192f1a"/><file name="Importv2.php" hash="e37b9a2b81d48ebe702443f7eae57bab"/><file name="Log.php" hash="946762df85433089899ae5aca9249258"/><dir name="Marketplace"><file name="Exception.php" hash="dbd62cc15a056b2320f615a568680adc"/></dir><file name="Marketplace.php" hash="a7bd14e6ffb78822a8bb913431d59d8e"/><file name="Marketplacev2.php" hash="d47d1f2df5eb37154ac3cb828f9b9704"/><dir name="Mysql4"><dir name="Log"><file name="Collection.php" hash="1b68041ff67f42b223179980db683fdb"/></dir><file name="Log.php" hash="e9412749a236f0b8945e9f351a094574"/><dir name="Orderline"><file name="Collection.php" hash="128f26f35ba71776f758f528148a3f83"/></dir><file name="Orderline.php" hash="90ad2f06e32c332672c72f0b994c1fe6"/></dir><file name="Observer.php" hash="81facfdefa1d75842af94a1a421f379a"/><file name="Order.php" hash="69b90caa3e444f0c00bf48388d931d63"/><file name="Orderline.php" hash="ca66071a3203ade0f0d67e1b2a700621"/><file name="Orderv2.php" hash="75ebb81b73fc3b6be686dc2a3d34c71a"/><dir name="Payment"><dir name="Method"><file name="Lengow.php" hash="5c0df253aba05f6d7e560e927d77e9a7"/></dir></dir><dir name="Quote"><file name="Item.php" hash="86d43d67e0ece05456e41c0e875e08b5"/></dir><file name="Quote.php" hash="7fea2a1e2bf29ba49019743d2c10ca41"/><file name="Quotev2.php" hash="b8c2c91db38bf56e361757ef10c01020"/><dir name="Shipping"><dir name="Carrier"><file name="Lengow.php" hash="8a3ff6d9b6aefa63b469d79ed02dfdc0"/></dir></dir><dir name="System"><dir name="Config"><dir name="Source"><dir name="Customer"><file name="Group.php" hash="511a95c3349c0499e452eb1a4ac6b080"/></dir><dir name="Shipping"><file name="Carrier.php" hash="11eff59379cf2484da883a416eb7c7f4"/><file name="Method.php" hash="58b15673151656e92b196425df04708a"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Lengow"><file name="DebugController.php" hash="35aed52135715929ee6612a6c2ea1de6"/><file name="LogController.php" hash="bf2a9a13991ef6ca8180a08e08776d5a"/><file name="OrderController.php" hash="d19ad1b8921007559b5f82c2d034a0da"/></dir></dir><file name="ApiController.php" hash="3eaedb71c8e20d74db2a408f21718dcd"/></dir><dir name="etc"><file name="config.xml" hash="61ca3694652ca0e8326d83ef06258030"/><file name="marketplaces.xml" hash="5dd557cf42faf2fd0224b2bf36847b72"/><file name="system.xml" hash="9a95b0c27264d8527cd0093f08fa6dfa"/></dir><dir name="sql"><dir name="lengow_setup"><file name="mysql4-install-2.0.0.0.php" hash="7349264abaf3d4c0b9dcf2a76b27c7b1"/><file name="mysql4-upgrade-2.0.0.0-2.0.0.1.php" hash="03e30e717bf4d80267ed27c3ce664b73"/><file name="mysql4-upgrade-2.0.2-2.1.0.php" hash="b4d1763189fadcd8a65a048242adf72e"/><file name="mysql4-upgrade-2.1.2-2.2.0.php" hash="d885ffa29963826bec38f9a9a82f53b9"/><file name="mysql4-upgrade-2.2.0-2.2.1.php" hash="ab8f8c4ac8d921a3522e315af5842dc1"/><file name="mysql4-upgrade-2.2.1-2.2.2.php" hash="ab8f8c4ac8d921a3522e315af5842dc1"/><file name="mysql4-upgrade-2.2.2-2.2.3.php" hash="ab8f8c4ac8d921a3522e315af5842dc1"/><file name="mysql4-upgrade-2.2.3-2.2.4.php" hash="ab8f8c4ac8d921a3522e315af5842dc1"/></dir></dir></dir><dir name="Tracker"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Check"><file name="Point.php" hash="de29cb19427434c1713d2dae9c97900a"/></dir><file name="Check.php" hash="c32f89869243ebd1b650ae671926b4ed"/></dir></dir></dir><dir name="Tag"><file name="Capsule.php" hash="1b3de855f57045c3b332a46f729b0e2b"/><file name="Simple.php" hash="bd7d0b6b6184cfc13df7a14fa4e186bc"/></dir><file name="Tracker.php" hash="eda4943e6d2f98db6f7411bba1219e40"/></dir><dir name="Helper"><file name="Check.php" hash="98047c85faa4fe8252a652185af121ae"/><file name="Data.php" hash="316044a45b952e3962ec6201674d010c"/></dir><dir name="Model"><file name="Capsule.php" hash="b6724b1bc4ee6ce1c49530a702ced2bb"/><file name="Config.php" hash="95a8c88d620a3f12405813d3e2a6f1b4"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Identifiant.php" hash="bad824895d8c4fcbb0111b8afc2eb018"/><file name="Tracker.php" hash="35993213e477b6ddec73426fdd845bcc"/></dir></dir></dir><file name="Tracker.php" hash="3e97e54211a48642276547bbd3f2a07f"/></dir><dir name="etc"><file name="config.xml" hash="d54b10df4d30775437f2864937a113e1"/><file name="plugins.xml" hash="63a6734a363dfa0959478a5161528c66"/><file name="system.xml" hash="dd6467884d9f7f51810aa2ac763f05a2"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="lengow.xml" hash="e942bf7a060ce83f12b988b68168ce9f"/></dir><dir name="template"><dir name="lengow"><dir name="check"><file name="point.phtml" hash="9791a2a673d45bb6db850ec802c63a71"/></dir><dir name="debug"><file name="index.phtml" hash="d6556eb7568bde4f1418f85ea866ff01"/></dir><dir name="export"><file name="product.phtml" hash="8c0c893621573c316bb7da14a3533224"/></dir><dir name="sales"><dir name="order"><dir name="tab"><file name="info.phtml" hash="fcaa52401ea83b17e52d0db2f8367b93"/></dir></dir><dir name="payment"><dir name="info"><file name="purchaseorder.phtml" hash="8e9e7a287ef57fe72023e28747fb0864"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="lengow.xml" hash="6db3d70576ab7348c511f787777f4935"/></dir><dir name="template"><dir name="lengow"><dir name="tracker"><file name="simpletag.phtml" hash="99c1d189fc5ef75c8a203cf65bca52b2"/><file name="tag.phtml" hash="619f7bc6fe20c3dd6c1d82cdf12811b5"/><file name="tagcapsule.phtml" hash="84eea04d5725bee7be263d356cdf513d"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="fr_FR"><file name="Lengow_Connector.csv" hash="38bf9337b49dcd291a144f2e60bcfd61"/></dir></target><target name="mageetc"><dir name="modules"><file name="Lengow_Connector.xml" hash="867540d2df75d0b4df26cd555c1a12de"/></dir></target><target name="magemedia"><dir name="lengow"><file name="import.flag" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="lengow"><dir name="css"><file name="admin.css" hash="d5c6ca988374baef720c2c0d8b964be8"/></dir><dir name="js"><file name="charts.min.js" hash="6806368c6a0bf73a5236b452fd5c2332"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="lengow"><dir name="js"><file name="tracker.js" hash="586395109b7c77475f11b82a88d35456"/></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
skin/adminhtml/default/default/lengow/css/admin.css CHANGED
@@ -82,6 +82,7 @@
82
  background-color: #5cb85c;
83
  border-color: #4cae4c;
84
  }
 
85
  .lengow-must-be-updated {
86
  color: #ffffff;
87
  background-color: #d2322d;
@@ -99,12 +100,14 @@
99
  color: white;
100
  text-align: center;
101
  }
 
102
  .lengow-debug-red {
103
  background: #9E0C00;
104
  text-align: center;
105
  font-weight: bold;
106
  color: white;
107
  }
 
108
  .lengow-debug-orange {
109
  background: #F37A00;
110
  text-align: center;
82
  background-color: #5cb85c;
83
  border-color: #4cae4c;
84
  }
85
+
86
  .lengow-must-be-updated {
87
  color: #ffffff;
88
  background-color: #d2322d;
100
  color: white;
101
  text-align: center;
102
  }
103
+
104
  .lengow-debug-red {
105
  background: #9E0C00;
106
  text-align: center;
107
  font-weight: bold;
108
  color: white;
109
  }
110
+
111
  .lengow-debug-orange {
112
  background: #F37A00;
113
  text-align: center;
skin/frontend/base/default/lengow/js/tracker.js CHANGED
@@ -1,35 +1,34 @@
1
  document.observe("dom:loaded", function() {
2
- var script_url = $('url_script').readAttribute('src');
3
- var body = $$('body')[0];
4
- var current_section = '';
5
 
6
- if (typeof Checkout !== 'undefined') {
7
- Checkout.prototype.gotoSection = function(section) {
8
- if(section !== current_section) {
9
- current_section = section;
10
-
11
- var content_script = $('lengow_tracker').innerHTML;
12
- var script = new Element('script', {type: 'text/javascript', src: script_url});
13
-
14
- if (section === 'billing' && this.method === 'guest') {
15
- window.page = 'lead';
16
- body.appendChild(script);
17
- } else if (section === 'payment') {
18
- window.page = 'basket';
19
- body.appendChild(script);
20
- // Set var page to 'basket'
21
- /*var new_content = content_script.replace(/page = \'\w+\'/, 'page = \'basket\'')
22
  var script = new Element('script', {type: 'text/javascript', src: script_url});
23
- alert(new_content);*/
24
- //$('lengow_tracker').update(new_content);
25
-
 
 
 
 
 
 
 
 
 
26
  }
 
 
 
 
27
  }
28
-
29
- var sectionElement = $('opc-' + section);
30
- sectionElement.addClassName('allow');
31
- this.accordion.openSection('opc-' + section);
32
- this.reloadProgressBlock(section);
33
  }
34
  }
 
35
  });
1
  document.observe("dom:loaded", function() {
 
 
 
2
 
3
+ if ($('url_script') != null) {
4
+ var script_url = $('url_script').readAttribute('src');
5
+ var body = $$('body')[0];
6
+ var current_section = '';
7
+ if (typeof Checkout !== 'undefined') {
8
+ Checkout.prototype.gotoSection = function(section) {
9
+ if(section !== current_section) {
10
+ current_section = section;
11
+ var content_script = $('lengow_tracker').innerHTML;
 
 
 
 
 
 
 
12
  var script = new Element('script', {type: 'text/javascript', src: script_url});
13
+ if (section === 'billing' && this.method === 'guest') {
14
+ window.page = 'lead';
15
+ body.appendChild(script);
16
+ } else if (section === 'payment') {
17
+ window.page = 'basket';
18
+ body.appendChild(script);
19
+ // Set var page to 'basket'
20
+ /*var new_content = content_script.replace(/page = \'\w+\'/, 'page = \'basket\'')
21
+ var script = new Element('script', {type: 'text/javascript', src: script_url});
22
+ alert(new_content);*/
23
+ //$('lengow_tracker').update(new_content);
24
+ }
25
  }
26
+ var sectionElement = $('opc-' + section);
27
+ sectionElement.addClassName('allow');
28
+ this.accordion.openSection('opc-' + section);
29
+ this.reloadProgressBlock(section);
30
  }
 
 
 
 
 
31
  }
32
  }
33
+
34
  });