Problem with custom shopaccounthandler

Author Message

Viktor Juhász

Wednesday 25 March 2009 12:47:43 pm

Hi!

I've tried to make a customized shopaccounthandler. Nothing special, it looks like the original ezusershopaccounthandler.php in kernel/classes/shopaccounthandlers folder, I just would like to add a new information called "takeovermode".

The new data looks in userregister page, but on the next confirmorder page the $order.account_information.takeovermode variable is always empty.

Anybody knows what could be the problem?

I use the following codes and settings:

extension/takeovermode/design/standard/templates/userregister.tpl

<h1>{"Your account information"|i18n("design/standard/shop")}</h1>

{section show=$input_error}
<div class="warning">
<p>
{"Input did not validate, all fields marked with * must be filled in"|i18n("design/standard/shop")}
</p>
</div>

{/section}
<form method="post" action={"/shop/userregister/"|ezurl}>

<div class="block">
    <div class="element">
    <label>
    {"First name"|i18n("design/standard/shop")}:*
    </label><div class="labelbreak"></div>
    <input class="halfbox" type="text" name="FirstName" size="20" value="{$first_name|wash}" />
    </div>
    <div class="element">
    <label>
    {"Last name"|i18n("design/standard/shop")}:*
    </label><div class="labelbreak"></div>
    <input class="halfbox" type="text" name="LastName" size="20" value="{$last_name|wash}" />
    </div>
    <div class="break"></div>
</div>
<br />
<div class="block">
<label>
{"Email"|i18n("design/standard/shop")}:*
</label><div class="labelbreak"></div>
<input class="box" type="text" name="EMail" size="20" value="{$email|wash}" />
</div>

<div class="block">
<label>
{"Company"|i18n("design/standard/shop")}:
</label><div class="labelbreak"></div>
<input class="box" type="text" name="Street1" size="20" value="{$street1|wash}" />
</div>

<div class="block">
<label>
{"Street"|i18n("design/standard/shop")}:*
</label><div class="labelbreak"></div>
<input class="box" type="text" name="Street2" size="20" value="{$street2|wash}" />
</div>

<div class="block">
    <div class="element">
    <label>
    {"Zip"|i18n("design/standard/shop")}:*
    </label><div class="labelbreak"></div>
    <input class="halfbox" type="text" name="Zip" size="20" value="{$zip|wash}" />
    </div>
    <div class="element">
    <label>
    {"Place"|i18n("design/standard/shop")}:*
    </label><div class="labelbreak"></div>
    <input class="halfbox" type="text" name="Place" size="20" value="{$place|wash}" />
    </div>
    <div class="break"></div>
</div>
<br/>
<div class="block">
<label>
{"State"|i18n("design/standard/shop")}:
</label><div class="labelbreak"></div>
<input class="box" type="text" name="State" size="20" value="{$state|wash}" />
</div>

<div class="block">
<label>
{"Country/region"|i18n("design/standard/shop")}:*
</label><div class="labelbreak"></div>
{include uri='design:shop/country/edit.tpl' select_name='Country' select_size=5 current_val=$country}
</div>

// THIS IS THE NEW DATA
<div class="block">
<label>
{'Takeover mode'|i18n('extension/takeovermode/design')}:
</label><div class="labelbreak"></div>
{include uri='design:shop/takeovermode/edit.tpl' select_name='Takeovermode' select_size=5 current_val=$takeovermode}
</div>


<div class="block">
<label>
{"Comment"|i18n("design/standard/shop")}:
</label><div class="labelbreak"></div>
<textarea name="Comment" cols="80" rows="5">{$comment|wash}</textarea>
</div>


<div class="buttonblock">
    <input class="button" type="submit" name="CancelButton" value="{"Cancel"|i18n('design/standard/shop')}" />
    <input class="defaultbutton" type="submit" name="StoreButton" value="{"Continue"|i18n( 'design/standard/shop')}" />
</div>

</form>

<p>
{"All fields marked with * must be filled in."|i18n("design/standard/shop")}
</p>

extension/takeovermode/design/standard/templates/shop/takeovermodes/edit.tpl

{if is_set( $takeovermodes ) | not }
    {def $takeovermodes = array("Takeover mode 1","Takeover mode 2","Takeover mode 3")}
{/if}
{default $max_len = 20
    $select_size = 1}

<select name="{$select_name}" size="{$select_size}">
{if and( is_set( $default_val ), is_set( $default_desc ) )}
    <option {if eq( $current_val, false )}selected="selected"{/if} value="{$default_val}">{$default_desc}</option>
{/if}
{foreach $takeovermodes as $takeovermode}
    <option 
        {if eq( $takeovermode, $current_val )}
            selected="selected"
        {/if}
        value="{$takeovermode}" > {$takeovermode}
    </option>
{/foreach}
</select>
{/default}

extension/takeovermode/design/standard/templates/shop/accounthandlers/html/ez.tpl

<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td valign="top">
<p>
<b>{"Customer"|i18n("design/standard/shop")}</b>
</p>
<p>
{'Name'|i18n('design/standard/shop')}: {$order.account_information.first_name} {$order.account_information.last_name}<br />
{'Email'|i18n('design/standard/shop')}: {$order.account_information.email}<br />
</p>
</td>
<td valign="top">
<p>
<b>{"Address"|i18n("design/standard/shop")}</b>
</p>
<p>
{'Company'|i18n('design/standard/shop')}: {$order.account_information.street1}<br />
{'Street'|i18n('design/standard/shop')}: {$order.account_information.street2}<br />
{'Zip'|i18n('design/standard/shop')}: {$order.account_information.zip}<br />
{'Place'|i18n('design/standard/shop')}: {$order.account_information.place}<br />
{'State'|i18n('design/standard/shop')}: {$order.account_information.state}<br />
{'Country/region'|i18n('design/standard/shop')}: {$order.account_information.country}<br />
// THIS IS THE NEW DATA
{'Takeover mode'|i18n('design/standard/shop')}: {$order.account_information.takeovermode}<br />
</p>
</td>
</tr>
</table>

extension/takeovermode/shopaccounthandlers/takeovermodeshopaccounthandler.php

<?php
class TakeOverModeShopAccountHandler
{
    /*!
    */
    function TakeOverModeShopAccountHandler()
    {

    }

    /*!
     Will verify that the user has supplied the correct user information.
     Returns true if we have all the information needed about the user.
    */
    function verifyAccountInformation()
    {
        return false;
    }

    /*!
     Redirectes to the user registration page.
    */
    function fetchAccountInformation( &$module )
    {
        $module->redirectTo( '/shop/userregister/' );
    }

    /*!
     \return the account information for the given order
    */
    function email( $order )
    {
        $email = false;
        $xmlString = $order->attribute( 'data_text_1' );
        if ( $xmlString != null )
        {
            $dom = new DOMDocument( '1.0', 'utf-8' );
            $success = $dom->loadXML( $xmlString );
            $emailNode = $dom->getElementsByTagName( 'email' )->item( 0 );
            if ( $emailNode )
            {
                $email = $emailNode->textContent;
            }
        }

        return $email;
    }

    /*!
     \return the account information for the given order
    */
    function accountName( $order )
    {
        $accountName = '';
        $xmlString = $order->attribute( 'data_text_1' );
        if ( $xmlString != null )
        {
            $dom = new DOMDocument( '1.0', 'utf-8' );
            $success = $dom->loadXML( $xmlString );
            $firstNameNode = $dom->getElementsByTagName( 'first-name' )->item( 0 );
            $lastNameNode = $dom->getElementsByTagName( 'last-name' )->item( 0 );
            $accountName = $firstNameNode->textContent . ' ' . $lastNameNode->textContent;
        }

        return $accountName;
    }

    function accountInformation( $order )
    {
        $firstName = '';
        $lastName = '';
        $email = '';
        $street1 = '';
        $street2 = '';
        $zip = '';
        $place = '';
        $country = '';
        $comment = '';
        $state = '';
	$takeovermode = '';

        $dom = new DOMDocument( '1.0', 'utf-8' );
        $xmlString = $order->attribute( 'data_text_1' );
        if ( $xmlString != null )
        {
            $dom = new DOMDocument( '1.0', 'utf-8' );
            $success = $dom->loadXML( $xmlString );

            $firstNameNode = $dom->getElementsByTagName( 'first-name' )->item( 0 );
            if ( $firstNameNode )
            {
                $firstName = $firstNameNode->textContent;
            }

            $lastNameNode = $dom->getElementsByTagName( 'last-name' )->item( 0 );
            if ( $lastNameNode )
            {
                $lastName = $lastNameNode->textContent;
            }

            $emailNode = $dom->getElementsByTagName( 'email' )->item( 0 );
            if ( $emailNode )
            {
                $email = $emailNode->textContent;
            }

            $street1Node = $dom->getElementsByTagName( 'street1' )->item( 0 );
            if ( $street1Node )
            {
                $street1 = $street1Node->textContent;
            }

            $street2Node = $dom->getElementsByTagName( 'street2' )->item( 0 );
            if ( $street2Node )
            {
                $street2 = $street2Node->textContent;
            }

            $zipNode = $dom->getElementsByTagName( 'zip' )->item( 0 );
            if ( $zipNode )
            {
                $zip = $zipNode->textContent;
            }

            $placeNode = $dom->getElementsByTagName( 'place' )->item( 0 );
            if ( $placeNode )
            {
                $place = $placeNode->textContent;
            }

            $stateNode = $dom->getElementsByTagName( 'state' )->item( 0 );
            if ( $stateNode )
            {
                $state = $stateNode->textContent;
            }

            $countryNode = $dom->getElementsByTagName( 'country' )->item( 0 );
            if ( $countryNode )
            {
                $country = $countryNode->textContent;
            }

            $commentNode = $dom->getElementsByTagName( 'comment' )->item( 0 );
            if ( $commentNode )
            {
                $comment = $commentNode->textContent;
            }
            // THIS IS THE NEW DATA
	    $takeovermodeNode = $dom->getElementsByTagName( 'takeovermode' )->item( 0 );
            if ( $takeovermodeNode )
            {
                $takeovermode = $takeovermodeNode->textContent;
            }
        }

        return array( 'first_name' => $firstName,
                      'last_name' => $lastName,
                      'email' => $email,
                      'street1' => $street1,
                      'street2' => $street2,
                      'zip' => $zip,
                      'place' => $place,
                      'state' => $state,
                      'country' => $country,
                      'comment' => $comment,
		      'takeovermode' => $takeovermode, // THIS IS THE NEW DATA
                      );
    }
}
?>

extension/takeovermode/design.ini.append.php

<?php /* #?ini charset="utf-8"?

[ExtensionSettings]
DesignExtensions[]=takeovermode

*/ ?>

extension/takeovermode/shopaccount.ini.append.php

<?php /* #?ini charset="utf-8"?

[HandlerSettings]
ExtensionRepositories[]=takeovermode

[AccountSettings]
Handler=takeovermode

*/ ?>

extension/takeovermode/site.ini.append.php

<?php /* #?ini charset="utf-8"?

[TemplateSettings]
ExtensionAutoloadPath[]=takeovermode

*/ ?>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.