0

I have created a module for the Onepage checkout that overrides and adds a custom step. The progress for this step is shown until I submit the information and then the progress block disappears entirely from the page. I'm using a custom rwd theme and followed mostly this tutorial: http://www.boolfly.com/add-custom-fields-to-order-magento-part-1/ I've traced it down to where my custom template is not able to get the checkout session:

<?php if($this->getCheckout()->getStepData('extra_fields', 'complete')): ?>
<dt class="complete">
    <?php echo $this->__('Person Placing Order') ?> 
    <span class="separator">|</span> 
    <a href="#deliverydate" onclick="checkout.accordion.openSection('opc-extra_fields'); return false;"><?php echo $this->__('Change') ?></a>
</dt>
<dd class="complete">
    <div>
        <?php echo $this->__('Person Placing Order: ');?>
    </div>
    <p class="printout"><?php echo $this->getCheckout()->getData('ef_first_name').' '.$this->getCheckout()->getData('ef_last_name') ?></p>
</dd>
<?php else: ?>
    <dt>
        <?php echo $this->__('Person Placing Order') ?>
    </dt>
<?php endif; ?>

I set the 'extra_fields' value as complete in the method:

 public function saveExtraFieldsAction()
{
    if($this->_expireAjax()) {
        return;
    }

    if($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('extra', array());
        $result = $this->getOnepage()->saveExtraFields($data);
        Mage::log($result);
        if(!isset($result['error'])) {
            Mage::dispatchEvent(
                'checkout_controller_onepage_save_extrafields_method',
                array(
                    'request' => $this->getRequest(),
                    'quote'   => $this->getOnepage()->getQuote()));
            $this->getOnepage()->getQuote()->collectTotals();
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
            $result['goto_section'] = 'payment';
            $result['update_section'] = array(
                'name' => 'payment-method',
                'html' => $this->_getPaymentMethodsHtml()
            );
        }
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}

The layout file that overrides the checkout.xml:

<?xml version="1.0"?>
<layout version="0.1.0">
    <checkout_onepage_index>
        <reference name="checkout.onepage">
            <action method="setTemplate">
                    <template>extrafields/checkout/onepage.phtml</template>
                </action>
                <block type="extrafields_checkout/onepage_extrafields" name="extra_fields" as="extra_fields" 
                        template="extrafields/checkout/onepage/extrafields.phtml"/>
            </reference>
            <reference name="checkout.progress" before="-">
                <action method="setTemplate">
                    <template>extrafields/checkout/onepage/progress.phtml</template>
                </action>
                <block type="checkout/onepage_progress" name="fields.progress" as="fields.progress" template="extrafields/checkout/onepage/progress/fields.phtml"/>
                <block type="checkout/onepage_progress" name="billing.progress" template="extrafields/checkout/onepage/progress/billing.phtml"/>
            </reference>
        </checkout_onepage_index>
        <checkout_onepage_progress>
            <reference name="root">
                <action method="setTemplate">
                    <template>extrafields/checkout/onepage/progress.phtml</template>
                </action>
                <block type="checkout/onepage_progress" name="fields.progress" template="extrafields/checkout/onepage/progress/fields.phtml"/>
                <block type="checkout/onepage_progress" name="billing.progress" template="extrafields/checkout/onepage/progress/billing.phtml"/>
            </reference>
        </checkout_onepage_progress>
        <checkout_onepage_progress_billing>
            <reference name="root">
                <action method="setTemplate">
                    <template>extrafields/checkout/onepage/progress/billing.phtml</template>
                </action>
            </reference>
        </checkout_onepage_progress_billing>
        <checkout_onepage_progress_extra_fields>
            <remove name="right"/>
            <remove name="left"/>

            <block type="checkout/onepage_progress" name="root" output="toHtml" template="extrafields/checkout/onepage/progress/fields.phtml">
                <action method="setInfoTemplate"><method></method><template></template></action>
            </block>
        </checkout_onepage_progress_extra_fields>
    </layout>

Any ideas why the template file is not able to access the checkout session?

0

The problem was in the overridden OnePage Model Type saveShippingMethod:

    public function saveShippingMethod($shippingMethod)
{
    if (empty($shippingMethod)) {
        return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
    }
    $rate = $this->getQuote()->getShippingAddress()->getShippingRateByCode($shippingMethod);
    if (!$rate) {
        return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
    }
    $this->getQuote()->getShippingAddress()
        ->setShippingMethod($shippingMethod);

    $this->getCheckout()
        ->setStepData('shipping_method', 'allow', true)
        ->setStepData('shipping_method', 'complete', true)
        ->setStepData('extra_fields', 'allow', true);
    return array();
}

I originally did not have the ->setStepData('shipping_method', 'allow', true) in there which was causing the error. Hope this helps someone!

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.