diff --git a/CHANGELOG.md b/CHANGELOG.md index f760ff2..606de98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/code/community/PedroTeixeira/Correios/Block/Adminhtml/System/Config/Form/Button.php b/app/code/community/PedroTeixeira/Correios/Block/Adminhtml/System/Config/Form/Button.php index f2f3302..376e1e8 100644 --- a/app/code/community/PedroTeixeira/Correios/Block/Adminhtml/System/Config/Form/Button.php +++ b/app/code/community/PedroTeixeira/Correios/Block/Adminhtml/System/Config/Form/Button.php @@ -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) @@ -28,7 +28,7 @@ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) /** * Retrieve an adminhtml button - * + * * @return string */ public function getButton() diff --git a/app/code/community/PedroTeixeira/Correios/Helper/Data.php b/app/code/community/PedroTeixeira/Correios/Helper/Data.php index 1fe098d..39aaa5e 100644 --- a/app/code/community/PedroTeixeira/Correios/Helper/Data.php +++ b/app/code/community/PedroTeixeira/Correios/Helper/Data.php @@ -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) @@ -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) @@ -41,7 +41,7 @@ public function getShippingLabel($value) /** * Retrieve stream context as a Soap parameter - * + * * @return array */ public function getStreamContext() diff --git a/app/code/community/PedroTeixeira/Correios/Model/Cache.php b/app/code/community/PedroTeixeira/Correios/Model/Cache.php index 92354b3..6dfb369 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Cache.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Cache.php @@ -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 diff --git a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php index 5ea5a06..fdeaa3f 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Carrier/CorreiosMethod.php @@ -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; } } @@ -185,7 +185,6 @@ protected function _getQuotes() $correiosReturn = $this->_addPostMethods($correiosReturn); foreach ($correiosReturn as $servicos) { - $errorId = (string) $servicos->Erro; $errorList[$errorId] = $servicos->MsgErro; @@ -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 * @@ -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'); @@ -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) @@ -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( @@ -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) @@ -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); } @@ -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'); diff --git a/app/code/community/PedroTeixeira/Correios/Model/Http/Client/Adapter/Socket.php b/app/code/community/PedroTeixeira/Correios/Model/Http/Client/Adapter/Socket.php index fa1c71c..e1a6b62 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Http/Client/Adapter/Socket.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Http/Client/Adapter/Socket.php @@ -140,4 +140,4 @@ public function getConfigData($field) $path = 'carriers/' . $this->_code . '/' . $field; return Mage::getStoreConfig($path); } -} \ No newline at end of file +} diff --git a/app/code/community/PedroTeixeira/Correios/Model/Observer.php b/app/code/community/PedroTeixeira/Correios/Model/Observer.php index e531984..82b19f0 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Observer.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Observer.php @@ -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; } } diff --git a/app/code/community/PedroTeixeira/Correios/Model/Postmethod.php b/app/code/community/PedroTeixeira/Correios/Model/Postmethod.php index 984b02d..ff44b14 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Postmethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Postmethod.php @@ -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() @@ -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() diff --git a/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod.php b/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod.php index 14f99ab..70b6418 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod.php @@ -16,9 +16,9 @@ class PedroTeixeira_Correios_Model_Resource_Postmethod { /** * Resource initialization - * + * * @see Mage_Core_Model_Resource_Abstract::_construct() - * + * * @return void */ protected function _construct() diff --git a/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod/Collection.php b/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod/Collection.php index 788615b..c0fd087 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod/Collection.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Resource/Postmethod/Collection.php @@ -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() diff --git a/app/code/community/PedroTeixeira/Correios/Model/Sigepweb.php b/app/code/community/PedroTeixeira/Correios/Model/Sigepweb.php index 0d8cc2c..72c71b9 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Sigepweb.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Sigepweb.php @@ -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() @@ -26,7 +26,7 @@ public function helper() /** * Request Correios service codes using configuration fields - * + * * @return SimpleXMLElement */ public function getBuscaCliente() diff --git a/app/code/community/PedroTeixeira/Correios/Model/Sro.php b/app/code/community/PedroTeixeira/Correios/Model/Sro.php index c84a714..6bb173f 100644 --- a/app/code/community/PedroTeixeira/Correios/Model/Sro.php +++ b/app/code/community/PedroTeixeira/Correios/Model/Sro.php @@ -16,18 +16,31 @@ class PedroTeixeira_Correios_Model_Sro extends Varien_Object const CARRIER_CODE = 'pedroteixeira_correios'; const ORDER_SHIPPED_STATUS = 'complete_shipped'; const ORDER_WARNED_STATUS = 'complete_warned'; - + + protected $_trackList = array(); + /** - * Request response - * - * @var SimpleXMLElement + * Retrieves all valid tracking codes + * + * @return PedroTeixeira_Correios_Model_Sro */ - protected $_xml = null; - + public function init() + { + $collection = $this->getShippedTracks(); + foreach ($collection as $track) { + if ($this->validateTrackNumber($track->getNumber())) { + $this->_trackList[$track->getNumber()] = $track; + continue; + } + Mage::log("{$track->getNumber()}: invalid tracking code"); + } + return $this; + } + /** * Load all opened tracks from database. * Filter tracks only with complete order state, and shipped status. - * + * * @return Mage_Sales_Model_Resource_Order_Shipment_Track_Collection */ public function getShippedTracks() @@ -47,48 +60,52 @@ public function getShippedTracks() /** * Load XML response from Correios - * - * @param string $trackingCode Tracking Code - * + * * @throws Exception - * + * * @link http://www.correios.com.br/para-voce/correios-de-a-a-z/pdf/rastreamento-de-objetos/ * Manual_SROXML_28fev14.pdf * @link http://www.corporativo.correios.com.br/encomendas/sigepweb/doc/ * Manual_de_Implementacao_do_Web_Service_SIGEPWEB_Logistica_Reversa.pdf - * - * @return boolean|PedroTeixeira_Correios_Model_Sro + * + * @return boolean|Correios_Rastro_BuscaEventosResponse */ - public function request($trackingCode) + public function request() { - $params = array( - 'usuario' => $this->getConfigData('sro_username'), - 'senha' => $this->getConfigData('sro_password'), - 'tipo' => $this->getConfigData('sro_type'), - 'resultado' => $this->getConfigData('sro_result'), - 'lingua' => $this->getConfigData('sro_language'), - 'objetos' => $trackingCode, - ); - - try { - $client = new SoapClient($this->getConfigData('url_sro_correios')); - $response = $client->buscaEventos($params); - if (empty($response)) { - throw new Exception("Empty response"); + $response = false; + if (count($this->_trackList)) { + $trackingCodes = implode('', array_keys($this->_trackList)); + $params = new Correios_Rastro_BuscaEventos( + $this->getConfigData('sro_username'), + $this->getConfigData('sro_password'), + $this->getConfigData('sro_type'), + $this->getConfigData('sro_result'), + $this->getConfigData('sro_language'), + $trackingCodes + ); + Mage::log(print_r($params, true)); + + try { + $client = new Correios_Rastro( + Mage::helper('pedroteixeira_correios')->getStreamContext(), + $this->getConfigData('url_sro_correios') + ); + $response = $client->buscaEventos($params); + if (empty($response)) { + throw new Exception("Empty response"); + } + } catch (Exception $e) { + Mage::log("Soap Error: {$e->getMessage()}"); } - $this->_xml = $response->return; - } catch (Exception $e) { - Mage::log("Soap Error: {$e->getMessage()}"); - return false; } - return $this; + return $response; } /** * Retrieve config value by path - * + * * @param string $path Variable Path - * + * * @return string */ public function getConfigData($path) @@ -98,13 +115,15 @@ public function getConfigData($path) /** * Returns a Shipping comment message - * + * + * @param Correios_Rastro_Objeto $obj Response Object + * * @return string */ - public function getComment() + public function getComment($obj) { - $code = $this->_xml->objeto->numero; - $evento = $this->_xml->objeto->evento; + $code = $obj->numero; + $evento = $obj->evento; $msg = array(); $msg[] = $code; $msg[] = "{$evento->cidade}/{$evento->uf}"; @@ -125,15 +144,18 @@ public function getComment() /** * Returns an Update Shipping e-mail comment - * + * + * @param Correios_Rastro_Objeto $obj Response Object + * @param Mage_Sales_Model_Order_Shipment_Track $track Tracking instance + * * @return string */ - public function getEmailComment() + public function getEmailComment($obj, $track) { - $trackUrl = $this->getConfigData('url_tracking'); - $code = $this->_xml->objeto->numero; - $evento = $this->_xml->objeto->evento; - $htmlAnchor = "{$code}"; + $trackUrl = Mage::helper('shipping')->getTrackingPopupUrlBySalesModel($track); + $code = $obj->numero; + $evento = $obj->evento; + $htmlAnchor = "{$code}"; $msg = array(); $msg[] = Mage::helper('pedroteixeira_correios')->__('Rastreador: %s', $htmlAnchor); $msg[] = Mage::helper('pedroteixeira_correios')->__('Local: %s', "{$evento->cidade}/{$evento->uf}"); @@ -153,15 +175,16 @@ public function getEmailComment() /** * Check the event type - * - * @param string $mode Event Type Mode - * + * + * @param Correios_Rastro_Objeto $obj Response Object + * @param string $mode Event Type Mode + * * @return boolean */ - public function validate($mode) + public function validate($obj, $mode) { $isValid = false; - $evento = $this->_xml->objeto->evento; + $evento = $obj->evento; $hashTypes = explode(',', $this->getConfigData("sro_event_type_{$mode}")); if (in_array($evento->tipo, $hashTypes)) { $type = strtolower($evento->tipo); @@ -174,42 +197,86 @@ public function validate($mode) /** * Track Description field are now being used to save the event id. * Event Id is a simple key to identify the last carrier event. - * + * + * @param Correios_Rastro_Objeto $obj Response Object + * * @return string */ - public function getEventId() + public function getEventId($obj) { - $code = $this->_xml->objeto->numero; - $date = $this->_xml->objeto->evento->data; - $hour = $this->_xml->objeto->evento->hora; - $type = $this->_xml->objeto->evento->tipo; - return "{$code}::{$date}{$hour}::{$type}"; + if ($obj->numero && $obj->evento) { + $code = $obj->numero; + $date = $obj->evento->data; + $hour = $obj->evento->hora; + $type = $obj->evento->tipo; + return "{$code}::{$date}{$hour}::{$type}"; + } + return false; } /** * Check whether event notify is enabled or not - * + * + * @param Correios_Rastro_Objeto $obj Response Object + * * @return boolean */ - public function isNotify() + public function isNotify($obj) { - return $this->validate('notify'); + return $this->validate($obj, 'notify'); } /** * Load order status based on event checking - * + * + * @param Correios_Rastro_Objeto $obj Response Object + * * @return string */ - public function getStatus() + public function getStatus($obj) { $status = self::ORDER_SHIPPED_STATUS; - if ($this->validate('warn')) { + if ($this->validate($obj, 'warn')) { $status = self::ORDER_WARNED_STATUS; } - if ($this->validate('last')) { + if ($this->validate($obj, 'last')) { $status = Mage_Sales_Model_Order::STATE_COMPLETE; } return $status; } + + /** + * Validates the tracking code + * + * @param string $trackNumber Tracking Code + * + * @return boolean + */ + public function validateTrackNumber($trackNumber) + { + return preg_match('/^[a-zA-Z]{2}[0-9]{9}[a-zA-Z]{2}$/', $trackNumber); + } + + /** + * Retrieves the tracking instance + * + * @param Correios_Rastro_Objeto $obj Return Object + * + * @throws Exception + * + * @return Mage_Sales_Model_Order_Shipment_Track + */ + public function getTrack($obj) + { + $track = $this->_trackList[$obj->numero]; + if (!($desc = $track->getDescription())) { + Mage::log("{$obj->numero}: tracking instance missed. Trying to reload"); + try { + $track = Mage::getModel('sales/order_shipment_track')->load($obj->numero, 'track_number'); + } catch (Exception $e) { + Mage::log("{$obj->numero}: {$e->getMessage()}"); + } + } + return $track; + } } diff --git a/app/code/community/PedroTeixeira/Correios/controllers/Adminhtml/SigepwebController.php b/app/code/community/PedroTeixeira/Correios/controllers/Adminhtml/SigepwebController.php index 92aa4fb..e6c8dd2 100644 --- a/app/code/community/PedroTeixeira/Correios/controllers/Adminhtml/SigepwebController.php +++ b/app/code/community/PedroTeixeira/Correios/controllers/Adminhtml/SigepwebController.php @@ -16,7 +16,7 @@ class PedroTeixeira_Correios_Adminhtml_SigepwebController { /** * This updates the available service codes from Correios - * + * * @return void */ public function postmethodsUpdateAction() diff --git a/app/code/community/PedroTeixeira/Correios/etc/config.xml b/app/code/community/PedroTeixeira/Correios/etc/config.xml index 21a2b71..a6f2656 100644 --- a/app/code/community/PedroTeixeira/Correios/etc/config.xml +++ b/app/code/community/PedroTeixeira/Correios/etc/config.xml @@ -15,7 +15,7 @@ - 4.8.1 + 4.9.0 diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.7.0.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.7.0.php index 2704604..0b9305e 100644 --- a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.7.0.php +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.7.0.php @@ -126,16 +126,14 @@ 'posting_days' ); -foreach ( $setIds as $setId ) { - +foreach ($setIds as $setId) { $setup->addAttributeGroup('catalog_product', $setId, 'Correios', 2); $groupId = $setup->getAttributeGroupId('catalog_product', $setId, 'Correios'); - foreach ( $attributes as $attribute ) { + foreach ($attributes as $attribute) { $attributeId = $setup->getAttributeId('catalog_product', $attribute); $setup->addAttributeToGroup('catalog_product', $setId, $groupId, $attributeId); } - } $installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.0.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.0.php index 2d475e0..160f7a4 100644 --- a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.0.php +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.0.php @@ -126,124 +126,100 @@ 'posting_days' ); -foreach ( $setIds as $setId ) { - +foreach ($setIds as $setId) { $setup->addAttributeGroup('catalog_product', $setId, 'Correios', 2); $groupId = $setup->getAttributeGroupId('catalog_product', $setId, 'Correios'); - foreach ( $attributes as $attribute ) { + foreach ($attributes as $attribute) { $attributeId = $setup->getAttributeId('catalog_product', $attribute); $setup->addAttributeToGroup('catalog_product', $setId, $groupId, $attributeId); } - } -$installer->run( - "CREATE TABLE IF NOT EXISTS {$this->getTable('pedroteixeira_correios/postmethod')} ( - method_id int(11) unsigned NOT NULL auto_increment, - method_code varchar(5) NOT NULL default '0', - method_title varchar(255) NOT NULL default '', - PRIMARY KEY (method_id) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;" -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '1', - 'method_code' => '41106', - 'method_title' => 'PAC SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '2', - 'method_code' => '40010', - 'method_title' => 'SEDEX SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), +$tableName = $this->getTable('pedroteixeira_correios/postmethod'); +$table = $installer->getConnection() + ->newTable($tableName) + ->addColumn( + 'method_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, + null, + array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), + 'ID' + )->addColumn( + 'method_code', + Varien_Db_Ddl_Table::TYPE_TEXT, + 5, + array( + 'nullable' => false, + 'default' => '0' + ), + 'Code' + )->addColumn( + 'method_title', + Varien_Db_Ddl_Table::TYPE_TEXT, + 255, + array( + 'nullable' => false, + 'default' => '' + ), + 'Title' + )->addIndex( + $installer->getIdxName( + $tableName, + array('method_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('method_code'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE) + ); +$installer->getConnection()->createTable($table); + +$services = array( array( - 'method_id' => '3', 'method_code' => '40045', 'method_title' => 'SEDEX A COBRAR SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '4', 'method_code' => '40215', 'method_title' => 'SEDEX 10 SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '5', 'method_code' => '40290', 'method_title' => 'SEDEX HOJE SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '6', 'method_code' => '04510', 'method_title' => 'PAC SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '7', 'method_code' => '04014', 'method_title' => 'SEDEX SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '8', 'method_code' => '04669', 'method_title' => 'PAC CONTRATO AGENCIA', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '9', 'method_code' => '04162', 'method_title' => 'SEDEX CONTRATO AGENCIA', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '10', 'method_code' => '04693', 'method_title' => 'PAC CONTRATO GRANDES FORMATOS', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '11', 'method_code' => '10065', 'method_title' => 'CARTA COMERCIAL A FATURAR', ) ); +foreach ($services as $service) { + $installer->getConnection()->insertOnDuplicate($tableName, $service, array('method_code')); +} + $installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.1.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.1.php index 9b1794f..160f7a4 100644 --- a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.1.php +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.8.1.php @@ -126,106 +126,100 @@ 'posting_days' ); -foreach ( $setIds as $setId ) { - +foreach ($setIds as $setId) { $setup->addAttributeGroup('catalog_product', $setId, 'Correios', 2); $groupId = $setup->getAttributeGroupId('catalog_product', $setId, 'Correios'); - foreach ( $attributes as $attribute ) { + foreach ($attributes as $attribute) { $attributeId = $setup->getAttributeId('catalog_product', $attribute); $setup->addAttributeToGroup('catalog_product', $setId, $groupId, $attributeId); } - } -$installer->run( - "CREATE TABLE IF NOT EXISTS {$this->getTable('pedroteixeira_correios/postmethod')} ( - method_id int(11) unsigned NOT NULL auto_increment, - method_code varchar(5) NOT NULL default '0', - method_title varchar(255) NOT NULL default '', - PRIMARY KEY (method_id) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;" -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), +$tableName = $this->getTable('pedroteixeira_correios/postmethod'); +$table = $installer->getConnection() + ->newTable($tableName) + ->addColumn( + 'method_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, + null, + array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), + 'ID' + )->addColumn( + 'method_code', + Varien_Db_Ddl_Table::TYPE_TEXT, + 5, + array( + 'nullable' => false, + 'default' => '0' + ), + 'Code' + )->addColumn( + 'method_title', + Varien_Db_Ddl_Table::TYPE_TEXT, + 255, + array( + 'nullable' => false, + 'default' => '' + ), + 'Title' + )->addIndex( + $installer->getIdxName( + $tableName, + array('method_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('method_code'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE) + ); +$installer->getConnection()->createTable($table); + +$services = array( array( - 'method_id' => '3', 'method_code' => '40045', 'method_title' => 'SEDEX A COBRAR SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '4', 'method_code' => '40215', 'method_title' => 'SEDEX 10 SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '5', 'method_code' => '40290', 'method_title' => 'SEDEX HOJE SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '6', 'method_code' => '04510', 'method_title' => 'PAC SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '7', 'method_code' => '04014', 'method_title' => 'SEDEX SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '8', 'method_code' => '04669', 'method_title' => 'PAC CONTRATO AGENCIA', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '9', 'method_code' => '04162', 'method_title' => 'SEDEX CONTRATO AGENCIA', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '10', 'method_code' => '04693', 'method_title' => 'PAC CONTRATO GRANDES FORMATOS', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), + ), array( - 'method_id' => '11', 'method_code' => '10065', 'method_title' => 'CARTA COMERCIAL A FATURAR', ) ); +foreach ($services as $service) { + $installer->getConnection()->insertOnDuplicate($tableName, $service, array('method_code')); +} + $installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.9.0.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.9.0.php new file mode 100644 index 0000000..73b9507 --- /dev/null +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/install-4.9.0.php @@ -0,0 +1,225 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ + +/** @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; +$installer->startSetup(); + +$status = Mage::getModel('sales/order_status'); +$status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_SHIPPED_STATUS) + ->setLabel('Pedido em Transporte') + ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE) + ->save(); + +$status = Mage::getModel('sales/order_status'); +$status->setStatus(PedroTeixeira_Correios_Model_Sro::ORDER_WARNED_STATUS) + ->setLabel('Dificuldade de Entrega') + ->assignState(Mage_Sales_Model_Order::STATE_COMPLETE) + ->save(); + +/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */ +$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); + +// Add volume to prduct attribute set +$codigo = 'volume_comprimento'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Comprimento (cm)', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,grouped', + 'note' => 'Comprimento da embalagem do produto (Para cálculo dos Correios)' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +// Add volume to prduct attribute set +$codigo = 'volume_altura'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Altura (cm)', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,grouped', + 'note' => 'Altura da embalagem do produto (Para cálculo dos Correios)' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +// Add volume to prduct attribute set +$codigo = 'volume_largura'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Largura (cm)', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,grouped', + 'note' => 'Largura da embalagem do produto (Para cálculo dos Correios)' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$codigo = 'postmethods'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Serviços de Entrega', + 'type' => 'text', + 'input' => 'multiselect', + 'source' => 'pedroteixeira_correios/source_postMethods', + 'backend' => 'eav/entity_attribute_backend_array', + 'apply_to' => 'simple,grouped', + 'note' => 'Selecione os serviços apropriados para o produto.' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$codigo = 'fit_size'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Diferença do Encaixe (cm)', + 'type' => 'varchar', + 'input' => 'text', + 'apply_to' => 'simple,grouped', + 'note' => 'Exemplo: Se 1 item mede 10cm de altura, e 2 itens encaixados medem 11cm. A diferença é de 1cm.' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +$codigo = 'posting_days'; +$config = array( + 'position' => 1, + 'required' => 0, + 'label' => 'Prazo de Postagem', + 'type' => 'int', + 'input' => 'text', + 'apply_to' => 'simple,grouped', + 'note' => 'O prazo total é o Prazo dos Correios acrescido do maior Prazo de Postagem dos produtos no carrinho.' +); + +$setup->addAttribute('catalog_product', $codigo, $config); + +// Add Correios Tab +$setIds = $setup->getAllAttributeSetIds('catalog_product'); + +$attributes = array( + 'volume_comprimento', + 'volume_altura', + 'volume_largura', + 'postmethods', + 'fit_size', + 'posting_days' +); + +foreach ($setIds as $setId) { + $setup->addAttributeGroup('catalog_product', $setId, 'Correios', 2); + $groupId = $setup->getAttributeGroupId('catalog_product', $setId, 'Correios'); + + foreach ($attributes as $attribute) { + $attributeId = $setup->getAttributeId('catalog_product', $attribute); + $setup->addAttributeToGroup('catalog_product', $setId, $groupId, $attributeId); + } +} + +$tableName = $this->getTable('pedroteixeira_correios/postmethod'); +$table = $installer->getConnection() + ->newTable($tableName) + ->addColumn( + 'method_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, + null, + array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), + 'ID' + )->addColumn( + 'method_code', + Varien_Db_Ddl_Table::TYPE_TEXT, + 5, + array( + 'nullable' => false, + 'default' => '0' + ), + 'Code' + )->addColumn( + 'method_title', + Varien_Db_Ddl_Table::TYPE_TEXT, + 255, + array( + 'nullable' => false, + 'default' => '' + ), + 'Title' + )->addIndex( + $installer->getIdxName( + $tableName, + array('method_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('method_code'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE) + ); +$installer->getConnection()->createTable($table); + +$services = array( + array( + 'method_code' => '40045', + 'method_title' => 'SEDEX A COBRAR SEM CONTRATO', + ), + array( + 'method_code' => '40215', + 'method_title' => 'SEDEX 10 SEM CONTRATO', + ), + array( + 'method_code' => '40290', + 'method_title' => 'SEDEX HOJE SEM CONTRATO', + ), + array( + 'method_code' => '04510', + 'method_title' => 'PAC SEM CONTRATO', + ), + array( + 'method_code' => '04014', + 'method_title' => 'SEDEX SEM CONTRATO', + ), + array( + 'method_code' => '04669', + 'method_title' => 'PAC CONTRATO AGENCIA', + ), + array( + 'method_code' => '04162', + 'method_title' => 'SEDEX CONTRATO AGENCIA', + ), + array( + 'method_code' => '04693', + 'method_title' => 'PAC CONTRATO GRANDES FORMATOS', + ), + array( + 'method_code' => '10065', + 'method_title' => 'CARTA COMERCIAL A FATURAR', + ) +); + +foreach ($services as $service) { + $installer->getConnection()->insertOnDuplicate($tableName, $service, array('method_code')); +} + +$installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.6.0-4.7.0.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.6.0-4.7.0.php index 2337b29..762615b 100644 --- a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.6.0-4.7.0.php +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.6.0-4.7.0.php @@ -28,16 +28,14 @@ 'posting_days' ); -foreach ( $setIds as $setId ) { - +foreach ($setIds as $setId) { $setup->addAttributeGroup('catalog_product', $setId, 'Correios', 2); $groupId = $setup->getAttributeGroupId('catalog_product', $setId, 'Correios'); - foreach ( $attributes as $attribute ) { + foreach ($attributes as $attribute) { $attributeId = $setup->getAttributeId('catalog_product', $attribute); $setup->addAttributeToGroup('catalog_product', $setId, $groupId, $attributeId); } - } $installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.7.2-4.8.0.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.7.2-4.8.0.php index c447d70..0f189ac 100644 --- a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.7.2-4.8.0.php +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.7.2-4.8.0.php @@ -11,99 +11,3 @@ * @license http://opensource.org/licenses/MIT MIT * @link https://github.com/pedro-teixeira/correios */ - -/* @var $installer Mage_Core_Model_Resource_Setup */ -$installer = $this; -$installer->startSetup(); - -$installer->run( - "CREATE TABLE IF NOT EXISTS {$this->getTable('pedroteixeira_correios/postmethod')} ( - method_id int(11) unsigned NOT NULL auto_increment, - method_code varchar(5) NOT NULL default '0', - method_title varchar(255) NOT NULL default '', - PRIMARY KEY (method_id) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;" -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '3', - 'method_code' => '40045', - 'method_title' => 'SEDEX A COBRAR SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '4', - 'method_code' => '40215', - 'method_title' => 'SEDEX 10 SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '5', - 'method_code' => '40290', - 'method_title' => 'SEDEX HOJE SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '6', - 'method_code' => '04510', - 'method_title' => 'PAC SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '7', - 'method_code' => '04014', - 'method_title' => 'SEDEX SEM CONTRATO', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '8', - 'method_code' => '04669', - 'method_title' => 'PAC CONTRATO AGENCIA', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '9', - 'method_code' => '04162', - 'method_title' => 'SEDEX CONTRATO AGENCIA', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '10', - 'method_code' => '04693', - 'method_title' => 'PAC CONTRATO GRANDES FORMATOS', - ) -); - -$installer->getConnection()->insertForce( - $this->getTable('pedroteixeira_correios/postmethod'), - array( - 'method_id' => '11', - 'method_code' => '10065', - 'method_title' => 'CARTA COMERCIAL A FATURAR', - ) -); - -$installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.8.0-4.8.1.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.8.0-4.8.1.php index 0f189ac..2f4cd90 100644 --- a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.8.0-4.8.1.php +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.8.0-4.8.1.php @@ -11,3 +11,111 @@ * @license http://opensource.org/licenses/MIT MIT * @link https://github.com/pedro-teixeira/correios */ + +/* @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; +$installer->startSetup(); + +$tableName = $this->getTable('pedroteixeira_correios/postmethod'); + +if ($installer->getConnection()->isTableExists($tableName)) { + // Fix old migration to 4.8.0 + // See https://github.com/pedro-teixeira/correios/pull/252 + $installer->getConnection()->addIndex( + $tableName, + $installer->getIdxName( + $tableName, + array('method_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('method_code'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE) + ); +} else { + $table = $installer->getConnection() + ->newTable($tableName) + ->addColumn( + 'method_id', + Varien_Db_Ddl_Table::TYPE_INTEGER, + null, + array( + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ), + 'ID' + )->addColumn( + 'method_code', + Varien_Db_Ddl_Table::TYPE_TEXT, + 5, + array( + 'nullable' => false, + 'default' => '0' + ), + 'Code' + )->addColumn( + 'method_title', + Varien_Db_Ddl_Table::TYPE_TEXT, + 255, + array( + 'nullable' => false, + 'default' => '' + ), + 'Title' + )->addIndex( + $installer->getIdxName( + $tableName, + array('method_code'), + Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE + ), + array('method_code'), + array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE) + ); + $installer->getConnection()->createTable($table); + + $services = array( + array( + 'method_code' => '40045', + 'method_title' => 'SEDEX A COBRAR SEM CONTRATO', + ), + array( + 'method_code' => '40215', + 'method_title' => 'SEDEX 10 SEM CONTRATO', + ), + array( + 'method_code' => '40290', + 'method_title' => 'SEDEX HOJE SEM CONTRATO', + ), + array( + 'method_code' => '04510', + 'method_title' => 'PAC SEM CONTRATO', + ), + array( + 'method_code' => '04014', + 'method_title' => 'SEDEX SEM CONTRATO', + ), + array( + 'method_code' => '04669', + 'method_title' => 'PAC CONTRATO AGENCIA', + ), + array( + 'method_code' => '04162', + 'method_title' => 'SEDEX CONTRATO AGENCIA', + ), + array( + 'method_code' => '04693', + 'method_title' => 'PAC CONTRATO GRANDES FORMATOS', + ), + array( + 'method_code' => '10065', + 'method_title' => 'CARTA COMERCIAL A FATURAR', + ) + ); + + foreach ($services as $service) { + $installer->getConnection()->insertOnDuplicate($tableName, $service, array('method_code')); + } +} + +$installer->endSetup(); diff --git a/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.8.1-4.9.0.php b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.8.1-4.9.0.php new file mode 100644 index 0000000..e6a5b5e --- /dev/null +++ b/app/code/community/PedroTeixeira/Correios/sql/pedroteixeira_correios_setup/upgrade-4.8.1-4.9.0.php @@ -0,0 +1,63 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ + +/* @var $installer Mage_Core_Model_Resource_Setup */ +$installer = $this; +$installer->startSetup(); + +$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); + +$setup->updateAttribute( + 'catalog_product', + 'volume_altura', + 'apply_to', + 'simple,grouped' +); + +$setup->updateAttribute( + 'catalog_product', + 'volume_largura', + 'apply_to', + 'simple,grouped' +); + +$setup->updateAttribute( + 'catalog_product', + 'volume_comprimento', + 'apply_to', + 'simple,grouped' +); + +$setup->updateAttribute( + 'catalog_product', + 'postmethods', + 'apply_to', + 'simple,grouped' +); + +$setup->updateAttribute( + 'catalog_product', + 'fit_size', + 'apply_to', + 'simple,grouped' +); + +$setup->updateAttribute( + 'catalog_product', + 'posting_days', + 'apply_to', + 'simple,grouped' +); + +$installer->endSetup(); diff --git a/app/lib/Correios/Rastro.php b/app/lib/Correios/Rastro.php new file mode 100644 index 0000000..5569931 --- /dev/null +++ b/app/lib/Correios/Rastro.php @@ -0,0 +1,79 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro extends SoapClient +{ + + /** + * @var array $classmap The defined classes + * @access private + */ + private static $classmap = array( + 'BuscaEventosLista' => 'Correios_Rastro_BuscaEventosLista', + 'BuscaEventosListaResponse' => 'Correios_Rastro_BuscaEventosListaResponse', + 'Sroxml' => 'Correios_Rastro_Sroxml', + 'Objeto' => 'Correios_Rastro_Objeto', + 'Eventos' => 'Correios_Rastro_Eventos', + 'Destinos' => 'Correios_Rastro_Destinos', + 'EnderecoMobile' => 'Correios_Rastro_EnderecoMobile', + 'BuscaEventos' => 'Correios_Rastro_BuscaEventos', + 'BuscaEventosResponse' => 'Correios_Rastro_BuscaEventosResponse' + ); + + /** + * Class constructor method + * + * @param array $options An array of config values + * @param string $wsdl The wsdl file to use + * + * @access public + */ + public function __construct(array $options = array(), $wsdl = 'Rastro.wsdl') + { + foreach (self::$classmap as $key => $value) { + if (!isset($options['classmap'][$key])) { + $options['classmap'][$key] = $value; + } + } + + parent::__construct($wsdl, $options); + } + + /** + * Request method for buscaEventos + * + * @param Correios_Rastro_BuscaEventos $parameters Parameters + * + * @access public + * + * @return Correios_Rastro_BuscaEventosResponse + */ + public function buscaEventos(Correios_Rastro_BuscaEventos $parameters) + { + return $this->__soapCall('buscaEventos', array($parameters)); + } + + /** + * Request method for buscaEventosLista + * + * @param Correios_Rastro_BuscaEventosLista $parameters Parameters + * + * @access public + * + * @return Correios_Rastro_BuscaEventosListaResponse + */ + public function buscaEventosLista(Correios_Rastro_BuscaEventosLista $parameters) + { + return $this->__soapCall('buscaEventosLista', array($parameters)); + } +} diff --git a/app/lib/Correios/Rastro/BuscaEventos.php b/app/lib/Correios/Rastro/BuscaEventos.php new file mode 100644 index 0000000..c09a9c3 --- /dev/null +++ b/app/lib/Correios/Rastro/BuscaEventos.php @@ -0,0 +1,74 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_BuscaEventos +{ + + /** + * @var string $usuario + * @access public + */ + public $usuario = null; + + /** + * @var string $senha + * @access public + */ + public $senha = null; + + /** + * @var string $tipo + * @access public + */ + public $tipo = null; + + /** + * @var string $resultado + * @access public + */ + public $resultado = null; + + /** + * @var string $lingua + * @access public + */ + public $lingua = null; + + /** + * @var string $objetos + * @access public + */ + public $objetos = null; + + /** + * Class constructor method + * + * @param string $usuario Username + * @param string $senha Password + * @param string $tipo Type + * @param string $resultado Result + * @param string $lingua Language + * @param string $objetos Objects + * + * @access public + */ + public function __construct($usuario, $senha, $tipo, $resultado, $lingua, $objetos) + { + $this->usuario = $usuario; + $this->senha = $senha; + $this->tipo = $tipo; + $this->resultado = $resultado; + $this->lingua = $lingua; + $this->objetos = $objetos; + } +} diff --git a/app/lib/Correios/Rastro/BuscaEventosLista.php b/app/lib/Correios/Rastro/BuscaEventosLista.php new file mode 100644 index 0000000..d5b8118 --- /dev/null +++ b/app/lib/Correios/Rastro/BuscaEventosLista.php @@ -0,0 +1,74 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_BuscaEventosLista +{ + + /** + * @var string $usuario + * @access public + */ + public $usuario = null; + + /** + * @var string $senha + * @access public + */ + public $senha = null; + + /** + * @var string $tipo + * @access public + */ + public $tipo = null; + + /** + * @var string $resultado + * @access public + */ + public $resultado = null; + + /** + * @var string $lingua + * @access public + */ + public $lingua = null; + + /** + * @var string[] $objetos + * @access public + */ + public $objetos = null; + + /** + * Class constructor method + * + * @param string $usuario Username + * @param string $senha Password + * @param string $tipo Type + * @param string $resultado Result + * @param string $lingua Language + * @param string[] $objetos Object List + * + * @access public + */ + public function __construct($usuario, $senha, $tipo, $resultado, $lingua, $objetos) + { + $this->usuario = $usuario; + $this->senha = $senha; + $this->tipo = $tipo; + $this->resultado = $resultado; + $this->lingua = $lingua; + $this->objetos = $objetos; + } +} diff --git a/app/lib/Correios/Rastro/BuscaEventosListaResponse.php b/app/lib/Correios/Rastro/BuscaEventosListaResponse.php new file mode 100644 index 0000000..3048ee3 --- /dev/null +++ b/app/lib/Correios/Rastro/BuscaEventosListaResponse.php @@ -0,0 +1,34 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_BuscaEventosListaResponse +{ + + /** + * @var Correios_Rastro_Sroxml $return + * @access public + */ + public $return = null; + + /** + * Class constructor method + * + * @param Correios_Rastro_Sroxml $return Sroxml Object + * + * @access public + */ + public function __construct($return) + { + $this->return = $return; + } +} diff --git a/app/lib/Correios/Rastro/BuscaEventosResponse.php b/app/lib/Correios/Rastro/BuscaEventosResponse.php new file mode 100644 index 0000000..eef48ca --- /dev/null +++ b/app/lib/Correios/Rastro/BuscaEventosResponse.php @@ -0,0 +1,34 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_BuscaEventosResponse +{ + + /** + * @var Correios_Rastro_Sroxml $return + * @access public + */ + public $return = null; + + /** + * Class constructor method + * + * @param Correios_Rastro_Sroxml $return Sroxml Object + * + * @access public + */ + public function __construct($return) + { + $this->return = $return; + } +} diff --git a/app/lib/Correios/Rastro/Destinos.php b/app/lib/Correios/Rastro/Destinos.php new file mode 100644 index 0000000..ebbfa99 --- /dev/null +++ b/app/lib/Correios/Rastro/Destinos.php @@ -0,0 +1,66 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_Destinos +{ + + /** + * @var string $local + * @access public + */ + public $local = null; + + /** + * @var string $codigo + * @access public + */ + public $codigo = null; + + /** + * @var string $cidade + * @access public + */ + public $cidade = null; + + /** + * @var string $bairro + * @access public + */ + public $bairro = null; + + /** + * @var string $uf + * @access public + */ + public $uf = null; + + /** + * Class constructor method + * + * @param string $local Local + * @param string $codigo Code + * @param string $cidade City + * @param string $bairro Address + * @param string $uf Region Code + * + * @access public + */ + public function __construct($local, $codigo, $cidade, $bairro, $uf) + { + $this->local = $local; + $this->codigo = $codigo; + $this->cidade = $cidade; + $this->bairro = $bairro; + $this->uf = $uf; + } +} diff --git a/app/lib/Correios/Rastro/EnderecoMobile.php b/app/lib/Correios/Rastro/EnderecoMobile.php new file mode 100644 index 0000000..3c8db98 --- /dev/null +++ b/app/lib/Correios/Rastro/EnderecoMobile.php @@ -0,0 +1,126 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_EnderecoMobile +{ + + /** + * @var string $codigo + * @access public + */ + public $codigo = null; + + /** + * @var string $cep + * @access public + */ + public $cep = null; + + /** + * @var string $logradouro + * @access public + */ + public $logradouro = null; + + /** + * @var string $complemento + * @access public + */ + public $complemento = null; + + /** + * @var string $numero + * @access public + */ + public $numero = null; + + /** + * @var string $localidade + * @access public + */ + public $localidade = null; + + /** + * @var string $uf + * @access public + */ + public $uf = null; + + /** + * @var string $bairro + * @access public + */ + public $bairro = null; + + /** + * @var string $latitude + * @access public + */ + public $latitude = null; + + /** + * @var string $longitude + * @access public + */ + public $longitude = null; + + /** + * @var string $celular + * @access public + */ + public $celular = null; + + /** + * Class constructor method + * + * @param string $codigo Code + * @param string $cep Zip + * @param string $logradouro Street + * @param string $complemento Street 2 + * @param string $numero Number + * @param string $localidade Region + * @param string $uf Region Code + * @param string $bairro Address + * @param string $latitude Latitude + * @param string $longitude Longitude + * @param string $celular Cellphone + * + * @access public + */ + public function __construct( + $codigo, + $cep, + $logradouro, + $complemento, + $numero, + $localidade, + $uf, + $bairro, + $latitude, + $longitude, + $celular + ) { + + $this->codigo = $codigo; + $this->cep = $cep; + $this->logradouro = $logradouro; + $this->complemento = $complemento; + $this->numero = $numero; + $this->localidade = $localidade; + $this->uf = $uf; + $this->bairro = $bairro; + $this->latitude = $latitude; + $this->longitude = $longitude; + $this->celular = $celular; + } +} diff --git a/app/lib/Correios/Rastro/Eventos.php b/app/lib/Correios/Rastro/Eventos.php new file mode 100644 index 0000000..57dc004 --- /dev/null +++ b/app/lib/Correios/Rastro/Eventos.php @@ -0,0 +1,189 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_Eventos +{ + + /** + * @var string $tipo + * @access public + */ + public $tipo = null; + + /** + * @var string $status + * @access public + */ + public $status = null; + + /** + * @var string $data + * @access public + */ + public $data = null; + + /** + * @var string $hora + * @access public + */ + public $hora = null; + + /** + * @var string $descricao + * @access public + */ + public $descricao = null; + + /** + * @var string $detalhe + * @access public + */ + public $detalhe = null; + + /** + * @var string $recebedor + * @access public + */ + public $recebedor = null; + + /** + * @var string $documento + * @access public + */ + public $documento = null; + + /** + * @var string $comentario + * @access public + */ + public $comentario = null; + + /** + * @var string $local + * @access public + */ + public $local = null; + + /** + * @var string $codigo + * @access public + */ + public $codigo = null; + + /** + * @var string $cidade + * @access public + */ + public $cidade = null; + + /** + * @var string $uf + * @access public + */ + public $uf = null; + + /** + * @var string $sto + * @access public + */ + public $sto = null; + + /** + * @var string $amazoncode + * @access public + */ + public $amazoncode = null; + + /** + * @var string $amazontimezone + * @access public + */ + public $amazontimezone = null; + + /** + * @var Correios_Rastro_Destinos $destino + * @access public + */ + public $destino = null; + + /** + * @var Correios_Rastro_EnderecoMobile $endereco + * @access public + */ + public $endereco = null; + + /** + * Class constructor method + * + * @param string $tipo Type + * @param string $status State + * @param string $data Date + * @param string $hora Hour + * @param string $descricao Description + * @param string $detalhe Detail + * @param string $recebedor Receiver + * @param string $documento Document + * @param string $comentario Comment + * @param string $local Local + * @param string $codigo Code + * @param string $cidade City + * @param string $uf State + * @param string $sto Sto + * @param string $amazoncode Amazon Code + * @param string $amazontimezone Amazon Timezone + * @param Correios_Rastro_Destinos $destino Destination + * @param Correios_Rastro_EnderecoMobile $endereco Address + * + * @access public + */ + public function __construct( + $tipo, + $status, + $data, + $hora, + $descricao, + $detalhe, + $recebedor, + $documento, + $comentario, + $local, + $codigo, + $cidade, + $uf, + $sto, + $amazoncode, + $amazontimezone, + $destino, + $endereco + ) { + + $this->tipo = $tipo; + $this->status = $status; + $this->data = $data; + $this->hora = $hora; + $this->descricao = $descricao; + $this->detalhe = $detalhe; + $this->recebedor = $recebedor; + $this->documento = $documento; + $this->comentario = $comentario; + $this->local = $local; + $this->codigo = $codigo; + $this->cidade = $cidade; + $this->uf = $uf; + $this->sto = $sto; + $this->amazoncode = $amazoncode; + $this->amazontimezone = $amazontimezone; + $this->destino = $destino; + $this->endereco = $endereco; + } +} diff --git a/app/lib/Correios/Rastro/Objeto.php b/app/lib/Correios/Rastro/Objeto.php new file mode 100644 index 0000000..d2d9d02 --- /dev/null +++ b/app/lib/Correios/Rastro/Objeto.php @@ -0,0 +1,74 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_Objeto +{ + + /** + * @var string $numero + * @access public + */ + public $numero = null; + + /** + * @var string $sigla + * @access public + */ + public $sigla = null; + + /** + * @var string $nome + * @access public + */ + public $nome = null; + + /** + * @var string $categoria + * @access public + */ + public $categoria = null; + + /** + * @var string $erro + * @access public + */ + public $erro = null; + + /** + * @var Correios_Rastro_Eventos $evento + * @access public + */ + public $evento = null; + + /** + * Class constructor method + * + * @param string $numero Number + * @param string $sigla Initials + * @param string $nome Name + * @param string $categoria Category + * @param string $erro Error + * @param Correios_Rastro_Eventos $evento Event + * + * @access public + */ + public function __construct($numero, $sigla, $nome, $categoria, $erro, $evento) + { + $this->numero = $numero; + $this->sigla = $sigla; + $this->nome = $nome; + $this->categoria = $categoria; + $this->erro = $erro; + $this->evento = $evento; + } +} diff --git a/app/lib/Correios/Rastro/Sroxml.php b/app/lib/Correios/Rastro/Sroxml.php new file mode 100644 index 0000000..1b7d95f --- /dev/null +++ b/app/lib/Correios/Rastro/Sroxml.php @@ -0,0 +1,66 @@ + + * @copyright 2015 Pedro Teixeira (http://pedroteixeira.io) + * @license http://opensource.org/licenses/MIT MIT + * @link https://github.com/pedro-teixeira/correios + */ +class Correios_Rastro_Sroxml +{ + + /** + * @var string $versao + * @access public + */ + public $versao = null; + + /** + * @var string $qtd + * @access public + */ + public $qtd = null; + + /** + * @var string $TipoPesquisa + * @access public + */ + public $TipoPesquisa = null; + + /** + * @var string $TipoResultado + * @access public + */ + public $TipoResultado = null; + + /** + * @var Correios_Rastro_Objeto $objeto + * @access public + */ + public $objeto = null; + + /** + * Class constructor method + * + * @param string $versao Release + * @param string $qtd Quantity + * @param string $TipoPesquisa Search Type + * @param string $TipoResultado Result Type + * @param Correios_Rastro_Objeto $objeto Object + * + * @access public + */ + public function __construct($versao, $qtd, $TipoPesquisa, $TipoResultado, $objeto) + { + $this->versao = $versao; + $this->qtd = $qtd; + $this->TipoPesquisa = $TipoPesquisa; + $this->TipoResultado = $TipoResultado; + $this->objeto = $objeto; + } +} diff --git a/composer.json b/composer.json index aecd8d5..426155f 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description" : "Módulo de frete para Magento com tracking ", "require" : { "php" : ">=5.4", - "squizlabs/php_codesniffer" : "~1" + "squizlabs/php_codesniffer" : "~3" }, "config" : { "bin-dir" : "bin" diff --git a/composer.lock b/composer.lock index 8acaefd..92b5cb1 100644 --- a/composer.lock +++ b/composer.lock @@ -1,67 +1,44 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" ], - "hash": "ac1ab71a23addf4d4d1f0db627e9a526", + "content-hash": "ff3e1c6a7b395d8eec2a4b14003e7718", "packages": [ { "name": "squizlabs/php_codesniffer", - "version": "1.5.5", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "5d973e59cf58a0c847f298de84374c96b42b17b3" + "reference": "b95ff2c3b122a3ee4b57d149a57d2afce65522c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5d973e59cf58a0c847f298de84374c96b42b17b3", - "reference": "5d973e59cf58a0c847f298de84374c96b42b17b3", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b95ff2c3b122a3ee4b57d149a57d2afce65522c3", + "reference": "b95ff2c3b122a3ee4b57d149a57d2afce65522c3", "shasum": "" }, "require": { + "ext-simplexml": "*", "ext-tokenizer": "*", - "php": ">=5.1.2" + "ext-xmlwriter": "*", + "php": ">=5.4.0" }, - "suggest": { - "phpunit/php-timer": "dev-master" + "require-dev": { + "phpunit/phpunit": "~4.0" }, "bin": [ - "scripts/phpcs" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", "extra": { "branch-alias": { - "dev-phpcs-fixer": "2.0.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/CommentParser/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -72,19 +49,21 @@ "role": "lead" } ], - "description": "PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", "homepage": "http://www.squizlabs.com/php-codesniffer", "keywords": [ "phpcs", "standards" ], - "time": "2014-09-25 03:33:46" + "time": "2017-05-04T00:33:04+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": ">=5.4" }, diff --git a/ruleset.xml b/ruleset.xml index 96b0090..6d064f3 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,52 +1,11 @@ - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file +