retrieve custom customer property

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

retrieve custom customer property

Post by columbo » 01 Mar 2020, 12:00

Hi,

I added a custom property (for AccountNo) to my customers object.
How can I retriev and show the property value (account ID) in the customer profile view (/shop/profil)?
I havent found any examples. I tried

Code: Select all

$this->getRefItems( 'customer', null, 'accountid' ) as $attrId => $attrItem ) : ?>
but without success

thanks
Attachments
customer property.PNG
customer property.PNG (30.76 KiB) Viewed 2280 times

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

Re: retrieve custom customer property

Post by aimeos » 02 Mar 2020, 08:55

The getRefItems() method is only for resources referenced by the *_list tables like attributes, images, prices, products, texts, etc. For properties, please use getPropertyItems() or a related method:
https://github.com/aimeos/aimeos-core/b ... /Iface.php
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: retrieve custom customer property

Post by columbo » 02 Mar 2020, 17:00

thanks, but unfortunately i don't get it to work:
the first one (customer.company) works fine, but as soon as I add getPropertyItems( 'accountid', true ) I just receive "A non-recoverable error occured"

Code: Select all

<div class="form-item form-group row company">
	company: <?= $enc->attr( $this->value( $addr, 'customer.company' ) ); ?>
</div>
<div class="form-item form-group row company">
	Account-ID: <?php foreach( $this->getPropertyItems( 'accountid', true ) as $props ) : ?>
</div>

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

Re: retrieve custom customer property

Post by aimeos » 03 Mar 2020, 08:23

"$this" refers to the view in the templates. You need the customer item (either it's already added by the component or you need to write a decorator that adds item to the view), then you can use getPropertyItems() on that 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: retrieve custom customer property

Post by columbo » 06 Mar 2020, 12:50

sorry, but I couldn't solve it and I couldn't find a similar forum post / question either.
Can you provde an example or any other hint how I can create this decorator please?
Goal: I'd like to show the customer porperty "AccountNo" on the users profile page (next to the adress details) and in the confirmation mail.

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

Re: retrieve custom customer property

Post by aimeos » 07 Mar 2020, 11:14

Here's the relevant code to see what is required:
https://github.com/aimeos/ai-client-htm ... #L363-L366

The customer item is assigned as "profileCustomerItem" to the view but doesn't have the properties by default, so:
1.) Add a configuration for "client/html/account/profile/domains" which contains ['customer/address', 'customer/property']
2.) In the account profile view, you can than use $this->profileCustomerItem->getProperties('accountno'), which returns an array

In the e-mail, things are a bit more complicated because there's not customer item available by default (the e-mail template only contains the data from the order itself). Thus, create a decorator, that fetches the customer item and assigns it to the e-mail view:
https://aimeos.org/docs/Developers/Html ... components

The customer ID is in the order base item and available with $baseItem->getCustomerId(). You can use it to fetch the customer item with the customer manager. Then, you can do the same as in the profile template.

The code for the decorator would be:

Code: Select all

public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], &$expire = null )
{
	$custid = $view->extOrderBaseItem->getCustomerId();
	$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' );
	$view->customerItem = $manager->getItem( $custid, ['customer/property'] );
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply