Skip to content

Instantly share code, notes, and snippets.

@reindert-vetter
Created December 7, 2016 15:28
Show Gist options
  • Save reindert-vetter/4384daf7b811dffa9d847928a1ea1207 to your computer and use it in GitHub Desktop.
Save reindert-vetter/4384daf7b811dffa9d847928a1ea1207 to your computer and use it in GitHub Desktop.
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category design
* @package base_default
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
?>
<?php
/**
* @var $this Mage_Checkout_Block_Onepage_Shipping_Method_Available
* @var TIG_MyParcel2014_Helper_AddressValidation $helper
*/
$_shippingRateGroups = $this->getShippingRates();
$helper = Mage::helper('tig_myparcel/addressValidation');
$hideDays = $helper->getConfig('deliverydays_window', 'checkout') == '1' ? true : false;
/** Check if the checkout must use the MyParcel checkout */
$address = $helper->getQuoteAddress($this->getQuote());
if (isset($address) && is_array($address) && key_exists('country', $address)) {
$country = $address['country'];
} else {
$country = false;
}
$useMyParcel = ($_shippingRateGroups && $country == 'NL');
/**
* Hide and toggle MyParcel options (used by parnis.nl). Hidden field in the settings.
* Example: https://monosnap.com/file/gJ9DoOhbJF6p0qMit0NmjCMjNhP8rM
*/
$toggleOptions = $helper->getConfig('toggle_options', 'checkout') == '1' ? true : false;
?>
<script>myParcelToggleOptions = '<?php echo $toggleOptions;?>'</script>
<?php if (!$_shippingRateGroups): ?>
<p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
<?php else: ?>
<dl class="sp-methods shipment-methods">
<?php $shippingCodePrice = array(); ?>
<?php $_sole = count($_shippingRateGroups) == 1;
foreach ($_shippingRateGroups as $code => $_rates): ?>
<?php $hideRate = $code == 'myparcel' && $useMyParcel && !$toggleOptions; ?>
<dt style="<?php echo $hideRate ? 'display:none;' : '';?>" class="<?php echo $code . '_holder'; ?>"><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
<dd style="<?php echo $hideRate ? 'display:none;' : '';?>" class="<?php echo $code . '_holder'; ?>">
<ul>
<?php $_sole = $_sole && count($_rates) == 1;
$lastRate = null;
foreach ($_rates as $_rate): ?>
<?php if ($_rate->getCode() != $lastRate): ?>
<?php $lastRate = $_rate->getCode(); ?>
<?php $shippingCodePrice[] = "'" . $_rate->getCode() . "':" . (float)$_rate->getPrice(); ?>
<li style="<?php if ($code == 'myparcel') echo $_rate->getMethod() != 'flatrate' && $_rate->getMethod() != 'tablerate' ? 'display:none' : '';?>">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages">
<li class="error-msg">
<ul>
<li><?php echo $this->escapeHtml($_rate->getErrorMessage()) ?></li>
</ul>
</li>
</ul>
<?php else: ?>
<?php if ($_sole) : ?>
<span class="no-display"><input name="shipping_method" type="radio"
value="<?php echo $_rate->getCode() ?>"
id="s_method_<?php echo $_rate->getCode() ?>"
checked="checked"/></span>
<?php else: ?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>"
id="s_method_<?php echo $_rate->getCode() ?>"<?php if ($_rate->getCode() === $this->getAddressShippingMethod()) echo ' checked="checked"' ?>
class="radio <?php
if ($code == 'myparcel') {
if ($_rate->getMethod() != 'flatrate' && $_rate->getMethod() != 'tablerate') {
echo 'myparcel_method myparcel_extra_method';
} else {
echo 'myparcel_method myparcel_base_method';
}
}
?>"/>
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
<script type="text/javascript">
//<![CDATA[
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
//]]>
</script>
<?php endif; ?>
<?php endif; ?>
<label for="s_method_<?php echo $_rate->getCode() ?>">
<?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
<?php if ($code != 'myparcel' || !$toggleOptions):?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?><?php echo $_incl; ?>)
<?php endif; ?>
<?php endif;?>
</label>
<?php endif ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</dd>
<?php if ($code == 'myparcel' && $useMyParcel): ?>
<div id="mypa-load" style="<?php echo $toggleOptions && $_rate->getCode() !== $this->getAddressShippingMethod() ? 'display: none;' : ''; ?>">
<iframe id="myparcel-iframe" src="<?php echo Mage::getUrl('',array('_secure'=>true));?>/myparcel2014/checkout/checkout_options" frameborder="0" scrolling="auto" style="width: 100%;" >Bezig met laden...</iframe>
<input style="display: none;" id="mypa-input" name="mypa-post-nl-data">
<input style="display: none;" type="checkbox" name='mypa-signed' id="mypa-signed">
<input style="display: none;" type="checkbox" name='mypa-recipient-only' id="mypa-recipient-only">
</div>
<?php endif; ?>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
//<![CDATA[
if (typeof quoteBaseGrandTotal == 'undefined') {
var quoteBaseGrandTotal;
}
<?php if (!empty($shippingCodePrice)): ?>
var shippingCodePrice = {<?php echo implode(',', $shippingCodePrice); ?>};
<?php endif; ?>
$$('input[type="radio"][name="shipping_method"]').each(function (el) {
Event.observe(el, 'click', function () {
if (el.checked == true) {
var getShippingCode = el.getValue();
<?php if (!empty($shippingCodePrice)): ?>
var newPrice = shippingCodePrice[getShippingCode];
if (!lastPrice) {
lastPrice = newPrice;
quoteBaseGrandTotal += newPrice;
}
if (newPrice != lastPrice) {
quoteBaseGrandTotal += (newPrice - lastPrice);
lastPrice = newPrice;
}
<?php endif; ?>
checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
return false;
}
});
});
//]]>
</script>
<?php if ($useMyParcel) : ?>
<script>
mypajQuery(document).ready(function () {
iframeLoaded();
mypajQuery('#mypa-input').on('change', (function () {
iframeLoaded()
}));
});
</script>
<?php endif; ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment