Subversion-Projekte lars-tiefland.laravel_shop

Revision

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