File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace AlexWestergaard \PhpGa4 \Helper ;
44
5+ use AlexWestergaard \PhpGa4 \Item ;
6+ use AlexWestergaard \PhpGa4 \Facade \Type \ItemType ;
57use AlexWestergaard \PhpGa4 \Facade \Type \IOType ;
68use AlexWestergaard \PhpGa4 \Exception \Ga4IOException ;
79
@@ -303,6 +305,10 @@ public static function fromArray(IOType|array $importable): static
303305 foreach ($ importable as $ key => $ val ) {
304306 if (is_array ($ val )) {
305307 foreach ($ val as $ single ) {
308+ if (in_array ($ key , ['item ' , 'items ' ]) && !($ importable instanceof ItemType)) {
309+ $ single = Item::fromArray ($ single );
310+ }
311+
306312 $ static [$ key ] = $ single ;
307313 }
308314 } else {
Original file line number Diff line number Diff line change @@ -26,6 +26,31 @@ public function test_convert_helper_transforms_array_into_events()
2626 $ this ->assertCount (2 , $ this ->analytics ['events ' ]);
2727 }
2828
29+ public function test_convert_helper_transforms_events_with_items ()
30+ {
31+ $ request = [
32+ [
33+ 'AddToCart ' => [
34+ 'currency ' => 'AUD ' ,
35+ 'value ' => 38 ,
36+ 'items ' => [
37+ [
38+ 'item_id ' => 29 ,
39+ 'item_name ' => '500g Musk Scrolls ' ,
40+ 'price ' => 38 ,
41+ 'quantity ' => 1 ,
42+ ],
43+ ],
44+ ],
45+ ],
46+ ];
47+
48+ $ list = Helper \ConvertHelper::parseEvents ($ request );
49+
50+ var_dump ($ request , $ list );
51+ exit ;
52+ }
53+
2954 public function test_snakecase_helper_transforms_camelcase_names ()
3055 {
3156 $ output = Helper \ConvertHelper::snake ('snakeCase ' );
You can’t perform that action at this time.
0 commit comments