LithiumSoftware_Akhilleus - Version 1.0.4

Version Notes

Changes to calculation of international freight - Correios Exporta Fácil

Download this release

Release Info

Developer Frenet
Extension LithiumSoftware_Akhilleus
Version 1.0.4
Comparing to
See all releases


Code changes from version 1.0.3 to 1.0.4

app/code/community/LithiumSoftware/Akhilleus/Model/Carrier/Akhilleus.php CHANGED
@@ -27,11 +27,14 @@ class LithiumSoftware_Akhilleus_Model_Carrier_Akhilleus
27
  protected $_title = NULL; // Título do método de envio
28
  protected $_from = NULL; // CEP de origem
29
  protected $_to = NULL; // CEP de destino
 
30
  protected $_recipientDocument = NULL; // CPF / CNPJ do destinatario
31
  protected $_packageWeight = NULL; // valor ajustado do pacote
32
  protected $_showDelivery = NULL; // Determina exibição de prazo de entrega
33
  protected $_addDeliveryDays = NULL; // Adiciona n dias ao prazo de entrega
34
 
 
 
35
 
36
  /**
37
  * Collect rates for this shipping method based on information in $request
@@ -149,12 +152,18 @@ class LithiumSoftware_Akhilleus_Model_Carrier_Akhilleus
149
  // gerar o array de produtos
150
  $shippingItemArray = array();
151
  $count = 0;
152
- foreach($request->getAllItems() as $item){
153
- $product_id = $item->getProductId();
154
- $productObj = Mage::getModel('catalog/product')->load($product_id);
 
 
 
 
 
 
155
 
156
  $shippingItem = new stdClass();
157
- $shippingItem->Weight = $this->_fixWeight($productObj->getWeight()) * $item->getQty();
158
  if ($this->getConfigFlag('use_default'))
159
  {
160
  $shippingItem->Length = $this->getConfigData('default_length'); //16
@@ -191,8 +200,8 @@ class LithiumSoftware_Akhilleus_Model_Carrier_Akhilleus
191
 
192
  $shippingItem->Category = $result;
193
 
194
- if($item->getProduct()->getData('fragile'))
195
- $shippingItem->isFragile = $item->getProduct()->getData('fragile');
196
  else
197
  $shippingItem->isFragile=false;
198
 
@@ -206,6 +215,7 @@ class LithiumSoftware_Akhilleus_Model_Carrier_Akhilleus
206
  'Password' => $this->getConfigData('password'),
207
  'SellerCEP' => $this->_from,
208
  'RecipientCEP' => $this->_to,
 
209
  'RecipientDocument' => $this->_recipientDocument,
210
  'ShipmentInvoiceValue' => $this->_value,
211
  'ShippingItemArray' => $shippingItemArray
@@ -412,12 +422,20 @@ class LithiumSoftware_Akhilleus_Model_Carrier_Akhilleus
412
  $this->_from = $this->_formatZip(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
413
  $this->_to = $this->_formatZip($request->getDestPostcode());
414
 
 
 
 
 
 
 
 
 
415
  if(!$this->_from){
416
  $this->_log('Erro com CEP de origem');
417
  return false;
418
  }
419
 
420
- if(!$this->_to){
421
  $this->_log('Erro com CEP de destino');
422
  $this->_throwError('zipcodeerror', 'CEP Inválido', __LINE__);
423
  return false;
@@ -426,23 +444,6 @@ class LithiumSoftware_Akhilleus_Model_Carrier_Akhilleus
426
  return true;
427
  }
428
 
429
- /**
430
- * Verifica se o país está dentro da área atendida
431
- *
432
- * @param Mage_Shipping_Model_Rate_Request $request
433
- * @return boolean
434
- */
435
- protected function _checkCountry(Mage_Shipping_Model_Rate_Request $request) {
436
- $from = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
437
- $to = $request->getDestCountryId();
438
- if ($from != "BR" || $to != "BR"){
439
- $this->_log('Fora da área de atendimento');
440
- return false;
441
- }
442
-
443
- return true;
444
- }
445
-
446
  /**
447
  * Corrige o peso informado com base na medida de peso configurada
448
  * @param string|int|float $weight
@@ -604,5 +605,49 @@ class LithiumSoftware_Akhilleus_Model_Carrier_Akhilleus
604
  }
605
  }
606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
 
608
  }
27
  protected $_title = NULL; // Título do método de envio
28
  protected $_from = NULL; // CEP de origem
29
  protected $_to = NULL; // CEP de destino
30
+ protected $_destCountry = NULL; // IATA do pais destino
31
  protected $_recipientDocument = NULL; // CPF / CNPJ do destinatario
32
  protected $_packageWeight = NULL; // valor ajustado do pacote
33
  protected $_showDelivery = NULL; // Determina exibição de prazo de entrega
34
  protected $_addDeliveryDays = NULL; // Adiciona n dias ao prazo de entrega
35
 
36
+ protected $_simpleProducts = array();
37
+ protected $_productsQty = array();
38
 
39
  /**
40
  * Collect rates for this shipping method based on information in $request
152
  // gerar o array de produtos
153
  $shippingItemArray = array();
154
  $count = 0;
155
+ $this->getSimpleProducts($request->getAllItems());
156
+ $productsCount = count ($this->_simpleProducts);
157
+ $j = 0;
158
+ for ($i = 0; $i < $productsCount; $i ++)
159
+ {
160
+ $productObj = $this->_simpleProducts[$i];
161
+
162
+ //$this->_log(json_encode($productObj->getData()));
163
+ //$this->_log('Quantidade: ' . $this->_productsQty[$i]);
164
 
165
  $shippingItem = new stdClass();
166
+ $shippingItem->Weight = $this->_fixWeight($productObj->getWeight()) * $this->_productsQty[$i];
167
  if ($this->getConfigFlag('use_default'))
168
  {
169
  $shippingItem->Length = $this->getConfigData('default_length'); //16
200
 
201
  $shippingItem->Category = $result;
202
 
203
+ if($productObj->getFragile())
204
+ $shippingItem->isFragile = $productObj->getFragile();
205
  else
206
  $shippingItem->isFragile=false;
207
 
215
  'Password' => $this->getConfigData('password'),
216
  'SellerCEP' => $this->_from,
217
  'RecipientCEP' => $this->_to,
218
+ 'RecipientCountry' => $this->_destCountry,
219
  'RecipientDocument' => $this->_recipientDocument,
220
  'ShipmentInvoiceValue' => $this->_value,
221
  'ShippingItemArray' => $shippingItemArray
422
  $this->_from = $this->_formatZip(Mage::getStoreConfig('shipping/origin/postcode', $this->getStore()));
423
  $this->_to = $this->_formatZip($request->getDestPostcode());
424
 
425
+ if ($request->getDestCountryId()) {
426
+ $this->_destCountry = $request->getDestCountryId();
427
+ } else {
428
+ $this->_destCountry = 'BR';
429
+ }
430
+
431
+ $this->_log('Country ID ' . $this->_destCountry);
432
+
433
  if(!$this->_from){
434
  $this->_log('Erro com CEP de origem');
435
  return false;
436
  }
437
 
438
+ if(!$this->_to && $this->_destCountry == 'BR'){
439
  $this->_log('Erro com CEP de destino');
440
  $this->_throwError('zipcodeerror', 'CEP Inválido', __LINE__);
441
  return false;
444
  return true;
445
  }
446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
  /**
448
  * Corrige o peso informado com base na medida de peso configurada
449
  * @param string|int|float $weight
605
  }
606
  }
607
 
608
+ private function getSimpleProducts($items)
609
+ {
610
+ $j = 0;
611
+ foreach ($items as $child)
612
+ {
613
+ $product_id = $child->getProductId ();
614
+ $product = Mage::getModel ('catalog/product')->load ($product_id);
615
+ $type_id = $product->getTypeId ();
616
+ if (strcmp ($type_id, 'simple')) continue;
617
+
618
+ $qty = $this->_getQty ($child);
619
+
620
+ $product = Mage::getModel ('catalog/product')->load ($child->getProductId());
621
+
622
+ $this->_simpleProducts [$j] = $product;
623
+ $this->_productsQty [$j] = (int)$qty;
624
+ $j = $j + 1;
625
+ }
626
+
627
+ return $this;
628
+ }
629
+
630
+ private function _getQty ($item)
631
+ {
632
+ $qty = 0;
633
+
634
+ $parentItem = $item->getParentItem ();
635
+ $targetItem = !empty ($parentItem) && $parentItem->getId () > 0 ? $parentItem : $item;
636
+
637
+ if ($targetItem instanceof Mage_Sales_Model_Quote_Item)
638
+ {
639
+ $qty = $targetItem->getQty ();
640
+ }
641
+ elseif ($targetItem instanceof Mage_Sales_Model_Order_Item)
642
+ {
643
+ $qty = $targetItem->getShipped () ? $targetItem->getShipped () : $targetItem->getQtyInvoiced ();
644
+ if ($qty == 0) {
645
+ $qty = $targetItem->getQtyOrdered();
646
+ }
647
+ }
648
+
649
+ return $qty;
650
+ }
651
+
652
 
653
  }
app/code/community/LithiumSoftware/Akhilleus/etc/config.xml CHANGED
@@ -14,7 +14,7 @@
14
  <config>
15
  <modules>
16
  <LithiumSoftware_Akhilleus>
17
- <version>1.0.3</version>
18
  <depends>
19
  <Mage_Shipping/>
20
  </depends>
14
  <config>
15
  <modules>
16
  <LithiumSoftware_Akhilleus>
17
+ <version>1.0.4</version>
18
  <depends>
19
  <Mage_Shipping/>
20
  </depends>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>LithiumSoftware_Akhilleus</name>
4
- <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/MIT">MIT</license>
7
  <channel>community</channel>
@@ -9,13 +9,11 @@
9
  <summary>Frenet allows merchants to display freight options from multiple carriers, including brazilian Correios.</summary>
10
  <description>The Frenet freight gateway is able to integrate and process tables of freight carriers and brazilian Correios. The freight calculation for the brazilian Correios services is done on-line (via Correios webservice) or in case of unavailability, uses database in the cloud highly available and regularly updated automatically, with the values of quotations. &#xD;
11
  It provides to the store owners, major carriers in Brazil to transport large volumes as well as JadLog, TNT, Direct, Total Express, JAMEF among others.</description>
12
- <notes>Bugfix:&#xD;
13
- - Weight - weightType == 'gr'&#xD;
14
- </notes>
15
  <authors><author><name>Frenet</name><user>MAG002970201</user><email>contato@frenet.com.br</email></author></authors>
16
- <date>2016-04-04</date>
17
- <time>22:04:51</time>
18
- <contents><target name="magecommunity"><dir name="LithiumSoftware"><dir name="Akhilleus"><dir name="Helper"><file name="Data.php" hash="fae99f78422836771d71873f253e8471"/></dir><dir name="Model"><dir name="Carrier"><file name="Akhilleus.php" hash="8aaf63e0c2dd7a9b458bfc053bd5e75a"/></dir><file name="Observer.php" hash="927d49b0b02ecfe36aa708a7f186422a"/><dir name="Source"><file name="WeightType.php" hash="90bd2253381d2c2094aa0183e3129eb7"/></dir></dir><dir name="etc"><file name="config.xml" hash="2dab27db22137030872ac99b7d79f8a7"/><file name="system.xml" hash="162638242c34a75a65091ec10b971741"/></dir><dir name="sql"><dir name="akhilleus_setup"><file name="install-1.0.0.php" hash="17104e4cf30a39bd0980837310ae940a"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="LithiumSoftware_Akhilleus.xml" hash="ad180127bc24251a43a18818f2a30c21"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>LithiumSoftware_Akhilleus</name>
4
+ <version>1.0.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/MIT">MIT</license>
7
  <channel>community</channel>
9
  <summary>Frenet allows merchants to display freight options from multiple carriers, including brazilian Correios.</summary>
10
  <description>The Frenet freight gateway is able to integrate and process tables of freight carriers and brazilian Correios. The freight calculation for the brazilian Correios services is done on-line (via Correios webservice) or in case of unavailability, uses database in the cloud highly available and regularly updated automatically, with the values of quotations. &#xD;
11
  It provides to the store owners, major carriers in Brazil to transport large volumes as well as JadLog, TNT, Direct, Total Express, JAMEF among others.</description>
12
+ <notes>Changes to calculation of international freight - Correios Exporta F&#xE1;cil</notes>
 
 
13
  <authors><author><name>Frenet</name><user>MAG002970201</user><email>contato@frenet.com.br</email></author></authors>
14
+ <date>2016-06-06</date>
15
+ <time>21:11:24</time>
16
+ <contents><target name="magecommunity"><dir name="LithiumSoftware"><dir name="Akhilleus"><dir name="Helper"><file name="Data.php" hash="fae99f78422836771d71873f253e8471"/></dir><dir name="Model"><dir name="Carrier"><file name="Akhilleus.php" hash="140fb55b0adc541a2031528c9b9fef19"/></dir><file name="Observer.php" hash="927d49b0b02ecfe36aa708a7f186422a"/><dir name="Source"><file name="WeightType.php" hash="90bd2253381d2c2094aa0183e3129eb7"/></dir></dir><dir name="etc"><file name="config.xml" hash="71710774ce6a68a2534b5a727cb3273b"/><file name="system.xml" hash="162638242c34a75a65091ec10b971741"/></dir><dir name="sql"><dir name="akhilleus_setup"><file name="install-1.0.0.php" hash="17104e4cf30a39bd0980837310ae940a"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="LithiumSoftware_Akhilleus.xml" hash="ad180127bc24251a43a18818f2a30c21"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>