66use Illuminate \Support \Collection ;
77use Statamic \Contracts \Entries \Entry ;
88use Statamic \Entries \AugmentedEntry ;
9+ use Statamic \Facades \Entry as EntryFacade ;
910use Statamic \Structures \AugmentedPage ;
1011use Statamic \Structures \Page ;
1112use 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