# Attribut aus Attribute/Customer Model mit getAttribute()-\>fromArray($data)  holen?

**URL:** <https://forum.shopware.com/t/attribut-aus-attribute-customer-model-mit-getattribute-fromarray-data-holen/39486>\
**Category:** Programmierung\
**Created:** [1. September 2016 um 09:06 UTC](https://forum.shopware.com/t/attribut-aus-attribute-customer-model-mit-getattribute-fromarray-data-holen/39486 "2016-09-01T09:06:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DenKon26](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@DenKon26](https://forum.shopware.com/u/DenKon26)\
**Post date:** [1. September 2016 um 09:06 UTC](https://forum.shopware.com/t/attribut-aus-attribute-customer-model-mit-getattribute-fromarray-data-holen/39486/1 "2016-09-01T09:06:33Z")

</div>

Hallo,

folgendes Problem: Ich brauche aus dem Attribute/Customer Model ein Attribut für einen bestimmten $customer. Ich kenne von diesem Attribut nur den Namen.

```
        // Get Customer
        $customerModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer');
        /** @var $customer \Shopware\Models\Customer\Customer */
        $customer = $customerModel->findOneBy(array('id' => $user));
        /** @var $attribute \Shopware\Models\Attribute\Customer */
        $attribute = $customer->getAttribute()->fromArray($data);

```

Kann ich nun auf das Attribut mit der Methode fromArray($data) zugreifen bzw. dieses holen?

Welche Form muss dann das $data-Array haben?

---

<div class="post-metadata">

**Author:** ![johanneshoffmann](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@johanneshoffmann](https://forum.shopware.com/u/johanneshoffmann)\
**Post date:** [24. Oktober 2017 um 09:15 UTC](https://forum.shopware.com/t/attribut-aus-attribute-customer-model-mit-getattribute-fromarray-data-holen/39486/2 "2017-10-24T09:15:14Z")

</div>

Hi,

ist zwar schon über ein Jahr her aber dennoch ist das sehr schlecht Dokumentiert. Hatte gerade das selbe Problem. Ich schreibe es mal zusammen, für die Nächsten, die hier landen 😉

1. eigenes Attribut anlegen via Anleitung hier:  
[Attribute system](https://developers.shopware.com/developers-guide/attribute-system/#create-a-new-attribute)

2. Das Model hierfür wird automatisch generiert anhand der Spalten in der MySQL. Daher umbedingt das Model neu bauen, siehe:  
[Attribute system](https://developers.shopware.com/developers-guide/attribute-system/#rebuild-attribute-models)  
(einfach nach dem erstellen der Attribute ausführen)

3. Ab jetzt kann man einfach wie folgt die Attribute auslesen:  
Als Beispiel heißt ein Attribut **foo\_bar** als Spaltenname.

Fertig, hoffe das Hilft jemand.

Shopware hat hier extremen Aufholbedarf was die Dokumenation angeht…
