Subversion-Projekte lars-tiefland.laravel_shop

Revision

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