Skip to content

Commit

Permalink
Merge pull request #2207 from solverat/payment_details_fix
Browse files Browse the repository at this point in the history
improve payment detail rendering
  • Loading branch information
dpfaffenbauer authored Feb 10, 2023
2 parents bd5b828 + ccd7c36 commit 9de5bf8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
64 changes: 48 additions & 16 deletions src/CoreShop/Bundle/OrderBundle/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,26 +624,18 @@ protected function getPayments(OrderInterface $order): array
foreach ($payments as $payment) {
$details = [];
foreach ($payment->getDetails() as $detailName => $detailValue) {
if (empty($detailValue) && $detailValue !== 0) {
continue;
}
if (is_array($detailValue)) {
$detailValue = implode(', ', $detailValue);
}

if (true === is_bool($detailValue)) {
if (true === $detailValue) {
$detailValue = 'true';
} else {
$detailValue = 'false';
}
}
$parsedDetailLine = $this->parsePaymentDetailLine($detailValue);

if (false === is_string($detailValue)) {
$detailValue = (string) $detailValue;
if (null === $parsedDetailLine) {
continue;
}

$details[] = [$detailName, $detailValue ? htmlentities($detailValue) : ''];
$details[] = [
'name' => $detailName,
'value' => $parsedDetailLine['value'],
'detail' => $parsedDetailLine['detail']
];
}

$availableTransitions = $this->workflowStateManager->parseTransitions($payment, 'coreshop_payment', [
Expand Down Expand Up @@ -696,6 +688,46 @@ protected function getDataForObject($data): array
return [];
}

protected function parsePaymentDetailLine(mixed $data): ?array
{
$detail = null;

if (empty($data) && $data !== 0) {
return null;
}

if (is_array($data)) {
if (count(
array_filter($data, static function ($row) {
return is_array($row);
})
) > 0) {
// we don't support sub arrays
$detail = htmlentities(json_encode($data, JSON_THROW_ON_ERROR));
$data = '';
} else {
$data = implode(', ', $data);
}
}

if (true === is_bool($data)) {
if (true === $data) {
$data = 'true';
} else {
$data = 'false';
}
}

if (false === is_string($data)) {
$data = (string) $data;
}

return [
'value' => htmlentities($data),
'detail' => $detail
];
}

public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,18 @@ coreshop.order.order.editPayment = {
viewConfig: {
enableTextSelection: true
},
store: new Ext.data.ArrayStore({
features: [{
ftype: 'rowbody',
getAdditionalData: function(data, idx, record, orig) {
return {
rowBody: '<div>' + record.get('detail') + '</div>',
rowBodyCls: record.get('detail') === null ? 'x-hidden' : ''
};
}
}],
store: new Ext.data.Store({
data: payment.get('details'),
fields: ['name', 'value']
fields: ['name', 'value', 'detail']
}),
columns: [
{
Expand All @@ -88,7 +97,7 @@ coreshop.order.order.editPayment = {
text: 'Value',
dataIndex: 'value',
flex: 2,
renderer: function arg(val, test, test2){
renderer: function arg(val){
return '<div style="white-space: normal;">' + val + '</div>';
}
}
Expand Down

0 comments on commit 9de5bf8

Please sign in to comment.