Indexa_Fretefacil - Version 0.1.0

Version Notes

- Este módulo possui um pacote de alteração de layout, que pode ser instalado posteriormente.

Download this release

Release Info

Developer Gabriel Zamprogna
Extension Indexa_Fretefacil
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Indexa/Fretefacil/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Indexa Frete Facil
4
+ *
5
+ * @category Shipping Method
6
+ * @package Indexa_Fretefacil
7
+ * @author Indexa Team <desenvolvimento@indexainternet.com.br>
8
+ * @copyright Copyright (c) 2011 Indexa
9
+ */
10
+ class Indexa_Fretefacil_Helper_Data extends Mage_Core_Helper_Abstract
11
+ {
12
+ }
app/code/local/Indexa/Fretefacil/Model/Carrier/Indexafretefacil.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Indexa Frete Facil
5
+ *
6
+ * @category Shipping Method
7
+ * @package Indexa_Fretefacil
8
+ * @author Indexa Team <desenvolvimento@indexainternet.com.br>
9
+ * @copyright Copyright (c) 2011 Indexa
10
+ */
11
+ class Indexa_Fretefacil_Model_Carrier_Indexafretefacil extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface {
12
+
13
+ /**
14
+ * _code property
15
+ *
16
+ * @var string
17
+ */
18
+ protected $_code = 'indexafretefacil';
19
+
20
+ /**
21
+ * _result property
22
+ *
23
+ * @var Mage_Shipping_Model_Rate_Result | Mage_Shipping_Model_Tracking_Result
24
+ */
25
+ protected $_result = null;
26
+
27
+ /**
28
+ * $request property
29
+ *
30
+ * @var Mage_Shipping_Model_Rate_Request
31
+ */
32
+ protected $request;
33
+
34
+ /**
35
+ * $error property
36
+ *
37
+ * @var boolean
38
+ */
39
+ protected $error = false;
40
+
41
+ /**
42
+ * Test URL
43
+ *
44
+ * @var string
45
+ */
46
+ const WS_TEST_MODE_ENABLED_URL = 'https://sistemas.homol.fastsolutions.com.br/FretesPayPalWS/WSFretesPayPal?wsdl';
47
+
48
+ /**
49
+ * Production URL
50
+ *
51
+ * @var string
52
+ */
53
+ const WS_TEST_MODE_DISABLED_URL = 'https://ff.paypal-brasil.com.br/FretesPayPalWS/WSFretesPayPal?wsdl';
54
+
55
+ /**
56
+ * Location Test URL
57
+ *
58
+ * @var string
59
+ */
60
+ const WS_LOCATION_TEST_URL = 'https://sistemas.homol.fastsolutions.com.br/FretesPayPalWS/WSFretesPayPal';
61
+
62
+ /**
63
+ * Location Production URL
64
+ *
65
+ * @var string
66
+ */
67
+ const WS_LOCATION_PROD_URL = 'https://ff.paypal-brasil.com.br/FretesPayPalWS/WSFretesPayPal';
68
+
69
+ /**
70
+ * define weight unit
71
+ *
72
+ * @var string
73
+ */
74
+ const WEIGHT_UNIT = 1;
75
+ /**
76
+ * shipping method code
77
+ *
78
+ * @var string
79
+ */
80
+ const SHIPPING_METHOD_CODE = 'indexafretefacil_indexafretefacil';
81
+
82
+ /**
83
+ * @param boolean $error
84
+ *
85
+ * return void
86
+ */
87
+ public function setError( $error ){
88
+ $this->error = $error;
89
+ }
90
+
91
+ /**
92
+ * @return boolean
93
+ */
94
+ public function hasError(){
95
+ return $this->error;
96
+ }
97
+
98
+ /**
99
+ * @param Mage_Shipping_Model_Rate_Request $request
100
+ *
101
+ * return void
102
+ */
103
+ public function setRequest( Mage_Shipping_Model_Rate_Request $request ){
104
+ $this->request = $request;
105
+ }
106
+
107
+ /**
108
+ * @return Mage_Shipping_Model_Rate_Request
109
+ */
110
+ public function getRequest(){
111
+ return $this->request;
112
+ }
113
+
114
+ /**
115
+ * Check if carrier has shipping tracking option available
116
+ *
117
+ * @return boolean
118
+ */
119
+ public function isTrackingAvailable() {
120
+ return false;
121
+ }
122
+
123
+ /**
124
+ * Get allowed shipping methods
125
+ *
126
+ * @return array
127
+ */
128
+ public function getAllowedMethods() {
129
+ return array($this->_code => $this->getConfigData('title'));
130
+ }
131
+
132
+ /**
133
+ * Collects the shipping rates from Frete facil.
134
+ *
135
+ * @param Mage_Shipping_Model_Rate_Request $request
136
+ * @return Mage_Shipping_Model_Rate_Result
137
+ */
138
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
139
+
140
+ /**
141
+ * check if this method is active
142
+ */
143
+ if (!$this->getConfigFlag('active')) {
144
+ return false;
145
+ }
146
+ $this->setRequest($request);
147
+
148
+ $result = Mage::getModel('shipping/rate_result');
149
+
150
+ $error = Mage::getModel('shipping/rate_result_error')
151
+ ->setCarrier($this->_code)
152
+ ->setErrorMessage($this->getConfigData('error_shipping'))
153
+ ->setCarrierTitle($this->getConfigData('title'));
154
+
155
+ $shippingPrice = $this->getShippingPrice();
156
+
157
+ /**
158
+ * something is wrong when API returns less then zero
159
+ */
160
+ if ( $this->hasError() ) {
161
+ return $error;
162
+ }
163
+
164
+ /**
165
+ * set carrier values
166
+ */
167
+ $method = Mage::getModel('shipping/rate_result_method');
168
+ $method->setCarrier($this->_code)
169
+ ->setCarrierTitle($this->getConfigData('title'))
170
+ ->setCost($shippingPrice)
171
+ ->setPrice($shippingPrice)
172
+ ->setMethod($this->_code)
173
+ ->setMethodTitle("SEDEX {$this->getConfigData('description')} ");
174
+
175
+ $result->append($method);
176
+ $this->_result = $result;
177
+
178
+ $this->_updateFreeMethodQuote($request);
179
+
180
+ return $this->_result;
181
+ }
182
+
183
+ /**
184
+ * prepare product params
185
+ *
186
+ * @param Mage_Sales_Model_Quote_Item $item
187
+ *
188
+ * @return int|float
189
+ */
190
+ public function calculate($item) {
191
+
192
+ /**
193
+ * get attributes
194
+ */
195
+ $cProduct = Mage::getModel('catalog/product')->load( $item->getProduct()->getId() );
196
+
197
+ $measureA = $cProduct->getPaypalAltura();
198
+ $measureB = $cProduct->getPaypalLargura();
199
+ $measureC = $cProduct->getPaypalComprimento();
200
+
201
+ $measureW = $cProduct->getWeight();
202
+
203
+ /**
204
+ * multiply quantity
205
+ */
206
+ if( $measureB < $measureC ){
207
+ $measureB = $measureB * $item->getQty();
208
+ }else{
209
+ $measureC = $measureC * $item->getQty();
210
+ }
211
+
212
+ /**
213
+ * keeping paypal_altura < paypal_comprimento
214
+ */
215
+ if( $measureA > $measureC ){
216
+ $tmpMeasure = $measureC;
217
+ $measureC = $measureA;
218
+ $measureA = $tmpMeasure;
219
+ $tmpMeasure = false;
220
+ }
221
+
222
+ $lMin = 11;
223
+ $cMin = 16;
224
+ $aMin = 2;
225
+ /**
226
+ * prepare params
227
+ */
228
+ $soapParams['peso'] = ($measureW * $item->getQty()) / self::WEIGHT_UNIT;
229
+ $soapParams['altura'] = $measureA < $aMin ? $aMin: $measureA;
230
+ $soapParams['largura'] = $measureB < $lMin ? $lMin: $measureB;
231
+ $soapParams['profundidade'] = $measureC < $cMin ? $cMin: $measureC;
232
+
233
+ return $this->call($soapParams);
234
+ }
235
+
236
+ /**
237
+ * send request to paypal frete facil
238
+ *
239
+ * @param array $soapParams
240
+ * @return int|float
241
+ */
242
+ public function call( $soapParams ){
243
+ /**
244
+ * set postal codes
245
+ */
246
+ $soapParams['cepOrigem'] = Mage::getStoreConfig('shipping/origin/postcode', $this->getStore());
247
+ $soapParams['cepDestino'] = $this->getRequest()->getDestPostcode();
248
+
249
+ /**
250
+ * prepare soap url and location
251
+ */
252
+ if ($this->getConfigData('test_mode')) {
253
+ $soapUrl = self::WS_TEST_MODE_ENABLED_URL;
254
+ $soapLocation = self::WS_LOCATION_TEST_URL;
255
+ } else {
256
+ $soapUrl = self::WS_TEST_MODE_DISABLED_URL;
257
+ $soapLocation = self::WS_LOCATION_PROD_URL;
258
+ }
259
+
260
+ /**
261
+ * soap instance
262
+ */
263
+ $oPaypalFrete = new SoapClient($soapUrl, array("connection_timeout" => 120, "location" => $soapLocation));
264
+
265
+ $result = $oPaypalFrete->getPreco($soapParams)->return;
266
+ if( $result <= 0 ){
267
+ $this->setError(true);
268
+ }
269
+ return $result;
270
+ }
271
+ /**
272
+ * calculates total value from quote
273
+ *
274
+ * @return int|float
275
+ */
276
+ public function getShippingPrice() {
277
+ /**
278
+ * get quote items
279
+ */
280
+ $items = Mage::getSingleton('checkout/cart')->getItems();
281
+
282
+ $sumTotals = 0;
283
+ if($items){
284
+ foreach ($items as $item){
285
+ /**
286
+ * calculate price by items
287
+ */
288
+ $sumTotals += $this->calculate($item);
289
+ }
290
+ }
291
+
292
+ return $sumTotals;
293
+ }
294
+
295
+ }
app/code/local/Indexa/Fretefacil/Model/Checkout/Type/Onepage.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * One page checkout status
5
+ *
6
+ * @category Indexa
7
+ * @package Indexa_Fretefacil
8
+ * @author Indexa Team -> desenvolvimento [at] indexainternet [dot] com [dot] br
9
+ * @copyright Copyright (c) 2011 Indexa
10
+ */
11
+ class Indexa_Fretefacil_Model_Checkout_Type_Onepage extends Mage_Checkout_Model_Type_Onepage {
12
+
13
+ /**
14
+ * Specify quote payment method
15
+ *
16
+ * @param array $data
17
+ * @return array
18
+ */
19
+ public function savePayment($data)
20
+ {
21
+ if (empty($data)) {
22
+ return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
23
+ }
24
+ $quote = $this->getQuote();
25
+ if ($quote->isVirtual()) {
26
+ $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
27
+ } else {
28
+ $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
29
+ }
30
+
31
+ $shipping = $this->getQuote()->getShippingAddress();
32
+ /* @var Mage_Sales_Model_Quote_Address $shipping */
33
+ $shippingMethod = $shipping->getShippingMethod();
34
+
35
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
36
+ $quote->getShippingAddress()->setCollectShippingRates(true);
37
+ }
38
+
39
+ $payment = $quote->getPayment();
40
+ /* @var Mage_Sales_Model_Quote_Payment $payment */
41
+ $payment->importData($data);
42
+
43
+ /**
44
+ * define payment methods to check
45
+ */
46
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_BILLING_AGREEMENT;
47
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_HOSTEDPRO;
48
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_PAYFLOWLINK;
49
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_PAYFLOWPRO;
50
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS;
51
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_WPP_DIRECT;
52
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_WPP_PE_DIRECT;
53
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_WPP_PE_EXPRESS;
54
+ $paypal_methods[] = Mage_Paypal_Model_Config::METHOD_WPS;
55
+
56
+ /**
57
+ * check if fretefacil is selected as shipping method
58
+ */
59
+ if( Indexa_Fretefacil_Model_Carrier_Indexafretefacil::SHIPPING_METHOD_CODE == $shippingMethod && !in_array( $payment->getMethod(), $paypal_methods ) ){
60
+ return array('error' => Mage::getStoreConfig('carriers/indexafretefacil/error_payment'), 'message' => Mage::getStoreConfig('carriers/indexafretefacil/error_payment') );
61
+ }
62
+
63
+ $quote->save();
64
+
65
+ $this->getCheckout()
66
+ ->setStepData('payment', 'complete', true)
67
+ ->setStepData('review', 'allow', true);
68
+
69
+ return array();
70
+ }
71
+ }
app/code/local/Indexa/Fretefacil/etc/config.xml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Indexa Frete Facil
5
+ *
6
+ * @category Shipping Method
7
+ * @package Indexa_Fretefacil
8
+ * @author Indexa Team <desenvolvimento@indexainternet.com.br>
9
+ * @copyright Copyright (c) 2011 Indexa
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Indexa_Fretefacil>
15
+ <version>0.1.0</version>
16
+ <depends>
17
+ <Mage_Shipping />
18
+ </depends>
19
+ </Indexa_Fretefacil>
20
+ </modules>
21
+ <default>
22
+ <carriers>
23
+ <indexafretefacil>
24
+ <error_shipping>Ocorreu um erro na comunicação com o serviço. Se você deseja utilizar este método contate-nos.</error_shipping>
25
+ <error_payment>Frete Fácil libera apenas pagamentos usando os métodos Paypal.</error_payment>
26
+ </indexafretefacil>
27
+ </carriers>
28
+ </default>
29
+ <global>
30
+ <resources>
31
+ <fretefacil_setup>
32
+ <setup>
33
+ <module>Indexa_Fretefacil</module>
34
+ </setup>
35
+ <connection>
36
+ <use>directory_setup</use>
37
+ </connection>
38
+ </fretefacil_setup>
39
+ <fretefacil_read>
40
+ <connection>
41
+ <use>core_read</use>
42
+ </connection>
43
+ </fretefacil_read>
44
+ <fretefacil_write>
45
+ <connection>
46
+ <use>core_write</use>
47
+ </connection>
48
+ </fretefacil_write>
49
+ </resources>
50
+ <sales>
51
+ <shipping>
52
+ <carriers>
53
+ <indexafretefacil>
54
+ <class>Indexa_Fretefacil_Model_Carrier_Indexafretefacil</class>
55
+ </indexafretefacil>
56
+ </carriers>
57
+ </shipping>
58
+ </sales>
59
+ <models>
60
+ <checkout>
61
+ <rewrite>
62
+ <type_onepage>Indexa_Fretefacil_Model_Checkout_Type_Onepage</type_onepage>
63
+ </rewrite>
64
+ </checkout>
65
+ </models>
66
+ </global>
67
+ <frontend>
68
+ <layout>
69
+ <updates>
70
+ <fretefacil>
71
+ <file>indexa_fretefacil.xml</file>
72
+ </fretefacil>
73
+ </updates>
74
+ </layout>
75
+ </frontend>
76
+ <default>
77
+ <carriers>
78
+ <indexafretefacil>
79
+ <active>0</active>
80
+ <sallowspecific>0</sallowspecific>
81
+ <model>Indexa_Fretefacil_model_carrier_indexafretefacil</model>
82
+ <name><![CDATA[Frete F&aacute;cil]]></name>
83
+ <title><![CDATA[Frete F&aacute;cil]]></title>
84
+ <test_mode>0</test_mode>
85
+ <specificerrmsg><![CDATA[Houve uma falha moment&acirc;nea ao obter os custos de envio. Por favor, tente novamente.]]></specificerrmsg>
86
+ </indexafretefacil>
87
+ </carriers>
88
+ </default>
89
+ </config>
app/code/local/Indexa/Fretefacil/etc/system.xml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Indexa Frete Facil
5
+ *
6
+ * @category Shipping Method
7
+ * @package Indexa_Fretefacil
8
+ * @author Indexa Team <desenvolvimento@indexainternet.com.br>
9
+ * @copyright Copyright (c) 2011 Indexa
10
+ */
11
+ -->
12
+ <config>
13
+ <sections>
14
+ <carriers>
15
+ <groups>
16
+ <indexafretefacil translate="label" module="shipping">
17
+ <label><![CDATA[Indexa Frete F&aacute;cil]]></label>
18
+ <frontend_type>text</frontend_type>
19
+ <sort_order>1</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ <fields>
24
+ <active translate="label">
25
+ <label>Enabled</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>1</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ </active>
33
+ <title translate="label">
34
+ <label>Title</label>
35
+ <frontend_type>text</frontend_type>
36
+ <sort_order>2</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>1</show_in_store>
40
+ </title>
41
+ <description translate="label">
42
+ <label>Description</label>
43
+ <frontend_type>text</frontend_type>
44
+ <sort_order>3</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>1</show_in_store>
48
+ </description>
49
+ <error_shipping translate="label">
50
+ <label>Mensagem de Erro 1</label>
51
+ <frontend_type>textarea</frontend_type>
52
+ <sort_order>4</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ <comment><![CDATA[Define mensagem de erro a ser exibida por falha na comunicação com o serviço.]]></comment>
57
+ </error_shipping>
58
+ <error_payment translate="label">
59
+ <label>Mensagem de Erro 2</label>
60
+ <frontend_type>textarea</frontend_type>
61
+ <sort_order>5</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ <comment><![CDATA[Define mensagem de erro a ser exibida por falha na escolha do método de pagamento.]]></comment>
66
+ </error_payment>
67
+ <sort_order translate="label">
68
+ <label><![CDATA[N&uacute;mero de Ordena&ccedil;&atilde;o]]></label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>6</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ </sort_order>
75
+ <test_mode translate="label">
76
+ <label>Test Mode</label>
77
+ <frontend_type>select</frontend_type>
78
+ <source_model>adminhtml/system_config_source_yesno</source_model>
79
+ <sort_order>7</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ </test_mode>
84
+ </fields>
85
+ </indexafretefacil>
86
+ </groups>
87
+ </carriers>
88
+ </sections>
89
+ </config>
app/code/local/Indexa/Fretefacil/sql/fretefacil_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Indexa Frete Facil
4
+ *
5
+ * @category Shipping Method
6
+ * @package Indexa_Fretefacil
7
+ * @author Indexa Team <desenvolvimento@indexainternet.com.br>
8
+ * @copyright Copyright (c) 2011 Indexa
9
+ */
10
+
11
+ $installer = $this;
12
+ $installer->startSetup();
13
+
14
+ $result = $installer->getTableRow($installer->getTable('directory_country_region'), 'default_name','Acre');
15
+ $start_id = $result["region_id"];
16
+
17
+ /**
18
+ * check for brazilian states
19
+ */
20
+ if (is_null($start_id) || !is_numeric($start_id))
21
+ {
22
+ $installer->run("
23
+ DELETE FROM {$installer->getTable('directory_country_region')} WHERE country_id = 'BR';
24
+ INSERT INTO {$installer->getTable('directory_country_region')} (country_id, code, default_name) VALUES
25
+ ('BR', 'AC', 'Acre'),
26
+ ('BR', 'AL', 'Alagoas'),
27
+ ('BR', 'AP', 'Amapá'),
28
+ ('BR', 'AM', 'Amazonas'),
29
+ ('BR', 'BA', 'Bahia'),
30
+ ('BR', 'CE', 'Ceará'),
31
+ ('BR', 'ES', 'Espírito Santo'),
32
+ ('BR', 'GO', 'Goiás'),
33
+ ('BR', 'MA', 'Maranhão'),
34
+ ('BR', 'MT', 'Mato Grosso'),
35
+ ('BR', 'MS', 'Mato Grosso do Sul'),
36
+ ('BR', 'MG', 'Minas Gerais'),
37
+ ('BR', 'PA', 'Pará'),
38
+ ('BR', 'PB', 'Paraíba'),
39
+ ('BR', 'PR', 'Paraná'),
40
+ ('BR', 'PE', 'Pernambuco'),
41
+ ('BR', 'PI', 'Piauí'),
42
+ ('BR', 'RJ', 'Rio de Janeiro'),
43
+ ('BR', 'RN', 'Rio Grande do Norte'),
44
+ ('BR', 'RS', 'Rio Grande do Sul'),
45
+ ('BR', 'RO', 'Rondônia'),
46
+ ('BR', 'RR', 'Roraima'),
47
+ ('BR', 'SC', 'Santa Catarina'),
48
+ ('BR', 'SP', 'São Paulo'),
49
+ ('BR', 'SE', 'Sergipe'),
50
+ ('BR', 'TO', 'Tocantins'),
51
+ ('BR', 'DF', 'Distrito Federal'); ");
52
+
53
+ $installer->getConnection()
54
+ ->commit();
55
+
56
+ $result = $installer->getConnection()
57
+ ->fetchAll("SELECT * FROM {$installer->getTable('directory_country_region')} WHERE default_name = 'Acre'");
58
+
59
+ if (isset($result[0]["region_id"]))
60
+ $start_id = $result[0]["region_id"];
61
+
62
+ if ($start_id > 0)
63
+ {
64
+ $installer->run("
65
+ DELETE FROM {$installer->getTable('directory_country_region_name')} WHERE locale = 'pt_BR';
66
+
67
+ INSERT INTO {$installer->getTable('directory_country_region_name')} (locale, region_id, name) VALUES
68
+ ('pt_BR', ".$start_id.", 'Acre'),
69
+ ('pt_BR', ".(++$start_id).", 'Alagoas'),
70
+ ('pt_BR', ".(++$start_id).", 'Amapá'),
71
+ ('pt_BR', ".(++$start_id).", 'Amazonas'),
72
+ ('pt_BR', ".(++$start_id).", 'Bahia'),
73
+ ('pt_BR', ".(++$start_id).", 'Ceará'),
74
+ ('pt_BR', ".(++$start_id).", 'Espírito Santo'),
75
+ ('pt_BR', ".(++$start_id).", 'Goiás'),
76
+ ('pt_BR', ".(++$start_id).", 'Maranhão'),
77
+ ('pt_BR', ".(++$start_id).", 'Mato Grosso'),
78
+ ('pt_BR', ".(++$start_id).", 'Mato Grosso do Sul'),
79
+ ('pt_BR', ".(++$start_id).", 'Minas Gerais'),
80
+ ('pt_BR', ".(++$start_id).", 'Pará'),
81
+ ('pt_BR', ".(++$start_id).", 'Paraíba'),
82
+ ('pt_BR', ".(++$start_id).", 'Paraná'),
83
+ ('pt_BR', ".(++$start_id).", 'Pernambuco'),
84
+ ('pt_BR', ".(++$start_id).", 'Piauí'),
85
+ ('pt_BR', ".(++$start_id).", 'Rio de Janeiro'),
86
+ ('pt_BR', ".(++$start_id).", 'Rio Grande do Norte'),
87
+ ('pt_BR', ".(++$start_id).", 'Rio Grande do Sul'),
88
+ ('pt_BR', ".(++$start_id).", 'Rondônia'),
89
+ ('pt_BR', ".(++$start_id).", 'Roraima'),
90
+ ('pt_BR', ".(++$start_id).", 'Santa Catarina'),
91
+ ('pt_BR', ".(++$start_id).", 'São Paulo'),
92
+ ('pt_BR', ".(++$start_id).", 'Sergipe'),
93
+ ('pt_BR', ".(++$start_id).", 'Tocantins'),
94
+ ('pt_BR', ".(++$start_id).", 'Distrito Federal');
95
+ ");
96
+
97
+ $installer->getConnection()
98
+ ->commit();
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Insert paypal attributes on "Default" Attribute set, to calculate shipping price
104
+ */
105
+ $installer->run("
106
+
107
+ INSERT INTO {$installer->getTable('eav/attribute')} (entity_type_id, attribute_code, backend_type, frontend_input, frontend_label, is_required, is_user_defined) VALUES (4, 'paypal_altura', 'text', 'text', 'Altura', 0, 1);
108
+ INSERT INTO {$installer->getTable('catalog/eav_attribute')} ( attribute_id, is_global, is_visible ) VALUES (( SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'paypal_altura' ) , 1, 1 );
109
+ INSERT INTO {$installer->getTable('eav/entity_attribute')} ( entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order ) VALUES ( '4', '4', '7', ( SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'paypal_altura' ) , 6 );
110
+
111
+
112
+ INSERT INTO {$installer->getTable('eav/attribute')} (entity_type_id, attribute_code, backend_type, frontend_input, frontend_label, is_required, is_user_defined) VALUES (4, 'paypal_largura', 'text', 'text', 'Largura', 0, 1);
113
+ INSERT INTO {$installer->getTable('catalog/eav_attribute')} ( attribute_id, is_global, is_visible ) VALUES (( SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'paypal_largura' ) , 1, 1 );
114
+ INSERT INTO {$installer->getTable('eav/entity_attribute')} ( entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order ) VALUES ( '4', '4', '7', ( SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'paypal_largura' ) , 6 );
115
+
116
+
117
+ INSERT INTO {$installer->getTable('eav/attribute')} (entity_type_id, attribute_code, backend_type, frontend_input, frontend_label, is_required, is_user_defined) VALUES (4, 'paypal_comprimento', 'text', 'text', 'Comprimento', 0, 1);
118
+ INSERT INTO {$installer->getTable('catalog/eav_attribute')} ( attribute_id, is_global, is_visible ) VALUES (( SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'paypal_comprimento' ) , 1, 1 );
119
+ INSERT INTO {$installer->getTable('eav/entity_attribute')} ( entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order ) VALUES ( '4', '4', '7', ( SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'paypal_comprimento' ) , 6 );
120
+
121
+ ");
122
+
123
+ $installer->getConnection()
124
+ ->commit();
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+ $installer->endSetup();
app/etc/modules/Indexa_Fretefacil.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Indexa Frete Facil
5
+ *
6
+ * @category Indexa
7
+ * @package Indexa_Fretefacil
8
+ * @author Indexa Team <desenvolvimento@indexainternet.com.br>
9
+ * @copyright Copyright (c) 2011 Indexa
10
+ */
11
+ -->
12
+ <config>
13
+ <modules>
14
+ <Indexa_Fretefacil>
15
+ <active>true</active>
16
+ <codePool>local</codePool>
17
+ </Indexa_Fretefacil>
18
+ </modules>
19
+ </config>
20
+
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Indexa_Fretefacil</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>M&#xF3;dulo de integra&#xE7;&#xE3;o com o Frete F&#xE1;cil, servi&#xE7;o de envio do Paypal.</summary>
10
+ <description>M&#xF3;dulo de integra&#xE7;&#xE3;o com o Frete F&#xE1;cil, servi&#xE7;o de envio do Paypal.</description>
11
+ <notes>- Este m&#xF3;dulo possui um pacote de altera&#xE7;&#xE3;o de layout, que pode ser instalado posteriormente.</notes>
12
+ <authors><author><name>Desenvolvimento Indexa</name><user>gabrielz</user><email>desenvolvimento@indexainternet.com.br</email></author></authors>
13
+ <date>2011-12-01</date>
14
+ <time>19:33:20</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Indexa_Fretefacil.xml" hash="8153edf3f8708215d69dfaaa3a3f7c0a"/></dir></target><target name="magelocal"><dir name="Indexa"><dir name="Fretefacil"><dir name="Helper"><file name="Data.php" hash="1a17a0127355eaa1fc2672d1f538aafb"/></dir><dir name="Model"><dir name="Carrier"><file name="Indexafretefacil.php" hash="935586a548c4d86fc136f49713291d61"/></dir><dir name="Checkout"><dir name="Type"><file name="Onepage.php" hash="a95c3fac19648e9e3722505ddd654122"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="39ad858f2a795453484feaf644ad0a44"/><file name="system.xml" hash="ff2876692455e503af5d8892db111137"/></dir><dir name="sql"><dir name="fretefacil_setup"><file name="mysql4-install-0.1.0.php" hash="c5fcc0f2d53fafbb1da4f06ceb7a83c7"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>