Speedinfo_Opensi - Version 0.2.9

Version Notes

Mise à jour du module vers la version 0.2.9.
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.9
Comparing to
See all releases


Code changes from version 0.2.7 to 0.2.9

app/code/community/Speedinfo/Opensi/Model/Cron.php CHANGED
@@ -39,7 +39,7 @@ class Speedinfo_Opensi_Model_Cron extends Mage_Core_Model_Abstract {
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');
@@ -48,6 +48,8 @@ class Speedinfo_Opensi_Model_Cron extends Mage_Core_Model_Abstract {
48
  }
49
  } else {
50
  $lastStart = new DateTime($lastStartString);
 
 
51
  }
52
  $frequency = $webservice->getFrequency();
53
  $now = new Datetime();
@@ -55,8 +57,6 @@ class Speedinfo_Opensi_Model_Cron extends Mage_Core_Model_Abstract {
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) {
@@ -70,6 +70,7 @@ class Speedinfo_Opensi_Model_Cron extends Mage_Core_Model_Abstract {
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
  }
@@ -113,9 +114,9 @@ class Speedinfo_Opensi_Model_Cron extends Mage_Core_Model_Abstract {
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;
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');
48
  }
49
  } else {
50
  $lastStart = new DateTime($lastStartString);
51
+ // on prend une marge pour pas rater d'infos
52
+ $lastStart->modify('-5 min');
53
  }
54
  $frequency = $webservice->getFrequency();
55
  $now = new Datetime();
57
  $interval = ($now->format('U') - $lastStart->format('U')) / 60;
58
  // si le temps passe depuis le dernier lancement est superieur ou egal a la frequence de lancement
59
  if ($interval >= $frequency) {
 
 
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) {
70
  } else {
71
  $storeId = $baseStoreId;
72
  }
73
+
74
  Mage::log('debut ' . $webserviceName . ' store ' . $storeId, null, 'opensi.log');
75
  Mage::getModel('opensi/webservices')->$webserviceName($lastStart, $client, $storeId);
76
  }
114
  $storeList = array();
115
  $allStores = Mage::app()->getStores();
116
  foreach ($allStores as $key => $value) {
117
+ $storeId = Mage::app()->getStore($key)->getId();
118
  if ($storeId != '0')
119
+ array_push($storeList, $storeId);
120
  }
121
 
122
  return $storeList;
app/code/community/Speedinfo/Opensi/Model/Webservices.php CHANGED
@@ -9,6 +9,17 @@
9
  class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
10
 
11
  private $error = "";
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  /**
14
  * Envoie des donnees au serveur OpenSI
@@ -20,11 +31,13 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
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');
@@ -32,16 +45,45 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
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
 
@@ -63,9 +105,8 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
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
 
@@ -78,7 +119,11 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
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) {
@@ -89,13 +134,13 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
89
  $shippingDesc = $shippingDesc[1];
90
  }
91
  }
92
- $commandeWeb->setAttribute('Mode_Expedition', $shippingDesc);
93
  $commandeWeb->setAttribute('Edition_TTC', "true");
94
  // recuperation du taux de tva sur les frais de port
95
  $taxClassId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $storeId);
96
  if ($taxClassId != 0) {
97
  // $taxRequest = Mage::getSingleton('tax/calculation')->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), "", $storeId);
98
- $taxRequest = Mage::getSingleton('tax/calculation')->getRateRequest();
99
  if ($taxRequest->getCustomerClassId()) {
100
  $percent = Mage::getSingleton('tax/calculation')->getRate($taxRequest->setProductClassId($taxClassId));
101
  } else if ($taxRequest->getProductClassId()) {
@@ -164,17 +209,16 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
164
  $commandeWeb->setAttribute('Email_Liv', $customer->getEmail());
165
 
166
  $request->appendChild($commandeWeb);
167
-
168
  // Informations du contenu de la commande
169
  foreach ($order->getAllVisibleItems() as $item) {
170
  $ligneCommandeClient = $docXml->createElement("Ligne_Commande_Client");
171
 
172
  if($item->getProductType() == "configurable"){
173
- $ligneCommandeClient->setAttribute('Reference', $item->getProductOptionByCode('simple_sku'));
174
- $ligneCommandeClient->setAttribute('Designation', $item->getProductOptionByCode('simple_name'));
175
  }else{
176
- $ligneCommandeClient->setAttribute('Reference', $item->getSku());
177
- $ligneCommandeClient->setAttribute('Designation', $item->getName());
178
  }
179
  $ligneCommandeClient->setAttribute('Quantite', $item->getQtyOrdered());
180
 
@@ -234,21 +278,35 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
234
  // ->addStoreFilter($storeId)
235
  // ->addAttributeToSelect('*');
236
  // }else{
 
237
  $productCollection = Mage::getModel('catalog/product')->getCollection()
238
  ->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
239
  ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))
240
  ->addStoreFilter($storeId)
241
  ->addAttributeToSelect('*');
242
- // }
 
243
  foreach ($productCollection as $product) {
 
 
 
 
 
 
244
  $articleData = $this->articleData($product, $storeId, 'create', $client);
245
- $this->sendData('POST', 'create_article', $articleData, $client);
 
246
  //Vérifier si 409 ne pas lancer
247
  if($this->_error != "409")
248
- $this->setStockArticle($product,$client);
249
  } // endforeach $productCollection
 
 
 
 
 
250
  if ($productCollection->count() > 0)
251
- $this->setPubwebArticle($startedAt, $client, $storeId);
252
  }
253
 
254
  /**
@@ -261,14 +319,21 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
261
  ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))
262
  ->addStoreFilter($storeId)
263
  ->addAttributeToSelect('*');
264
-
265
  foreach ($productCollection as $product) {
 
 
 
 
 
 
266
  $articleData = $this->articleData($product, $storeId, 'update', $client);
267
  $params = array('reference' => $product->getSku());
268
- $this->sendData('PUT', 'update_article', $articleData, $client, $params);
 
269
  } // endforeach $productCollection
270
  if ($productCollection->count() > 0)
271
- $this->setPubwebArticle($startedAt, $client, $storeId);
272
  }
273
 
274
  /**
@@ -280,66 +345,70 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
280
 
281
  $docXml->appendChild($request);
282
  $article = $docXml->createElement('Article');
283
-
284
- // Informations du produit
285
- $article->setAttribute('Reference', substr($product->getSku(), 0, 39));
286
- $article->setAttribute('Designation', substr($product->getName(), 0, 99));
287
- $article->setAttribute('Description_1', $product->getDescription());
288
- $shortDescription = $product->getShortDescription();
289
- if (!empty($shortDescription))
290
- $article->setattribute('Description_2', $shortDescription);
291
- $brand = $product->getAttributeText('manufacturer');
292
- if (!empty($brand))
293
- $article->setAttribute('Marque', $brand);
294
-
295
- // Gestion des familles
296
- $fam1 = $this->getSimpleAttributes($product, $client->famille1);
297
- if (!empty($client->famille1) && !empty($fam1)) {
298
- $article->setAttribute('Famille_1', substr($this->getSimpleAttributes($product, $client->famille1), 0, 39));
299
- } else {
300
- $article->setAttribute('Famille_1', 'NC');
301
- }
302
- !empty($client->famille2) && $this->getSimpleAttributes($product, $client->famille2) ? $article->setAttribute('Famille_2', substr($this->getSimpleAttributes($product, $client->famille2), 0, 39)) : false;
303
- !empty($client->famille3) && $this->getSimpleAttributes($product, $client->famille3) ? $article->setAttribute('Famille_3', substr($this->getSimpleAttributes($product, $client->famille3), 0, 39)) : false;
304
-
305
- // Gestion des attributs
306
- !empty($client->attribut1) && $this->getSimpleAttributes($product, $client->attribut1) ? $article->setAttribute('Attribut_1', substr($this->getSimpleAttributes($product, $client->attribut1), 0, 39)) : false;
307
- !empty($client->attribut2) && $this->getSimpleAttributes($product, $client->attribut2) ? $article->setAttribute('Attribut_2', substr($this->getSimpleAttributes($product, $client->attribut2), 0, 39)) : false;
308
- !empty($client->attribut3) && $this->getSimpleAttributes($product, $client->attribut3) ? $article->setAttribute('Attribut_3', substr($this->getSimpleAttributes($product, $client->attribut3), 0, 39)) : false;
309
- !empty($client->attribut4) && $this->getSimpleAttributes($product, $client->attribut4) ? $article->setAttribute('Attribut_4', substr($this->getSimpleAttributes($product, $client->attribut4), 0, 39)) : false;
310
- !empty($client->attribut5) && $this->getSimpleAttributes($product, $client->attribut5) ? $article->setAttribute('Attribut_5', substr($this->getSimpleAttributes($product, $client->attribut5), 0, 39)) : false;
311
- !empty($client->attribut6) && $this->getSimpleAttributes($product, $client->attribut6) ? $article->setAttribute('Attribut_6', substr($this->getSimpleAttributes($product, $client->attribut6), 0, 39)) : false;
312
- !empty($client->code_barre) && $this->getSimpleAttributes($product, $client->code_barre) ? $article->setAttribute('Code_Barre', substr($this->getSimpleAttributes($product, $client->code_barre), 0, 14)) : false;
313
- !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;
314
- !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;
315
- !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;
316
- !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;
317
-
318
- $weight = $product->getWeight();
319
- if (!empty($weight))
320
- $article->setAttribute('Poids', $weight);
321
-
322
- if ($type == 'create') {
323
- $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
324
- if ($includeTax) {
325
- $article->setAttribute('Tarif_TTC_1', $product->getFinalPrice());
326
  } else {
327
-
328
- $article->setAttribute('Tarif_HT_1', $product->getFinalPrice());
329
  }
330
- $product->getCost() != "" ? $article->setAttribute('Prix_Achat', $product->getCost()) : false;
331
- // $taxRequest = Mage::getSingleton('tax/calculation');
332
- // Mage::log(Mage::getSingleton('tax/calculation')->getRate($taxRequest->setProductClassId($product->getTaxClassId())),null,'opensi.log');
333
- // $product->getTaxPercent() != "" ? $article->setAttribute('Taux_Tva', $product->getTaxPercent()) : false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
  }
335
- $updatedAt = new Datetime($product->getUpdatedAt());
336
- $createdAt = new Datetime($product->getCreatedAt());
337
- $article->setAttribute('Date_M', $updatedAt->format('d-m-Y H:i:s'));
338
- $article->setAttribute('Date_C', $createdAt->format('d-m-Y H:i:s'));
339
-
340
- $active = "true";
341
- $article->setAttribute('Actif', $active);
342
-
343
  $request->appendChild($article);
344
 
345
  return $docXml->saveXML();
@@ -349,8 +418,10 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
349
  * Envoie des nouveaux clients vers OpenSI
350
  */
351
  public function createClientWeb($startedAt, $client, $storeId) {
352
- $customerCollection = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
353
- ->addAttributeToSelect('*')->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
 
 
354
  foreach ($customerCollection as $customer) {
355
  $clientData = $this->clientData($customer, $client);
356
  $this->sendData('POST', 'create_client_web', $clientData, $client);
@@ -361,8 +432,11 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
361
  * Envoie des clients modifies vers OpenSI
362
  */
363
  public function updateClientWeb($startedAt, $client, $storeId) {
364
- $customerCollection = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
365
- ->addFieldToFilter('created_at', array('lteq' => $startedAt->format('Y-m-d H:i:s')))->addAttributeToSelect('*')->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
 
 
 
366
 
367
  foreach ($customerCollection as $customer) {
368
  $clientData = $this->clientData($customer, $client);
@@ -420,33 +494,50 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
420
  */
421
  public function getStockArticle($startedAt, $client, $storeId) {
422
  $params = array('code_depot' => $client->deposit, 'date_debut' => $startedAt->format('d-m-Y'));
423
-
424
  $resultXML = $this->sendData("GET", "get_stock_article", "", $client, $params);
 
425
 
426
  $xmlDomDocument = new DomDocument();
427
- $xmlDomDocument->loadXML($resultXML);
428
-
429
  $stockArticles = $xmlDomDocument->getElementsByTagName("Stock_Article");
430
-
431
  foreach ($stockArticles as $stockArticle) {
432
-
433
- $sku = $stockArticle->getAttribute('Reference');
434
- $qty = $stockArticle->getAttribute('Stock_Dispo');
435
- $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
436
- if ($product && $product->getTypeId() != "bundle") {
437
- $stockArticle = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
438
- if ($qty > 0) {
439
- $stockArticle->setQty($qty);
440
- $stockArticle->setIsInStock(true);
441
- } else {
442
- $stockArticle->setQty(0);
443
- $stockArticle->setIsInStock(false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  }
445
-
446
- $stockArticle->setStoreId($storeId);
447
- $stockArticle->save();
448
- }
449
  }
 
 
 
 
 
450
  }
451
 
452
  /**
@@ -476,8 +567,20 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
476
  $orderCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))->addFieldToFilter('store_id', $storeId);
477
 
478
  foreach ($orderCollection as $order) {
479
- $methodPayment = $order->getPayment()->getMethod();
480
  $numOrder = $order->getIncrementId();
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  $numeroTransaction = $numOrder;
482
 
483
  $invoiceCollection = Mage::getResourceModel('sales/order_invoice_collection')
@@ -541,6 +644,8 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
541
  continue;
542
  }
543
 
 
 
544
  //recup du statut de paiement = si termine on facture pour considerer la commande paye
545
  if ($etatCommande->getAttribute('Statut_Paiement') == 'T') {
546
 
@@ -586,12 +691,12 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
586
  }
587
  }
588
  }
 
589
 
590
-
591
- //recup du statut de livraison
592
  if ($etatCommande->getAttribute('Statut_Logistique') == 'E') {
593
 
594
- if ($order->canShip()) {
595
  $shipmentCollection = $order->getShipmentsCollection();
596
  $shipmentId = '';
597
  foreach ($shipmentCollection as $shipment) {
@@ -601,28 +706,29 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
601
  $shipmentId = Mage::getModel('sales/order_shipment_api')->create($order->getIncrementId(), array());
602
  }
603
  }
604
-
605
- $status = $order->getStatus();
606
  //passer derniere valeur a true pour envoyer mail au client
607
  switch ($etatCommande->getAttribute('Etat')) {
608
- case 'N':
609
  if ($status != 'pending')
610
- $order->setState('pending', true, 'changement de statut OpenSI', true);
611
  break;
612
 
613
- case 'T':
614
  if ($status != 'processing')
615
- $order->setState('processing', true, 'changement de statut OpenSI', true);
616
  break;
617
 
618
- case 'A':
619
  if ($status != 'canceled')
620
- $order->setState('canceled', true, 'changement de statut OpenSI', true);
621
  break;
622
 
623
- case 'C':
624
- if ($status != 'complete' && Mage::getVersion() < '1.4.0.0')
625
- $order->setState('complete', true, 'changement de statut OpenSI', true);
 
626
  break;
627
  }
628
  $order->save();
@@ -676,8 +782,11 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
676
  $xmlDomDocument = new DomDocument();
677
  $xmlDomDocument->loadXML($resultXML);
678
  $listPublicationArticle = $xmlDomDocument->getElementsByTagName("Pubweb_Article");
679
-
680
  foreach ($listPublicationArticle as $publicationArticle) {
 
 
 
681
  $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $publicationArticle->getAttribute('Reference'));
682
  if ($product) {
683
  if ($publicationArticle->getAttribute('Publication') == "true") {
@@ -699,8 +808,14 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
699
  $productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
700
  ->addStoreFilter($storeId)
701
  ->addAttributeToSelect(array('sku', 'status'));
702
-
703
  foreach ($productCollection as $product) {
 
 
 
 
 
 
704
  $docXml = $this->createXml();
705
  $request = $docXml->createElement("request");
706
 
@@ -728,14 +843,16 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
728
  public function getPrixArticle($startedAt, $client, $storeId) {
729
  $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
730
  $resultXML = $this->sendData("GET", "get_prix_article", "", $client, $params);
731
-
732
  $xmlDomDocument = new DomDocument();
733
  $xmlDomDocument->loadXML($resultXML);
734
  $listPrixArticle = $xmlDomDocument->getElementsByTagName("Prix_Article");
735
-
736
  //Verif si dans la configuration le prix est TTC ou HT
737
  $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
 
738
  foreach ($listPrixArticle as $prixArticle) {
 
 
 
739
  $reference = $prixArticle->getAttribute('Reference');
740
  $tarifHT = $prixArticle->getAttribute('Tarif_HT_1');
741
  $tarifTTC = $prixArticle->getAttribute('Tarif_TTC_1');
@@ -743,8 +860,12 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
743
  $product = Mage::getModel('catalog/product')->loadByAttribute("sku", $reference);
744
  if ($product && $product->getTypeId() != "bundle") {
745
  if ($includeTax) {
 
 
746
  $product->setPrice($tarifTTC);
747
  } else {
 
 
748
  $product->setPrice($tarifHT);
749
  }
750
  $product->setCost($prixAchat);
@@ -777,5 +898,24 @@ class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
777
  return '';
778
  }
779
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
780
 
781
  }
9
  class Speedinfo_Opensi_Model_Webservices extends Mage_Core_Model_Abstract {
10
 
11
  private $error = "";
12
+
13
+ /** Crée l'objet Zend_Http_Client, qu'une fois pour éviter de faire sauter la mémoire **/
14
+ private static $zHttpClient;
15
+
16
+ private function create_Zend_Http_Client(){
17
+ if (!isset(self::$zHttpClient)) {
18
+ self::$zHttpClient = new Zend_Http_Client();
19
+ }
20
+
21
+ return self::$zHttpClient;
22
+ }
23
 
24
  /**
25
  * Envoie des donnees au serveur OpenSI
31
  * @return String $response reponse du serveur
32
  */
33
  protected function sendData($method, $action, $xmlData, $client, $params = '') {
34
+
35
+ $httpRequest = $this->create_Zend_Http_Client();
36
  $httpRequest->setAuth($client->webservice_user, $client->webservice_pwd);
37
  $httpRequest->setUri('https://webservices.opensi.eu/cows/Gateway');
38
+ $httpRequest->resetParameters();
39
  $httpRequest->setParameterGet(array('service_id' => $client->opensi_id, 'action' => $action));
40
+
41
  $log = '';
42
  if (!empty($xmlData)) {
43
  $httpRequest->setRawData($xmlData, 'text/xml');
45
  }
46
  if (!empty($params))
47
  $httpRequest->setParameterGet($params);
48
+
49
+ //On tente 10 fois de se connecter au serveur
50
+ for ($i = 0; $i < 10; $i++){
51
+ try{
52
+ $response = $httpRequest->request($method);
53
+ }
54
+ catch (Exception $e){
55
+ Mage::log('Exception levée :' . $e->getMessage().'\n'.$xmlData, null, 'opensi.log');
56
+ $response = null;
57
+ }
58
+ //si on a une requête on sort des tentatives
59
+ if(isset($response) && is_object($response)){
60
+ break;
61
+ }else{
62
+ //on attend deux secondes avant de refaire une requete
63
+ sleep(2);
64
+ $response = null;
65
+ }
66
+ }
67
+ //Si reponse pas defini, on leve une exception
68
+ try{
69
+ if(!isset($response)){
70
+ throw new Exception('Pas de reponse renvoyée par httpRequest');
71
+ }
72
+ }
73
+ catch(Exception $e){
74
+ Mage::log('Exception levée : ' . $e->getMessage().'\n'.$xmlData, null, 'opensi.log');
75
+ return null;
76
+ }
77
+
78
  $log .= $response->getStatus();
 
79
  //on gere les logs / erreurs
80
  if ($response->isError() && $response->getStatus() != '409') {
81
  $this->setLogs($response, $client, $action);
82
  Mage::log($log, null, 'opensi.log');
83
  }
84
+
85
  $this->_error = $response->getStatus();
86
+
87
  return $response->getRawBody();
88
  }
89
 
105
  $this->createArticle($startedAt, $client, $storeId);
106
  $this->createClientWeb($startedAt, $client, $storeId);
107
  }
108
+
109
  foreach ($orderCollection as $order) {
 
110
  $docXml = $this->createXml();
111
  $request = $docXml->createElement("request");
112
 
119
  // Informations de commande
120
  $commandeWeb->setAttribute('Num_Com_Web', $order->getIncrementId());
121
  $commandeWeb->setAttribute('Code_Site_Web', $client->web_site_code);
122
+ if($customer->getId()){
123
+ $commandeWeb->setAttribute('Login', $customer->getId());
124
+ }else{
125
+ $commandeWeb->setAttribute('Login', "Invité");
126
+ }
127
  $commandeWeb->setAttribute('Date_Commande', $orderDate->format('d-m-Y H:i:s'));
128
  $shippingDesc = $order->getShippingDescription();
129
  if (strlen($shippingDesc) > 30) {
134
  $shippingDesc = $shippingDesc[1];
135
  }
136
  }
137
+ !empty($shippingDesc) ? $commandeWeb->setAttribute('Mode_Expedition',$shippingDesc) : "";
138
  $commandeWeb->setAttribute('Edition_TTC', "true");
139
  // recuperation du taux de tva sur les frais de port
140
  $taxClassId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $storeId);
141
  if ($taxClassId != 0) {
142
  // $taxRequest = Mage::getSingleton('tax/calculation')->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), "", $storeId);
143
+ $taxRequest = Mage::getSingleton('tax/calculation')->getRateRequest();
144
  if ($taxRequest->getCustomerClassId()) {
145
  $percent = Mage::getSingleton('tax/calculation')->getRate($taxRequest->setProductClassId($taxClassId));
146
  } else if ($taxRequest->getProductClassId()) {
209
  $commandeWeb->setAttribute('Email_Liv', $customer->getEmail());
210
 
211
  $request->appendChild($commandeWeb);
 
212
  // Informations du contenu de la commande
213
  foreach ($order->getAllVisibleItems() as $item) {
214
  $ligneCommandeClient = $docXml->createElement("Ligne_Commande_Client");
215
 
216
  if($item->getProductType() == "configurable"){
217
+ $ligneCommandeClient->setAttribute('Reference', substr($item->getProductOptionByCode('simple_sku'),0,39));
218
+ $ligneCommandeClient->setAttribute('Designation', substr($item->getProductOptionByCode('simple_name'),0,99));
219
  }else{
220
+ $ligneCommandeClient->setAttribute('Reference', substr($item->getSku(),0,39));
221
+ $ligneCommandeClient->setAttribute('Designation', substr($item->getName(),0,99));
222
  }
223
  $ligneCommandeClient->setAttribute('Quantite', $item->getQtyOrdered());
224
 
278
  // ->addStoreFilter($storeId)
279
  // ->addAttributeToSelect('*');
280
  // }else{
281
+ // $startedAt = new DateTime('1970-01-01');
282
  $productCollection = Mage::getModel('catalog/product')->getCollection()
283
  ->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
284
  ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))
285
  ->addStoreFilter($storeId)
286
  ->addAttributeToSelect('*');
287
+ ini_set('max_execution_time', 50 );
288
+ // $time_start = microtime(true);
289
  foreach ($productCollection as $product) {
290
+ ini_set('max_execution_time', ini_get('max_execution_time')+1 );
291
+ if (ini_get('max_execution_time') == 100)
292
+ ini_set('max_execution_time', 50 );
293
+ if(!$this->verfiSku($product)){
294
+ continue;
295
+ }
296
  $articleData = $this->articleData($product, $storeId, 'create', $client);
297
+ if (!empty($articleData))
298
+ $this->sendData('POST', 'create_article', $articleData, $client);
299
  //Vérifier si 409 ne pas lancer
300
  if($this->_error != "409")
301
+ $this->setStockArticle($product,$client);
302
  } // endforeach $productCollection
303
+ // $time_end = microtime(true);
304
+ // $time = $time_end - $time_start;
305
+ // Mage::log("CREATE ARTICLE",null,'opensiTimer.log');
306
+ // Mage::log($time,null,'opensiTimer.log');
307
+ // Mage::log("END CREATE ARTICLE",null,'opensiTimer.log');
308
  if ($productCollection->count() > 0)
309
+ $this->setPubwebArticle($startedAt, $client, $storeId);
310
  }
311
 
312
  /**
319
  ->addFieldToFilter('type_id', array('nin' => array('configurable', 'grouped')))
320
  ->addStoreFilter($storeId)
321
  ->addAttributeToSelect('*');
322
+ ini_set('max_execution_time', 50 );
323
  foreach ($productCollection as $product) {
324
+ if(!$this->verfiSku($product)){
325
+ continue;
326
+ }
327
+ ini_set('max_execution_time', ini_get('max_execution_time')+1 );
328
+ if (ini_get('max_execution_time') == 100)
329
+ ini_set('max_execution_time', 50 );
330
  $articleData = $this->articleData($product, $storeId, 'update', $client);
331
  $params = array('reference' => $product->getSku());
332
+ if (!empty($articleData))
333
+ $this->sendData('PUT', 'update_article', $articleData, $client, $params);
334
  } // endforeach $productCollection
335
  if ($productCollection->count() > 0)
336
+ $this->setPubwebArticle($startedAt, $client, $storeId);
337
  }
338
 
339
  /**
345
 
346
  $docXml->appendChild($request);
347
  $article = $docXml->createElement('Article');
348
+ try{
349
+ // Informations du produit
350
+ $article->setAttribute('Reference', $product->getSku());
351
+ $article->setAttribute('Designation', substr($product->getName(), 0, 99));
352
+ $article->setAttribute('Description_1', $product->getDescription());
353
+ $shortDescription = $product->getShortDescription();
354
+ if (!empty($shortDescription))
355
+ $article->setattribute('Description_2', $shortDescription);
356
+ $brand = $product->getAttributeText('manufacturer');
357
+ if (!empty($brand))
358
+ $article->setAttribute('Marque', substr($brand, 0, 39));
359
+
360
+ // Gestion des familles
361
+ $fam1 = $this->getSimpleAttributes($product, $client->famille1);
362
+ if (!empty($client->famille1) && !empty($fam1)) {
363
+ $article->setAttribute('Famille_1', substr($this->getSimpleAttributes($product, $client->famille1), 0, 39));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  } else {
365
+ $article->setAttribute('Famille_1', 'NC');
 
366
  }
367
+ !empty($client->famille2) && $this->getSimpleAttributes($product, $client->famille2) ? $article->setAttribute('Famille_2', substr($this->getSimpleAttributes($product, $client->famille2), 0, 39)) : false;
368
+ !empty($client->famille3) && $this->getSimpleAttributes($product, $client->famille3) ? $article->setAttribute('Famille_3', substr($this->getSimpleAttributes($product, $client->famille3), 0, 39)) : false;
369
+
370
+ // Gestion des attributs
371
+ !empty($client->attribut1) && $this->getSimpleAttributes($product, $client->attribut1) ? $article->setAttribute('Attribut_1', substr($this->getSimpleAttributes($product, $client->attribut1), 0, 39)) : false;
372
+ !empty($client->attribut2) && $this->getSimpleAttributes($product, $client->attribut2) ? $article->setAttribute('Attribut_2', substr($this->getSimpleAttributes($product, $client->attribut2), 0, 39)) : false;
373
+ !empty($client->attribut3) && $this->getSimpleAttributes($product, $client->attribut3) ? $article->setAttribute('Attribut_3', substr($this->getSimpleAttributes($product, $client->attribut3), 0, 39)) : false;
374
+ !empty($client->attribut4) && $this->getSimpleAttributes($product, $client->attribut4) ? $article->setAttribute('Attribut_4', substr($this->getSimpleAttributes($product, $client->attribut4), 0, 39)) : false;
375
+ !empty($client->attribut5) && $this->getSimpleAttributes($product, $client->attribut5) ? $article->setAttribute('Attribut_5', substr($this->getSimpleAttributes($product, $client->attribut5), 0, 39)) : false;
376
+ !empty($client->attribut6) && $this->getSimpleAttributes($product, $client->attribut6) ? $article->setAttribute('Attribut_6', substr($this->getSimpleAttributes($product, $client->attribut6), 0, 39)) : false;
377
+ !empty($client->code_barre) && $this->getSimpleAttributes($product, $client->code_barre) ? $article->setAttribute('Code_Barre', substr($this->getSimpleAttributes($product, $client->code_barre), 0, 14)) : false;
378
+ !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;
379
+ !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;
380
+ !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;
381
+ !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;
382
+
383
+ $weight = $product->getWeight();
384
+ if (!empty($weight))
385
+ $article->setAttribute('Poids', $weight);
386
+
387
+ if ($type == 'create') {
388
+ $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
389
+ if ($includeTax) {
390
+ $article->setAttribute('Tarif_TTC_1', $product->getFinalPrice());
391
+ } else {
392
+
393
+ $article->setAttribute('Tarif_HT_1', $product->getFinalPrice());
394
+ }
395
+ $product->getCost() != "" ? $article->setAttribute('Prix_Achat', $product->getCost()) : false;
396
+ // $taxRequest = Mage::getSingleton('tax/calculation');
397
+ // Mage::log(Mage::getSingleton('tax/calculation')->getRate($taxRequest->setProductClassId($product->getTaxClassId())),null,'opensi.log');
398
+ // $product->getTaxPercent() != "" ? $article->setAttribute('Taux_Tva', $product->getTaxPercent()) : false;
399
+ }
400
+ $updatedAt = new Datetime($product->getUpdatedAt());
401
+ $createdAt = new Datetime($product->getCreatedAt());
402
+ $article->setAttribute('Date_M', $updatedAt->format('d-m-Y H:i:s'));
403
+ $article->setAttribute('Date_C', $createdAt->format('d-m-Y H:i:s'));
404
+
405
+ $active = "true";
406
+ $article->setAttribute('Actif', $active);
407
+ }
408
+ catch(Exception $e){
409
+ Mage::log("Erreur ".$e->getMessage(),null,"opensi.log");
410
+ return null;
411
  }
 
 
 
 
 
 
 
 
412
  $request->appendChild($article);
413
 
414
  return $docXml->saveXML();
418
  * Envoie des nouveaux clients vers OpenSI
419
  */
420
  public function createClientWeb($startedAt, $client, $storeId) {
421
+ $customerCollection = Mage::getModel('customer/customer')->getCollection()
422
+ ->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
423
+ ->addAttributeToSelect('*')
424
+ ->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
425
  foreach ($customerCollection as $customer) {
426
  $clientData = $this->clientData($customer, $client);
427
  $this->sendData('POST', 'create_client_web', $clientData, $client);
432
  * Envoie des clients modifies vers OpenSI
433
  */
434
  public function updateClientWeb($startedAt, $client, $storeId) {
435
+ $customerCollection = Mage::getModel('customer/customer')->getCollection()
436
+ ->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
437
+ ->addFieldToFilter('created_at', array('lteq' => $startedAt->format('Y-m-d H:i:s')))
438
+ ->addAttributeToSelect('*')
439
+ ->addAttributeToFilter('website_id', Mage::getModel('core/store')->load($storeId)->getWebsiteId());
440
 
441
  foreach ($customerCollection as $customer) {
442
  $clientData = $this->clientData($customer, $client);
494
  */
495
  public function getStockArticle($startedAt, $client, $storeId) {
496
  $params = array('code_depot' => $client->deposit, 'date_debut' => $startedAt->format('d-m-Y'));
 
497
  $resultXML = $this->sendData("GET", "get_stock_article", "", $client, $params);
498
+ ini_set('max_execution_time', 50 );
499
 
500
  $xmlDomDocument = new DomDocument();
501
+ $result = $xmlDomDocument->loadXML($resultXML);
 
502
  $stockArticles = $xmlDomDocument->getElementsByTagName("Stock_Article");
503
+ //$time_start = microtime(true);
504
  foreach ($stockArticles as $stockArticle) {
505
+ ini_set('max_execution_time', ini_get('max_execution_time')+1 );
506
+ if (ini_get('max_execution_time') == 100)
507
+ ini_set('max_execution_time', 50 );
508
+ try{
509
+ $sku = $stockArticle->getAttribute('Reference');
510
+ $qty = $stockArticle->getAttribute('Stock_Dispo');
511
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
512
+ if ($product && $product->getTypeId() != "bundle") {
513
+ $stockArticle2 = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
514
+ if($stockArticle2->getQty() == $qty){
515
+ unset($product);
516
+ unset($stockArticle2);
517
+ continue;
518
+ }
519
+ if ($qty > 0) {
520
+ $stockArticle2->setQty($qty);
521
+ $stockArticle2->setIsInStock(true);
522
+ } else {
523
+ $stockArticle2->setQty(0);
524
+ $stockArticle2->setIsInStock(false);
525
+ }
526
+
527
+ $stockArticle2->setStoreId($storeId);
528
+ $stockArticle2->save();
529
+ unset($product);
530
+ unset($stockArticle2);
531
  }
532
+ }catch(Exception $e){
533
+ Mage::log($e,null,'opensi.log');
534
+ }
 
535
  }
536
+ // $time_end = microtime(true);
537
+ // $time = $time_end - $time_start;
538
+ // Mage::log("GET STOCK",null,'opensiTimer.log');
539
+ // Mage::log($time,null,'opensiTimer.log');
540
+ // Mage::log("END GET STOCK",null,'opensiTimer.log');
541
  }
542
 
543
  /**
567
  $orderCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('created_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))->addFieldToFilter('store_id', $storeId);
568
 
569
  foreach ($orderCollection as $order) {
 
570
  $numOrder = $order->getIncrementId();
571
+
572
+ //Test pour savoir si la commande est déjà payée
573
+ $params = array('code_site_web' => $client->web_site_code, 'num_com_web' => $numOrder, 'date_debut' => "01-01-1970");
574
+ $resultXML = $this->sendData("GET", "get_etat_commande", "", $client, $params);
575
+
576
+ $xmlDomDocument = new DomDocument();
577
+ $xmlDomDocument->loadXML($resultXML);
578
+ $etatCommande = $xmlDomDocument->getElementsByTagName("Etat_Commande")->item(0);
579
+ if ($etatCommande->getAttribute('Statut_Paiement') == 'T')
580
+ continue;
581
+
582
+
583
+ $methodPayment = $order->getPayment()->getMethod();
584
  $numeroTransaction = $numOrder;
585
 
586
  $invoiceCollection = Mage::getResourceModel('sales/order_invoice_collection')
644
  continue;
645
  }
646
 
647
+ $status = $order->getStatus();
648
+ //Mage::log($order->getIncrementId()." ".$order->getStatus()." ".$etatCommande->getAttribute('Statut_Paiement')." ".$etatCommande->getAttribute('Statut_Logistique')." ".$etatCommande->getAttribute('Etat') ,null,'opensi.log');
649
  //recup du statut de paiement = si termine on facture pour considerer la commande paye
650
  if ($etatCommande->getAttribute('Statut_Paiement') == 'T') {
651
 
691
  }
692
  }
693
  }
694
+ $order->save();
695
 
696
+ //recup du statut de livraison | E = Expediée
 
697
  if ($etatCommande->getAttribute('Statut_Logistique') == 'E') {
698
 
699
+ if ($order->canShip()) {
700
  $shipmentCollection = $order->getShipmentsCollection();
701
  $shipmentId = '';
702
  foreach ($shipmentCollection as $shipment) {
706
  $shipmentId = Mage::getModel('sales/order_shipment_api')->create($order->getIncrementId(), array());
707
  }
708
  }
709
+ $order->save();
710
+
711
  //passer derniere valeur a true pour envoyer mail au client
712
  switch ($etatCommande->getAttribute('Etat')) {
713
+ case 'N': //Non validée
714
  if ($status != 'pending')
715
+ $order->setState('pending', true, 'changement de statut OpenSI (Pending)', true);
716
  break;
717
 
718
+ case 'T': // En cours mais validée
719
  if ($status != 'processing')
720
+ $order->setState('processing', true, 'changement de statut OpenSI (Processing)', true);
721
  break;
722
 
723
+ case 'A': // Annulée
724
  if ($status != 'canceled')
725
+ $order->setState('canceled', true, 'changement de statut OpenSI (Canceled)', true);
726
  break;
727
 
728
+ case 'C': // Cloturée expédiée et facturée
729
+ if ($status != 'complete' && Mage::getVersion() < '1.4.0.0'){
730
+ $order->setState('complete', true, 'changement de statut OpenSI (Complete)', true);
731
+ }
732
  break;
733
  }
734
  $order->save();
782
  $xmlDomDocument = new DomDocument();
783
  $xmlDomDocument->loadXML($resultXML);
784
  $listPublicationArticle = $xmlDomDocument->getElementsByTagName("Pubweb_Article");
785
+ ini_set('max_execution_time', 50 );
786
  foreach ($listPublicationArticle as $publicationArticle) {
787
+ ini_set('max_execution_time', ini_get('max_execution_time')+1 );
788
+ if (ini_get('max_execution_time') == 100)
789
+ ini_set('max_execution_time', 50 );
790
  $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $publicationArticle->getAttribute('Reference'));
791
  if ($product) {
792
  if ($publicationArticle->getAttribute('Publication') == "true") {
808
  $productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('updated_at', array('gteq' => $startedAt->format('Y-m-d H:i:s')))
809
  ->addStoreFilter($storeId)
810
  ->addAttributeToSelect(array('sku', 'status'));
811
+ ini_set('max_execution_time', 50 );
812
  foreach ($productCollection as $product) {
813
+ if(!$this->verfiSku($product)){
814
+ continue;
815
+ }
816
+ ini_set('max_execution_time', ini_get('max_execution_time')+1 );
817
+ if (ini_get('max_execution_time') == 100)
818
+ ini_set('max_execution_time', 50 );
819
  $docXml = $this->createXml();
820
  $request = $docXml->createElement("request");
821
 
843
  public function getPrixArticle($startedAt, $client, $storeId) {
844
  $params = array('code_site_web' => $client->web_site_code, 'date_debut' => $startedAt->format('d-m-Y'));
845
  $resultXML = $this->sendData("GET", "get_prix_article", "", $client, $params);
 
846
  $xmlDomDocument = new DomDocument();
847
  $xmlDomDocument->loadXML($resultXML);
848
  $listPrixArticle = $xmlDomDocument->getElementsByTagName("Prix_Article");
 
849
  //Verif si dans la configuration le prix est TTC ou HT
850
  $includeTax = Mage::getStoreConfig('tax/calculation/price_includes_tax', $storeId);
851
+ ini_set('max_execution_time', 50 );
852
  foreach ($listPrixArticle as $prixArticle) {
853
+ ini_set('max_execution_time', ini_get('max_execution_time')+1 );
854
+ if (ini_get('max_execution_time') == 100)
855
+ ini_set('max_execution_time', 50 );
856
  $reference = $prixArticle->getAttribute('Reference');
857
  $tarifHT = $prixArticle->getAttribute('Tarif_HT_1');
858
  $tarifTTC = $prixArticle->getAttribute('Tarif_TTC_1');
860
  $product = Mage::getModel('catalog/product')->loadByAttribute("sku", $reference);
861
  if ($product && $product->getTypeId() != "bundle") {
862
  if ($includeTax) {
863
+ if($product->getPrice() == $tarifTTC && $product->getCost() == $prixAchat)
864
+ continue;
865
  $product->setPrice($tarifTTC);
866
  } else {
867
+ if($product->getPrice() == $tarifHT && $product->getCost() == $prixAchat)
868
+ continue;
869
  $product->setPrice($tarifHT);
870
  }
871
  $product->setCost($prixAchat);
898
  return '';
899
  }
900
  }
901
+
902
+ protected function verfiSku($product){
903
+ $sku = $product->getSku();
904
+ $designation = $product->getName();
905
+ if($sku[0] == " "){
906
+ Mage::log('Error espace avant référence '.$sku,null,'opensi.log');
907
+ return false;
908
+ }elseif(strlen($sku) > 40){
909
+ Mage::log('Référence trop longue '.$sku,null,'opensi.log');
910
+ return false;
911
+ }elseif(strlen($designation) > 100){
912
+ Mage::log('Le nom est trop long '.$designation,null,'opensi.log');
913
+ return false;
914
+ }elseif(empty($sku)){
915
+ Mage::log('Pas de référence',null,'opensi.log');
916
+ return false;
917
+ }
918
+ return true;
919
+ }
920
 
921
  }
app/code/community/Speedinfo/Opensi/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Speedinfo_Opensi>
5
- <version>0.2.7</version>
6
  </Speedinfo_Opensi>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <Speedinfo_Opensi>
5
+ <version>0.2.9</version>
6
  </Speedinfo_Opensi>
7
  </modules>
8
  <global>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Speedinfo_Opensi</name>
4
- <version>0.2.7</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -10,12 +10,12 @@
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.7.
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>2011-01-21</date>
17
- <time>15:09:19</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="44197706123f54d5c2e17475cd64b9f1"/></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Speedinfo_Opensi.xml" hash="16cc3fbf8e32ce7b8add016bfbc89c5f"/></dir></dir><dir name="locale"><dir name="fr_FR"><file name="Speedinfo_OpenSi.csv" hash="51f46b50056059d178766fa9111fe072"/></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="09ccc564f6ba4e7cbb58e0357c43e035"/></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="9754ad25b294a0306d4e28090bf9e4cb"/></dir><dir name="etc"><file name="config.xml" hash="dfca6910aef226a620fa2b018b23fb21"/></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="136456ed98a080680fd353d176fffdc9"/></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"/><file name="mysql4-upgrade-0.2.4-0.2.5.php" hash="99fcd03734f514441005dd8af5c22809"/></dir></dir></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies/>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Speedinfo_Opensi</name>
4
+ <version>0.2.9</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
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.9.
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>2011-02-22</date>
17
+ <time>15:37:43</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="44197706123f54d5c2e17475cd64b9f1"/></dir></dir></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Speedinfo_Opensi.xml" hash="16cc3fbf8e32ce7b8add016bfbc89c5f"/></dir></dir><dir name="locale"><dir name="fr_FR"><file name="Speedinfo_OpenSi.csv" hash="51f46b50056059d178766fa9111fe072"/></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="09ccc564f6ba4e7cbb58e0357c43e035"/></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="9754ad25b294a0306d4e28090bf9e4cb"/></dir><dir name="etc"><file name="config.xml" hash="641ce07c8e9cc355fbdddc33376ce88b"/></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="d7040e0bdb5fa735ff976ed357e1d4c7"/><file name="Errorlog.php" hash="d269ec20ae481684a1daa2c515848252"/><file name="Webservice.php" hash="c77708c3507d79a83e64a1801ea255c2"/><file name="Webservices.php" hash="ad2827363526cc2323116d029eea3be3"/></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"/><file name="mysql4-upgrade-0.2.4-0.2.5.php" hash="99fcd03734f514441005dd8af5c22809"/></dir></dir></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies/>
21
  </package>