2

I'm currently working on a custom shipping method for Magento 1.9.

Right now, I have to add a custom field in the checkout page and fill it with the timeslots available for delivery (I plan to add a select field).

I followed this tutorial : http://excellencemagentoblog.com/blog/2015/08/20/checkout-add-extra-address-field/#disqus_thread to create a custom field and save it in the database when the customer make an order.

It's working but I don't know how to change the field position from billing/shipping address block to shipping method block. I want to place my field after the shipping methods.

I tried to do something like this :

layout file (app/design/frontend/base/default/layout/address.xml) :

<?xml version="1.0"?>
<layout version="0.1.0">
    <checkout_onepage_index>
        <reference name='checkout.onepage.shipping_method.available'>
            <block type='checkout/onepage_shipping_method_available' name='form.additional.info' template='checkout/onepage/shipping_method/timeslots_field.phtml'></block>
            <!-- <block type='checkout/onepage_shipping_method' name='form.additional.info' template='address/checkout/onepage/billing_field.phtml'></block> -->
        </reference>
    </checkout_onepage_index>
</layout>

template file (app/design/frontend/base/default/template/checkout/onepage/shipping_method/timeslots_field.phtml) :

<div class="field">
    <label for="available:delivery_instruction" class="required">
        <?php echo $this->__('Delivery Instructions') ?>
    </label>
    <div class="input-box">
        <input type="text" name="available[delivery_instruction]" id="available:delivery_instruction" value="<?php echo $this->escapeHtml($this->getAddress()->getDeliveryInstruction()) ?>" title="<?php echo $this->__('Delivery Instructions') ?>" class="input-text required-entry" />
    </div>
</div>

template file (app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml)

// lot of stuff
<?php echo $this->getChildHtml('form.additional.info'); ?>

Does someone can help me ?

Thanks.

Edit : edited code with newest version, I can't manage to make it work.

4

Don't change base files; create copy of

/app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml

To

 /app/design/frontend/default/default/template/checkout/onepage/shipping_method/available.phtml

Now add line

<?php echo $this->getChildHtml('form.additional.info'); ?>

At last in phtml.

  • Thanks. If I understand well : I create copy of /app/design/frontend/base files I need in /app/design/frontend/default (e.g. my layout and my template) instead of using directly base files. Btw, which template should I use ? available.phtml or my template (timeslots_field.phtml). Next, I just have to add the $this->getChildHtml() line to make it work. Well... I tried but it doesn't work (the field is not appearing). – cdauphin Mar 23 '16 at 13:11
  • did you try adding <?php echo $this->getChildHtml('form.additional.info'); ?> in available.phtml ? – PHP Mar 24 '16 at 6:55
  • Yes, I also tried something like this : Test1 <?php echo $this->getChildHtml('form.additional.info'); ?> Test2 I can see Test1 & Test2 but there is nothing between them. – cdauphin Mar 24 '16 at 8:31
2

You should add call

$this->getChildHtml('form.additional.info')

in template of

checkout.onepage.shipping_method

block in the place where you want to see it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.