cancel
Showing results for 
Search instead for 
Did you mean: 

Ability to add additional phtml to each shipping method

0 Kudos

Ability to add additional phtml to each shipping method

Feature request from toonvd, posted on GitHub Jul 28, 2015

This was not possible in Magento 1 for shipping methods but was for payment methods. This makes shipping extension creators override phtmls every time. Could it be usefull to make sure we can do this in Magento 2?

To be clear, I want shipping method - custom template file, shipping method - custom template file (not required to add one tough)

21 Comments
apiuser
New Member

Comment from jensvandorpe, posted on GitHub Jul 29, 2015

+1

apiuser
New Member

Comment from vpelipenko, posted on GitHub Jul 29, 2015

Guys, let's summarize. @Toonvd, are you going to provide some examples?

apiuser
New Member

Comment from septembrium, posted on GitHub Jul 29, 2015

+1

apiuser
New Member

Comment from toonvd, posted on GitHub Jul 29, 2015

@vpelipenko ok, I will do it in Mage 1 code (how I would do it): Shipping method phtml (changes marked by start custom changes):

<?php $_sole = count($_shippingRateGroups) == 1;
foreach ($_shippingRateGroups as $code => $_rates): ?>
    <dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
    <dd>
        <ul>
            <?php $_sole = $_sole && count($_rates) == 1;
            foreach ($_rates as $_rate): ?>
                <?php $shippingCodePrice[] = "'" . $_rate->getCode() . "':" . (float)$_rate->getPrice(); ?>
                <li>
                    <?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 ($_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 $_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; ?>
                        </label>
                    <?php endif ?>
                   // start custom changes
                    <?php if ($html = $this->getShippingMethodFormHtml($_rate->getCode())): ?>
                        <span>
                          <?php echo $html; ?>
                     </span>
                    <?php endif; ?>
                  // end custom changes
                </li>
            <?php endforeach; ?>
        </ul>
    </dd>
<?php endforeach; ?>

Block:

    public function getShippingMethodFormHtml($rateCode)
    {
         return $this->getChildHtml('shipping.method.' . rateCode);
    }
apiuser
New Member

Comment from toonvd, posted on GitHub Jul 29, 2015

Image of Stackoverflow

Payment method equivalent

apiuser
New Member

Comment from toonvd, posted on GitHub Jul 29, 2015

@vpelipenko clear enough? or do you need more examples? (not used to doing this stuff Smiley Happy )

apiuser
New Member

Comment from pronto2000, posted on GitHub Jul 29, 2015

Actually this is an improvement I'd LOVE to see backported to Magento 1 as well.

apiuser
New Member

Comment from ilol, posted on GitHub Aug 05, 2015

I put the improvement into our backlog. Will keep you inform with this task. Tracking id is MAGETWO-41144

apiuser
New Member

Comment from toonvd, posted on GitHub Aug 05, 2015

awesome, thank you @ilol !

apiuser
New Member

Comment from toonvd, posted on GitHub Jan 08, 2016

@ilol any news on this? Cliënts will want to start porting shipping extension to Mage 2 soon.