Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- Improvements to frontend.
  • Loading branch information
tiagosampaio committed May 14, 2020
1 parent e60691d commit 3daa90a
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Class Frenet_Shipping_Block_Catalog_Product_View_Quote
*/
class Frenet_Shipping_Block_Catalog_Product_View_Quote extends Mage_Core_Block_Template
class Frenet_Shipping_Block_Catalog_Product_View_Quote extends Mage_Catalog_Block_Product_View
{
use Frenet_Shipping_Helper_ObjectsTrait;

Expand Down
35 changes: 35 additions & 0 deletions app/code/community/Frenet/Shipping/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,41 @@ public function getDebugFilename($store = null)
return (string) $this->getCarrierConfig('debug_filename', $store);
}

/**
* @param null|string|int|Mage_Core_Model_Store $store
*
* @return bool
*/
public function isProductQuoteEnabled($store = null)
{
return (bool) $this->getCarrierConfig('product_quote_enabled', $store);
}

/**
* @param string $productTypeId
* @param null|string|int|Mage_Core_Model_Store $store
*
* @return bool
*/
public function isProductQuoteAllowed($productTypeId, $store = null)
{
$allowedTypes = $this->getProductQuoteProductTypes($store);
return in_array($productTypeId, $allowedTypes);
}

/**
* @param null|string|int|Mage_Core_Model_Store $store
*
* @return array
*/
public function getProductQuoteProductTypes($store = null)
{
return explode(
',',
$this->getCarrierConfig('product_quote_product_types', $store)
);
}

/**
* @param string|int|Mage_Core_Model_Store $store
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@
use Frenet_Shipping_Model_Catalog_ProductType as ProductType;

/**
* Class ProductTypes
*
* @package Frenet\Shipping\Model\Config\Source\Catalog\Product\Quote
* Class Frenet_Shipping_Model_Config_Source_Product_Quote_Product_Types
*/
class Frenet_Shipping_Model_Config_Source_Catalog_Product_Quote_ProductTypes
class Frenet_Shipping_Model_Config_Source_Product_Quote_Product_Types
{
/**
* @var array
*/
private $options = [];

/**
* @var Frenet_Shipping_Helper_Data
*/
private $helper;

public function __construct()
{
$this->helper = Mage::helper('frenet_shipping');
}

/**
* Return array of options as value-label pairs
*
Expand Down Expand Up @@ -53,10 +61,10 @@ public function toOptionArray()
public function toArray()
{
$this->options = [
ProductType::TYPE_SIMPLE => Mage::helper('frenet_shipping')->__('Simple Products'),
ProductType::TYPE_CONFIGURABLE => Mage::helper('frenet_shipping')->__('Configurable Products'),
ProductType::TYPE_BUNDLE => Mage::helper('frenet_shipping')->__('Bundle Products'),
ProductType::TYPE_GROUPED => Mage::helper('frenet_shipping')->__('Grouped Products'),
ProductType::TYPE_SIMPLE => $this->helper->__('Simple Products'),
ProductType::TYPE_CONFIGURABLE => $this->helper->__('Configurable Products'),
ProductType::TYPE_BUNDLE => $this->helper->__('Bundle Products'),
ProductType::TYPE_GROUPED => $this->helper->__('Grouped Products'),
];

return $this->options;
Expand Down
11 changes: 11 additions & 0 deletions app/code/community/Frenet/Shipping/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
</frenet_shipping>
</modules>
</translate>
<layout>
<updates>
<frenet_shipping>
<file>frenet/frenet_shipping.xml</file>
</frenet_shipping>
</updates>
</layout>
<routers>
<frenet_shipping>
<use>standard</use>
Expand Down Expand Up @@ -112,6 +119,10 @@
<default_measurements_default_length>16</default_measurements_default_length>
<default_measurements_default_width>11</default_measurements_default_width>

<!-- PRODUCT QUOTE -->
<product_quote_enabled>1</product_quote_enabled>
<product_quote_product_types>simple,configurable,bundle,grouped</product_quote_product_types>

<!-- DEBUG -->
<debug>0</debug>
<debug_filename>frenet_request_debug.log</debug_filename>
Expand Down
29 changes: 29 additions & 0 deletions app/code/community/Frenet/Shipping/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,35 @@
</depends>
</default_measurements_default_width>

<!-- PRODUCT QUOTE OPTIONS -->
<product_quote_enabled translate="label">
<label>Product Quote Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_enabledisable</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<sort_order>220</sort_order>
<comment><![CDATA[If enabled the product shipping quote will be possible from product page.]]></comment>
<depends>
<active>1</active>
</depends>
</product_quote_enabled>
<product_quote_product_types translate="label">
<label>Product Quote Enable for Product Types</label>
<frontend_type>multiselect</frontend_type>
<source_model>frenet_shipping/config_source_product_quote_product_types</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<sort_order>230</sort_order>
<comment><![CDATA[These are the product types allowed to be quote in the product page.]]></comment>
<depends>
<product_quote_enabled>1</product_quote_enabled>
<active>1</active>
</depends>
</product_quote_product_types>

<!-- ADDITIONAL LEAD TIME -->
<additional_lead_time translate="label">
<label>Additional Lead Time</label>
Expand Down
32 changes: 32 additions & 0 deletions app/design/frontend/base/default/layout/frenet/frenet_shipping.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<layout version="0.1.0">
<frenet_product_shipping_quote>
<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">
</block>
<reference name="product.info.extrahint">
<action method="append">
<block>product.info.frenet.shipping.quote</block>
</action>
</reference>
</frenet_product_shipping_quote>

<!-- Simple Products -->
<PRODUCT_TYPE_simple>
<update handle="frenet_product_shipping_quote" />
</PRODUCT_TYPE_simple>

<!-- Configurable Products -->
<PRODUCT_TYPE_configurable>
<update handle="frenet_product_shipping_quote" />
</PRODUCT_TYPE_configurable>

<!-- Bundle Products -->
<PRODUCT_TYPE_bundle>
<update handle="frenet_product_shipping_quote" />
</PRODUCT_TYPE_bundle>

<!-- Grouped Products -->
<PRODUCT_TYPE_grouped>
<update handle="frenet_product_shipping_quote" />
</PRODUCT_TYPE_grouped>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Frenet Shipping Gateway
*
* @category Frenet
*
* @author Tiago Sampaio <[email protected]>
* @link https://github.com/tiagosampaio
* @link https://tiagosampaio.com
*
* Copyright (c) 2020.
*/

/**
* @var Frenet_Shipping_Block_Catalog_Product_View_Quote $this
* @var Mage_Catalog_Model_Product $product
*/

$product = $this->getProduct();
?>

<?php if ($product->isSaleable()) :?>
<!-- <script type="text/x-magento-init">-->
<!-- {-->
<!-- "*": {-->
<!-- "Magento_Ui/js/core/app": --><?//= $block->getJsLayout() ?>
<!-- }-->
<!-- }-->
<!-- </script>-->
<div class="box-frenet-quote" data-bind="scope: 'frenet-quote'">
<div class="fieldset">
<h2><?php echo $this->__('Shipping Quote')?></h2>
<p><?php echo $this->__('Calculate the shipping quote for this product with Frenet.')?></p>
<div class="field">
<label class="label" for="frenet-postcode-field">
<span><?php echo $this->__('Postcode') ?></span>
</label>
<div class="control">
<input type="text"
name="postcode"
id="frenet-postcode-field"
min="0"
value=""
maxlength="9"
class="input-text postcode"
data-validate="required: true"
data-bind="value: postcode, event: {change: activate}, attr: {title: fieldTitle}"
/>
</div>
</div>
<div class="actions">
<button type="button" class="button btn-cart">
<span><?php echo $this->__('Get Quote')?></span>
</button>
</div>
<div class="table-wrapper">
<div data-bind="visible: error">
<span class="text-red" data-bind="text: errorMessage"></span>
</div>
<div data-bind="visible: displayNoResults">
<span data-bind="text: noResultsMessage"></span>
</div>
<table data-bind="visible: visible" class="data table">
<col width="60%">
<col width="10%">
<col width="10%">
<thead>
<tr>
<th data-bind="i18n: 'Description'"></th>
<th data-bind="i18n: 'Time'"></th>
<th data-bind="i18n: 'Price'"></th>
</tr>
</thead>
<tbody>
<!-- ko foreach: rates -->
<tr>
<td data-bind="text: service_description"></td>
<td data-bind="text: delivery_time"></td>
<td data-bind="text: shipping_price"></td>
</tr>
<tr data-bind="visible: message" class="footer">
<td colspan="4">
<small class="note" data-bind="text: message"></small>
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
</div>
<div id="frenet-loader" data-mage-init='{"loader": {}}'>
</div>
</div>
</div>
<?php endif; ?>

0 comments on commit 3daa90a

Please sign in to comment.