Skip to content

Commit

Permalink
Adjustments.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosampaio committed May 18, 2020
1 parent 3daa90a commit c8e489f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/code/community/Frenet/Shipping/Helper/Objects.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Class Frenet_Shipping_Helper_Objects
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
* Copyright (c) 2020.
*/
Frenet_Shipping_Model_DependencyFinder::includeDependency();

use Mage_Catalog_Model_Product as Product;
use Mage_Shipping_Model_Rate_Request as RateRequest;
use Frenet_Shipping_Model_Rate_Request_Provider as RateRequestProvider;
Expand Down Expand Up @@ -53,10 +55,18 @@ public function __construct()
public function quoteByProductId($productId, $postcode, $qty = 1, array $options = [])
{
try {
if (!$postcode) {
Mage::throwException('Postcode cannot be empty.');
}

/** @var Product $product */
$product = Mage::getModel('catalog/product')->load($productId);

if (!$product || !$product->getId()) {
Mage::throwException("Product ID '{$productId}' does not exist.");
}
} catch (Exception $exception) {
Mage::log('Product ID %s does not exist.', $productId);
Mage::log($exception->getMessage());

return [];
}
Expand Down Expand Up @@ -84,7 +94,7 @@ public function quoteByProductSku($sku, $postcode, $qty = 1, array $options = []
/**
* @inheritDoc
*/
private function quote(Product $product, string $postcode, int $qty = 1, $options = [])
private function quote(Product $product, $postcode, $qty = 1, $options = [])
{
/** @var RateRequest $rateRequest */
$rateRequest = $this->rateRequestBuilder->build($product, $postcode, $qty, $options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function fixQuoteItems(Mage_Sales_Model_Quote $quote)
*
* @return float
*/
private function getItemRowWeight(QuoteItem $item, $qty) : float
private function getItemRowWeight(QuoteItem $item, $qty)
{
$this->dimensionsExtractor->setProductByCartItem($item);
$weight = $this->dimensionsExtractor->getWeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ protected function _construct()

public function quoteAction()
{
$productId = (int) $this->getRequest()->getParam('product');
$postcode = (string) $this->getRequest()->getParam('postcode');
$qty = (float) $this->getRequest()->getParam('qty');
$options = (array) $this->getRequest()->getParams();
$productId = (int) $this->getRequest()->getPost('product');
$postcode = (string) $this->getRequest()->getPost('postcode');
$qty = (float) $this->getRequest()->getPost('qty');
$options = (array) $this->getRequest()->getPost();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $product = $this->getProduct();
</div>
</div>
<div class="actions">
<button type="button" class="button btn-cart">
<button type="button" id="frenet-postcode-button" class="button btn-cart">
<span><?php echo $this->__('Get Quote')?></span>
</button>
</div>
Expand Down Expand Up @@ -91,4 +91,58 @@ $product = $this->getProduct();
</div>
</div>
</div>
<script type="text/javascript">
var productQuote = Class.create();
productQuote.prototype = {
initialize: function () {
this.url = '/frenet/product/quote';
this.postcode = null;
this.active = false;
this.field = $('frenet-postcode-field');
this.button = $('frenet-postcode-button');

// this.field.observe('change', this.updateRates.bind(this));
this.button.observe('click', this.updateRates.bind(this));
},
updateRates: function () {
this.postcode = this.field.value;
if (this.postcode) {
// this.loaderStart();

new Ajax.Request(this.url, {
method: 'POST',
parameters: $('product_addtocart_form').serialize(),
onSuccess: this.processSuccess.bind(this),
onFailure: this.processFailure.bind(this),
onComplete: this.processAlways.bind(this)
});
}

// if (!this.postcode()) {
// this.reset();
// }
},
processSuccess: function (result) {
console.log("RESULT SUCCESS", result);
// if (result.error) {
// this.processFailure(result);
// return;
// }

// this.pushRates(result.rates);
},
processFailure: function (result) {
console.log("RESULT FAILURE", result);
// this.reset();
// this.errorMessage(result.message);
// this.error(true);
},
processAlways: function (result) {
console.log("RESULT ALWAYS", result);
// this.loaderStop();
},
}

var quote = new productQuote();
</script>
<?php endif; ?>

0 comments on commit c8e489f

Please sign in to comment.