Skip to content

Commit

Permalink
Merge pull request #15 from pedro-teixeira/master
Browse files Browse the repository at this point in the history
Atualização do fork
  • Loading branch information
rafaelpatro committed May 29, 2017
2 parents 18b2c6b + 2352e1d commit 8007d58
Show file tree
Hide file tree
Showing 35 changed files with 1,629 additions and 467 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# v4.9.0

### Bugfix

- [#265](https://github.com/pedro-teixeira/correios/issues/265) Correção para Produtos Configuráveis

### Feature

- [#266](https://github.com/pedro-teixeira/correios/issues/266) Melhoria no Monitoramento Automático
- [#268](https://github.com/pedro-teixeira/correios/issues/268) Adiciona PSR2 com algumas modificações e atualiza PHPCS

# v4.8.1

### Bugfix

- [#252](https://github.com/pedro-teixeira/correios/issues/252) Corrige atualizações das versões 4.7.1 e 4.7.2

# v4.8.0

### Bugfix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class PedroTeixeira_Correios_Block_Adminhtml_System_Config_Form_Button
{
/**
* Retrieve the html code for Element
*
*
* @param Varien_Data_Form_Element_Abstract $element Element
*
*
* @return string
*/
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
Expand All @@ -28,7 +28,7 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)

/**
* Retrieve an adminhtml button
*
*
* @return string
*/
public function getButton()
Expand Down
10 changes: 5 additions & 5 deletions app/code/community/PedroTeixeira/Correios/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class PedroTeixeira_Correios_Helper_Data extends Mage_Core_Helper_Abstract
{
/**
* Gets the configuration value by path
*
*
* @param string $path System Config Path
*
*
* @return mixed
*/
public function getConfigData($path)
Expand All @@ -28,9 +28,9 @@ public function getConfigData($path)

/**
* Get a text for option value
*
*
* @param string|int $value Method Code
*
*
* @return string|bool
*/
public function getShippingLabel($value)
Expand All @@ -41,7 +41,7 @@ public function getShippingLabel($value)

/**
* Retrieve stream context as a Soap parameter
*
*
* @return array
*/
public function getStreamContext()
Expand Down
6 changes: 3 additions & 3 deletions app/code/community/PedroTeixeira/Correios/Model/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,17 @@ public function loadByTags()
/**
* Validate the response data from Correios.
* This method will choose between Request Cache or Save in Cache
*
*
* Step 1:
* Invalid responses must call the Cache load.
* Cache loading is requested by throwing adapter exception.
*
*
* Step 2:
* To save valid responses, it must contain no errors.
* Errors are detected by pattern_nocache and returns false.
*
* @param string $data XML Content
*
*
* @throws Zend_Http_Client_Adapter_Exception
*
* @return boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ protected function _getRequestItems($request)
$allItems = $request->getAllItems();
$items = array();

foreach ( $allItems as $item ) {
if ( !$item->getParentItemId() ) {
foreach ($allItems as $item) {
if (!$item->getParentItemId()) {
$items[] = $item;
}
}
Expand Down Expand Up @@ -185,7 +185,6 @@ protected function _getQuotes()
$correiosReturn = $this->_addPostMethods($correiosReturn);

foreach ($correiosReturn as $servicos) {

$errorId = (string) $servicos->Erro;
$errorList[$errorId] = $servicos->MsgErro;

Expand Down Expand Up @@ -427,6 +426,27 @@ protected function _throwError($message, $log = null, $line = 'NO LINE', $custom
$this->_result->append($error);
}

/**
* Retrieves a simple product
*
* @param Mage_Catalog_Model_Product $product Catalog Product
*
* @return Mage_Catalog_Model_Product
*/
protected function _getSimpleProduct($product)
{
$type = $product->getTypeInstance(true);
if ($type->getProduct($product)->hasCustomOptions()
&& ($simpleProductOption = $type->getProduct($product)->getCustomOption('simple_product'))
) {
$simpleProduct = $simpleProductOption->getProduct($product);
if ($simpleProduct) {
return $this->_getSimpleProduct($simpleProduct);
}
}
return $type->getProduct($product);
}

/**
* Generate Volume weight
*
Expand All @@ -441,7 +461,7 @@ protected function _generateVolumeWeight($request)
$items = $this->_getRequestItems($request);

foreach ($items as $item) {
$_product = $item->getProduct();
$_product = $this->_getSimpleProduct($item->getProduct());

if ($_product->getData('volume_altura') == '' || (int) $_product->getData('volume_altura') == 0) {
$itemAltura = $this->getConfigData('altura_padrao');
Expand Down Expand Up @@ -566,11 +586,11 @@ public function getTracking($trackings)

/**
* Loads the parameters and calls the webservice using SOAP
*
*
* @param string $code Code
*
*
* @return bool|array
*
*
* @throws Exception
*/
protected function _getTrackingRequest($code)
Expand Down Expand Up @@ -601,13 +621,13 @@ protected function _getTrackingRequest($code)

/**
* Loads tracking progress details
*
*
* @param SimpleXMLElement $evento XML Element Node
* @param bool $isDelivered Delivery Flag
*
*
* @return array
*/
protected function _getTrackingProgressDetails($evento, $isDelivered=false)
protected function _getTrackingProgressDetails($evento, $isDelivered = false)
{
$date = new Zend_Date($evento->data, 'dd/MM/YYYY', new Zend_Locale('pt_BR'));
$track = array(
Expand All @@ -627,10 +647,10 @@ protected function _getTrackingProgressDetails($evento, $isDelivered=false)
}

/**
* Loads progress data using the WSDL response
*
* Loads progress data using the WSDL response
*
* @param string $request Request response
*
*
* @return array
*/
protected function _getTrackingProgress($request)
Expand Down Expand Up @@ -846,12 +866,15 @@ protected function _addPostMethods($cServico)
protected function _filterMethodByItemRestriction($request)
{
if ($this->getConfigFlag('filter_by_item')) {

$items = $this->_getRequestItems($request);
$intersection = $this->_postMethodsExplode;
foreach ($items as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$prodPostMethods = explode(',', $product->getData('postmethods'));
$product = $this->_getSimpleProduct($item->getProduct());
$prodPostMethods = explode(
',', $product->getResource()->getAttributeRawValue(
$product->getId(), 'postmethods', $request->getStoreId()
)
);
$intersection = array_intersect($prodPostMethods, $intersection);
}

Expand Down Expand Up @@ -880,7 +903,7 @@ protected function _filterMethodByItemRestriction($request)
*/
protected function _getFitHeight($item)
{
$product = $item->getProduct();
$product = $this->_getSimpleProduct($item->getProduct());
$height = $product->getData('volume_altura');
$height = ($height > 0) ? $height : (int) $this->getConfigData('altura_padrao');
$fitSize = (float) $product->getData('fit_size');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ public function getConfigData($field)
$path = 'carriers/' . $this->_code . '/' . $field;
return Mage::getStoreConfig($path);
}
}
}
81 changes: 58 additions & 23 deletions app/code/community/PedroTeixeira/Correios/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,72 @@ class PedroTeixeira_Correios_Model_Observer
{
/**
* Look for shipped trackings, and send notifications if available and enabled
*
*
* @return string
*/
public function sroTrackingJob()
{
$count = 0;
/* @var $sro PedroTeixeira_Correios_Model_Sro */
$sro = Mage::getModel('pedroteixeira_correios/sro');
if ($sro->getConfigData('sro_tracking_job') == 0) {
return "SRO Tracking Job disabled.";
$message = "SRO Tracking Job disabled.";
if (Mage::helper('pedroteixeira_correios')->getConfigData('sro_tracking_job') == 0) {
return $message;
}

$collection = $sro->getShippedTracks();
foreach ($collection as $track) {
/* @var $track Mage_Sales_Model_Order_Shipment_Track */
if ($sro->request($track->getNumber())) {
$savedId = $track->getDescription();
$eventId = $sro->getEventId();
if ($eventId != $savedId) {
$track->setDescription($eventId)->save();
$track->getShipment()->getOrder()
->setStatus($sro->getStatus())
->save();
$track->getShipment()
->addComment($sro->getComment(), $sro->isNotify(), true)
->sendUpdateEmail($sro->isNotify(), $sro->getEmailComment())
->save();
$count++;
$message = "No tracking updates";
$count = 0;
$countTrack = 0;
$trackList = array();
$sro = Mage::getModel('pedroteixeira_correios/sro')->init();
$response = $sro->request();

if ($response && $response->return->qtd > 0) {
$tracksTxn = Mage::getModel('core/resource_transaction');
$ordersTxn = Mage::getModel('core/resource_transaction');
$shipmentsTxn = Mage::getModel('core/resource_transaction');
foreach ($response->return->objeto as $obj) {
if (isset($obj->erro)) {
Mage::log("{$obj->numero}: {$obj->erro}");
continue;
}

if ($track = $sro->getTrack($obj)) {
$savedId = $track->getDescription();
$eventId = $sro->getEventId($obj);
if ($eventId != $savedId) {
$status = $sro->getStatus($obj);
$notify = $sro->isNotify($obj);
$comment = $sro->getComment($obj);
$mailComment = $sro->getEmailComment($obj, $track);
$tracksTxn->addObject(
$track->setDescription($eventId)
);
$ordersTxn->addObject(
$track->getShipment()->getOrder()->setStatus($status)
);
$shipmentsTxn->addObject(
$track->getShipment()
->addComment($comment, $notify, true)
->sendUpdateEmail($notify, $mailComment)
);
Mage::log("{$obj->numero}: saving scheduled");
$count++;
}
}
$countTrack++;
}

if ($count) {
try {
$tracksTxn->save();
$ordersTxn->save();
$shipmentsTxn->save();
$message = "Updated {$count} objects of {$countTrack} tracked.";
} catch (Exception $e) {
$message = $e->getMessage();
}
}
}
return "Tracked {$count} objects of {$collection->getSize()}.";

Mage::log($message);
return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @copyright 2015 Pedro Teixeira (http://pedroteixeira.io)
* @license http://opensource.org/licenses/MIT MIT
* @link https://github.com/pedro-teixeira/correios
*
*
* @method string getMethodId()
* @method string getMethodCode()
* @method string getMethodTitle()
Expand All @@ -23,9 +23,9 @@ class PedroTeixeira_Correios_Model_Postmethod extends Mage_Core_Model_Abstract
{
/**
* Internal constructor
*
*
* @see Varien_Object::_construct()
*
*
* @return void
*/
protected function _construct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class PedroTeixeira_Correios_Model_Resource_Postmethod
{
/**
* Resource initialization
*
*
* @see Mage_Core_Model_Resource_Abstract::_construct()
*
*
* @return void
*/
protected function _construct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class PedroTeixeira_Correios_Model_Resource_Postmethod_Collection
{
/**
* Resource initialization
*
*
* @see Mage_Core_Model_Resource_Db_Collection_Abstract::_construct()
*
*
* @return void
*/
protected function _construct()
Expand Down
4 changes: 2 additions & 2 deletions app/code/community/PedroTeixeira/Correios/Model/Sigepweb.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PedroTeixeira_Correios_Model_Sigepweb extends Mage_Core_Model_Abstract

/**
* Retrieve the module helper
*
*
* @return Pedroteixeira_Correios_Helper_Data
*/
public function helper()
Expand All @@ -26,7 +26,7 @@ public function helper()

/**
* Request Correios service codes using configuration fields
*
*
* @return SimpleXMLElement
*/
public function getBuscaCliente()
Expand Down
Loading

0 comments on commit 8007d58

Please sign in to comment.