Display custom field in user profile and mail

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
columbo
Advanced
Posts: 124
Joined: 09 Oct 2019, 09:42

Display custom field in user profile and mail

Post by columbo » 23 Sep 2021, 20:33

Hi,

I added a custom field to customer's address using a Address\Decorator:

Code: Select all

namespace Aimeos\MShop\Customer\Manager\Address\Decorator;

class Myproject extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    private $attr = [
        'custid' => [
            'code' => 'custid',
            'internalcode' => 'lvuad."custid"',
            'label' => 'Kundennummer',
            'type' => 'string',
            'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
        ],
    ];

    public function getSaveAttributes() : array
    {
        return parent::getSaveAttributes() + $this->createAttributes( $this->attr );
    }

    public function getSearchAttributes( bool $sub = true ) : array
    {
        return parent::getSearchAttributes( $sub ) + $this->createAttributes( $this->attr );
    }
}
The field is displayed in the customers profile (backend) and also stored in DB.
How can I display the field value eg. on the checkout confirm page or in the payment mail?

tried with $addr->get( 'custid' ); but without success:

Code: Select all

<?php foreach( $this->summaryBasket->getAddress( 'custid' ) as $addr ) : ?> 
    <?= $addr->getCompany();?>
    <?= $addr->getPostal();?>
    <?= $addr->getCity();?><br>
    <?= $addr->get( 'custid' ); ?>
<?php endforeach; ?>
thank you.

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

Re: Display custom field in user profile and mail

Post by aimeos » 24 Sep 2021, 07:03

This doesn't return anything:

Code: Select all

$this->summaryBasket->getAddress( 'custid' )
You have to use:

Code: Select all

$this->summaryBasket->getAddress( 'delivery' )
// or
$this->summaryBasket->getAddress( 'payment' )
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 124
Joined: 09 Oct 2019, 09:42

Re: Display custom field in user profile and mail

Post by columbo » 24 Sep 2021, 07:19

sorry, copy/paste mistake, I already have: $this->summaryBasket->getAddress( 'delivery' )

how can I print out the value of the custom field custid?

Code: Select all

<?php foreach( $this->summaryBasket->getAddress( 'delivery' ) as $addr ) : ?> 
    <?= $addr->get( 'custid' ); ?>
<?php endforeach; ?>
does not return any value

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

Re: Display custom field in user profile and mail

Post by aimeos » 26 Sep 2021, 10:17

Should be working. You can use print_r() to display the content of the address item object.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 124
Joined: 09 Oct 2019, 09:42

Re: Display custom field in user profile and mail

Post by columbo » 27 Sep 2021, 20:40

Custid is stored in DB table "users_address" successfully, but not part of the address item object displayed with:

Code: Select all

<?= print_r( $this->summaryBasket->getAddress( 'delivery' ) ) ; ?>
Do I have an error in my decorator?

Code: Select all

<?php
namespace Aimeos\MShop\Customer\Manager\Address\Decorator;

// add custid-field to each customer address
class Myproject extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    private $attr = [
        'custid' => [
            'code' => 'custid',
            'internalcode' => 'lvuad."custid"',
            'label' => 'CustId Address',
            'type' => 'string',
            'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
        ],
    ];

    public function getSaveAttributes() : array
    {
        return parent::getSaveAttributes() + $this->createAttributes( $this->attr );
    }

    public function getSearchAttributes( bool $sub = true ) : array
    {
        return parent::getSearchAttributes( $sub ) + $this->createAttributes( $this->attr );
    }
}

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

Re: Display custom field in user profile and mail

Post by aimeos » 28 Sep 2021, 08:30

Implementation looks fine and your decorator is used. Otherwise, the values won't be stored.
Did you change the SQL for "search" in user_address? What's the current SQL statement?

You can check if you configure:

Code: Select all

madmin/log/manager/loglevel = 7
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 124
Joined: 09 Oct 2019, 09:42

Re: Display custom field in user profile and mail

Post by columbo » 28 Sep 2021, 20:57

yes, custid is part of the select query.

Code: Select all

SELECT lvuad."custid",
lvuad."id" AS "customer.address.id", lvuad."parentid" AS "customer.address.parentid",
lvuad."company" AS "customer.address.company", lvuad."vatid" AS "customer.address.vatid",
lvuad."salutation" AS "customer.address.salutation", lvuad."title" AS "customer.address.title",
lvuad."firstname" AS "customer.address.firstname", lvuad."lastname" AS "customer.address.lastname",
lvuad."address1" AS "customer.address.address1", lvuad."address2" AS "customer.address.address2",
lvuad."address3" AS "customer.address.address3", lvuad."postal" AS "customer.address.postal",
lvuad."city" AS "customer.address.city", lvuad."state" AS "customer.address.state",
lvuad."countryid" AS "customer.address.countryid", lvuad."langid" AS "customer.address.languageid",
lvuad."telephone" AS "customer.address.telephone", lvuad."email" AS "customer.address.email",
lvuad."telefax" AS "customer.address.telefax", lvuad."website" AS "customer.address.website",
lvuad."longitude" AS "customer.address.longitude", lvuad."latitude" AS "customer.address.latitude",
lvuad."pos" AS "customer.address.position", lvuad."mtime" AS "customer.address.mtime",
lvuad."editor" AS "customer.address.editor", lvuad."ctime" AS "customer.address.ctime",
lvuad."siteid" AS "customer.address.siteid", lvuad."birthday" AS "customer.address.birthday"
FROM "users_address" AS lvuad
WHERE ( ( lvuad."siteid" = '' OR lvuad."siteid" = '1.' ) AND lvuad."parentid" IN ('3') )
ORDER BY lvuad."pos" ASC
OFFSET 0 ROWS FETCH NEXT 2147483647 ROWS ONLY

and I got it to appear on checkout\standard page address-delivery-body-standard.php

Code: Select all

<?php foreach( $this->get( 'addressDeliveryValues', '' ) as $addr ) : ?> 
    Lastname: <?=  $addr['order.base.address.lastname']; ?>
    Custid: <?=  $addr['custid']; ?>
<?php endforeach; ?>
but Unfortunately still not on the checkout\confirm page order-body-standard.php

Code: Select all

<?php foreach( $this->summaryBasket->getAddress( 'delivery' ) as $addr ) : ?> 
    Lastname:  <?= $addr->get( 'order.base.address.lastname' ); ?><br>
    Custid: : <?= $addr->get( 'custid' ); ?>	<br>		
<?php endforeach; ?>

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

Re: Display custom field in user profile and mail

Post by aimeos » 29 Sep 2021, 12:02

You need another decorator for the order/base/address manager to tell it how the custid should be stored/retrieved just like you've did for the customer/address manager.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply