Skip to content

Commit 8a9b19b

Browse files
committed
fix #7
1 parent 20c3cdb commit 8a9b19b

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/Http/Middleware/ABTesterMiddleware.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Collection;
77
use Statamic\Contracts\Entries\Entry;
88
use Statamic\Entries\AugmentedEntry;
9+
use Statamic\Facades\Entry as EntryFacade;
910
use Statamic\Structures\AugmentedPage;
1011
use Statamic\Structures\Page;
1112
use Statamic\Support\Arr;
@@ -71,13 +72,13 @@ private function setupAugmentationHooks(Collection $experiments)
7172

7273
$experiment->recordHit($variant);
7374

74-
$self->populateVariationForItemExperiment(
75+
$augmented = $self->populateVariationForItemExperiment(
7576
experiment: $experiment,
7677
item: $item,
7778
variant: $variant
7879
);
7980

80-
$alreadyAugmented->put($id, $item);
81+
$alreadyAugmented->put($id, $augmented);
8182
}
8283

8384
if ($variant !== null) {
@@ -98,15 +99,27 @@ private function setupAugmentationHooks(Collection $experiments)
9899
public function populateVariationForItemExperiment($experiment, $item, $variant)
99100
{
100101
if ($variant == 1) {
101-
return;
102+
return $item;
102103
}
103104

104105
$values = Arr::get($experiment->get('experiment_fields'), 'values', []);
105106

107+
$entry = $item;
108+
109+
if ($item instanceof AugmentedEntry) {
110+
$entry = EntryFacade::find($item->get('id')->raw());
111+
}
112+
106113
// $data is private, so :shrug:
107-
$reflection = new \ReflectionClass($item);
114+
$reflection = new \ReflectionClass($entry);
108115
$property = $reflection->getProperty('data');
109116
$property->setAccessible(true);
110-
$property->setValue($item, $item->data()->merge($values));
117+
$property->setValue($entry, $entry->data()->merge($values));
118+
119+
if ($item instanceof AugmentedEntry) {
120+
$entry = new AugmentedEntry($entry);
121+
}
122+
123+
return $entry;
111124
}
112125
}

0 commit comments

Comments
 (0)