Skip to content

Commit

Permalink
Order: helper method for nice formatting of Total in GridFields
Browse files Browse the repository at this point in the history
See silvershop#811

Can be removed if Total() works like other DB Fields
  • Loading branch information
wernerkrauss committed Jan 2, 2024
1 parent 6882433 commit a828c33
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions client/dist/css/shopcms.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lang/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ de:
ShipTo: 'Lieferung an'
SubTotal: Zwischensumme
Total: Gesamt
TotalNice: Gesamt
TotalOutstanding: 'Gesamt ausstehend'
TotalPrice: 'Gesamtpreis'
TotalPriceWithCurrency: 'Gesamtpreis ({Currency})'
Expand Down
1 change: 1 addition & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ en:
db_Status: Status
db_Surname: Surname
db_Total: Total
TotalNice: Total
has_many_Items: Items
has_many_Modifiers: Modifiers
has_many_OrderStatusLogs: 'Order Status Logs'
Expand Down
1 change: 1 addition & 0 deletions lang/hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ hr:
ShipTo: 'Pošalji na'
SubTotal: Međuzbroj
Total: Ukupno
TotalNice: Ukupno
TotalOutstanding: 'Ukupno nepodmireno'
TotalPrice: 'Ukupna cijena'
TotalPriceWithCurrency: 'Ukupna cijena ({Currency})'
Expand Down
1 change: 1 addition & 0 deletions lang/nb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ nb:
ShipTo: 'Send til'
SubTotal: Sum total
Total: Pris
TotalNice: Pris
TotalOutstanding: 'Total utestående'
TotalPrice: 'Pris'
TotalPriceWithCurrency: 'Pris ({Currency})'
Expand Down
1 change: 1 addition & 0 deletions lang/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ nl:
ShipTo: 'Verzend naar'
SubTotal: Subtotaal
Total: Totaal
TotalNice: Totaal
TotalOutstanding: 'Totaal openstaand'
TotalPrice: 'Totaalprijs'
TotalPriceWithCurrency: 'Totaalprijs ({Currency})'
Expand Down
1 change: 1 addition & 0 deletions lang/nn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ nn:
ShipTo: 'Send sending til:'
SubTotal: Sum total
Total: Total
TotalNice: Total
TotalOutstanding: 'Total uteståande'
TotalPrice: 'Total pris'
TotalPriceWithCurrency: 'Total pris ({Currency})'
Expand Down
24 changes: 22 additions & 2 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Order extends DataObject
'Placed',
'Name',
'LatestEmail',
'Total',
'TotalNice',
'StatusI18N',
];

Expand Down Expand Up @@ -343,6 +343,7 @@ public function fieldLabels($includerelations = true)
$labels['Name'] = _t('SilverShop\Generic.Customer', 'Customer');
$labels['LatestEmail'] = _t(__CLASS__ . '.db_Email', 'Email');
$labels['StatusI18N'] = _t(__CLASS__ . '.db_Status', 'Status');
$labels['TotalNice'] = _t(__CLASS__ . '.TotalNice', 'Total');

return $labels;
}
Expand Down Expand Up @@ -482,6 +483,25 @@ public function GrandTotal()
return $this->Total();
}

/**
* Helper method for getting nice currency-formatted values.
*
* This is needed, cause Total() conflicts with casting to Currency.
* Related Issue: https://github.com/silvershop/silvershop-core/issues/811
*
* Can be deprecated and removed once the issue is resolved.
*
* @return string
*/
public function TotalNice(): string
{
$total = $this->dbObject('Total');
if ($total instanceof DBCurrency) {
return $total->Nice();
}
return '';
}

/**
* Calculate how much is left to be paid on the order.
* Enforces rounding precision.
Expand Down Expand Up @@ -518,7 +538,7 @@ public function getStatusI18N()
public function Link()
{
$link = CheckoutPage::find_link(false, 'order', $this->ID);

if (Security::getCurrentUser()) {
$link = Controller::join_links(AccountPage::find_link(), 'order', $this->ID);
}
Expand Down

0 comments on commit a828c33

Please sign in to comment.