Forums / Developer / Problem with custom shopaccounthandler

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

*/ ?>

eZ debug

Timing: Jan 18 2025 11:03:46
Script start
Timing: Jan 18 2025 11:03:46
Module start 'content'
Timing: Jan 18 2025 11:03:47
Module end 'content'
Timing: Jan 18 2025 11:03:47
Script end

Main resources:

Total runtime0.8471 sec
Peak memory usage4,096.0000 KB
Database Queries183

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 587.8281180.8281
Module start 'content' 0.00670.6981 768.6563457.2734
Module end 'content' 0.70480.1422 1,225.9297346.1094
Script end 0.8471  1,572.0391 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.4955210.0002
Check MTime0.00150.1731210.0001
Mysql Total
Database connection0.00120.135910.0012
Mysqli_queries0.781292.22291830.0043
Looping result0.00200.23981810.0000
Template Total0.818196.620.4090
Template load0.00210.247720.0010
Template processing0.815996.319320.4080
Template load and register function0.00010.016910.0001
states
state_id_array0.00190.221710.0019
state_identifier_array0.00150.172820.0007
Override
Cache load0.00170.1986220.0001
Sytem overhead
Fetch class attribute can translate value0.00160.192620.0008
Fetch class attribute name0.00090.101310.0009
XML
Image XML parsing0.00040.051720.0002
class_abstraction
Instantiating content class attribute0.00000.000610.0000
General
dbfile0.00470.5535210.0002
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 5

Time used to render debug report: 0.0002 secs