Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1358 | Revision 1361 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
108 lars 1
<?php
2
 
779 lars 3
    namespace App\Http\Controllers;
108 lars 4
 
1337 lars 5
    use App\Http\Requests\ActionRequest;
6
    use App\Models\Action;
962 lars 7
    use App\Models\WebSetting;
1337 lars 8
    use Illuminate\Contracts\Foundation\Application;
9
    use Illuminate\Contracts\View\Factory;
10
    use Illuminate\Contracts\View\View;
11
    use Illuminate\Database\Eloquent\Relations\HasMany;
12
    use Illuminate\Http\RedirectResponse;
779 lars 13
    use Illuminate\Http\Request;
14
    use App\Models\OrderAddress;
15
    use App\Models\OrderItem;
16
    use App\Models\Order;
108 lars 17
 
779 lars 18
    class OrderController extends Controller
19
    {
20
        //
958 lars 21
        private int       $shipAddrId;
22
        private int       $billAddrId;
23
        private Order     $order;
24
        private int       $orderId;
25
        private OrderItem $orderItem;
26
        private array     $orderItems;
27
 
1337 lars 28
        /**
29
         * Display a listing of the resource.
30
         *
31
         */
32
        public function index(): Factory|View|Application
33
        {
34
            //
1358 lars 35
            $orders = Order::with( [ 'shop', 'orderType', 'orderItem', 'billAddr', 'shipAddr' ] )->orderBy( "created_at", 'desc' )->paginate( 100 );
36
            //$links = $orders->links();
1359 lars 37
            $links = array();
1356 lars 38
            return view( 'admin/orders', [ "orders" => $orders, "links" => $links ] );
1337 lars 39
        }
40
 
779 lars 41
        public function create()
42
        {
958 lars 43
            $this->billAddr = new OrderAddress();
787 lars 44
            if ( !( isset( $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) && $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) )
45
            {
46
                $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] = 1;
47
            }
958 lars 48
            $this->billAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
49
            $this->billAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["Vorname"];
50
            $this->billAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["Nachname"];
781 lars 51
            if ( $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"] )
52
            {
958 lars 53
                $this->billAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"];
781 lars 54
            }
958 lars 55
            $this->billAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["Strasse"];
56
            $this->billAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["Hausnummer"];
57
            $this->billAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["PLZ"];
58
            $this->billAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["Ort"];
59
            $this->billAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["Land"];
60
            $this->billAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
61
            $this->billAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
62
            $this->billAddr->save();
63
            $this->billAddrId = $this->billAddr->id;
778 lars 64
 
782 lars 65
            if ( $_SESSION["SHOP"]["Lieferadresse"] == "packstation" )
779 lars 66
            {
958 lars 67
                $this->shipAddr = new OrderAddress();
68
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
69
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname_pst"];
70
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname_pst"];
781 lars 71
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"] )
72
                {
958 lars 73
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"];
781 lars 74
                }
958 lars 75
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["lieferStrasse_pst"];
76
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer_pst"];
77
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ_pst"];
78
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort_pst"];
79
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land_pst"];
80
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
81
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
82
                $this->shipAddr->save();
83
                $this->shipAddrId = $this->billAddr->id;
779 lars 84
            }
85
            else
86
            {
958 lars 87
                $this->shipAddr = new OrderAddress();
88
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
89
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname"];
781 lars 90
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"] )
91
                {
958 lars 92
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"];
781 lars 93
                }
958 lars 94
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname"];
95
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Strasse"];
96
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer"];
97
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ"];
98
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort"];
99
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land"];
100
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
101
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
102
                $this->shipAddr->save();
103
                $this->shipAddrId = $this->billAddr->id;
779 lars 104
            }
958 lars 105
            $this->order = new Order();
106
            $this->order->shop_id = $GLOBALS["INI"]["shops_ID"];
107
            $this->order->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
108
            $this->order->order_type_id = 1;
109
            $this->order->ship_addr_id = $this->shipAddrId;
110
            $this->order->bill_addr_id = $this->billAddrId;
111
            $this->order->created_by = "(Bestellung)";
112
            $this->order->save();
113
            $this->orderId = $this->order->id;
114
            $this->orderItems = array();
779 lars 115
            foreach ( $_SESSION["SHOP"]["BASKET"]->items as $item )
116
            {
958 lars 117
                $this->orderItem = new OrderItem();
118
                $this->orderItem->name = $item->name;
119
                $this->orderItem->item_id = $item->id;
120
                $this->orderItem->price = $item->price;
121
                $this->orderItem->amount = $item->menge;
122
                $this->orderItem->option_input = $item->addinfo;
123
                $this->orderItem->save();
124
                $this->orderItems[] = $this->orderItem;
779 lars 125
            }
958 lars 126
            return $this->orderId;
779 lars 127
        }
958 lars 128
 
129
        public function mail()
130
        {
962 lars 131
            $webSettings = WebSetting::where( 'shop_id', '=', $this->order->shop_id )->where( 'order_type_id', '=', $this->order->order_type_id )->whereIn( 'id', [ 11, 12, 13, 14, 17, 18, 1000, ] )->get();
132
            foreach ( $webSettings as $webSetting )
133
            {
134
                switch ( $webSetting->id )
135
                {
136
                    case 11:
137
                        $fromEmail = $webSetting->content;
138
                        break;
139
                    case 12:
140
                        $customerSubject = $webSetting->content;
141
                        break;
142
                    case 13:
143
                        $customerBody = $webSetting->content;
144
                        break;
145
                    case 14:
146
                        $bccAddress = $webSetting->content;
147
                        break;
148
                    case 17:
149
                        $shopSubject = $webSetting->content;
150
                        break;
151
                    case 18:
152
                        $shopBody = $webSetting->content;
153
                        break;
154
                    case 1000:
155
                        $template = $webSetting->content;
156
                        break;
157
                }
158
            }
159
 
958 lars 160
        }
1337 lars 161
 
162
        /**
163
         * Store a newly created resource in storage.
164
         *
165
         * @param Request $request
166
         * @return RedirectResponse
167
         */
168
        public function store( Request $request ): RedirectResponse
169
        {
170
            //
171
            $rules = [
172
                'name' => 'bail|max:255',
173
            ];
174
            $request->validate( $rules );
175
            $bu = new Order();
176
            $bu->update( $request->validated() );
177
            return redirect( "/backend/orders" );
178
        }
179
 
180
        /**
181
         * Display the specified resource.
182
         *
183
         * @param int $id
184
         */
185
        public function show( int $id )
186
        {
187
            //
188
        }
189
 
190
        /**
191
         * Show the form for editing the specified resource.
192
         *
193
         * @param int $id
194
         * @return Factory|View|Application
195
         */
196
        public function edit( int $id ): Factory|View|Application
197
        {
198
            //
199
            $order = Action::find( $id );
200
            return view( 'admin/order', [ "order" => $order, ] );
201
        }
202
 
203
 
204
        /**
205
         * Update the specified resource in storage.
206
         *
207
         * @param ActionRequest $request
208
         * @param int $id
209
         * @return RedirectResponse
210
         */
211
        public function update( ActionRequest $request, int $id ): RedirectResponse
212
        {
213
            //
214
            $rules = [
215
                'name' => 'bail|max:255',
216
            ];
217
            $request->validate( $rules );
218
            $bu = Order::find( $id );
219
            $data = $request->validated();
220
            $bu->update( $data );
221
            return redirect( "/backend/orders" );
222
        }
223
 
224
        /**
225
         * Remove the specified resource from storage.
226
         *
227
         * @param int $id
228
         * @return RedirectResponse
229
         */
230
        public function destroy( int $id ): RedirectResponse
231
        {
232
            //
233
            $bu = Order::find( $id );
234
            $bu->update( [ "status" => "cancelled" ] );
235
            return redirect( "/backend/orders" );
236
        }
779 lars 237
    }