Skip to content

Commit 1b662b0

Browse files
committed
Changes:
- Improvements to quotation in product page.
1 parent c8e489f commit 1b662b0

File tree

9 files changed

+226
-86
lines changed

9 files changed

+226
-86
lines changed

app/code/community/Frenet/Shipping/controllers/ProductController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ protected function _construct()
1616

1717
public function quoteAction()
1818
{
19-
$productId = (int) $this->getRequest()->getPost('product');
20-
$postcode = (string) $this->getRequest()->getPost('postcode');
21-
$qty = (float) $this->getRequest()->getPost('qty');
22-
$options = (array) $this->getRequest()->getPost();
19+
$productId = (int) $this->getRequest()->getPost('product');
20+
$postcode = (string) $this->getRequest()->getPost('postcode');
21+
$qty = (float) $this->getRequest()->getPost('qty');
22+
$options = (array) $this->getRequest()->getPost();
2323

2424
$this->getResponse()->setHeader('Content-type', 'application/json', true);
2525

app/code/community/Frenet/Shipping/etc/config.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Frenet Shipping Gateway
5+
*
6+
* @category Frenet
7+
*
8+
* @author Tiago Sampaio <tiago@tiagosampaio.com>
9+
* @link https://github.com/tiagosampaio
10+
* @link https://tiagosampaio.com
11+
*
12+
* Copyright (c) 2020.
13+
*/
14+
-->
215
<config>
316
<modules>
417
<Frenet_Shipping>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<jstranslator>
3+
<delivery-time translate="message" module="frenet_shipping">
4+
<message> day(s)</message>
5+
</delivery-time>
6+
</jstranslator>

app/code/community/Frenet/Shipping/etc/system.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Frenet Shipping Gateway
5+
*
6+
* @category Frenet
7+
*
8+
* @author Tiago Sampaio <tiago@tiagosampaio.com>
9+
* @link https://github.com/tiagosampaio
10+
* @link https://tiagosampaio.com
11+
*
12+
* Copyright (c) 2020.
13+
*/
14+
-->
215
<config>
316
<sections>
417
<carriers>

app/design/frontend/base/default/layout/frenet/frenet_shipping.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Frenet Shipping Gateway
5+
*
6+
* @category Frenet
7+
*
8+
* @author Tiago Sampaio <tiago@tiagosampaio.com>
9+
* @link https://github.com/tiagosampaio
10+
* @link https://tiagosampaio.com
11+
*
12+
* Copyright (c) 2020.
13+
*/
14+
-->
215
<layout version="0.1.0">
316
<frenet_product_shipping_quote>
17+
<reference name="head">
18+
<action method="addJs"><script>varien/js.js</script></action>
19+
<action method="addItem"><type>skin_js</type><name>js/frenet/shipping.js</name></action>
20+
<action method="addItem"><type>skin_css</type><name>css/frenet/shipping.css</name></action>
21+
</reference>
422
<block type="frenet_shipping/catalog_product_view_quote" name="product.info.frenet.shipping.quote" as="frenet.shipping.quote" template="frenet/shipping/catalog/product/view/quote.phtml">
523
</block>
624
<reference name="product.info.extrahint">

app/design/frontend/base/default/template/frenet/shipping/catalog/product/view/quote.phtml

Lines changed: 14 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ $product = $this->getProduct();
2020
?>
2121

2222
<?php if ($product->isSaleable()) :?>
23-
<!-- <script type="text/x-magento-init">-->
24-
<!-- {-->
25-
<!-- "*": {-->
26-
<!-- "Magento_Ui/js/core/app": --><?//= $block->getJsLayout() ?>
27-
<!-- }-->
28-
<!-- }-->
29-
<!-- </script>-->
30-
<div class="box-frenet-quote" data-bind="scope: 'frenet-quote'">
23+
<div class="box-frenet-quote">
3124
<div class="fieldset">
3225
<h2><?php echo $this->__('Shipping Quote')?></h2>
3326
<p><?php echo $this->__('Calculate the shipping quote for this product with Frenet.')?></p>
@@ -42,8 +35,7 @@ $product = $this->getProduct();
4235
min="0"
4336
value=""
4437
maxlength="9"
45-
class="input-text postcode"
46-
data-validate="required: true"
38+
class="input-text postcode required"
4739
data-bind="value: postcode, event: {change: activate}, attr: {title: fieldTitle}"
4840
/>
4941
</div>
@@ -60,89 +52,29 @@ $product = $this->getProduct();
6052
<div data-bind="visible: displayNoResults">
6153
<span data-bind="text: noResultsMessage"></span>
6254
</div>
63-
<table data-bind="visible: visible" class="data table">
55+
<table id="frenet-result-table" class="data-table" style="display: none;">
6456
<col width="60%">
65-
<col width="10%">
66-
<col width="10%">
57+
<col width="20%">
58+
<col width="20%">
6759
<thead>
6860
<tr>
69-
<th data-bind="i18n: 'Description'"></th>
70-
<th data-bind="i18n: 'Time'"></th>
71-
<th data-bind="i18n: 'Price'"></th>
61+
<th><?php echo $this->__('Description') ?></th>
62+
<th><?php echo $this->__('Delivery Time') ?></th>
63+
<th><?php echo $this->__('Price') ?></th>
7264
</tr>
7365
</thead>
74-
<tbody>
75-
<!-- ko foreach: rates -->
76-
<tr>
77-
<td data-bind="text: service_description"></td>
78-
<td data-bind="text: delivery_time"></td>
79-
<td data-bind="text: shipping_price"></td>
80-
</tr>
81-
<tr data-bind="visible: message" class="footer">
82-
<td colspan="4">
83-
<small class="note" data-bind="text: message"></small>
84-
</td>
85-
</tr>
86-
<!-- /ko -->
66+
<tbody id="frenet-result-table-body">
8767
</tbody>
8868
</table>
8969
</div>
90-
<div id="frenet-loader" data-mage-init='{"loader": {}}'>
70+
<div id="frenet-loader">
9171
</div>
9272
</div>
9373
</div>
9474
<script type="text/javascript">
95-
var productQuote = Class.create();
96-
productQuote.prototype = {
97-
initialize: function () {
98-
this.url = '/frenet/product/quote';
99-
this.postcode = null;
100-
this.active = false;
101-
this.field = $('frenet-postcode-field');
102-
this.button = $('frenet-postcode-button');
103-
104-
// this.field.observe('change', this.updateRates.bind(this));
105-
this.button.observe('click', this.updateRates.bind(this));
106-
},
107-
updateRates: function () {
108-
this.postcode = this.field.value;
109-
if (this.postcode) {
110-
// this.loaderStart();
111-
112-
new Ajax.Request(this.url, {
113-
method: 'POST',
114-
parameters: $('product_addtocart_form').serialize(),
115-
onSuccess: this.processSuccess.bind(this),
116-
onFailure: this.processFailure.bind(this),
117-
onComplete: this.processAlways.bind(this)
118-
});
119-
}
120-
121-
// if (!this.postcode()) {
122-
// this.reset();
123-
// }
124-
},
125-
processSuccess: function (result) {
126-
console.log("RESULT SUCCESS", result);
127-
// if (result.error) {
128-
// this.processFailure(result);
129-
// return;
130-
// }
131-
132-
// this.pushRates(result.rates);
133-
},
134-
processFailure: function (result) {
135-
console.log("RESULT FAILURE", result);
136-
// this.reset();
137-
// this.errorMessage(result.message);
138-
// this.error(true);
139-
},
140-
processAlways: function (result) {
141-
console.log("RESULT ALWAYS", result);
142-
// this.loaderStop();
143-
},
144-
}
145-
146-
var quote = new productQuote();
75+
var config = {
76+
priceFormat: JSON.parse('<?php echo json_encode(Mage::app()->getLocale()->getJsPriceFormat()) ?>')
77+
};
78+
var quote = new ProductQuote(config);
14779
</script>
14880
<?php endif; ?>

app/locale/pt_BR/Frenet/Shipping.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@
3030
"Debug Filename","Nome do Arquivo de Log"
3131
"Sort Order","Ordenação"
3232
"When the cart's total weight is greater than the limit (30kg) multiple calls will be done for Correios.<br/><br/><b>Note</b>: with this feature enabled you'll need to ship the products in diferent packages.<br/><br/><b style='color:red;'>Warning</b>: The shipping rules and restrictions based in cart total or weight may not work properly when this option is enabled.","Quando o peso total do carrinho for maior do que o limite (30kg), múltiplas cotações serão feitas para o método dos Correios apenas.<br/><br/><b>Nota</b>: com essa funcionalidade habilitada você precisará enviar os produtos em pacotes diferentes.<br/><br/><b style='color:red;'>Warning</b>: As regras e restrições de frete baseada em valor de carrinho ou peso pode não funcionar corretamente ao habilitar essa funcionalidade."
33+
"Calculate the shipping quote for this product with Frenet.","Calcule a cotação de entrega para este produto com a Frenet."
34+
"Postcode","CEP"
35+
"Get Quote","Obter Cotação"
36+
"Description","Descrição"
37+
"Delivery Time","Tempo de Entrega"
38+
"Price","Preço"
39+
" day(s)"," dias(s)"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Frenet Shipping Gateway
3+
*
4+
* @category Frenet
5+
*
6+
* @author Tiago Sampaio <tiago@tiagosampaio.com>
7+
* @link https://github.com/tiagosampaio
8+
* @link https://tiagosampaio.com
9+
*
10+
* Copyright (c) 2020.
11+
*/
12+
13+
.box-frenet-quote {
14+
margin: 20px 0;
15+
}
16+
17+
.box-frenet-quote .data-table {
18+
margin: 20px 0;
19+
}
20+
21+
.box-frenet-quote .field {
22+
margin-top: 10px;
23+
}
24+
25+
.box-frenet-quote .field .postcode {
26+
margin: 10px 0;
27+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* Frenet Shipping Gateway
3+
*
4+
* @category Frenet
5+
*
6+
* @author Tiago Sampaio <tiago@tiagosampaio.com>
7+
* @link https://github.com/tiagosampaio
8+
* @link https://tiagosampaio.com
9+
*
10+
* Copyright (c) 2020.
11+
*/
12+
13+
var ProductQuote = Class.create();
14+
ProductQuote.prototype = {
15+
initialize: function (config) {
16+
this.url = '/frenet/product/quote';
17+
this.postcode = null;
18+
this.active = false;
19+
this.field = $('frenet-postcode-field');
20+
this.button = $('frenet-postcode-button');
21+
this.table = $('frenet-result-table');
22+
this.tableBody = $('frenet-result-table-body');
23+
this.errorMessage = null;
24+
this.priceFormat = config.priceFormat;
25+
26+
this.field.observe('change', this.check.bind(this));
27+
this.button.observe('click', this.updateRates.bind(this));
28+
this.disable();
29+
},
30+
check: function () {
31+
if (this.field.value.length === 0) {
32+
this.disable();
33+
this.reset();
34+
return;
35+
}
36+
37+
this.enable();
38+
},
39+
reset: function () {
40+
this.table.hide();
41+
this.tableBody.update('');
42+
},
43+
updateRates: function () {
44+
this.postcode = this.field.value;
45+
this.reset();
46+
47+
if (this.postcode) {
48+
// this.loaderStart();
49+
50+
new Ajax.Request(this.url, {
51+
method: 'POST',
52+
parameters: $('product_addtocart_form').serialize(),
53+
onSuccess: this.processSuccess.bind(this),
54+
onFailure: this.processFailure.bind(this),
55+
onComplete: this.processAlways.bind(this)
56+
});
57+
}
58+
59+
if (!this.postcode) {
60+
}
61+
},
62+
processSuccess: function (result) {
63+
// console.log("RESULT SUCCESS", result);
64+
var response = result.responseJSON;
65+
66+
if (response.error) {
67+
this.processFailure(result);
68+
return;
69+
}
70+
71+
this.pushRates(response.rates);
72+
},
73+
processFailure: function (result) {
74+
// console.log("RESULT FAILURE", result);
75+
// this.reset();
76+
this.errorMessage(result.message);
77+
// this.error(true);
78+
},
79+
processAlways: function (result) {
80+
console.log("RESULT ALWAYS", result);
81+
this.table.show();
82+
// this.loaderStop();
83+
},
84+
pushRates: function (rates) {
85+
var Rates = $A(rates);
86+
87+
if (Rates.size() <= 0) {
88+
return;
89+
// this.visible(true);
90+
// this.error(false);
91+
// this.deactivate();
92+
}
93+
94+
Rates.each(this.appendRate.bind(this));
95+
96+
// if (rates.length === 0) {
97+
// this.visible(false);
98+
// }
99+
100+
// this.displayNoResults(!this.visible());
101+
},
102+
appendRate: function (rate, index) {
103+
var row = new Element('tr');
104+
this.createColumn(row, rate.service_description);
105+
this.createColumn(row, this.formatDeliveryTime(rate.delivery_time));
106+
this.createColumn(row, this.formatPrice(rate.shipping_price));
107+
this.tableBody.appendChild(row);
108+
},
109+
createColumn: function (row, text) {
110+
row.appendChild(new Element('td').update(text))
111+
},
112+
formatDeliveryTime: function (days) {
113+
return days + Translator.translate(' day(s)')
114+
},
115+
formatPrice: function (price) {
116+
return formatCurrency(price, this.priceFormat);
117+
},
118+
disable: function () {
119+
this.button.addClassName('disabled');
120+
},
121+
enable: function () {
122+
this.button.removeClassName('disabled');
123+
}
124+
}

0 commit comments

Comments
 (0)