Subversion-Projekte lars-tiefland.laravel_shop

Revision

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