Look for proper way to add additional field in checkout/address page

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
switch-cheehau
Posts: 14
Joined: 23 Jun 2021, 02:39

Look for proper way to add additional field in checkout/address page

Post by switch-cheehau » 23 Jun 2021, 03:00

Hi Aimeos,

Hope you can guide me on this:

I'm trying to add new field passport no. in the checkout process.
So in order to make the checkout process seamlessly:

Extend the table users and mshop_order_base_address with new column passport
adding in users table is to set a default passport number.
adapting client/html/templates/checkout/standard/address-partial-standard.php to add the new field
but i do not know how to pass in the value from customer.password into attr( $this->value( 'address', 'order.base.address.passport' ) ) ?>
adapting client/html/templates/common/summary/address-standard.php to display the new field in summary tab
Save the new field into order.base.address.passport
I'm refering to this doc:
https://aimeos.org/docs/2021.x/infrastr ... properties
But i'm having hard time to relate to my problem.

Can you shed some light over here?

I would be happy to help on documented the solution.

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: Look for proper way to add additional field in checkout/address page

Post by aimeos » 24 Jun 2021, 07:29

switch-cheehau wrote: 23 Jun 2021, 03:00 adapting client/html/templates/checkout/standard/address-partial-standard.php to add the new field
but i do not know how to pass in the value from customer.password into attr( $this->value( 'address', 'order.base.address.passport' ) ) ?>
You have added a new field in the address partial like for the email address?
https://github.com/aimeos/ai-client-htm ... #L286-L301

The values are automatcally passed to the template:
https://github.com/aimeos/ai-client-htm ... d.php#L255

But this doesn't exist as your field is named "passport" not "order.base.address.passport":

Code: Select all

$this->value( 'address', 'order.base.address.passport' )
Use this instead:

Code: Select all

$this->value( 'address', 'passport' )
In https://aimeos.org/docs/2021.x/infrastr ... properties the examples are alsways "mycolumn", not "customer.mycolumn" or "order.base.address.mycolumn". Your property is exactly named like the column name.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
switch-cheehau
Posts: 14
Joined: 23 Jun 2021, 02:39

Re: Look for proper way to add additional field in checkout/address page

Post by switch-cheehau » 29 Jun 2021, 08:29

Hi Aimeos,
Thanks for the help. able to make it works.
Here's the things i've done.

added new column in users table:
lib/custom/setup/default/schema/customer.php

Code: Select all

$table->addColumn( 'passport', 'string', array( 'length' => 32, 'default' => '' ) );
added new field:
client/html/templates/checkout/standard/address-partial-standard.php

Code: Select all

<div class="row form-item form-group passport <?= $enc->attr( ( $this->value( 'error', 'passport' ) ? 'error ' : '' ) . join( ' ', $this->value( 'css', 'passport', [] ) ) ) ?>"
    data-regex="<?= $enc->attr( $this->config( 'client/html/checkout/standard/address/validate/passport' ) ) ?>">

    <label class="col-md-5" for="address-<?= $this->get( 'type', 'billing' ) ?>-passport-<?= $this->get( 'id' ) ?>">
        <?= $enc->html( $this->translate( 'client', 'Passport' ), $enc::TRUST ) ?>
    </label>
    <div class="col-md-7">
        <input class="form-control" type="tel"
            id="address-<?= $this->get( 'type', 'billing' ) ?>-passport-<?= $this->get( 'id' ) ?>"
            name="<?= $enc->attr( $this->formparam( array( $fname, 'passport' ) ) ) ?>"
            value="<?= $enc->attr( $this->value( 'address', 'passport' ) ) ?>"
            <?= $this->value( 'css', 'passport' ) ? '' : 'disabled' ?>
        >
    </div>
</div>
Followed the instruction - easy-way
https://aimeos.org/docs/2021.x/infrastr ... /#easy-way

one last thing is config/shop.php, without this, it won't preserved in summary page.

Code: Select all

'client/html/checkout/standard/address/billing/mandatory' => [
	'order.base.address.firstname',
	'order.base.address.lastname',
	'order.base.address.address1',
	'order.base.address.postal',
	'order.base.address.city',
	'order.base.address.languageid',
	'order.base.address.email',
	'passport',
            ]

Post Reply