Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Fix augmentation of Status Log fieldtype when using Database Orders #1014

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Fieldtypes/StatusLogFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use DuncanMcClean\SimpleCommerce\Orders\OrderStatus;
use DuncanMcClean\SimpleCommerce\Orders\PaymentStatus;
use DuncanMcClean\SimpleCommerce\Orders\StatusLogEvent;
use DuncanMcClean\SimpleCommerce\Orders\StatusLogModel;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Arr;
use Statamic\Fields\Fieldtype;

Expand Down Expand Up @@ -34,6 +36,15 @@ public function preload()

public function augment($value)
{
// When orders are stored in the database, the status log is stored as a HasMany relationship.
if ($value instanceof HasMany) {
$value = $value->get();

$value = collect($value)->map(function (StatusLogModel $statusLogModel) {
return ['status' => $statusLogModel->status, 'timestamp' => $statusLogModel->timestamp, 'data' => $statusLogModel->data ?? []];
});
}

// Support the old format for the status log. We can remove this in the future.
if (! empty($value) && ! is_array(Arr::first($value))) {
$value = collect($value)->map(function ($date, $status) {
Expand Down
Loading