if (!
empty($this->_config
['attributes'
])) { // Get the updated document
$updatedDocument =
Shopware()->
Models()->
getRepository(Document::
class)->
findOneBy([ 'type' =>
$typID,
'customerId' =>
$this->_order->userID,
'orderId' =>
$this->_order->id,
]);
// Check its attributes
if ($updatedDocument->
getAttribute() === null
) { // Create a new attribute entity for the document
$updatedDocument->
setAttribute(new DocumentAttribute());
// Persist the document
Shopware()->
Models()->
flush($updatedDocument);
} // Save all given attributes
$documentAttributes =
$updatedDocument->
getAttribute();
if (!
$documentAttributes instanceof DocumentAttribute
) { throw new RuntimeException('Document attributes are not set correctly'
);
} $documentAttributes->
fromArray($this->_config
['attributes'
]);
// Persist the attributes
Shopware()->
Models()->
flush($documentAttributes);
}