Speedinfo_Opensi - Version 0.2.1

Version Notes

Mise à jour du module vers la version 0.2.1.
Pour plus d'informations, se référer à la documentation.

Download this release

Release Info

Developer Magento Core Team
Extension Speedinfo_Opensi
Version 0.2.1
Comparing to
See all releases


Code changes from version 0.2.0 to 0.2.1

app/code/community/Speedinfo/Opensi/Block/Adminhtml/Edit.php CHANGED
@@ -24,7 +24,7 @@ class Speedinfo_Opensi_Block_Adminhtml_Edit extends Mage_Adminhtml_Block_Widget_
24
 
25
  public function getHeaderText()
26
  {
27
- return 'Configuration Opensi';
28
  }
29
 
30
  }
24
 
25
  public function getHeaderText()
26
  {
27
+ return 'Configuration OpenSi';
28
  }
29
 
30
  }
app/code/community/Speedinfo/Opensi/Block/Adminhtml/Edit/Tab/Attributs.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Block Tab General
4
+ *
5
+ * @Author Speedinfo
6
+ * http://wwww.speedinfo.fr | http://www.opensi.fr
7
+ */
8
+
9
+ class Speedinfo_Opensi_Block_Adminhtml_Edit_Tab_Attributs extends Mage_Adminhtml_Block_Widget_Form{
10
+
11
+ /**
12
+ * Initialize tab
13
+ *
14
+ */
15
+ public function __construct() {
16
+ parent::__construct();
17
+ }
18
+
19
+ public function _prepareLayout()
20
+ {
21
+ parent::_prepareLayout();
22
+ $form = new Varien_Data_Form();
23
+ $client = $this->getClient();
24
+
25
+ $fieldset = $form->addFieldset('attributs_fieldset', array('legend'=>Mage::helper('opensi')->__('Liaison des Attributs')));
26
+
27
+ $list_attr = $this->getProductAttributes();
28
+
29
+ $fieldset->addField('attribut_1', 'select', array(
30
+ 'name' => 'opensi[attribut][0]',
31
+ 'label' => Mage::helper('opensi')->__('Attribute')." 1 :",
32
+ 'title' => Mage::helper('opensi')->__('Attribute')." 1 :",
33
+ 'required' => false,
34
+ 'value' => isset($client->attribut1) ? $client->attribut1 : '',
35
+ 'values' => $list_attr,
36
+ ));
37
+
38
+ $fieldset->addField('attribut_2', 'select', array(
39
+ 'name' => 'opensi[attribut][1]',
40
+ 'label' => Mage::helper('opensi')->__('Attribute')." 2 :",
41
+ 'title' => Mage::helper('opensi')->__('Attribute')." 2 :",
42
+ 'required' => false,
43
+ 'value' => isset($client->attribut2) ? $client->attribut2 : '',
44
+ 'values' => $list_attr,
45
+ ));
46
+
47
+ $fieldset->addField('attribut_3', 'select', array(
48
+ 'name' => 'opensi[attribut][2]',
49
+ 'label' => Mage::helper('opensi')->__('Attribute')." 3 :",
50
+ 'title' => Mage::helper('opensi')->__('Attribute')." 3 :",
51
+ 'required' => false,
52
+ 'value' => isset($client->attribut3) ? $client->attribut3 : '',
53
+ 'values' => $list_attr,
54
+ ));
55
+
56
+ $fieldset->addField('attribut_4', 'select', array(
57
+ 'name' => 'opensi[attribut][3]',
58
+ 'label' => Mage::helper('opensi')->__('Attribute')." 4 :",
59
+ 'title' => Mage::helper('opensi')->__('Attribute')." 4 :",
60
+ 'required' => false,
61
+ 'value' => isset($client->attribut4) ? $client->attribut4 : '',
62
+ 'values' => $list_attr,
63
+ ));
64
+
65
+ $fieldset->addField('attribut_5', 'select', array(
66
+ 'name' => 'opensi[attribut][4]',
67
+ 'label' => Mage::helper('opensi')->__('Attribute')." 5 :",
68
+ 'title' => Mage::helper('opensi')->__('Attribute')." 5 :",
69
+ 'required' => false,
70
+ 'value' => isset($client->attribut5) ? $client->attribut5 : '',
71
+ 'values' => $list_attr,
72
+ ));
73
+
74
+ $fieldset->addField('attribut_6', 'select', array(
75
+ 'name' => 'opensi[attribut][5]',
76
+ 'label' => Mage::helper('opensi')->__('Attribute')." 6 :",
77
+ 'title' => Mage::helper('opensi')->__('Attribute')." 6 :",
78
+ 'required' => false,
79
+ 'value' => isset($client->attribut6) ? $client->attribut6 : '',
80
+ 'values' => $list_attr,
81
+ ));
82
+
83
+ $fieldset->addField('code_barre', 'select', array(
84
+ 'name' => 'opensi[code_barre]',
85
+ 'label' => Mage::helper('opensi')->__('Barcode :'),
86
+ 'title' => Mage::helper('opensi')->__('Barcode :'),
87
+ 'required' => false,
88
+ 'value' => isset($client->code_barre) ? $client->code_barre : '',
89
+ 'values' => $list_attr,
90
+ ));
91
+
92
+ $fieldset->addField('volume', 'select', array(
93
+ 'name' => 'opensi[volume]',
94
+ 'label' => Mage::helper('opensi')->__('Volume in m³ :'),
95
+ 'title' => Mage::helper('opensi')->__('Volume in m³ :'),
96
+ 'required' => false,
97
+ 'value' => isset($client->volume) ? $client->volume : '',
98
+ 'values' => $list_attr,
99
+ ));
100
+
101
+ $fieldset->addField('hauteur', 'select', array(
102
+ 'name' => 'opensi[hauteur]',
103
+ 'label' => Mage::helper('opensi')->__('Height in m :'),
104
+ 'title' => Mage::helper('opensi')->__('Height in m :'),
105
+ 'required' => false,
106
+ 'value' => isset($client->hauteur) ? $client->hauteur : '',
107
+ 'values' => $list_attr,
108
+ ));
109
+
110
+ $fieldset->addField('longueur', 'select', array(
111
+ 'name' => 'opensi[longueur]',
112
+ 'label' => Mage::helper('opensi')->__('Length in m :'),
113
+ 'title' => Mage::helper('opensi')->__('Length in m :'),
114
+ 'required' => false,
115
+ 'value' => isset($client->longueur) ? $client->longueur : '',
116
+ 'values' => $list_attr,
117
+ ));
118
+
119
+ $fieldset->addField('largeur', 'select', array(
120
+ 'name' => 'opensi[largeur]',
121
+ 'label' => Mage::helper('opensi')->__('Width in m :'),
122
+ 'title' => Mage::helper('opensi')->__('Width in m :'),
123
+ 'required' => false,
124
+ 'value' => isset($client->largeur) ? $client->largeur : '',
125
+ 'values' => $list_attr,
126
+ ));
127
+
128
+ $this->setForm($form);
129
+ }
130
+
131
+ public function getStore()
132
+ {
133
+ if(Mage::registry('store_id') != ""){
134
+ $store_id = Mage::registry('store_id');
135
+ }else{
136
+ $store_id = $this->getRequest()->getParam('store');
137
+ if($store_id == ""){
138
+ $store_id = 0;
139
+ }
140
+ }
141
+ return $store_id;
142
+ }
143
+
144
+ public function getClient(){
145
+ return Mage::getModel("opensi/client")->loadByStore($this->getStore());
146
+ }
147
+
148
+ /**
149
+ * Get Product's Attributes
150
+ *
151
+ * @return array
152
+ */
153
+ public function getProductAttributes(){
154
+ if(empty($this->_productAttributes)){
155
+ $attributeArray = array();
156
+ $attributeArray[] = array('value' => '','label'=>'');
157
+ // get product model
158
+ $model = Mage::getResourceModel('catalog/product');
159
+ // get product's entityId
160
+ $typeId = $model->getTypeId();
161
+
162
+ $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
163
+ ->setEntityTypeFilter($typeId)
164
+ ->setOrder('frontend_label','asc')
165
+ ->load();
166
+
167
+ // get attribute list
168
+ foreach ($attributes as $att) {
169
+ $attributeArray[] = array('value' => $att->attribute_id,'label'=>Mage::helper('opensi')->__($att->getFrontend()->getLabel()).' ('.$att->getAttributeCode().')');
170
+ }
171
+ $this->_productAttributes = $attributeArray;
172
+ }
173
+
174
+ return $this->_productAttributes;
175
+ }
176
+ }
app/code/community/Speedinfo/Opensi/Block/Adminhtml/Edit/Tab/Familles.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Block Tab General
4
+ *
5
+ * @Author Speedinfo
6
+ * http://wwww.speedinfo.fr | http://www.opensi.fr
7
+ */
8
+
9
+ class Speedinfo_Opensi_Block_Adminhtml_Edit_Tab_Familles extends Mage_Adminhtml_Block_Widget_Form{
10
+
11
+ /**
12
+ * Initialize tab
13
+ *
14
+ */
15
+ public function __construct() {
16
+ parent::__construct();
17
+ }
18
+
19
+ public function _prepareLayout()
20
+ {
21
+ parent::_prepareLayout();
22
+ $form = new Varien_Data_Form();
23
+ $client = $this->getClient();
24
+
25
+ $fieldset = $form->addFieldset('famille_fieldset', array('legend'=>Mage::helper('opensi')->__('Liaison des familles')));
26
+
27
+ $list_attr = $this->getProductAttributes();
28
+
29
+ $fieldset->addField('famille_1', 'select', array(
30
+ 'name' => 'opensi[familles][0]',
31
+ 'label' => Mage::helper('opensi')->__('Family')." 1 :",
32
+ 'title' => Mage::helper('opensi')->__('Family')." 1 :",
33
+ 'required' => false,
34
+ 'value' => isset($client->famille1) ? $client->famille1 : '',
35
+ 'values' => $list_attr,
36
+ ));
37
+
38
+ $fieldset->addField('famille_2', 'select', array(
39
+ 'name' => 'opensi[familles][1]',
40
+ 'label' => Mage::helper('opensi')->__('Family')." 2 :",
41
+ 'title' => Mage::helper('opensi')->__('Family')." 2 :",
42
+ 'required' => false,
43
+ 'value' => isset($client->famille2) ? $client->famille2 : '',
44
+ 'values' => $list_attr,
45
+ ));
46
+
47
+ $fieldset->addField('famille_3', 'select', array(
48
+ 'name' => 'opensi[familles][2]',
49
+ 'label' => Mage::helper('opensi')->__('Family')." 3 :",
50
+ 'title' => Mage::helper('opensi')->__('Family')." 3 :",
51
+ 'required' => false,
52
+ 'value' => isset($client->famille3) ? $client->famille3 : '',
53
+ 'values' => $list_attr,
54
+ ));
55
+
56
+ $this->setForm($form);
57
+ }
58
+
59
+ public function getStore()
60
+ {
61
+ if(Mage::registry('store_id') != ""){
62
+ $store_id = Mage::registry('store_id');
63
+ }else{
64
+ $store_id = $this->getRequest()->getParam('store');
65
+ if($store_id == ""){
66
+ $store_id = 0;
67
+ }
68
+ }
69
+ return $store_id;
70
+ }
71
+
72
+ public function getClient(){
73
+ return Mage::getModel("opensi/client")->loadByStore($this->getStore());
74
+ }
75
+
76
+ /**
77
+ * Get Product's Attributes
78
+ *
79
+ * @return array
80
+ */
81
+ public function getProductAttributes(){
82
+ if(empty($this->_productAttributes)){
83
+ $attributeArray = array();
84
+ $attributeArray[] = array('value' => '','label'=>'');
85
+ // get product model
86
+ $model = Mage::getResourceModel('catalog/product');
87
+ // get product's entityId
88
+ $typeId = $model->getTypeId();
89
+
90
+ $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
91
+ ->setEntityTypeFilter($typeId)
92
+ ->setOrder('frontend_label','asc')
93
+ ->load();
94
+
95
+ // get attribute list
96
+ foreach ($attributes as $att) {
97
+ $attributeArray[] = array('value' => $att->attribute_id,'label'=>Mage::helper('opensi')->__($att->getFrontend()->getLabel()).' ('.$att->getAttributeCode().')');
98
+ }
99
+ $this->_productAttributes = $attributeArray;
100
+ }
101
+
102
+ return $this->_productAttributes;
103
+ }
104
+ }
app/code/community/Speedinfo/Opensi/Block/Adminhtml/Edit/Tab/General.php CHANGED
@@ -23,11 +23,11 @@ class Speedinfo_Opensi_Block_Adminhtml_Edit_Tab_General extends Mage_Adminhtml_B
23
  $client = $this->getClient();
24
 
25
  $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('opensi')->__('General Information')));
26
-
27
  $fieldset->addField('opensi_id', 'text', array(
28
  'name' => 'opensi[opensi_id]',
29
- 'label' => Mage::helper('opensi')->__('Identifiant OpenSi'),
30
- 'title' => Mage::helper('opensi')->__('Identifiant OpenSi'),
31
  'required' => true,
32
  'value' => !empty($client) ? $client->opensi_id : '',
33
  'class' => 'validate-number',
@@ -35,32 +35,32 @@ class Speedinfo_Opensi_Block_Adminhtml_Edit_Tab_General extends Mage_Adminhtml_B
35
 
36
  $fieldset->addField('webservice_user', 'text', array(
37
  'name' => 'opensi[webservice_user]',
38
- 'label' => Mage::helper('opensi')->__('Utilisateur webservice'),
39
- 'title' => Mage::helper('opensi')->__('Utilisateur webservice'),
40
  'required' => true,
41
  'value' => !empty($client) ? $client->webservice_user : '',
42
  ));
43
 
44
  $fieldset->addField('webservice_pwd', 'text', array(
45
  'name' => 'opensi[webservice_pwd]',
46
- 'label' => Mage::helper('opensi')->__('Mot de passe webservice'),
47
- 'title' => Mage::helper('opensi')->__('Mot de passe webservice'),
48
  'required' => true,
49
  'value' => !empty($client) ? $client->webservice_pwd : '',
50
  ));
51
 
52
  $fieldset->addField('web_site_code', 'text', array(
53
  'name' => 'opensi[web_site_code]',
54
- 'label' => Mage::helper('opensi')->__('Code site web'),
55
- 'title' => Mage::helper('opensi')->__('Code site web'),
56
  'required' => true,
57
  'value' => !empty($client) ? $client->web_site_code : '',
58
  ));
59
 
60
  $fieldset->addField('deposit', 'text', array(
61
  'name' => 'opensi[deposit]',
62
- 'label' => Mage::helper('opensi')->__('Code dépôt'),
63
- 'title' => Mage::helper('opensi')->__('Code dépôt'),
64
  'required' => true,
65
  'value' => !empty($client) ? $client->deposit : '',
66
  ));
23
  $client = $this->getClient();
24
 
25
  $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('opensi')->__('General Information')));
26
+
27
  $fieldset->addField('opensi_id', 'text', array(
28
  'name' => 'opensi[opensi_id]',
29
+ 'label' => Mage::helper('opensi')->__('OpenSi ID'),
30
+ 'title' => Mage::helper('opensi')->__('OpenSi ID'),
31
  'required' => true,
32
  'value' => !empty($client) ? $client->opensi_id : '',
33
  'class' => 'validate-number',
35
 
36
  $fieldset->addField('webservice_user', 'text', array(
37
  'name' => 'opensi[webservice_user]',
38
+ 'label' => Mage::helper('opensi')->__('Webservice user'),
39
+ 'title' => Mage::helper('opensi')->__('Webservice user'),
40
  'required' => true,
41
  'value' => !empty($client) ? $client->webservice_user : '',
42
  ));
43
 
44
  $fieldset->addField('webservice_pwd', 'text', array(
45
  'name' => 'opensi[webservice_pwd]',
46
+ 'label' => Mage::helper('opensi')->__('Webservice password'),
47
+ 'title' => Mage::helper('opensi')->__('Webservice password'),
48
  'required' => true,
49
  'value' => !empty($client) ? $client->webservice_pwd : '',
50
  ));
51
 
52
  $fieldset->addField('web_site_code', 'text', array(
53
  'name' => 'opensi[web_site_code]',
54
+ 'label' => Mage::helper('opensi')->__('Website code'),
55
+ 'title' => Mage::helper('opensi')->__('Website code'),
56
  'required' => true,
57
  'value' => !empty($client) ? $client->web_site_code : '',
58
  ));
59
 
60
  $fieldset->addField('deposit', 'text', array(
61
  'name' => 'opensi[deposit]',
62
+ 'label' => Mage::helper('opensi')->__('Deposit code'),
63
+ 'title' => Mage::helper('opensi')->__('Deposit code'),
64
  'required' => true,
65
  'value' => !empty($client) ? $client->deposit : '',
66
  ));
app/code/community/Speedinfo/Opensi/Block/Adminhtml/Edit/Tab/Webservices.php CHANGED
@@ -12,28 +12,29 @@ class Speedinfo_Opensi_Block_Adminhtml_Edit_Tab_Webservices extends Mage_Adminht
12
  * Initialize tab
13
  *
14
  */
15
- public function __construct()
16
- {
17
- parent::__construct();
18
- // fields are not enought here, we use a template
19
- $this->setTemplate('opensi/tab/webservices.phtml');
20
- }
21
-
22
- public function getWebservice($name){
23
- $client = Mage::getModel("opensi/client")->loadByStore($this->getStore());
24
- return !empty($client) ? Mage::getModel("opensi/webservice")->loadByNameClient($name,$client->id) : '';
25
- }
26
-
27
- public function getStore()
28
- {
29
- if(Mage::registry('store_id') != ""){
30
- $store_id = Mage::registry('store_id');
31
- }else{
32
- $store_id = $this->getRequest()->getParam('store');
33
- if($store_id == ""){
34
- $store_id = 0;
35
- }
36
- }
37
- return $store_id;
38
- }
 
39
  }
12
  * Initialize tab
13
  *
14
  */
15
+ public function __construct()
16
+ {
17
+ parent::__construct();
18
+ // fields are not enought here, we use a template
19
+ $this->setTemplate('opensi/tab/webservices.phtml');
20
+ }
21
+
22
+ public function getWebservice($name){
23
+ $client = Mage::getModel("opensi/client")->loadByStore($this->getStore());
24
+ return !empty($client) ? Mage::getModel("opensi/webservice")->loadByNameClient($name,$client->id) : '';
25
+ }
26
+
27
+ public function getStore()
28
+ {
29
+ if(Mage::registry('store_id') != ""){
30
+ $store_id = Mage::registry('store_id');
31
+ }else{
32
+ $store_id = $this->getRequest()->getParam('store');
33
+ if($store_id == ""){
34
+ $store_id = 0;
35
+ }
36
+ }
37
+ return $store_id;
38
+ }
39
+
40
  }
app/code/community/Speedinfo/Opensi/Block/Adminhtml/Grid.php CHANGED
@@ -47,20 +47,20 @@ class Speedinfo_Opensi_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_
47
 
48
 
49
  $this->addColumn('opensi_action', array(
50
- 'header' => Mage::helper('opensi')->__('Webservice invoqué'),
51
  'index' => 'opensi_action',
52
  ));
53
 
54
  $this->addColumn('error_code',
55
  array(
56
- 'header' => Mage::helper('opensi')->__('Code erreur HTTP'),
57
  'width' => '50px',
58
  'type' => 'number',
59
  'index' => 'error_code',
60
  ));
61
 
62
  $this->addColumn('message', array(
63
- 'header' => Mage::helper('opensi')->__('Signification du code erreur HTTP'),
64
  'index' => 'error_message',
65
  ));
66
 
47
 
48
 
49
  $this->addColumn('opensi_action', array(
50
+ 'header' => Mage::helper('opensi')->__('Webservice invoked'),
51
  'index' => 'opensi_action',
52
  ));
53
 
54
  $this->addColumn('error_code',
55
  array(
56
+ 'header' => Mage::helper('opensi')->__('Error code HTTP'),
57
  'width' => '50px',
58
  'type' => 'number',
59
  'index' => 'error_code',
60
  ));
61
 
62
  $this->addColumn('message', array(
63
+ 'header' => Mage::helper('opensi')->__('Meaning of error code HTTP'),
64
  'index' => 'error_message',
65
  ));
66
 
app/code/community/Speedinfo/Opensi/Block/Adminhtml/Tabs.php CHANGED
@@ -34,6 +34,16 @@ class Speedinfo_Opensi_Block_Adminhtml_Tabs extends Mage_Adminhtml_Block_Widget_
34
  'label' => Mage::helper('opensi')->__('General Information'),
35
  'content' => $this->getLayout()->createBlock('opensi/adminhtml_edit_tab_general')->toHtml(),
36
  ));
 
 
 
 
 
 
 
 
 
 
37
 
38
  $this->addTab('webservices', array(
39
  'label' => Mage::helper('opensi')->__('Webservices'),
34
  'label' => Mage::helper('opensi')->__('General Information'),
35
  'content' => $this->getLayout()->createBlock('opensi/adminhtml_edit_tab_general')->toHtml(),
36
  ));
37
+
38
+ $this->addTab('Liaison des familles', array(
39
+ 'label' => Mage::helper('opensi')->__('Linking families'),
40
+ 'content' => $this->getLayout()->createBlock('opensi/adminhtml_edit_tab_familles')->toHtml(),
41
+ ));
42
+
43
+ $this->addTab('Liaison des attributs', array(
44
+ 'label' => Mage::helper('opensi')->__('Linking attributes'),
45
+ 'content' => $this->getLayout()->createBlock('opensi/adminhtml_edit_tab_attributs')->toHtml(),
46
+ ));
47
 
48
  $this->addTab('webservices', array(
49
  'label' => Mage::helper('opensi')->__('Webservices'),
app/code/community/Speedinfo/Opensi/Helper/Data.php CHANGED
@@ -10,23 +10,23 @@ class Speedinfo_Opensi_Helper_Data extends Mage_Core_Helper_Abstract {
10
 
11
  public function getWebservicesName() {
12
  $ws['Articles'] = array(
13
- 'getStockArticle' => array('title' => 'Récupération du stock des articles', 'subtitle' => '(Envoi du stock d\'OpenSi vers le site)', 'frequency' => 30),
14
  'getPrixArticle' => array('title' => 'Récupération du prix des articles', 'subtitle' => '(Envoi du prix des articles d\'OpenSi vers le site)', 'frequency' => 30),
15
- 'getPubwebArticle' => array('title' => 'Récupération des statuts de publicatoin des articles', 'subtitle' => '(Envoi des statuts de publicatoin d\'OpenSi vers le site)', 'frequency' => 30),
16
  'createArticle' => array('title' => 'Création des articles', 'subtitle' => '(Envoi des articles du site vers OpenSi)', 'frequency' => 120),
17
- 'updateArticle' => array('title' => 'Mise à jour des articles', 'subtitle' => '(Envoi des mises à jour du site vers OpenSi)', 'frequency' => 60)
18
  );
19
 
20
  $ws['Commandes'] = array(
21
  'createCommandeWeb' => array('title' => 'Création des commandes', 'subtitle' => '(Envoi des commandes du site vers OpenSi)', 'frequency' => 10),
22
- 'createTransactionBancaire' => array('title' => 'Création des transactions bancaires', 'subtitle' => '(Envoi des transactions bancaires du site vers OpenSi)', 'frequency' => 60),
23
- 'getEtatCommande' => array('title' => 'Récupération des états des commandes', 'subtitle' => '(Envoi des états des commandes d\'OpenSi vers le site)', 'frequency' => 60),
24
- 'getTrackingColis' => array('title' => 'Récupération des numéros de suivie de colis', 'subtitle' => '(Envoi des numéros de suivie de colis d\'OpenSi vers le site)', 'frequency' => 60)
25
  );
26
 
27
  $ws['Clients'] = array(
28
- 'createClientWeb' => array('title' => 'Création des clients', 'subtitle' => '(Envoi des clients du site vers OpenSi)', 'frequency' => 60),
29
- 'updateClientWeb' => array('title' => 'Mise à jour des clients', 'subtitle' => '(Envoi des mises à jour du site vers OpenSi)', 'frequency' => 300)
30
  );
31
  return $ws;
32
  }
10
 
11
  public function getWebservicesName() {
12
  $ws['Articles'] = array(
13
+ 'getStockArticle' => array('title' => 'Récupération du stock des articles', 'subtitle' => '(Envoi du stock d\'OpenSi vers le site)', 'frequency' => 10),
14
  'getPrixArticle' => array('title' => 'Récupération du prix des articles', 'subtitle' => '(Envoi du prix des articles d\'OpenSi vers le site)', 'frequency' => 30),
15
+ //'getPubwebArticle' => array('title' => 'Récupération des statuts de publicatoin des articles', 'subtitle' => '(Envoi des statuts de publicatoin d\'OpenSi vers le site)', 'frequency' => 30),
16
  'createArticle' => array('title' => 'Création des articles', 'subtitle' => '(Envoi des articles du site vers OpenSi)', 'frequency' => 120),
17
+ 'updateArticle' => array('title' => 'Mise à jour des articles', 'subtitle' => '(Envoi des mises à jour du site vers OpenSi)', 'frequency' => 120)
18
  );
19
 
20
  $ws['Commandes'] = array(
21
  'createCommandeWeb' => array('title' => 'Création des commandes', 'subtitle' => '(Envoi des commandes du site vers OpenSi)', 'frequency' => 10),
22
+ 'createTransactionBancaire' => array('title' => 'Création des transactions bancaires', 'subtitle' => '(Envoi des transactions bancaires du site vers OpenSi)', 'frequency' => 10),
23
+ 'getEtatCommande' => array('title' => 'Récupération des états des commandes', 'subtitle' => '(Envoi des états des commandes d\'OpenSi vers le site)', 'frequency' => 30),
24
+ 'getTrackingColis' => array('title' => 'Récupération des numéros de suivie de colis', 'subtitle' => '(Envoi des numéros de suivie de colis d\'OpenSi vers le site)', 'frequency' => 30)
25
  );
26
 
27
  $ws['Clients'] = array(
28
+ 'createClientWeb' => array('title' => 'Création des clients', 'subtitle' => '(Envoi des clients du site vers OpenSi)', 'frequency' => 30),
29
+ 'updateClientWeb' => array('title' => 'Mise à jour des clients', 'subtitle' => '(Envoi des mises à jour du site vers OpenSi)', 'frequency' => 30)
30
  );
31
  return $ws;
32
  }
app/code/community/Speedinfo/Opensi/Model/Cron.php CHANGED
@@ -8,116 +8,117 @@
8
  */
9
  class Speedinfo_Opensi_Model_Cron extends Mage_Core_Model_Abstract {
10
 
11
- /**
12
- * Cron tourne toutes les 5 minutes et verifie si des actions sont a lancer ou non
13
- */
14
- public function scheduleCron() {
 
 
 
 
 
 
 
15
 
16
- // on gere le storeId 0 differement
17
- $clientDefault = Mage::getModel('opensi/client')->loadByStore(0);
18
- if (!empty($clientDefault)) {
19
- $webservicesDefault = Mage::getModel('opensi/webservice')->getCollection()->addFieldToFilter('client_id', $clientDefault->id);
20
- } else {
21
- $webservicesDefault = '';
22
- }
 
 
 
 
 
 
 
23
 
24
- // on verifie la config pour chaque store
25
- $storeIds = $this->getStoreIds();
26
- foreach ($storeIds as $storeId) {
27
- $baseStoreId = $storeId;
28
- $client = Mage::getModel('opensi/client')->loadByStore($storeId);
29
- // le client du store existe, on utilise sa config
30
- if (!empty($client)) {
31
- $useDefaultView = false;
32
- $webservices = Mage::getModel('opensi/webservice')->getCollection()->addFieldToFilter('client_id,', $client->id);
33
- } else {
34
- $useDefaultView = true;
35
- $webservices = $webservicesDefault;
36
- $client = $clientDefault;
37
- }
 
 
38
 
39
- if (!empty($webservices)) {
40
- foreach ($webservices as $webservice) {
41
- $webserviceName = $webservice->getName();
42
- $lastStartString = $webservice->getStartedAt();
43
- // si y'a pas date de dernier lancement, on tous les articles, et les commandes / clients du jour
44
- if (empty($lastStartString)) {
45
- if ($webserviceName == 'createArticle') {
46
- $lastStart = new DateTime('1970-01-01');
47
- } else {
48
- $lastStart = new DateTime(date('Y-m-d'));
49
- }
50
- } else {
51
- $lastStart = new DateTime($lastStartString);
52
- }
53
- $frequency = $webservice->getFrequency();
54
- $now = new Datetime();
55
 
56
- $interval = ($now->format('U') - $lastStart->format('U')) / 60;
57
- // si le temps passe depuis le dernier lancement est superieur ou egal a la frequence de lancement
58
- if ($interval >= $frequency) {
59
- // on prend une marge pour pas rater d'infos
60
- $lastStart->modify('-5 min');
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- // si c'est un store par defaut on le met pas a jour parce qu'il peut y'en avoir plusieurs en suivant
63
- if (!$useDefaultView) {
64
- $webservice->setStartedAt($now->format('Y-m-d H:i:s'));
65
- $webservice->save();
66
- }
67
- if ($webserviceName == 'createArticle' || $webserviceName == 'updateArticle') {
68
- $storeId = 0;
69
- } else {
70
- $storeId = $baseStoreId;
71
- }
72
- Mage::log('debut ' . $webserviceName . ' store ' . $storeId, null, 'opensi.log');
73
- Mage::getModel('opensi/webservices')->$webserviceName($lastStart, $client, $storeId);
74
- }
75
- }
76
- }
77
- }
 
78
 
79
- // on met a jour les dates pour le store par defaut
80
- if (!empty($webservicesDefault)) {
81
- foreach ($webservicesDefault as $webservice) {
82
- $webserviceName = $webservice->getName();
83
- $lastStartString = $webservice->getStartedAt();
84
- // si y'a pas date de dernier lancement, on tous les articles, et les commandes / clients du jour
85
- if (empty($lastStartString)) {
86
- if ($webserviceName == 'createArticle') {
87
- $lastStart = new DateTime('1970-01-01');
88
- } else {
89
- $lastStart = new DateTime(date('Y-m-d'));
90
- }
91
- } else {
92
- $lastStart = new DateTime($lastStartString);
93
- }
94
- $frequency = $webservice->getFrequency();
95
- $now = new Datetime();
96
 
97
- $interval = ($now->format('U') - $lastStart->format('U')) / 60;
98
- // si le temps passe depuis le dernier lancement est superieur ou egal a la frequence de lancement
99
- if ($interval >= $frequency) {
100
- $webservice->setStartedAt($now->format('Y-m-d H:i:s'));
101
- $webservice->save();
102
- }
103
- }
104
- }
105
- }
 
 
 
106
 
107
- /**
108
- * Retourne la liste des store_id
109
- * @return array $storeList liste des store_id excluant le store par defaut
110
- */
111
- protected function getStoreIds() {
112
- $storeList = array();
113
- $allStores = Mage::app()->getStores();
114
- foreach ($allStores as $key => $value) {
115
- $storeId = $storeId = Mage::app()->getStore($key)->getId();
116
- if ($storeId != '0')
117
- array_push($storeList, $storeId);
118
- }
119
-
120
- return $storeList;
121
- }
122
 
123
  }
8
  */
9
  class Speedinfo_Opensi_Model_Cron extends Mage_Core_Model_Abstract {
10
 
11
+ /**
12
+ * Cron tourne toutes les 5 minutes et verifie si des actions sont a lancer ou non
13
+ */
14
+ public function scheduleCron() {
15
+ // on gere le storeId 0 differement
16
+ $clientDefault = Mage::getModel('opensi/client')->loadByStore(0);
17
+ if (!empty($clientDefault)) {
18
+ $webservicesDefault = Mage::getModel('opensi/webservice')->getCollection()->addFieldToFilter('client_id', $clientDefault->id);
19
+ } else {
20
+ $webservicesDefault = '';
21
+ }
22
 
23
+ // on verifie la config pour chaque store
24
+ $storeIds = $this->getStoreIds();
25
+ foreach ($storeIds as $storeId) {
26
+ $baseStoreId = $storeId;
27
+ $client = Mage::getModel('opensi/client')->loadByStore($storeId);
28
+ // le client du store existe, on utilise sa config
29
+ if (!empty($client)) {
30
+ $useDefaultView = false;
31
+ $webservices = Mage::getModel('opensi/webservice')->getCollection()->addFieldToFilter('client_id,', $client->id);
32
+ } else {
33
+ $useDefaultView = true;
34
+ $webservices = $webservicesDefault;
35
+ $client = $clientDefault;
36
+ }
37
 
38
+ if (!empty($webservices)) {
39
+ foreach ($webservices as $webservice) {
40
+ $webserviceName = $webservice->getName();
41
+ $lastStartString = $webservice->getStartedAt();
42
+ // si y'a pas date de dernier lancement, on tous les articles, et les commandes / clients du jour
43
+ if (empty($lastStartString)) {
44
+ if ($webserviceName == 'createArticle') {
45
+ $lastStart = new DateTime('1970-01-01');
46
+ } else {
47
+ $lastStart = new DateTime(date('Y-m-d'));
48
+ }
49
+ } else {
50
+ $lastStart = new DateTime($lastStartString);
51
+ }
52
+ $frequency = $webservice->getFrequency();
53
+ $now = new Datetime();
54
 
55
+ $interval = ($now->format('U') - $lastStart->format('U')) / 60;
56
+ // si le temps passe depuis le dernier lancement est superieur ou egal a la frequence de lancement
57
+ if ($interval >= $frequency) {
58
+ // on prend une marge pour pas rater d'infos
59
+ $lastStart->modify('-5 min');
 
 
 
 
 
 
 
 
 
 
 
60
 
61
+ // si c'est un store par defaut on le met pas a jour parce qu'il peut y'en avoir plusieurs en suivant
62
+ if (!$useDefaultView) {
63
+ $webservice->setStartedAt($now->format('Y-m-d H:i:s'));
64
+ $webservice->save();
65
+ }
66
+ if ($webserviceName == 'createArticle' || $webserviceName == 'updateArticle') {
67
+ $storeId = 0;
68
+ $webservice->setStartedAt($now->format('Y-m-d H:i:s'));
69
+ $webservice->save();
70
+ } else {
71
+ $storeId = $baseStoreId;
72
+ }
73
+ Mage::log('debut ' . $webserviceName . ' store ' . $storeId, null, 'opensi.log');
74
+ Mage::getModel('opensi/webservices')->$webserviceName($lastStart, $client, $storeId);
75
+ }
76
+ }
77
+ }
78
+ }
79
 
80
+ // on met a jour les dates pour le store par defaut
81
+ if (!empty($webservicesDefault)) {
82
+ foreach ($webservicesDefault as $webservice) {
83
+ $webserviceName = $webservice->getName();
84
+ $lastStartString = $webservice->getStartedAt();
85
+ // si y'a pas date de dernier lancement, on tous les articles, et les commandes / clients du jour
86
+ if (empty($lastStartString)) {
87
+ if ($webserviceName == 'createArticle') {
88
+ $lastStart = new DateTime('1970-01-01');
89
+ } else {
90
+ $lastStart = new DateTime(date('Y-m-d'));
91
+ }
92
+ } else {
93
+ $lastStart = new DateTime($lastStartString);
94
+ }
95
+ $frequency = $webservice->getFrequency();
96
+ $now = new Datetime();
97
 
98
+ $interval = ($now->format('U') - $lastStart->format('U')) / 60;
99
+ // si le temps passe depuis le dernier lancement est superieur ou egal a la frequence de lancement
100
+ if ($interval >= $frequency) {
101
+ $webservice->setStartedAt($now->format('Y-m-d H:i:s'));
102
+ $webservice->save();
103
+ }
104
+ }
105
+ }
106
+ }
 
 
 
 
 
 
 
 
107
 
108
+ /**
109
+ * Retourne la liste des store_id
110
+ * @return array $storeList liste des store_id excluant le store par defaut
111
+ */
112
+ protected function getStoreIds() {
113
+ $storeList = array();
114
+ $allStores = Mage::app()->getStores();
115
+ foreach ($allStores as $key => $value) {
116
+ $storeId = $storeId = Mage::app()->getStore($key)->getId();
117
+ if ($storeId != '0')
118
+ array_push($storeList, $storeId);
119
+ }
120
 
121
+ return $storeList;
122
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  }
app/code/community/Speedinfo/Opensi/Model/Webservices.php CHANGED
@@ -8,641 +8,741 @@
8
  */
9
  class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
10
 
11
- /**
12
- * Envoie des donnees au serveur OpenSI
13
- * @param String $method POST / GET / PUT
14
- * @param String $action action a effectuer
15
- * @param String $xmlData donnees a envoyer format XML
16
- * @param Array $client les infos sur le client opensi
17
- * @param Array $params liste des parametres a envoyer au serveur
18
- * @return String $response reponse du serveur
19
- */
20
- protected function sendData($method, $action, $xmlData, $client, $params = '') {
21
-
22
- $httpRequest = new Zend_Http_Client();
23
- $httpRequest->setAuth($client->webservice_user, $client->webservice_pwd);
24
- $httpRequest->setUri('https://webservices.opensi.eu/cows/Gateway');
25
- $httpRequest->setParameterGet(array('service_id' => $client->opensi_id, 'action' => $action));
26
- if (!empty($xmlData))
27
- $httpRequest->setRawData($xmlData, 'text/xml');
28
- if (!empty($params))
29
- $httpRequest->setParameterGet($params);
30
-
31
- $response = $httpRequest->request($method);
32
-
33
- //on gere les logs / erreurs
34
- if ($response->isError() && $response->getStatus() != '409') {
35
- $this->setLogs($response, $client, $action);
36
- }
37
- Mage::log($httpRequest, null, 'opensi.log');
38
-
39
- return $response->getRawBody();
40
- }
41
-
42
- protected function createXml() {
43
- $docXml = new DomDocument('1.0', 'UTF-8');
44
- $docXml->formatOutput = true;
45
-
46
- return $docXml;
47
- }
48
-
49
- /**
50
- * Envoie des nouvelles commandes vers OpenSI
51
- */
52
- public function createCommandeWeb($startedAt, $client, $storeId) {
53
-
54
- $orderCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))->addFieldToFilter('store_id', $storeId);
55
- if ($orderCollection->count() > 0) {
56
- $this->createArticle($startedAt, $client, $storeId);
57
- $this->createClientWeb($startedAt, $client, $storeId);
58
- }
59
-
60
- foreach ($orderCollection as $order) {
61
- $docXml = $this->createXml();
62
- $request = $docXml->createElement("request");
63
-
64
- $docXml->appendChild($request);
65
- $commandeWeb = $docXml->createElement("Commande_Web");
66
-
67
- $orderDate = new Datetime($order->getCreatedAt());
68
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
69
- // Informations de commande
70
- $commandeWeb->setAttribute('Num_Com_Web', $order->getIncrementId());
71
- $commandeWeb->setAttribute('Code_Site_Web', $client->web_site_code);
72
- $commandeWeb->setAttribute('Login', $customer->getEmail());
73
- $commandeWeb->setAttribute('Date_Commande', $orderDate->format('d-m-Y H:i:s'));
74
- //prix en ttc ou ht ?
75
- $commandeWeb->setAttribute('Edition_TTC', 0);
76
- $commandeWeb->setAttribute('Frais_Port', $order->getShippingAmount());
77
-
78
- // recuperation du taux de tva sur les frais de port
79
- $taxClassId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $storeId);
80
- if ($taxClassId != 0) {
81
- $taxRequest = Mage::getSingleton('tax/calculation')->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), "", $storeId);
82
- $percent = Mage::getSingleton('tax/calculation')->getRate($taxRequest->setProductClassId($taxClassId));
83
- } else {
84
- $percent = 0;
85
- }
86
-
87
- $commandeWeb->setAttribute('Taux_Tva_Port', $percent);
88
- $totalTTC = $order->getSubtotal() + $order->getBaseTaxAmount();
89
- //$commandeWeb->setAttribute('Remise_Pourc', ((($totalTTC - ($order->getBaseGrandTotal() - $order->getBaseShippingAmount())) / $totalTTC) * 100));
90
- $commandeWeb->setAttribute('Remise_Pourc', '0');
91
- $commandeWeb->setAttribute('Mode_Reglement', $order->getPayment()->getMethod());
92
-
93
- // Informations de facturation
94
- $commandeWeb->setAttribute('Civ_Fact', 0);
95
- $commandeWeb->setAttribute('Nom_Fact', $order->getBillingAddress()->getLastname());
96
- $commandeWeb->setAttribute('Prenom_Fact', $order->getBillingAddress()->getFirstname());
97
- $billingCompany = $order->getBillingAddress()->getCompany();
98
- if (!empty($billingCompany))
99
- $commandeWeb->setAttribute('Societe_Fact', $billingCompany);
100
- $commandeWeb->setAttribute('Adresse_1_Fact', $order->getBillingAddress()->getStreet1());
101
- $billingStreet2 = $order->getBillingAddress()->getStreet2();
102
- $billingStreet3 = $order->getBillingAddress()->getStreet3();
103
- if (!empty($billingStreet2))
104
- $commandeWeb->setAttribute('Adresse_2_Fact', $billingStreet2);
105
- if (!empty($billingStreet3))
106
- $commandeWeb->setAttribute('Adresse_3_Fact', $billingStreet3);
107
- $commandeWeb->setAttribute('Code_Postal_Fact', $order->getBillingAddress()->getPostcode());
108
- $commandeWeb->setAttribute('Ville_Fact', $order->getBillingAddress()->getCity());
109
- $commandeWeb->setAttribute('Code_Pays_Fact', $order->getBillingAddress()->getCountry());
110
- $billingPhone = $order->getBillingAddress()->getTelephone();
111
- if (!empty($billingPhone))
112
- $commandeWeb->setAttribute('Tel_Fact', $billingPhone);
113
- $billingFax = $order->getBillingAddress()->getFax();
114
- if (!empty($billingFax))
115
- $commandeWeb->setAttribute('Fax_Fact', $billingFax);
116
- $commandeWeb->setAttribute('Email_Fact', $customer->getEmail());
117
-
118
- //Informations de livraison
119
- $commandeWeb->setAttribute('Civ_Liv', 0);
120
- $commandeWeb->setAttribute('Nom_Liv', $order->getShippingAddress()->getLastname());
121
- $commandeWeb->setAttribute('Prenom_Liv', $order->getShippingAddress()->getFirstname());
122
- $shippingCompany = $order->getShippingAddress()->getCompany();
123
- if (!empty($shippingCompany))
124
- $commandeWeb->setAttribute('Societe_Liv', $shippingCompany);
125
- $commandeWeb->setAttribute('Adresse_1_Liv', $order->getShippingAddress()->getStreet1());
126
- $shippingStreet2 = $order->getShippingAddress()->getStreet2();
127
- $shippingStreet3 = $order->getShippingAddress()->getStreet3();
128
- if (!empty($shippingStreet2))
129
- $commandeWeb->setAttribute('Adresse_2_Liv', $shippingStreet2);
130
- if (!empty($shippingStreet3))
131
- $commandeWeb->setAttribute('Adresse_3_Liv', $shippingStreet3);
132
- $commandeWeb->setAttribute('Code_Postal_Liv', $order->getShippingAddress()->getPostcode());
133
- $commandeWeb->setAttribute('Ville_Liv', $order->getShippingAddress()->getCity());
134
- $commandeWeb->setAttribute('Code_Pays_Liv', $order->getShippingAddress()->getCountry());
135
- $shippingPhone = $order->getShippingAddress()->getTelephone();
136
- if (!empty($shippingPhone))
137
- $commandeWeb->setAttribute('Tel_Liv', $shippingPhone);
138
- $shippingFax = $order->getShippingAddress()->getFax();
139
- if (!empty($shippingFax))
140
- $commandeWeb->setAttribute('Fax_Liv', $shippingFax);
141
- $commandeWeb->setAttribute('Email_Liv', $customer->getEmail());
142
-
143
- $request->appendChild($commandeWeb);
144
-
145
- // Informations du contenu de la commande
146
- foreach ($order->getAllVisibleItems() as $item) {
147
- $ligneCommandeClient = $docXml->createElement("Ligne_Commande_Client");
148
-
149
- $ligneCommandeClient->setAttribute('Reference', $item->getSku());
150
- $ligneCommandeClient->setAttribute('Designation', $item->getName());
151
- $ligneCommandeClient->setAttribute('Quantite', $item->getQtyOrdered());
152
- $ligneCommandeClient->setAttribute('Prix_Unitaire', $item->getPrice());
153
- $discountAmount = $item->getDiscountAmount();
154
-
155
- //Si il existe une remise en valeur
156
- if (!empty($discountAmount) && $item->getPrice() != 0) {
157
- $discount = (1 - (($item->getPrice() - $item->getDiscountAmount()) / $item->getPrice())) * 100;
158
- $discount = round($discount, 2);
159
- }
160
-
161
- $discountPourcent = $item->getDiscountPercent();
162
- //Si il existe un poucentage de remise.
163
- if ($discountPourcent != 0) {
164
- $discount = $discountPourcent;
165
- }
166
-
167
- //Si il existe les 2 types de remise % et montant
168
- if (!empty($discountAmount) && !empty($discountPourcent)) {
169
- $discountValeurDepuisPourcentage = ($item->getPrice() * $discountPourcent) / 100;
170
- $discountTotalValue = $discountAmount + $discountValeurDepuisPourcentage;
171
- $discountPourcent = (1 - (($item->getPrice() - $discountTotalValue) / $item->getPrice())) * 100;
172
- $discount = $discountPourcent;
173
- }
174
-
175
- $ligneCommandeClient->setAttribute('Remise_Pourc', $discount);
176
- $ligneCommandeClient->setAttribute('Taux_Tva', $item->getTaxPercent());
177
-
178
- $commandeWeb->appendChild($ligneCommandeClient);
179
- }
180
-
181
- $this->sendData('POST', 'create_commande_web', $docXml->saveXml(), $client);
182
- } // endforeach $ordercollection
183
-
184
- if ($orderCollection->count() > 0) {
185
- $this->createTransactionBancaire($startedAt, $client, $storeId);
186
- }
187
- }
188
-
189
- /**
190
- * Envoie des nouveaux produits vers OpenSI
191
- */
192
- public function createArticle($startedAt, $client, $storeId) {
193
- $productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
194
- ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))->addStoreFilter($storeId)
195
- ->addAttributeToSelect(array('sku', 'price', 'name', 'description', 'short_description', 'manufacturer', 'weight', 'status'));
196
- foreach ($productCollection as $product) {
197
- $articleData = $this->articleData($product, $storeId);
198
- $this->sendData('POST', 'create_article', $articleData, $client);
199
- } // endforeach $productCollection
200
- if ($productCollection->count() > 0)
201
- $this->setPubwebArticle($startedAt, $client, $storeId);
202
- }
203
-
204
- /**
205
- * Envoie des produits modifies vers OpenSI
206
- */
207
- public function updateArticle($startedAt, $client, $storeId) {
208
- $productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
209
- ->addFieldToFilter('created_at', array('lteq' => $startedAt->format('Y-m-d H:i:s')))->addStoreFilter($storeId)
210
- ->addAttributeToSelect(array('sku', 'price', 'name', 'description', 'short_description', 'manufacturer', 'weight', 'status'));
211
-
212
- foreach ($productCollection as $product) {
213
- $articleData = $this->articleData($product, $storeId);
214
- $params = array('reference' => $product->getSku());
215
- $this->sendData('PUT', 'update_article', $articleData, $client, $params);
216
- } // endforeach $productCollection
217
- if ($productCollection->count() > 0)
218
- $this->setPubwebArticle($startedAt, $client, $storeId);
219
- }
220
-
221
- /**
222
- * Creation du XML pour la creation / modification de produits
223
- */
224
- public function articleData($product, $storeId) {
225
- $docXml = $this->createXml();
226
- $request = $docXml->createElement("request");
227
-
228
- $docXml->appendChild($request);
229
- $article = $docXml->createElement('Article');
230
-
231
- // Informations du produit
232
- $article->setAttribute('Reference', $product->getSku());
233
- $article->setAttribute('Designation', $product->getName());
234
- $article->setAttribute('Description_1', $product->getDescription());
235
- $shortDescription = $product->getShortDescription();
236
- if (!empty($shortDescription))
237
- $article->setattribute('Description_2', $shortDescription);
238
- $brand = $product->getAttributeText('manufacturer');
239
- if (!empty($brand))
240
- $article->setAttribute('Marque', $brand);
241
- $categories = $product->getCategoryIds();
242
-
243
- //limite a 3 categories
244
- $i = 1;
245
- $empty = true;
246
- foreach ($categories as $category) {
247
- $empty = false;
248
- $category = Mage::getModel('catalog/category')->load($category);
249
- $article->setAttribute('Famille_' . $i, $category->getName());
250
- if ($i >= 3)
251
- break;
252
- $i++;
253
- }
254
- if($empty) $article->setAttribute('Famille_1','NC');
255
-
256
- $weight = $product->getWeight();
257
- if (!empty($weight))
258
- $article->setAttribute('Poids', $weight);
259
- $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
260
- // Mage::log('tax :' . $includeTax);
261
- if ($includeTax) {
262
- $article->setAttribute('Tarif_TTC_1', $product->getFinalPrice());
263
- } else {
264
- $article->setAttribute('Tarif_HT_1', $product->getFinalPrice());
265
- }
266
- $updatedAt = new Datetime($product->getUpdatedAt());
267
- $createdAt = new Datetime($product->getCreatedAt());
268
- $article->setAttribute('Date_M', $updatedAt->format('d-m-Y H:i:s'));
269
- $article->setAttribute('Date_C', $createdAt->format('d-m-Y H:i:s'));
270
- //$active = $product->getStatus();
271
- // Mage::log('active :' . $active);
272
- //if ($active == 2) {
273
- // $active = "false";
274
- //} else {
275
- $active = "true";
276
- //}
277
- $article->setAttribute('Actif', $active);
278
-
279
- $request->appendChild($article);
280
-
281
- return $docXml->saveXML();
282
- }
283
-
284
- /**
285
- * Envoie des nouveaux clients vers OpenSI
286
- */
287
- public function createClientWeb($startedAt, $client, $storeId) {
288
-
289
- $customerCollection = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
290
- ->addAttributeToSelect(array('lastname', 'firstname'))->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
291
-
292
- foreach ($customerCollection as $customer) {
293
- $clientData = $this->clientData($customer, $client);
294
- $this->sendData('POST', 'create_client_web', $clientData, $client);
295
- }
296
- }
297
-
298
- /**
299
- * Envoie des clients modifies vers OpenSI
300
- */
301
- public function updateClientWeb($startedAt, $client, $storeId) {
302
-
303
- $customerCollection = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
304
- ->addFieldToFilter('created_at', array('lteq' => $startedAt->format('Y-m-d H:i:s')))->addAttributeToSelect(array('lastname', 'firstname'))->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
305
-
306
- foreach ($customerCollection as $customer) {
307
- $clientData = $this->clientData($customer, $client);
308
- $params = array('code_site_web' => $client->web_site_code, 'login' => $customer->getId());
309
- $this->sendData('PUT', 'update_client_web', $clientData, $client, $params);
310
- }
311
- }
312
-
313
- /**
314
- * Creation du XML pour la creation / modification de clients
315
- */
316
- public function clientData($customer, $client) {
317
- $docXml = $this->createXml();
318
- $request = $docXml->createElement("request");
319
-
320
- $docXml->appendChild($request);
321
- $clientWeb = $docXml->createElement('Client_Web');
322
-
323
- // Informations du client
324
- $clientWeb->setAttribute('Code_Site_Web', $client->web_site_code);
325
- $clientWeb->setAttribute('Login', $customer->getId());
326
- $clientWeb->setAttribute('Civilite', '0');
327
- $clientWeb->setAttribute('Nom', $customer->getLastname());
328
- $clientWeb->setAttribute('Prenom', $customer->getFirstname());
329
- $clientWeb->setAttribute('Adresse_1', 'NC');
330
- $clientWeb->setAttribute('Ville', 'NC');
331
- $clientWeb->setAttribute('Code_Pays', 'FR');
332
- $clientWeb->setAttribute('Email', $customer->getEmail());
333
-
334
- $request->appendChild($clientWeb);
335
-
336
- return $docXml->saveXML();
337
- }
338
-
339
- /**
340
- * Recuperation des stocks depuis OpenSI et mise a jour du site
341
- */
342
- public function getStockArticle($startedAt, $client, $storeId) {
343
- $params = array('code_depot' => $client->deposit, 'date_debut' => $startedAt->format('d-m-Y'));
344
-
345
- $resultXML = $this->sendData("GET", "get_stock_article", "", $client, $params);
346
-
347
- $xmlDomDocument = new DomDocument();
348
- $xmlDomDocument->loadXML($resultXML);
349
-
350
- $stockArticles = $xmlDomDocument->getElementsByTagName("Stock_Article");
351
-
352
- foreach ($stockArticles as $stockArticle) {
353
-
354
- $sku = $stockArticle->getAttribute('Reference');
355
- $qty = $stockArticle->getAttribute('Stock_Dispo');
356
- $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
357
- if ($product) {
358
- $stockArticle = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
359
- if ($qty > 0) {
360
- $stockArticle->setQty($qty);
361
- $stockArticle->setIsInStock(true);
362
- } else {
363
- $stockArticle->setQty(0);
364
- $stockArticle->setIsInStock(false);
365
- }
366
-
367
- $stockArticle->setStoreId($storeId);
368
- $stockArticle->save();
369
- }
370
- }
371
- }
372
-
373
- /**
374
- * Envoie des infos de paiement a OpenSI
375
- */
376
- public function createTransactionBancaire($startedAt, $client, $storeId) {
377
- //recuperation des commandes
378
- $orderCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))->addFieldToFilter('store_id', $storeId);
379
-
380
- foreach ($orderCollection as $order) {
381
- $methodPayment = $order->getPayment()->getMethod();
382
- $numOrder = $order->getIncrementId();
383
- $numeroTransaction = $numOrder;
384
-
385
- $invoiceCollection = Mage::getResourceModel('sales/order_invoice_collection')
386
- ->addAttributeToSelect('order_id')
387
- ->addAttributeToSelect('increment_id')
388
- ->addAttributeToSelect('created_at')
389
- ->addAttributeToSelect('state')
390
- ->addAttributeToSelect('base_grand_total')
391
- ->setOrderFilter($order);
392
-
393
- $dateTransaction = "";
394
- $montant = 0;
395
- $bool = false;
396
- foreach ($invoiceCollection as $invoice) {
397
- //On vérifie que la facture est payé
398
- if ($invoice->getState() == 2) {
399
- $bool = true;
400
- $dateTransaction = $invoice->getCreatedAt();
401
- $montant += $invoice->getBaseGrandTotal();
402
- }
403
- }
404
-
405
- if ($bool) {
406
- $dateTransaction = new Datetime($dateTransaction);
407
-
408
- $docXml = $this->createXml();
409
- $request = $docXml->createElement("request");
410
-
411
- $docXml->appendChild($request);
412
- $transactionComWeb = $docXml->createElement("Transaction_Com_Web");
413
-
414
- $transactionComWeb->setAttribute('Code_Site_Web', $client->web_site_code);
415
- $transactionComWeb->setAttribute('Num_Com_Web', $numOrder);
416
- $transactionComWeb->setAttribute('Num_Transaction', $numeroTransaction);
417
- $transactionComWeb->setAttribute('Mode_Reglement', $methodPayment);
418
- $transactionComWeb->setAttribute('Date_Transaction', $dateTransaction->format('d-m-Y'));
419
- $transactionComWeb->setAttribute('Montant', $montant);
420
-
421
- $request->appendChild($transactionComWeb);
422
-
423
- $this->sendData('POST', 'create_transaction_bancaire', $docXml->saveXml(), $client);
424
- }
425
- }
426
- }
427
-
428
- /**
429
- * Recuperation des etats de commande depuis OpenSI et mise a jour du site
430
- */
431
- public function getEtatCommande($startedAt, $client, $storeId) {
432
- $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
433
- $resultXML = $this->sendData("GET", "get_etat_commande", "", $client, $params);
434
-
435
- $xmlDomDocument = new DomDocument();
436
- $xmlDomDocument->loadXML($resultXML);
437
- $listEtatCommande = $xmlDomDocument->getElementsByTagName("Etat_Commande");
438
-
439
- foreach ($listEtatCommande as $etatCommande) {
440
- $order = Mage::getModel('sales/order')->loadByIncrementId($etatCommande->getAttribute('Num_Com_Web'));
441
-
442
- if (!$order->getId()) {
443
- continue;
444
- }
445
-
446
- //recup du statut de paiement = si termine on facture pour considerer la commande paye
447
- if ($etatCommande->getAttribute('Statut_Paiement') == 'T') {
448
-
449
- if ($order->canInvoice()) {
450
- $invoiceCollection = $order->getInvoiceCollection();
451
- $invoiceId = '';
452
- foreach ($invoiceCollection as $invoice) {
453
- $invoiceId = $invoice->getIncrementId();
454
- }
455
-
456
- if (empty($invoiceId))
457
- $invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(), array());
458
-
459
- $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId);
460
- if ($invoice->canCapture()) {
461
- $invoice->capture();
462
- }
463
- $invoice->save();
464
- }
465
- }
466
-
467
-
468
- //recup du statut de livraison
469
- if ($etatCommande->getAttribute('Statut_Logistique') == 'E') {
470
-
471
- if ($order->canShip()) {
472
- $shipmentCollection = $order->getShipmentsCollection();
473
- $shipmentId = '';
474
- foreach ($shipmentCollection as $shipment) {
475
- $shipmentId = $shipment->getIncrementId();
476
- }
477
- Mage::log('shipmentId = ' . $shipmentId);
478
- if (empty($shipmentId))
479
- $shipmentId = Mage::getModel('sales/order_shipment_api')->create($order->getIncrementId(), array());
480
- }
481
- }
482
-
483
- $status = $order->getStatus();
484
- //passer derniere valeur a true pour envoyer mail au client
485
- switch ($etatCommande->getAttribute('Etat')) {
486
- case 'N':
487
- if ($status != 'pending')
488
- $order->setState('pending', true, 'changement de statut OpenSI', false);
489
- break;
490
-
491
- case 'T':
492
- if ($status != 'processing')
493
- $order->setState('processing', true, 'changement de statut OpenSI', false);
494
- break;
495
-
496
- case 'A':
497
- if ($status != 'canceled')
498
- $order->setState('canceled', true, 'changement de statut OpenSI', false);
499
- break;
500
-
501
- case 'C':
502
- if ($status != 'complete' && Mage::getVersion() > '1.4.0.0')
503
- $order->setState('complete', true, 'changement de statut OpenSI', false);
504
- break;
505
- }
506
- $order->save();
507
- }
508
- }
509
-
510
- /**
511
- * Recuperation des infos de suivi de colis depuis OpenSI et mise a jour du site
512
- */
513
- public function getTrackingColis($startedAt, $client, $storeId) {
514
- $now = new Datetime();
515
- $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'), 'date_fin' => $now->format('d-m-Y'));
516
- $resultXML = $this->sendData("GET", "get_tracking_colis", "", $client, $params);
517
-
518
- $xmlDomDocument = new DomDocument();
519
- $xmlDomDocument->loadXML($resultXML);
520
- $listExpedition = $xmlDomDocument->getElementsByTagName("Colis_Expedition");
521
-
522
- foreach ($listExpedition as $expedition) {
523
- $order = Mage::getModel('sales/order')->loadByIncrementId($expedition->getAttribute('Num_Com_Web'));
524
- /**
525
- * Check order existing
526
- */
527
- if (!$order->getId()) {
528
- continue;
529
- }
530
- /**
531
- * Check shipment create availability
532
- */
533
- if (!$order->canShip()) {
534
- continue;
535
- }
536
- $shipmentCollection = $order->getShipmentsCollection();
537
- $shipmentId = '';
538
- foreach ($shipmentCollection as $shipment) {
539
- $shipmentId = $shipment->getIncrementId();
540
- }
541
- if (empty($shipmentId))
542
- $shipmentId = Mage::getModel('sales/order_shipment_api')->create($order->getIncrementId(), array());
543
- $track = Mage::getModel('sales/order_shipment_api')->addTrack($shipmentId, "custom", $expedition->getAttribute('Transporteur') . ' - ' . $expedition->getAttribute('Mode_Expedition'), $expedition->getAttribute('Num_Colis'));
544
- }
545
- }
546
-
547
- /**
548
- * Recuperation des publications de produits depuis OpenSI et mise a jour du site
549
- */
550
- public function getPubwebArticle($startedAt, $client, $storeId) {
551
- $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
552
- $resultXML = $this->sendData("GET", "get_pubweb_article", "", $client, $params);
553
-
554
- $xmlDomDocument = new DomDocument();
555
- $xmlDomDocument->loadXML($resultXML);
556
- $listPublicationArticle = $xmlDomDocument->getElementsByTagName("Pubweb_Article");
557
-
558
- foreach ($listPublicationArticle as $publicationArticle) {
559
- $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $publicationArticle->getAttribute('Reference'));
560
- if ($product) {
561
- if ($publicationArticle->getAttribute('Publication') == "true") {
562
- $product->setStatus('1');
563
- } else {
564
- $product->setStatus('2');
565
- }
566
-
567
- $product->setStoreId($storeId);
568
- $product->save();
569
- }
570
- }
571
- }
572
-
573
- /**
574
- * Envoie des publications a OpenSI
575
- */
576
- public function setPubwebArticle($startedAt, $client, $storeId) {
577
- $productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
578
- ->addStoreFilter($storeId)
579
- ->addAttributeToSelect(array('sku', 'status'));
580
-
581
- foreach ($productCollection as $product) {
582
- $docXml = $this->createXml();
583
- $request = $docXml->createElement("request");
584
-
585
- $docXml->appendChild($request);
586
- $pubWebArticle = $docXml->createElement("Pubweb_Article");
587
-
588
- $pubWebArticle->setAttribute('Reference', $product->getSku());
589
- $pubWebArticle->setAttribute('Code_Site_Web', $client->web_site_code);
590
- if ($product->getStatus() == 2) {
591
- $pubWebArticle->setAttribute('Publication', "false");
592
- } else {
593
- $pubWebArticle->setAttribute('Publication', "true");
594
- }
595
-
596
- $request->appendChild($pubWebArticle);
597
-
598
- $params = array('reference' => $product->getSku());
599
- $this->sendData('PUT', 'update_pubweb_article', $docXml->saveXml(), $client, $params);
600
- } // endforeach $productCollection
601
- }
602
-
603
- /**
604
- * Recuperation des prix produits depuis OpenSI et mise a jour du site
605
- */
606
- public function getPrixArticle($startedAt, $client, $storeId) {
607
- $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
608
- $resultXML = $this->sendData("GET", "get_prix_article", "", $client, $params);
609
-
610
- $xmlDomDocument = new DomDocument();
611
- $xmlDomDocument->loadXML($resultXML);
612
- $listPrixArticle = $xmlDomDocument->getElementsByTagName("Prix_Article");
613
-
614
- //Verif si dans la configuration le prix est TTC ou HT
615
- $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
616
- foreach ($listPrixArticle as $prixArticle) {
617
- $reference = $prixArticle->getAttribute('Reference');
618
- $tarifHT = $prixArticle->getAttribute('Tarif_HT_1');
619
- $tarifTTC = $prixArticle->getAttribute('Tarif_TTC_1');
620
- $product = Mage::getModel('catalog/product')->loadByAttribute("sku", $reference);
621
- if ($product) {
622
- if ($includeTax) {
623
- $product->setPrice($tarifTTC);
624
- } else {
625
- $product->setPrice($tarifHT);
626
- }
627
- $product->setStoreId($storeId);
628
- $product->save();
629
- }
630
- }
631
- }
632
-
633
- /**
634
- * On log les erreurs pour les afficher dans l'interface
635
- */
636
- public function setLogs($response, $client, $action) {
637
- $errorLogs = Mage::getModel("opensi/errorlog");
638
- $errorLogs->setErrorCode($response->getStatus());
639
- $errorLogs->setErrorMessage(utf8_encode($response->getMessage()));
640
- $errorLogs->setOpensiId($client->opensi_id);
641
- $errorLogs->setOpensiAction($action);
642
- $createdAt = new dateTime();
643
- $errorLogs->setCreatedAt($createdAt->format('Y-m-d H:i:s'));
644
- $errorLogs->setStoreId($client->store_id);
645
- $errorLogs->save();
646
- }
647
-
648
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  */
9
  class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
10
 
11
+ private $error = "";
12
+
13
+ /**
14
+ * Envoie des donnees au serveur OpenSI
15
+ * @param String $method POST / GET / PUT
16
+ * @param String $action action a effectuer
17
+ * @param String $xmlData donnees a envoyer format XML
18
+ * @param Array $client les infos sur le client opensi
19
+ * @param Array $params liste des parametres a envoyer au serveur
20
+ * @return String $response reponse du serveur
21
+ */
22
+ protected function sendData($method, $action, $xmlData, $client, $params = '') {
23
+
24
+ $httpRequest = new Zend_Http_Client();
25
+ $httpRequest->setAuth($client->webservice_user, $client->webservice_pwd);
26
+ $httpRequest->setUri('https://webservices.opensi.eu/cows/Gateway');
27
+ $httpRequest->setParameterGet(array('service_id' => $client->opensi_id, 'action' => $action));
28
+ $log = '';
29
+ if (!empty($xmlData)) {
30
+ $httpRequest->setRawData($xmlData, 'text/xml');
31
+ $log .= $xmlData . ' - ';
32
+ }
33
+ if (!empty($params))
34
+ $httpRequest->setParameterGet($params);
35
+
36
+ $response = $httpRequest->request($method);
37
+ $log .= $response->getStatus();
38
+
39
+ //on gere les logs / erreurs
40
+ if ($response->isError() && $response->getStatus() != '409') {
41
+ $this->setLogs($response, $client, $action);
42
+ Mage::log($log, null, 'opensi.log');
43
+ }
44
+ $this->_error = $response->getStatus();
45
+ return $response->getRawBody();
46
+ }
47
+
48
+ protected function createXml() {
49
+ $docXml = new DomDocument('1.0', 'UTF-8');
50
+ $docXml->formatOutput = true;
51
+
52
+ return $docXml;
53
+ }
54
+
55
+ /**
56
+ * Envoie des nouvelles commandes vers OpenSI
57
+ */
58
+ public function createCommandeWeb($startedAt, $client, $storeId) {
59
+ $orderCollection = Mage::getModel('sales/order')->getCollection()
60
+ ->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
61
+ ->addFieldToFilter('store_id', $storeId);
62
+ if ($orderCollection->count() > 0) {
63
+ $this->createArticle($startedAt, $client, $storeId);
64
+ $this->createClientWeb($startedAt, $client, $storeId);
65
+ }
66
+
67
+ foreach ($orderCollection as $order) {
68
+
69
+ $docXml = $this->createXml();
70
+ $request = $docXml->createElement("request");
71
+
72
+ $docXml->appendChild($request);
73
+ $commandeWeb = $docXml->createElement("Commande_Web");
74
+
75
+ $orderDate = new Datetime($order->getCreatedAt());
76
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
77
+
78
+ // Informations de commande
79
+ $commandeWeb->setAttribute('Num_Com_Web', $order->getIncrementId());
80
+ $commandeWeb->setAttribute('Code_Site_Web', $client->web_site_code);
81
+ $commandeWeb->setAttribute('Login', $customer->getId());
82
+ $commandeWeb->setAttribute('Date_Commande', $orderDate->format('d-m-Y H:i:s'));
83
+ $shippingDesc = $order->getShippingDescription();
84
+ if (strlen($shippingDesc) > 30) {
85
+ $shippingDesc = explode(' - ', $shippingDesc);
86
+ if (strlen($shippingDesc[1]) > 30){
87
+ $shippingDesc = substr($shippingDesc[1], 0, 29);
88
+ } else {
89
+ $shippingDesc = $shippingDesc[1];
90
+ }
91
+ }
92
+ $commandeWeb->setAttribute('Mode_Expedition', $shippingDesc);
93
+ $commandeWeb->setAttribute('Edition_TTC', "false");
94
+ $commandeWeb->setAttribute('Frais_Port', $order->getShippingAmount());
95
+
96
+ // recuperation du taux de tva sur les frais de port
97
+ $taxClassId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $storeId);
98
+
99
+ if ($taxClassId != 0) {
100
+ $taxRequest = Mage::getSingleton('tax/calculation')->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), "", $storeId);
101
+
102
+ if ($taxRequest->getCustomerClassId()) {
103
+ $percent = Mage::getSingleton('tax/calculation')->getRate($taxRequest->setCustomerClassId($taxClassId));
104
+ } else if ($taxRequest->getProductClassId()) {
105
+ $percent = Mage::getSingleton('tax/calculation')->getRate($taxRequest->setProductClassId($taxClassId));
106
+ } else {
107
+ $percent = 0;
108
+ }
109
+ } else {
110
+ $percent = 0;
111
+ }
112
+
113
+ $commandeWeb->setAttribute('Taux_Tva_Port', $percent);
114
+ $totalTTC = $order->getSubtotal() + $order->getBaseTaxAmount();
115
+ //$commandeWeb->setAttribute('Remise_Pourc', ((($totalTTC - ($order->getBaseGrandTotal() - $order->getBaseShippingAmount())) / $totalTTC) * 100));
116
+ $commandeWeb->setAttribute('Remise_Pourc', '0');
117
+ $commandeWeb->setAttribute('Mode_Reglement', $order->getPayment()->getMethod());
118
+
119
+ // Informations de facturation
120
+ $commandeWeb->setAttribute('Civ_Fact', 0);
121
+ $commandeWeb->setAttribute('Nom_Fact', $order->getBillingAddress()->getLastname());
122
+ $commandeWeb->setAttribute('Prenom_Fact', $order->getBillingAddress()->getFirstname());
123
+ $billingCompany = $order->getBillingAddress()->getCompany();
124
+ if (!empty($billingCompany))
125
+ $commandeWeb->setAttribute('Societe_Fact', $billingCompany);
126
+ $commandeWeb->setAttribute('Adresse_1_Fact', $order->getBillingAddress()->getStreet1());
127
+ $billingStreet2 = $order->getBillingAddress()->getStreet2();
128
+ $billingStreet3 = $order->getBillingAddress()->getStreet3();
129
+ if (!empty($billingStreet2))
130
+ $commandeWeb->setAttribute('Adresse_2_Fact', $billingStreet2);
131
+ if (!empty($billingStreet3))
132
+ $commandeWeb->setAttribute('Adresse_3_Fact', $billingStreet3);
133
+ $commandeWeb->setAttribute('Code_Postal_Fact', $order->getBillingAddress()->getPostcode());
134
+ $commandeWeb->setAttribute('Ville_Fact', $order->getBillingAddress()->getCity());
135
+ $commandeWeb->setAttribute('Code_Pays_Fact', $order->getBillingAddress()->getCountry());
136
+ $billingPhone = $order->getBillingAddress()->getTelephone();
137
+ if (!empty($billingPhone))
138
+ $commandeWeb->setAttribute('Tel_Fact', $billingPhone);
139
+ $billingFax = $order->getBillingAddress()->getFax();
140
+ if (!empty($billingFax))
141
+ $commandeWeb->setAttribute('Fax_Fact', $billingFax);
142
+ $commandeWeb->setAttribute('Email_Fact', $customer->getEmail());
143
+
144
+ //Informations de livraison
145
+ $commandeWeb->setAttribute('Civ_Liv', 0);
146
+ $commandeWeb->setAttribute('Nom_Liv', $order->getShippingAddress()->getLastname());
147
+ $commandeWeb->setAttribute('Prenom_Liv', $order->getShippingAddress()->getFirstname());
148
+ $shippingCompany = $order->getShippingAddress()->getCompany();
149
+ if (!empty($shippingCompany))
150
+ $commandeWeb->setAttribute('Societe_Liv', $shippingCompany);
151
+ $commandeWeb->setAttribute('Adresse_1_Liv', $order->getShippingAddress()->getStreet1());
152
+ $shippingStreet2 = $order->getShippingAddress()->getStreet2();
153
+ $shippingStreet3 = $order->getShippingAddress()->getStreet3();
154
+ if (!empty($shippingStreet2))
155
+ $commandeWeb->setAttribute('Adresse_2_Liv', $shippingStreet2);
156
+ if (!empty($shippingStreet3))
157
+ $commandeWeb->setAttribute('Adresse_3_Liv', $shippingStreet3);
158
+ $commandeWeb->setAttribute('Code_Postal_Liv', $order->getShippingAddress()->getPostcode());
159
+ $commandeWeb->setAttribute('Ville_Liv', $order->getShippingAddress()->getCity());
160
+ $commandeWeb->setAttribute('Code_Pays_Liv', $order->getShippingAddress()->getCountry());
161
+ $shippingPhone = $order->getShippingAddress()->getTelephone();
162
+ if (!empty($shippingPhone))
163
+ $commandeWeb->setAttribute('Tel_Liv', $shippingPhone);
164
+ $shippingFax = $order->getShippingAddress()->getFax();
165
+ if (!empty($shippingFax))
166
+ $commandeWeb->setAttribute('Fax_Liv', $shippingFax);
167
+ $commandeWeb->setAttribute('Email_Liv', $customer->getEmail());
168
+
169
+ $request->appendChild($commandeWeb);
170
+
171
+ // Informations du contenu de la commande
172
+ foreach ($order->getAllVisibleItems() as $item) {
173
+ $ligneCommandeClient = $docXml->createElement("Ligne_Commande_Client");
174
+
175
+ if($item->getProductType() == "configurable"){
176
+ $ligneCommandeClient->setAttribute('Reference', $item->getProductOptionByCode('simple_sku'));
177
+ $ligneCommandeClient->setAttribute('Designation', $item->getProductOptionByCode('simple_name'));
178
+ }else{
179
+ $ligneCommandeClient->setAttribute('Reference', $item->getSku());
180
+ $ligneCommandeClient->setAttribute('Designation', $item->getName());
181
+ }
182
+ $ligneCommandeClient->setAttribute('Quantite', $item->getQtyOrdered());
183
+ $ligneCommandeClient->setAttribute('Prix_Unitaire', $item->getPrice());
184
+ $discountAmount = $item->getDiscountAmount();
185
+
186
+ //Si il existe une remise en valeur
187
+ if (!empty($discountAmount) && $item->getPrice() != 0) {
188
+ $discount = (1 - (($item->getPrice() - $item->getDiscountAmount()) / $item->getPrice())) * 100;
189
+ $discount = round($discount, 2);
190
+ }
191
+
192
+ $discountPourcent = $item->getDiscountPercent();
193
+ //Si il existe un poucentage de remise.
194
+ if ($discountPourcent != 0) {
195
+ $discount = $discountPourcent;
196
+ }
197
+
198
+ //Si il existe les 2 types de remise % et montant
199
+ if (!empty($discountAmount) && !empty($discountPourcent)) {
200
+ $discountValeurDepuisPourcentage = ($item->getPrice() * $discountPourcent) / 100;
201
+ $discountTotalValue = $discountAmount + $discountValeurDepuisPourcentage;
202
+ $discountPourcent = (1 - (($item->getPrice() - $discountTotalValue) / $item->getPrice())) * 100;
203
+ $discount = $discountPourcent;
204
+ }
205
+
206
+ $ligneCommandeClient->setAttribute('Remise_Pourc', $discount);
207
+ $ligneCommandeClient->setAttribute('Taux_Tva', $item->getTaxPercent());
208
+
209
+ $commandeWeb->appendChild($ligneCommandeClient);
210
+ }
211
+
212
+ // Mage::log($docXml->saveXml(), null, 'opensi.log');
213
+ $this->sendData('POST', 'create_commande_web', $docXml->saveXml(), $client);
214
+ } // endforeach $ordercollection
215
+
216
+ if ($orderCollection->count() > 0) {
217
+ $this->createTransactionBancaire($startedAt, $client, $storeId);
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Envoie des nouveaux produits vers OpenSI
223
+ */
224
+ public function createArticle($startedAt, $client, $storeId) {
225
+ if(Mage::getVersion() < '1.4.0.0'){
226
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
227
+ ->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
228
+ ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))
229
+ ->addFieldToFilter('category_ids', array('gteq' => NULL))
230
+ ->addStoreFilter($storeId)
231
+ ->addAttributeToSelect('*');
232
+ }else{
233
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
234
+ ->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
235
+ ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))
236
+ ->addStoreFilter($storeId)
237
+ ->addAttributeToSelect('*');
238
+ }
239
+ foreach ($productCollection as $product) {
240
+ $articleData = $this->articleData($product, $storeId, 'create', $client);
241
+ $this->sendData('POST', 'create_article', $articleData, $client);
242
+ //Vérifier si 409 ne pas lancer
243
+ if($this->_error != "409")
244
+ $this->setStockArticle($product,$client);
245
+ } // endforeach $productCollection
246
+ if ($productCollection->count() > 0)
247
+ $this->setPubwebArticle($startedAt, $client, $storeId);
248
+ }
249
+
250
+ /**
251
+ * Envoie des produits modifies vers OpenSI
252
+ */
253
+ public function updateArticle($startedAt, $client, $storeId) {
254
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
255
+ ->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
256
+ ->addFieldToFilter('created_at', array('lteq' => $startedAt->format('Y-m-d H:i:s')))
257
+ ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))
258
+ ->addStoreFilter($storeId)
259
+ ->addAttributeToSelect('*');
260
+
261
+ foreach ($productCollection as $product) {
262
+ $articleData = $this->articleData($product, $storeId, 'update', $client);
263
+ $params = array('reference' => $product->getSku());
264
+ $this->sendData('PUT', 'update_article', $articleData, $client, $params);
265
+ } // endforeach $productCollection
266
+ if ($productCollection->count() > 0)
267
+ $this->setPubwebArticle($startedAt, $client, $storeId);
268
+ }
269
+
270
+ /**
271
+ * Creation du XML pour la creation / modification de produits
272
+ */
273
+ public function articleData($product, $storeId, $type, $client) {
274
+ $docXml = $this->createXml();
275
+ $request = $docXml->createElement("request");
276
+
277
+ $docXml->appendChild($request);
278
+ $article = $docXml->createElement('Article');
279
+
280
+ // Informations du produit
281
+ $article->setAttribute('Reference', substr($product->getSku(), 0, 39));
282
+ $article->setAttribute('Designation', substr($product->getName(), 0, 99));
283
+ $article->setAttribute('Description_1', $product->getDescription());
284
+ $shortDescription = $product->getShortDescription();
285
+ if (!empty($shortDescription))
286
+ $article->setattribute('Description_2', $shortDescription);
287
+ $brand = $product->getAttributeText('manufacturer');
288
+ if (!empty($brand))
289
+ $article->setAttribute('Marque', $brand);
290
+
291
+ // Gestion des familles
292
+ $fam1 = $this->getSimpleAttributes($product, $client->famille1);
293
+ if (!empty($client->famille1) && !empty($fam1)) {
294
+ $article->setAttribute('Famille_1', substr($this->getSimpleAttributes($product, $client->famille1), 0, 39));
295
+ } else {
296
+ $article->setAttribute('Famille_1', 'NC');
297
+ }
298
+ !empty($client->famille2) && $this->getSimpleAttributes($product, $client->famille2) ? $article->setAttribute('Famille_2', substr($this->getSimpleAttributes($product, $client->famille2), 0, 39)) : false;
299
+ !empty($client->famille3) && $this->getSimpleAttributes($product, $client->famille3) ? $article->setAttribute('Famille_3', substr($this->getSimpleAttributes($product, $client->famille3), 0, 39)) : false;
300
+
301
+ // Gestion des attributs
302
+ !empty($client->attribut1) && $this->getSimpleAttributes($product, $client->attribut1) ? $article->setAttribute('Attribut_1', substr($this->getSimpleAttributes($product, $client->attribut1), 0, 39)) : false;
303
+ !empty($client->attribut2) && $this->getSimpleAttributes($product, $client->attribut2) ? $article->setAttribute('Attribut_2', substr($this->getSimpleAttributes($product, $client->attribut2), 0, 39)) : false;
304
+ !empty($client->attribut3) && $this->getSimpleAttributes($product, $client->attribut3) ? $article->setAttribute('Attribut_3', substr($this->getSimpleAttributes($product, $client->attribut3), 0, 39)) : false;
305
+ !empty($client->attribut4) && $this->getSimpleAttributes($product, $client->attribut4) ? $article->setAttribute('Attribut_4', substr($this->getSimpleAttributes($product, $client->attribut4), 0, 39)) : false;
306
+ !empty($client->attribut5) && $this->getSimpleAttributes($product, $client->attribut5) ? $article->setAttribute('Attribut_5', substr($this->getSimpleAttributes($product, $client->attribut5), 0, 39)) : false;
307
+ !empty($client->attribut6) && $this->getSimpleAttributes($product, $client->attribut6) ? $article->setAttribute('Attribut_6', substr($this->getSimpleAttributes($product, $client->attribut6), 0, 39)) : false;
308
+ !empty($client->code_barre) && $this->getSimpleAttributes($product, $client->code_barre) ? $article->setAttribute('Code_Barre', substr($this->getSimpleAttributes($product, $client->code_barre), 0, 14)) : false;
309
+ !empty($client->volume) && is_numeric($this->getSimpleAttributes($product, $client->volume)) && $this->getSimpleAttributes($product, round($client->volume,2)) ? $article->setAttribute('Volume',$this->getSimpleAttributes($product, round($client->volume,2) )) : false;
310
+ !empty($client->hauteur) && is_numeric($this->getSimpleAttributes($product, $client->hauteur)) && $this->getSimpleAttributes($product, round($client->hauteur,2)) ? $article->setAttribute('Hauteur',$this->getSimpleAttributes($product, round($client->hauteur,2))) : false;
311
+ !empty($client->longueur) && is_numeric($this->getSimpleAttributes($product, $client->longueur)) && $this->getSimpleAttributes($product, round($client->longueur,2)) ? $article->setAttribute('Longueur',$this->getSimpleAttributes($product, round($client->longueur,2))) : false;
312
+ !empty($client->largeur) && is_numeric($this->getSimpleAttributes($product, $client->largeur)) && $this->getSimpleAttributes($product, round($client->largeur,2)) ? $article->setAttribute('Largeur',$this->getSimpleAttributes($product, round($client->largeur,2))) : false;
313
+
314
+ $weight = $product->getWeight();
315
+ if (!empty($weight))
316
+ $article->setAttribute('Poids', $weight);
317
+
318
+ if ($type == 'create') {
319
+ $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
320
+ if ($includeTax) {
321
+ $article->setAttribute('Tarif_TTC_1', $product->getFinalPrice());
322
+ } else {
323
+ $article->setAttribute('Tarif_HT_1', $product->getFinalPrice());
324
+ }
325
+ $product->getCost() != "" ? $article->setAttribute('Prix_Achat', $product->getCost()) : false;
326
+ }
327
+ $updatedAt = new Datetime($product->getUpdatedAt());
328
+ $createdAt = new Datetime($product->getCreatedAt());
329
+ $article->setAttribute('Date_M', $updatedAt->format('d-m-Y H:i:s'));
330
+ $article->setAttribute('Date_C', $createdAt->format('d-m-Y H:i:s'));
331
+
332
+ $active = "true";
333
+ $article->setAttribute('Actif', $active);
334
+
335
+ $request->appendChild($article);
336
+
337
+ return $docXml->saveXML();
338
+ }
339
+
340
+ /**
341
+ * Envoie des nouveaux clients vers OpenSI
342
+ */
343
+ public function createClientWeb($startedAt, $client, $storeId) {
344
+ $customerCollection = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
345
+ ->addAttributeToSelect('*')->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
346
+ foreach ($customerCollection as $customer) {
347
+ $clientData = $this->clientData($customer, $client);
348
+ $this->sendData('POST', 'create_client_web', $clientData, $client);
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Envoie des clients modifies vers OpenSI
354
+ */
355
+ public function updateClientWeb($startedAt, $client, $storeId) {
356
+ $customerCollection = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
357
+ ->addFieldToFilter('created_at', array('lteq' => $startedAt->format('Y-m-d H:i:s')))->addAttributeToSelect('*')->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
358
+
359
+ foreach ($customerCollection as $customer) {
360
+ $clientData = $this->clientData($customer, $client);
361
+ $params = array('code_site_web' => $client->web_site_code, 'login' => $customer->getId());
362
+ $this->sendData('PUT', 'update_client_web', $clientData, $client, $params);
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Creation du XML pour la creation / modification de clients
368
+ */
369
+ public function clientData($customer, $client) {
370
+ $docXml = $this->createXml();
371
+ $request = $docXml->createElement("request");
372
+
373
+ $docXml->appendChild($request);
374
+ $clientWeb = $docXml->createElement('Client_Web');
375
+
376
+ // Informations du client
377
+ $clientWeb->setAttribute('Code_Site_Web', $client->web_site_code);
378
+ $clientWeb->setAttribute('Login', $customer->getId());
379
+ $clientWeb->setAttribute('Civilite', '0');
380
+ $clientWeb->setAttribute('Nom', $customer->getLastname());
381
+ $clientWeb->setAttribute('Prenom', $customer->getFirstname());
382
+ $address = Mage::getModel('customer/address')->load((int)$customer->getDefaultBilling());
383
+ $streets = $address->getStreet();
384
+ $postCode = $address->getPostcode();
385
+ $countryId= $address->getCountryId();
386
+ $city = $address->getCity();
387
+ $telephone = $address->getTelephone();
388
+ $fax = $address->getFax();
389
+ $company = $address->getCompany();
390
+
391
+ if(!empty($streets)){
392
+ isset($streets[0]) ? $clientWeb->setAttribute('Adresse_1', $streets[0] ? $streets[0] : 'NC') : 'NC';
393
+ isset($streets[1]) ? $clientWeb->setAttribute('Adresse_2', $streets[1] ? $streets[1] : '') : '';
394
+ }else{
395
+ $clientWeb->setAttribute('Adresse_1', 'NC');
396
+ }
397
+ $clientWeb->setAttribute('Ville', $city ? $city : 'NC');
398
+ $clientWeb->setAttribute('Code_Pays', $countryId ? $countryId : 'FR');
399
+ $clientWeb->setAttribute('Code_Postal', $postCode ? $postCode : '');
400
+ $clientWeb->setAttribute('Telephone', $telephone ? $telephone : '');
401
+ $clientWeb->setAttribute('Fax', $fax ? $fax : '');
402
+ $clientWeb->setAttribute('Societe', $company ? substr($company,0,49) : '');
403
+ $clientWeb->setAttribute('Email', $customer->getEmail());
404
+
405
+ $request->appendChild($clientWeb);
406
+
407
+ return $docXml->saveXML();
408
+ }
409
+
410
+ /**
411
+ * Recuperation des stocks depuis OpenSI et mise a jour du site
412
+ */
413
+ public function getStockArticle($startedAt, $client, $storeId) {
414
+ $params = array('code_depot' => $client->deposit, 'date_debut' => $startedAt->format('d-m-Y'));
415
+
416
+ $resultXML = $this->sendData("GET", "get_stock_article", "", $client, $params);
417
+
418
+ $xmlDomDocument = new DomDocument();
419
+ $xmlDomDocument->loadXML($resultXML);
420
+
421
+ $stockArticles = $xmlDomDocument->getElementsByTagName("Stock_Article");
422
+
423
+ foreach ($stockArticles as $stockArticle) {
424
+
425
+ $sku = $stockArticle->getAttribute('Reference');
426
+ $qty = $stockArticle->getAttribute('Stock_Dispo');
427
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
428
+ if ($product && $product->getTypeId() != "bundle") {
429
+ $stockArticle = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
430
+ if ($qty > 0) {
431
+ $stockArticle->setQty($qty);
432
+ $stockArticle->setIsInStock(true);
433
+ } else {
434
+ $stockArticle->setQty(0);
435
+ $stockArticle->setIsInStock(false);
436
+ }
437
+
438
+ $stockArticle->setStoreId($storeId);
439
+ $stockArticle->save();
440
+ }
441
+ }
442
+ }
443
+
444
+ /**
445
+ * Envoi des stocks depuis le site à Opensi
446
+ */
447
+ public function setStockArticle($product, $client) {
448
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId())->getQty();
449
+
450
+ $docXml = $this->createXml();
451
+ $request = $docXml->createElement("request");
452
+
453
+ $docXml->appendChild($request);
454
+ $stockArticle = $docXml->createElement("Invperm_Article");
455
+ $stockArticle->setAttribute('Code_Depot', $client->deposit);
456
+ $stockArticle->setAttribute('Reference', $product->getSku());
457
+ $stockArticle->setAttribute('Stock_Reel', $stock ? round($stock,3) : 0);
458
+ $request->appendChild($stockArticle);
459
+
460
+ $this->sendData('POST', 'create_invperm_article', $docXml->saveXml(), $client);
461
+ }
462
+
463
+ /**
464
+ * Envoie des infos de paiement a OpenSI
465
+ */
466
+ public function createTransactionBancaire($startedAt, $client, $storeId) {
467
+ //recuperation des commandes
468
+ $orderCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))->addFieldToFilter('store_id', $storeId);
469
+
470
+ foreach ($orderCollection as $order) {
471
+ $methodPayment = $order->getPayment()->getMethod();
472
+ $numOrder = $order->getIncrementId();
473
+ $numeroTransaction = $numOrder;
474
+
475
+ $invoiceCollection = Mage::getResourceModel('sales/order_invoice_collection')
476
+ ->addAttributeToSelect('order_id')
477
+ ->addAttributeToSelect('increment_id')
478
+ ->addAttributeToSelect('created_at')
479
+ ->addAttributeToSelect('state')
480
+ ->addAttributeToSelect('base_grand_total')
481
+ ->setOrderFilter($order);
482
+
483
+ $dateTransaction = "";
484
+ $montant = 0;
485
+ $bool = false;
486
+ foreach ($invoiceCollection as $invoice) {
487
+ //On vérifie que la facture est payé
488
+ if ($invoice->getState() == 2) {
489
+ $bool = true;
490
+ $dateTransaction = $invoice->getCreatedAt();
491
+ $montant += $invoice->getBaseGrandTotal();
492
+ }
493
+ }
494
+
495
+ if ($bool) {
496
+ $dateTransaction = new Datetime($dateTransaction);
497
+
498
+ $docXml = $this->createXml();
499
+ $request = $docXml->createElement("request");
500
+
501
+ $docXml->appendChild($request);
502
+ $transactionComWeb = $docXml->createElement("Transaction_Com_Web");
503
+
504
+ $transactionComWeb->setAttribute('Code_Site_Web', $client->web_site_code);
505
+ $transactionComWeb->setAttribute('Num_Com_Web', $numOrder);
506
+ $transactionComWeb->setAttribute('Num_Transaction', $numeroTransaction);
507
+ $transactionComWeb->setAttribute('Mode_Reglement', $methodPayment);
508
+ $transactionComWeb->setAttribute('Date_Transaction', $dateTransaction->format('d-m-Y'));
509
+ $transactionComWeb->setAttribute('Montant', $montant);
510
+
511
+ $request->appendChild($transactionComWeb);
512
+
513
+ $this->sendData('POST', 'create_transaction_bancaire', $docXml->saveXml(), $client);
514
+ }
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Recuperation des etats de commande depuis OpenSI et mise a jour du site
520
+ */
521
+ public function getEtatCommande($startedAt, $client, $storeId) {
522
+ $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
523
+ $resultXML = $this->sendData("GET", "get_etat_commande", "", $client, $params);
524
+
525
+ $xmlDomDocument = new DomDocument();
526
+ $xmlDomDocument->loadXML($resultXML);
527
+ $listEtatCommande = $xmlDomDocument->getElementsByTagName("Etat_Commande");
528
+
529
+ foreach ($listEtatCommande as $etatCommande) {
530
+ $order = Mage::getModel('sales/order')->loadByIncrementId($etatCommande->getAttribute('Num_Com_Web'));
531
+
532
+ if (!$order->getId()) {
533
+ continue;
534
+ }
535
+
536
+ //recup du statut de paiement = si termine on facture pour considerer la commande paye
537
+ if ($etatCommande->getAttribute('Statut_Paiement') == 'T') {
538
+
539
+ if ($order->canInvoice()) {
540
+ $invoiceCollection = $order->getInvoiceCollection();
541
+ $invoiceId = '';
542
+ foreach ($invoiceCollection as $invoice) {
543
+ $invoiceId = $invoice->getIncrementId();
544
+ }
545
+
546
+ if (empty($invoiceId))
547
+ $invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(), array());
548
+
549
+ $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId);
550
+ if ($invoice->canCapture()) {
551
+ $invoice->capture();
552
+ }
553
+ $invoice->save();
554
+ }
555
+ }
556
+
557
+
558
+ //recup du statut de livraison
559
+ if ($etatCommande->getAttribute('Statut_Logistique') == 'E') {
560
+
561
+ if ($order->canShip()) {
562
+ $shipmentCollection = $order->getShipmentsCollection();
563
+ $shipmentId = '';
564
+ foreach ($shipmentCollection as $shipment) {
565
+ $shipmentId = $shipment->getIncrementId();
566
+ }
567
+ if (empty($shipmentId))
568
+ $shipmentId = Mage::getModel('sales/order_shipment_api')->create($order->getIncrementId(), array());
569
+ }
570
+ }
571
+
572
+ $status = $order->getStatus();
573
+ //passer derniere valeur a true pour envoyer mail au client
574
+ switch ($etatCommande->getAttribute('Etat')) {
575
+ case 'N':
576
+ if ($status != 'pending')
577
+ $order->setState('pending', true, 'changement de statut OpenSI', true);
578
+ break;
579
+
580
+ case 'T':
581
+ if ($status != 'processing')
582
+ $order->setState('processing', true, 'changement de statut OpenSI', true);
583
+ break;
584
+
585
+ case 'A':
586
+ if ($status != 'canceled')
587
+ $order->setState('canceled', true, 'changement de statut OpenSI', true);
588
+ break;
589
+
590
+ case 'C':
591
+ if ($status != 'complete' && Mage::getVersion() < '1.4.0.0')
592
+ $order->setState('complete', true, 'changement de statut OpenSI', true);
593
+ break;
594
+ }
595
+ $order->save();
596
+ }
597
+ }
598
+
599
+ /**
600
+ * Recuperation des infos de suivi de colis depuis OpenSI et mise a jour du site
601
+ */
602
+ public function getTrackingColis($startedAt, $client, $storeId) {
603
+ $now = new Datetime();
604
+ $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'), 'date_fin' => $now->format('d-m-Y'));
605
+ $resultXML = $this->sendData("GET", "get_tracking_colis", "", $client, $params);
606
+
607
+ $xmlDomDocument = new DomDocument();
608
+ $xmlDomDocument->loadXML($resultXML);
609
+ $listExpedition = $xmlDomDocument->getElementsByTagName("Colis_Expedition");
610
+
611
+ foreach ($listExpedition as $expedition) {
612
+ $order = Mage::getModel('sales/order')->loadByIncrementId($expedition->getAttribute('Num_Com_Web'));
613
+ /**
614
+ * Check order existing
615
+ */
616
+ if (!$order->getId()) {
617
+ continue;
618
+ }
619
+ /**
620
+ * Check shipment create availability
621
+ */
622
+ if (!$order->canShip()) {
623
+ continue;
624
+ }
625
+ $shipmentCollection = $order->getShipmentsCollection();
626
+ $shipmentId = '';
627
+ foreach ($shipmentCollection as $shipment) {
628
+ $shipmentId = $shipment->getIncrementId();
629
+ }
630
+ if (empty($shipmentId))
631
+ $shipmentId = Mage::getModel('sales/order_shipment_api')->create($order->getIncrementId(), array());
632
+ $track = Mage::getModel('sales/order_shipment_api')->addTrack($shipmentId, "custom", $expedition->getAttribute('Transporteur') . ' - ' . $expedition->getAttribute('Mode_Expedition'), $expedition->getAttribute('Num_Colis'));
633
+ }
634
+ }
635
+
636
+ /**
637
+ * Recuperation des publications de produits depuis OpenSI et mise a jour du site
638
+ */
639
+ public function getPubwebArticle($startedAt, $client, $storeId) {
640
+ $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
641
+ $resultXML = $this->sendData("GET", "get_pubweb_article", "", $client, $params);
642
+
643
+ $xmlDomDocument = new DomDocument();
644
+ $xmlDomDocument->loadXML($resultXML);
645
+ $listPublicationArticle = $xmlDomDocument->getElementsByTagName("Pubweb_Article");
646
+
647
+ foreach ($listPublicationArticle as $publicationArticle) {
648
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $publicationArticle->getAttribute('Reference'));
649
+ if ($product) {
650
+ if ($publicationArticle->getAttribute('Publication') == "true") {
651
+ $product->setStatus('1');
652
+ } else {
653
+ $product->setStatus('2');
654
+ }
655
+
656
+ $product->setStoreId($storeId);
657
+ $product->save();
658
+ }
659
+ }
660
+ }
661
+
662
+ /**
663
+ * Envoie des publications a OpenSI
664
+ */
665
+ public function setPubwebArticle($startedAt, $client, $storeId) {
666
+ $productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
667
+ ->addStoreFilter($storeId)
668
+ ->addAttributeToSelect(array('sku', 'status'));
669
+
670
+ foreach ($productCollection as $product) {
671
+ $docXml = $this->createXml();
672
+ $request = $docXml->createElement("request");
673
+
674
+ $docXml->appendChild($request);
675
+ $pubWebArticle = $docXml->createElement("Pubweb_Article");
676
+
677
+ $pubWebArticle->setAttribute('Reference', $product->getSku());
678
+ $pubWebArticle->setAttribute('Code_Site_Web', $client->web_site_code);
679
+ if ($product->getStatus() == 2) {
680
+ $pubWebArticle->setAttribute('Publication', "false");
681
+ } else {
682
+ $pubWebArticle->setAttribute('Publication', "true");
683
+ }
684
+
685
+ $request->appendChild($pubWebArticle);
686
+
687
+ $params = array('reference' => $product->getSku());
688
+ $this->sendData('PUT', 'update_pubweb_article', $docXml->saveXml(), $client, $params);
689
+ } // endforeach $productCollection
690
+ }
691
+
692
+ /**
693
+ * Recuperation des prix produits depuis OpenSI et mise a jour du site
694
+ */
695
+ public function getPrixArticle($startedAt, $client, $storeId) {
696
+ $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
697
+ $resultXML = $this->sendData("GET", "get_prix_article", "", $client, $params);
698
+
699
+ $xmlDomDocument = new DomDocument();
700
+ $xmlDomDocument->loadXML($resultXML);
701
+ $listPrixArticle = $xmlDomDocument->getElementsByTagName("Prix_Article");
702
+
703
+ //Verif si dans la configuration le prix est TTC ou HT
704
+ $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
705
+ foreach ($listPrixArticle as $prixArticle) {
706
+ $reference = $prixArticle->getAttribute('Reference');
707
+ $tarifHT = $prixArticle->getAttribute('Tarif_HT_1');
708
+ $tarifTTC = $prixArticle->getAttribute('Tarif_TTC_1');
709
+ $prixAchat = $prixArticle->getAttribute('Prix_Achat');
710
+ $product = Mage::getModel('catalog/product')->loadByAttribute("sku", $reference);
711
+ if ($product && $product->getTypeId() != "bundle") {
712
+ if ($includeTax) {
713
+ $product->setPrice($tarifTTC);
714
+ } else {
715
+ $product->setPrice($tarifHT);
716
+ }
717
+ $product->setCost($prixAchat);
718
+ $product->setStoreId($storeId);
719
+ $product->save();
720
+ }
721
+ }
722
+ }
723
+
724
+ /**
725
+ * On log les erreurs pour les afficher dans l'interface
726
+ */
727
+ public function setLogs($response, $client, $action) {
728
+ $errorLogs = Mage::getModel("opensi/errorlog");
729
+ $errorLogs->setErrorCode($response->getStatus());
730
+ $errorLogs->setErrorMessage(utf8_encode($response->getMessage()));
731
+ $errorLogs->setOpensiId($client->opensi_id);
732
+ $errorLogs->setOpensiAction($action);
733
+ $createdAt = new dateTime();
734
+ $errorLogs->setCreatedAt($createdAt->format('Y-m-d H:i:s'));
735
+ $errorLogs->setStoreId($client->store_id);
736
+ $errorLogs->save();
737
+ }
738
+
739
+ protected function getSimpleAttributes($product, $idAttribute) {
740
+ $attribute = Mage::getModel('eav/entity_attribute')->load($idAttribute);
741
+ if ($product->getData($attribute->getAttributeCode())) {
742
+ return $product->getResource()->getAttribute($attribute->getAttributeCode())->getFrontend()->getValue($product);
743
+ } else {
744
+ return '';
745
+ }
746
+ }
747
+
748
+ }
app/code/community/Speedinfo/Opensi/controllers/IndexController.php CHANGED
@@ -8,92 +8,125 @@
8
  */
9
  class Speedinfo_Opensi_IndexController extends Mage_Adminhtml_Controller_Action {
10
 
11
- protected function _initAction() {
12
- $this->loadLayout()
13
- ->_setActiveMenu('opensi/webservice');
14
- return $this;
15
- }
16
 
17
- public function indexAction() {
18
- $block = $this->getLayout()->createBlock('opensi/adminhtml_edit');
19
- $menu = $this->getLayout()->createBlock('opensi/adminhtml_tabs');
20
 
21
- $this->_initAction();
22
- $this->_addLeft($this->getLayout()->createBlock('adminhtml/store_switcher'))
23
- ->_addLeft($menu)
24
- ->_addContent($block)
25
- ->renderLayout();
26
- }
27
 
28
- public function errorsAction() {
29
- $block = $this->getLayout()->createBlock('opensi/adminhtml_grid');
30
- $this->_initAction();
31
- $this->_addContent($block)->renderLayout();
32
- }
33
 
34
- public function saveAction() {
35
- if ($params = $this->getRequest()->getPost('opensi')) {
36
 
37
- //Création du client
38
- if ($params['id'] == 0) {
39
- $client = Mage::getModel('opensi/client');
40
- } else {
41
- // MAJ du client client
42
- $client = Mage::getModel('opensi/client')->load($params['id']);
43
- }
 
 
 
 
44
 
45
- // préparer les attributs
46
- $clientData = array(
47
- 'opensi_id' => $params['opensi_id'],
48
- 'webservice_user' => $params['webservice_user'],
49
- 'webservice_pwd' => $params['webservice_pwd'],
50
- 'web_site_code' => $params['web_site_code'],
51
- 'deposit' => $params['deposit'],
52
- 'store_id' => $params['store_id'],
53
- );
54
- $client->setData($clientData);
55
- $params['id'] != 0 ? $client->setId($params['id']) : '';
56
- try {
57
- $client->save();
58
- $idClient = $client->getId();
59
- $this->_getSession()->addSuccess($this->__('Client was successfully created.'));
60
- } catch (Exception $e) {
61
- $this->_getSession()->addError($e->getMessage());
62
- $this->_redirect('*/*/');
63
- }
64
- foreach (Mage::Helper('opensi')->getWebservicesName() as $title => $ws) {
65
- foreach ($ws as $name => $value) {
66
 
67
- if ($params['id'] == 0) {
68
- $ws = Mage::getModel('opensi/webservice');
69
- } else {
70
- $wsColl = Mage::getModel('opensi/webservice')->getCollection()
71
- ->addFieldToFilter("name", $name)
72
- ->addFieldToFilter("client_id", $idClient);
73
- foreach ($wsColl as $wst) {
74
- $ws = $wst;
75
- }
76
- $idWebservice = $ws->getId();
77
- }
78
- $wsData = array(
79
- 'name' => $name,
80
- 'client_id' => $idClient,
81
- 'active' => isset($params[$name]['active']) ? 1 : 0,
82
- 'frequency' => $params[$name]['frequency'],
83
- );
84
- $ws->setData($wsData);
85
- isset($idWebservice) ? $ws->setId($idWebservice) : '';
86
- try {
87
- $ws->save();
88
- } catch (Exception $e) {
89
- $this->_getSession()->addError($e->getMessage());
90
- }
91
- }
92
- }
93
- $this->_getSession()->addSuccess($this->__('Webservices was successfully saved.'));
94
- $storeId = Mage::registry('store_id') == "" ? $this->getRequest()->getParam('store') : Mage::registry('store_id');
95
- $this->_redirect('*/*/', array("store" => $storeId));
96
- }
97
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  }
8
  */
9
  class Speedinfo_Opensi_IndexController extends Mage_Adminhtml_Controller_Action {
10
 
11
+ protected function _initAction() {
12
+ $this->loadLayout()
13
+ ->_setActiveMenu('opensi/webservice');
14
+ return $this;
15
+ }
16
 
17
+ public function indexAction() {
18
+ $block = $this->getLayout()->createBlock('opensi/adminhtml_edit');
19
+ $menu = $this->getLayout()->createBlock('opensi/adminhtml_tabs');
20
 
21
+ $this->_initAction();
22
+ $this->_addLeft($this->getLayout()->createBlock('adminhtml/store_switcher'))
23
+ ->_addLeft($menu)
24
+ ->_addContent($block)
25
+ ->renderLayout();
26
+ }
27
 
28
+ public function errorsAction() {
29
+ $block = $this->getLayout()->createBlock('opensi/adminhtml_grid');
30
+ $this->_initAction();
31
+ $this->_addContent($block)->renderLayout();
32
+ }
33
 
34
+ public function saveAction() {
35
+ if ($params = $this->getRequest()->getPost('opensi')) {
36
 
37
+ //Création du client
38
+ if ($params['id'] == 0) {
39
+ $client = Mage::getModel('opensi/client');
40
+ } else {
41
+ // MAJ du client client
42
+ $client = Mage::getModel('opensi/client')->load($params['id']);
43
+ }
44
+ //Gestion des familles
45
+ $famille1 = $params['familles'][0];
46
+ $famille2 = $params['familles'][1];
47
+ $famille3 = $params['familles'][2];
48
 
49
+ //Gestion eds attributs
50
+ $attr1 = $params['attribut'][0];
51
+ $attr2 = $params['attribut'][1];
52
+ $attr3 = $params['attribut'][2];
53
+ $attr4 = $params['attribut'][3];
54
+ $attr5 = $params['attribut'][4];
55
+ $attr6 = $params['attribut'][5];
56
+ $codeBarre = $params['code_barre'];
57
+ $volume = $params['volume'];
58
+ $hauteur = $params['hauteur'];
59
+ $longueur = $params['longueur'];
60
+ $largeur = $params['largeur'];
 
 
 
 
 
 
 
 
 
61
 
62
+ // préparer les attributs
63
+ $clientData = array(
64
+ 'opensi_id' => $params['opensi_id'],
65
+ 'webservice_user' => $params['webservice_user'],
66
+ 'webservice_pwd' => $params['webservice_pwd'],
67
+ 'web_site_code' => $params['web_site_code'],
68
+ 'deposit' => $params['deposit'],
69
+ 'store_id' => $params['store_id'],
70
+ 'famille1' => $famille1,
71
+ 'famille2' => $famille2,
72
+ 'famille3' => $famille3,
73
+ 'attribut1' => $attr1,
74
+ 'attribut2' => $attr2,
75
+ 'attribut3' => $attr3,
76
+ 'attribut4' => $attr4,
77
+ 'attribut5' => $attr5,
78
+ 'attribut6' => $attr6,
79
+ 'code_barre' => $codeBarre,
80
+ 'volume' => $volume,
81
+ 'hauteur' => $hauteur,
82
+ 'longueur' => $longueur,
83
+ 'largeur' => $largeur,
84
+ );
85
+ $client->setData($clientData);
86
+ $params['id'] != 0 ? $client->setId($params['id']) : '';
87
+ try {
88
+ $client->save();
89
+ $idClient = $client->getId();
90
+ $this->_getSession()->addSuccess($this->__('Client was successfully created.'));
91
+ } catch (Exception $e) {
92
+ $this->_getSession()->addError($e->getMessage());
93
+ $this->_redirect('*/*/');
94
+ }
95
+ //Gestion des webservices
96
+ foreach (Mage::Helper('opensi')->getWebservicesName() as $title => $ws) {
97
+ foreach ($ws as $name => $value) {
98
+
99
+ if ($params['id'] == 0) {
100
+ $ws = Mage::getModel('opensi/webservice');
101
+ } else {
102
+ $wsColl = Mage::getModel('opensi/webservice')->getCollection()
103
+ ->addFieldToFilter("name", $name)
104
+ ->addFieldToFilter("client_id", $idClient);
105
+ foreach ($wsColl as $wst) {
106
+ $ws = $wst;
107
+ }
108
+ $idWebservice = $ws->getId();
109
+ }
110
+ $wsData = array(
111
+ 'name' => $name,
112
+ 'client_id' => $idClient,
113
+ 'active' => isset($params[$name]['active']) ? 1 : 0,
114
+ 'frequency' => $params[$name]['frequency'] < $value['frequency'] ? $value['frequency'] : $params[$name]['frequency'],
115
+ 'frequency' => $params[$name]['frequency'],
116
+ );
117
+ $ws->setData($wsData);
118
+ isset($idWebservice) ? $ws->setId($idWebservice) : '';
119
+ try {
120
+ $ws->save();
121
+ } catch (Exception $e) {
122
+ $this->_getSession()->addError($e->getMessage());
123
+ }
124
+ }
125
+ }
126
+ $this->_getSession()->addSuccess($this->__('Webservices was successfully saved.'));
127
+ $storeId = Mage::registry('store_id') == "" ? $this->getRequest()->getParam('store') : Mage::registry('store_id');
128
+ $this->_redirect('*/*/', array("store" => $storeId));
129
+ }
130
+ }
131
 
132
  }
app/code/community/Speedinfo/Opensi/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Speedinfo_Opensi>
5
- <version>0.2.0</version>
6
  </Speedinfo_Opensi>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Speedinfo_Opensi>
5
+ <version>0.2.1</version>
6
  </Speedinfo_Opensi>
7
  </modules>
8
  <global>
app/code/community/Speedinfo/Opensi/sql/opensi_setup/mysql4-upgrade-0.2.0-0.2.1.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Update des tables
4
+ *
5
+ * @Author Speedinfo
6
+ * http://wwww.speedinfo.fr | http://www.opensi.fr
7
+ */
8
+
9
+ $installer = $this;
10
+
11
+ $installer->startSetup();
12
+
13
+
14
+ $db = $installer->getConnection();
15
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'famille1')) {
16
+ $installer->run("
17
+ ALTER TABLE {$this->getTable('opensi_client')} ADD famille1 int(10) unsigned NOT NULL default '0';
18
+ ");
19
+ }
20
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'famille2')) {
21
+ $installer->run("
22
+ ALTER TABLE {$this->getTable('opensi_client')} ADD famille2 int(10) unsigned NOT NULL default '0';
23
+ ");
24
+ }
25
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'famille3')) {
26
+ $installer->run("
27
+ ALTER TABLE {$this->getTable('opensi_client')} ADD famille3 int(10) unsigned NOT NULL default '0';
28
+ ");
29
+ }
30
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'attribut1')) {
31
+ $installer->run("
32
+ ALTER TABLE {$this->getTable('opensi_client')} ADD attribut1 int(10) unsigned NOT NULL default '0';
33
+ ");
34
+ }
35
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'attribut2')) {
36
+ $installer->run("
37
+ ALTER TABLE {$this->getTable('opensi_client')} ADD attribut2 int(10) unsigned NOT NULL default '0';
38
+ ");
39
+ }
40
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'attribut3')) {
41
+ $installer->run("
42
+ ALTER TABLE {$this->getTable('opensi_client')} ADD attribut3 int(10) unsigned NOT NULL default '0';
43
+ ");
44
+ }
45
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'attribut4')) {
46
+ $installer->run("
47
+ ALTER TABLE {$this->getTable('opensi_client')} ADD attribut4 int(10) unsigned NOT NULL default '0';
48
+ ");
49
+ }
50
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'attribut5')) {
51
+ $installer->run("
52
+ ALTER TABLE {$this->getTable('opensi_client')} ADD attribut5 int(10) unsigned NOT NULL default '0';
53
+ ");
54
+ }
55
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'attribut6')) {
56
+ $installer->run("
57
+ ALTER TABLE {$this->getTable('opensi_client')} ADD attribut6 int(10) unsigned NOT NULL default '0';
58
+ ");
59
+ }
60
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'code_barre')) {
61
+ $installer->run("
62
+ ALTER TABLE {$this->getTable('opensi_client')} ADD code_barre int(10) unsigned NOT NULL default '0';
63
+ ");
64
+ }
65
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'volume')) {
66
+ $installer->run("
67
+ ALTER TABLE {$this->getTable('opensi_client')} ADD volume int(10) unsigned NOT NULL default '0';
68
+ ");
69
+ }
70
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'hauteur')) {
71
+ $installer->run("
72
+ ALTER TABLE {$this->getTable('opensi_client')} ADD hauteur int(10) unsigned NOT NULL default '0';
73
+ ");
74
+ }
75
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'longueur')) {
76
+ $installer->run("
77
+ ALTER TABLE {$this->getTable('opensi_client')} ADD longueur int(10) unsigned NOT NULL default '0';
78
+ ");
79
+ }
80
+ if(!$db->tableColumnExists($this->getTable('opensi_client'), 'largeur')) {
81
+ $installer->run("
82
+ ALTER TABLE {$this->getTable('opensi_client')} ADD largeur int(10) unsigned NOT NULL default '0';
83
+ ");
84
+ }
85
+ //end
86
+ $installer->endSetup();
app/design/adminhtml/default/default/template/opensi/tab/webservices.phtml CHANGED
@@ -1,33 +1,33 @@
1
  <div class="entry-edit">
2
- <?php foreach(Mage::Helper('opensi')->getWebservicesName() as $title=>$ws):?>
3
- <div class="entry-edit-head">
4
- <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__($title); ?></h4>
5
- </div>
6
- <div id="base_fieldset" class="fieldset ">
7
- <div class="hor-scroll">
8
- <table cellspacing="0" class="form-list">
9
- <thead>
10
- <tr>
11
- <th><?php echo $this->__('Action du webservice'); ?></th>
12
- <th style="display:none"><?php echo $this->__('Activé ?'); ?></th>
13
- <th><?php echo $this->__('Fréquence (En minutes)'); ?></th>
14
- </tr>
15
- </thead>
16
- <tbody>
17
- <?php foreach($ws as $name=>$value):?>
18
- <?php $webservice = $this->getWebservice($name);?>
19
- <tr>
20
- <td class="label" style="width:200px;">
21
- <label style="width:300px;" for="opensi[<?php echo $name ?>]"><?php echo $value['title'] ?></label>
22
- <span style="font-size:11px;color:#888"><?php echo $value['subtitle'];?></span>
23
- </td>
24
- <td style="width:50px;display:none"><input type="checkbox" id="opensi[<?php echo $name ?>][active]" checked="checked" class="checkbox website-checkbox" value="0" name="opensi[<?php echo $name ?>][active]"></td>
25
- <td class="value"><input type="text" class="validate-number input-text" style="width:50px;" title="<?php echo $value['title'] ?>" value="<?php echo !empty($webservice) ? $webservice->frequency : $value['frequency'];?>" name="opensi[<?php echo $name ?>][frequency]" id="opensi[<?php echo $name ?>][frequency]"></td>
26
- </tr>
27
- <?php endforeach;?>
28
- </tbody>
29
- </table>
30
- </div>
31
- </div>
32
- <?php endforeach;?>
33
  </div>
1
  <div class="entry-edit">
2
+ <?php foreach(Mage::Helper('opensi')->getWebservicesName() as $title=>$ws):?>
3
+ <div class="entry-edit-head">
4
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__($title); ?></h4>
5
+ </div>
6
+ <div id="base_fieldset" class="fieldset ">
7
+ <div class="hor-scroll">
8
+ <table cellspacing="0" class="form-list">
9
+ <thead>
10
+ <tr>
11
+ <th><?php echo $this->__('Action du webservice'); ?></th>
12
+ <th style="display:none"><?php echo $this->__('Activé ?'); ?></th>
13
+ <th><?php echo $this->__('Fréquence (en minutes)'); ?></th>
14
+ </tr>
15
+ </thead>
16
+ <tbody>
17
+ <?php foreach($ws as $name=>$value):?>
18
+ <?php $webservice = $this->getWebservice($name);?>
19
+ <tr>
20
+ <td class="label" style="width:200px;">
21
+ <label style="width:300px;" for="opensi[<?php echo $name ?>]"><?php echo $value['title'] ?></label>
22
+ <span style="font-size:11px;color:#888"><?php echo $value['subtitle'];?></span>
23
+ </td>
24
+ <td style="width:50px;display:none;"><input type="checkbox" id="opensi[<?php echo $name ?>][active]" <?php //echo ((!empty($webservice) && $webservice->active) || empty($webservice)) ? 'checked="checked"' : '';?> checked="checked" class="checkbox website-checkbox" value="0" name="opensi[<?php echo $name ?>][active]"></td>
25
+ <td class="value"><input type="text" class="validate-number input-text" style="width:50px;" title="<?php echo $value['title'] ?>" value="<?php echo !empty($webservice) ? $webservice->frequency : $value['frequency'];?>" name="opensi[<?php echo $name ?>][frequency]" id="opensi[<?php echo $name ?>][frequency]"> <span style="font-size:11px;color:#888">(Min : <?php echo $value['frequency'];?>)</span></td>
26
+ </tr>
27
+ <?php endforeach;?>
28
+ </tbody>
29
+ </table>
30
+ </div>
31
+ </div>
32
+ <?php endforeach;?>
33
  </div>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Speedinfo_Opensi</name>
4
- <version>0.2.0</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -9,12 +9,13 @@
9
  <summary>Le module OpenSi Connect vous permet de coupler Magento au logiciel de gestion commerciale et de comptabilit&#xE9; OpenSi E-Commerce.</summary>
10
  <description>Le module OpenSi Connect vous permet de coupler Magento au logiciel de gestion commerciale et de comptabilit&#xE9; OpenSi E-Commerce.
11
  Speedinfo a con&#xE7;u un connecteur pour OpenSi E-Commerce et Magento sous la forme du module OpenSi Connect
12
- OpenSi E-Commerce, est un logiciel de gestion commerciale et de comptabilit&#xE9; d&#xE9;di&#xE9; &#xE0; l'e-commerce</description>
13
- <notes>Correction du cron pour le multi-store</notes>
14
- <authors><author><name>Siau</name><user>auto-converted</user><email>jerome@speedinfo.fr</email></author></authors>
15
- <date>2010-11-22</date>
16
- <time>09:06:59</time>
17
- <contents><target name="mage"><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="opensi"><dir name="tab"><file name="webservices.phtml" hash="fa3ab728342e6e3b4b7990c959e1bfc3"/></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Speedinfo_Opensi.xml" hash="16cc3fbf8e32ce7b8add016bfbc89c5f"/></dir></dir></dir></target><target name="magecommunity"><dir name="Speedinfo"><dir name="Opensi"><dir name="Block"><dir name="Adminhtml"><dir name="Edit"><dir name="Tab"><file name="General.php" hash="d1c825f23321e21f0fea86ac599dbfd9"/><file name="Webservices.php" hash="831734689e81b44d51329b2dd89d3c61"/></dir><file name="Form.php" hash="3ce2dc7af0ec4c5a44178ac46d6178a8"/></dir><file name="Edit.php" hash="1b1bbc699e9b318c098e815d7d924a64"/><file name="Grid.php" hash="938359d0bf4a9d26037fd121c71d1658"/><file name="Tabs.php" hash="2ec68b8a4dce8b680344ebb2b1d8e0fc"/></dir></dir><dir name="controllers"><file name="IndexController.php" hash="b843e876de91d68e5851bd4f17d5c06e"/></dir><dir name="etc"><file name="config.xml" hash="555092cb71d54f3b3dcd8d6dc5a6a34c"/></dir><dir name="Helper"><file name="Data.php" hash="71b49d1649d80cb1bb84ba1c822a23c8"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Errorlog"><file name="Collection.php" hash="ad19bb95ad5e56f0dcaeff4db10cf52f"/></dir><dir name="Webservice"><file name="Collection.php" hash="3a5e5d973ffb834d4eadec4f9335b36e"/></dir><file name="Client.php" hash="0b47754c6aace0dc54340dfd807eb17a"/><file name="Errorlog.php" hash="9a8c882377bbdeada65c7c5d8346af35"/><file name="Webservice.php" hash="781eb93e76ba8bffe881f091904d0f98"/></dir><file name="Client.php" hash="f89aeb3dda8d8a27bf6a05e5082a945e"/><file name="Cron.php" hash="ae8fab79e5fd2124d4f94eb0fc858c83"/><file name="Errorlog.php" hash="d269ec20ae481684a1daa2c515848252"/><file name="Webservice.php" hash="c77708c3507d79a83e64a1801ea255c2"/><file name="Webservices.php" hash="d181ed0e32bd4e99662739d8ed3ceeff"/></dir><dir name="sql"><dir name="opensi_setup"><file name="mysql4-install-0.1.0.php" hash="ce8cef17aac76ccfadf09d7d84d23841"/></dir></dir></dir></dir></target></contents>
 
18
  <compatible/>
19
  <dependencies/>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Speedinfo_Opensi</name>
4
+ <version>0.2.1</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
9
  <summary>Le module OpenSi Connect vous permet de coupler Magento au logiciel de gestion commerciale et de comptabilit&#xE9; OpenSi E-Commerce.</summary>
10
  <description>Le module OpenSi Connect vous permet de coupler Magento au logiciel de gestion commerciale et de comptabilit&#xE9; OpenSi E-Commerce.
11
  Speedinfo a con&#xE7;u un connecteur pour OpenSi E-Commerce et Magento sous la forme du module OpenSi Connect
12
+ OpenSi E-Commerce, est un logiciel de gestion commerciale et de comptabilit&#xE9; d&#xE9;di&#xE9; &#xE0; l'e-commerce.</description>
13
+ <notes>Mise &#xE0; jour du module vers la version 0.2.1.
14
+ Pour plus d'informations, se r&#xE9;f&#xE9;rer &#xE0; la documentation.</notes>
15
+ <authors><author><name>Dray</name><user>auto-converted</user><email>rony.dray@speedinfo.fr</email></author></authors>
16
+ <date>2010-12-16</date>
17
+ <time>14:10:44</time>
18
+ <contents><target name="mage"><dir name="app"><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="opensi"><dir name="tab"><file name="webservices.phtml" hash="dc2a8632a3780c7e9ffaae2b94f0fde4"/></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Speedinfo_Opensi.xml" hash="16cc3fbf8e32ce7b8add016bfbc89c5f"/></dir></dir></dir></target><target name="magecommunity"><dir name="Speedinfo"><dir name="Opensi"><dir name="Block"><dir name="Adminhtml"><dir name="Edit"><dir name="Tab"><file name="Attributs.php" hash="562e895af0d5f2a1cffa1be63d0b5fa4"/><file name="Familles.php" hash="317e2361f1dcb6c494ca9ab6bf0d5cae"/><file name="General.php" hash="485e888e215dde1762a42d147cced3e1"/><file name="Webservices.php" hash="c75830c9708f854a26345d22be5edb01"/></dir><file name="Form.php" hash="3ce2dc7af0ec4c5a44178ac46d6178a8"/></dir><file name="Edit.php" hash="b91602dd06e9432d879db352fa2aaeaa"/><file name="Grid.php" hash="6ace416ae5264fed2bbc57aa5d152e6e"/><file name="Tabs.php" hash="4383dd11c3e1fffe43868e489f6b977f"/></dir></dir><dir name="controllers"><file name="IndexController.php" hash="9164508a161b872a18f644f015b6d221"/></dir><dir name="etc"><file name="config.xml" hash="3d0070cf51e4c60bafac6172e03be50e"/></dir><dir name="Helper"><file name="Data.php" hash="b5798cdae9319b34ada4c3de5964c0b4"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Errorlog"><file name="Collection.php" hash="ad19bb95ad5e56f0dcaeff4db10cf52f"/></dir><dir name="Webservice"><file name="Collection.php" hash="3a5e5d973ffb834d4eadec4f9335b36e"/></dir><file name="Client.php" hash="0b47754c6aace0dc54340dfd807eb17a"/><file name="Errorlog.php" hash="9a8c882377bbdeada65c7c5d8346af35"/><file name="Webservice.php" hash="781eb93e76ba8bffe881f091904d0f98"/></dir><file name="Client.php" hash="f89aeb3dda8d8a27bf6a05e5082a945e"/><file name="Cron.php" hash="94436f6e624d9f665bc27cb92cadb001"/><file name="Errorlog.php" hash="d269ec20ae481684a1daa2c515848252"/><file name="Webservice.php" hash="c77708c3507d79a83e64a1801ea255c2"/><file name="Webservices.php" hash="5bde98a8eb485029524b5c47b5a52ff9"/></dir><dir name="sql"><dir name="opensi_setup"><file name="mysql4-install-0.1.0.php" hash="ce8cef17aac76ccfadf09d7d84d23841"/><file name="mysql4-upgrade-0.2.0-0.2.1.php" hash="f207b0704a6cad542dced6b40ac25341"/></dir></dir></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies/>
21
  </package>