9

I try to add an additional login option during the checkout process. At the moment, you have the username/password way. I want to add a button image to login via an OAuth process (in my case Github).

I found a way but it's not the best way. There is in the checkout/onepage/login.phtml template file, a call to get a block child named form.additional.info.

I tried to insert my own block in it in this way but it didn't work.

<checkout_onepage_index>
        <reference name="form.additional.info">
            <block type="core/template" name="login_github_button" as="login.github.button">
                <action method="setTemplate" ifconfig="github/config/enabled">
                    <template>github/customer/login.phtml</template>
                </action>
            </block>
        </reference>
</checkout_onepage_index>

I found a different way like it is done by the captcha module:

<checkout_onepage_index>
    <reference name="checkout.onepage.login">
        <block type="core/text_list" name="form.additional.info">
            <block type="core/template" name="login_github_button" as="login.github.button">
                <action method="setTemplate" ifconfig="github/config/enabled">
                    <template>github/customer/login.phtml</template>
                </action>
            </block>
        </block>
    </reference>
</checkout_onepage_index>

In this case, it works BUT the captcha won't be displayed. How can I insert several blocks into form.additional.info block?

Thanks for your help

EDIT:

I found some reasons why the button is not displayed under the login fields when using the reference form.additional.info method. It is displayed in the checkout billing view instead.

  1. The block form.additional.info is created by the captcha module for the block checkout.onepage.login then it is also created for the block checkout.onepage.billing
  2. While generating the block in Mage_Core_Model_Layout::_generateBlock() it searches the parent block object of the block login_github_button. Instead of finding the one of checkout.onepage.login, it finds one of the latest created: checkout.onepage.billing. The block is attached to this last one, instead of the log in one. Then I find my login button in the billing address view instead of the login view!!!
  3. If I comment into the layout captcha.xml file the part about checkout.onepage.billing my first solution works.

It's still not ok but I begin to find the reasons.

2 Answers 2

3

Well, the only solution I see is to create into the layout module the block, add the code of the captcha and add as reference my customized code. In this case it is accepted.

Unfortunately, it will still be difficult to insert a block into the form.additional.info block.

Here is the solution I implemented:

<checkout_onepage_index>
    <reference name="checkout.onepage.login">
        <block type="core/text_list" name="form.additional.info">
            <block type="captcha/captcha" name="captcha">
                <reference name="head">
                    <action method="addJs"><file>mage/captcha.js</file></action>
                </reference>
                <action method="setFormId"><formId>user_login</formId></action>
                <action method="setImgWidth"><width>230</width></action>
                <action method="setImgHeight"><width>50</width></action>
            </block>
        </block>

        <reference name="form.additional.info">
            <block type="core/template" name="login_github_button" as="login.github.button">
                <action method="setTemplate" ifconfig="github/config/enabled">
                    <template>github/customer/login.phtml</template>
                </action>
            </block>
        </reference>
    </reference>
</checkout_onepage_index> 
2
  • As you state, this will prevent any other modules from using this block as well, and will also cause problems with upgrades. The <reference name="form.additional.info"> and <depends> solution above is much cleaner and more maintainable.
    – mybluevan
    Commented Jan 29, 2013 at 16:34
  • @mybluevan I don't understand the downvote (if you did it). A downvote is deserved for these cases stackoverflow.com/privileges/vote-down My answer is put here to show an alternative solution. It's not the best I know but it allows to have captcha and the customized module layout. I was not clear by saying that it will prevent the use by other modules. I wanted to mean that if you want to add a child to this block, it will still continue to be a problem. I'm still investigating a cleaner way. The Fabian's one doesn't work at all, I invite you to test it by yourself in the same condition Commented Jan 30, 2013 at 1:54
1

the captcha.xml generates the block, so it should be useable. Did you add a

<depends>
    <Mage_Captcha />
</depends>

to be sure, that your block already exists, when you try to add a child to it?

3
  • Do not work. My module seems to overwrite or have priority over the Captcha module. As you mentionned it in twitter, the 'form.additional.info' block doesn't exist yet. So a module layout creates it and doesn't allow to add an other one. The second layout module doesn't refer to the 'form.additional.info' but try to create one. That's the reason it's not working. I try to find a clean way to allow both. A solution could be to overwrite login.phtml of the onepage template but it will provide additional work for other developers in case of custom theme Commented Jan 28, 2013 at 21:28
  • What Fabian is trying to advise is to use that first block that uses <reference name="form.additional.info"> and then add the <depends>. If you use that second block <reference name="checkout.onepage.login"> with the <depends> it will overwrite the captcha block as you mentioned.
    – mybluevan
    Commented Jan 29, 2013 at 16:30
  • @mybluevan thank you I'm not a newbie. If I have written, it doesn't work, it means I tested as Fabian suggested. First the Magento core modules are loaded then community then local. Same order for the default layout xml files. My module is in the community, it is loaded at last. The tag depends is not necessary in this case. And we are all agree about the overwritten way of my second block. I found the reason why it doesn't work but I still don't find yet the clean solution. See my edit in the question. Commented Jan 30, 2013 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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