Skip to content

Commit c8e489f

Browse files
committed
Adjustments.
1 parent 3daa90a commit c8e489f

File tree

5 files changed

+72
-9
lines changed

5 files changed

+72
-9
lines changed

app/code/community/Frenet/Shipping/Helper/Objects.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* Class Frenet_Shipping_Helper_Objects
54
*/

app/code/community/Frenet/Shipping/Model/Catalog/Product/View/Quote.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*
1111
* Copyright (c) 2020.
1212
*/
13+
Frenet_Shipping_Model_DependencyFinder::includeDependency();
14+
1315
use Mage_Catalog_Model_Product as Product;
1416
use Mage_Shipping_Model_Rate_Request as RateRequest;
1517
use Frenet_Shipping_Model_Rate_Request_Provider as RateRequestProvider;
@@ -53,10 +55,18 @@ public function __construct()
5355
public function quoteByProductId($productId, $postcode, $qty = 1, array $options = [])
5456
{
5557
try {
58+
if (!$postcode) {
59+
Mage::throwException('Postcode cannot be empty.');
60+
}
61+
5662
/** @var Product $product */
5763
$product = Mage::getModel('catalog/product')->load($productId);
64+
65+
if (!$product || !$product->getId()) {
66+
Mage::throwException("Product ID '{$productId}' does not exist.");
67+
}
5868
} catch (Exception $exception) {
59-
Mage::log('Product ID %s does not exist.', $productId);
69+
Mage::log($exception->getMessage());
6070

6171
return [];
6272
}
@@ -84,7 +94,7 @@ public function quoteByProductSku($sku, $postcode, $qty = 1, array $options = []
8494
/**
8595
* @inheritDoc
8696
*/
87-
private function quote(Product $product, string $postcode, int $qty = 1, $options = [])
97+
private function quote(Product $product, $postcode, $qty = 1, $options = [])
8898
{
8999
/** @var RateRequest $rateRequest */
90100
$rateRequest = $this->rateRequestBuilder->build($product, $postcode, $qty, $options);

app/code/community/Frenet/Shipping/Model/Catalog/Product/View/Rate/Request/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private function fixQuoteItems(Mage_Sales_Model_Quote $quote)
110110
*
111111
* @return float
112112
*/
113-
private function getItemRowWeight(QuoteItem $item, $qty) : float
113+
private function getItemRowWeight(QuoteItem $item, $qty)
114114
{
115115
$this->dimensionsExtractor->setProductByCartItem($item);
116116
$weight = $this->dimensionsExtractor->getWeight();

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()->getParam('product');
20-
$postcode = (string) $this->getRequest()->getParam('postcode');
21-
$qty = (float) $this->getRequest()->getParam('qty');
22-
$options = (array) $this->getRequest()->getParams();
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/design/frontend/base/default/template/frenet/shipping/catalog/product/view/quote.phtml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $product = $this->getProduct();
4949
</div>
5050
</div>
5151
<div class="actions">
52-
<button type="button" class="button btn-cart">
52+
<button type="button" id="frenet-postcode-button" class="button btn-cart">
5353
<span><?php echo $this->__('Get Quote')?></span>
5454
</button>
5555
</div>
@@ -91,4 +91,58 @@ $product = $this->getProduct();
9191
</div>
9292
</div>
9393
</div>
94+
<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();
147+
</script>
94148
<?php endif; ?>

0 commit comments

Comments
 (0)