@@ -68,7 +68,7 @@ public function buildChain ( Product $product, User $user, int $quantity, string
6868
6969 }
7070
71- return $ chain ;
71+ return $ chain-> reverse () ;
7272
7373 }
7474 public function startOrder ( array $ data = [] ) {
@@ -80,17 +80,22 @@ public function startOrder ( array $data = [] ) {
8080
8181 return $ this ->orderRepository ->dbTransaction (function () use ( $ product , $ user , $ quantity , $ payType , $ data ) {
8282
83- return $ this ->buildChain ($ product , $ user , $ quantity , $ payType , $ data )->map (function ( $ item ) {
83+ $ ref_id = null ;
84+
85+ return $ this ->buildChain ($ product , $ user , $ quantity , $ payType , $ data )->map (function ( $ item ) use ( &$ ref_id ) {
8486
85- return $ this ->withTenant ($ item ->storeId , function () use ( $ item ) {
87+ return $ this ->withTenant ($ item ->storeId , function () use ( $ item, & $ ref_id ) {
8688
87- $ data = $ this ->applyCoupon ($ item ->product , $ item ->user , $ item ->quantity , $ item ->pay_type , $ item ->data );
88- $ data = $ this ->applyGiftCode ($ item ->product , $ item ->user , $ data );
89- return $ this ->completeOrder ($ item ->product , $ item ->user , $ item ->quantity , $ item ->pay_type , $ data );
89+ $ data = $ this ->applyCoupon ($ item ->product , $ item ->user , $ item ->quantity , $ item ->pay_type , $ item ->data );
90+ $ data = $ this ->applyGiftCode ($ item ->product , $ item ->user , $ data );
91+ $ order = $ this ->completeOrder ($ item ->product , $ item ->user , $ item ->quantity , $ item ->pay_type , [... $ data, ' ref_id ' => $ ref_id ] );
9092
93+ $ ref_id = integer (data_get ($ order , 'original.item.id ' ));
94+ return $ order ;
95+
9196 });
9297
93- })->first ();
98+ })->last ();
9499
95100 });
96101
0 commit comments