Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1670 | Revision 1690 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
730 lars 3
    use App\Http\Controllers\BasketController;
4
    use App\Http\Controllers\BuyController;
1669 lars 5
    use App\Http\Controllers\PriceAgencyController;
875 lars 6
    use App\Http\Controllers\ShippingController;
765 lars 7
    use App\Http\Controllers\UserController;
375 lars 8
    use Illuminate\Support\Facades\DB;
673 lars 9
    use Illuminate\Support\Facades\Schema;
365 lars 10
    use PHPHtmlParser\Dom;
333 lars 11
    use App\Models\Action;
12
    use App\Models\Item;
13
    use App\Models\Directory;
14
    use Illuminate\Support\Facades\Route;
366 lars 15
    use PHPHtmlParser\Exceptions\ChildNotFoundException;
16
    use PHPHtmlParser\Exceptions\CircularException;
17
    use PHPHtmlParser\Exceptions\CurlException;
375 lars 18
    use PHPHtmlParser\Exceptions\NotLoadedException;
366 lars 19
    use PHPHtmlParser\Exceptions\StrictException;
2 lars 20
 
333 lars 21
    /*
22
    |--------------------------------------------------------------------------
23
    | Web Routes
24
    |--------------------------------------------------------------------------
25
    |
26
    | Here is where you can register web routes for your application. These
27
    | routes are loaded by the RouteServiceProvider within a group which
28
    | contains the "web" middleware group. Now create something great!
29
    |
30
     */
2 lars 31
 
848 lars 32
    $GLOBALS["INI"] = getConfig();
850 lars 33
    $GLOBALS["zahlsysteme"] = [
832 lars 34
        "kreditkarte",
35
        "paypal",
36
        "sofortueberweisung",
37
        "frei",
38
        "finanzierung",
39
        "billsafe",
40
        "billsafe_hire",
41
        "amazon",
42
        "PayPalExpress",
43
        "Ratenzahlung",
44
        "PayPalPlus",
45
        "paymill",
46
        "klarna",
47
        "paydirekt",
48
        "payever",
49
        "billie",
50
        "easycredit",
51
        "crefopay",
52
        "crefopayKK",
53
        "PayPalCheckout",
850 lars 54
    ];
832 lars 55
 
624 lars 56
    if ( php_sapi_name() == "cli" )
582 lars 57
    {
58
        return;
59
    }
704 lars 60
    session_start();
847 lars 61
    if ( isset( $_GET["killSession"] ) )
62
    {
63
        unset( $_SESSION );
64
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
65
    }
710 lars 66
    $GLOBALS["steuern"] = array();
67
    //default LandID für Deutschland
68
    $landID = 47;
69
    //Wenn das Flag gesetzt ist, dann nimm diesen wert, damit auch "ausländische Shops" den richtigen MwSt angezeigt bekommen
70
    if ( isset( $GLOBALS["INI"]["steuern"]["default_countryID"] ) )
71
    {
72
        $landID = $GLOBALS["INI"]["steuern"]["default_countryID"];
73
    }
74
 
75
    $countryIDs = ( isset( $GLOBALS['INI']['steuern']['use_countries_tax'] ) ) ? $GLOBALS['INI']['steuern']['use_countries_tax'] : $landID;
76
 
723 lars 77
    $sql = "SELECT
78
            *
79
        FROM
1619 lars 80
            content_management.countries_tax
723 lars 81
        WHERE
82
            country_id IN (" . $countryIDs . ")
83
    ";
84
    $rows = DB::connection( "cms" )->select( $sql );
710 lars 85
    foreach ( $rows as $r )
86
    {
711 lars 87
        $GLOBALS["steuern"][$r->country_id][$r->taxes_id] = $r->tax_percent;
88
        $GLOBALS["steuern"][$r->country_id][null] = $GLOBALS["steuern"][$r->country_id][0];
710 lars 89
    }
697 lars 90
    if ( !isset( $_SESSION["SHOP"]["BASKET"] ) )
91
    {
730 lars 92
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
697 lars 93
    }
700 lars 94
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
697 lars 95
    {
96
        $items = $_SESSION["SHOP"]["BASKET"];
97
        unset( $_SESSION["SHOP"]["BASKET"] );
730 lars 98
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
699 lars 99
        $_SESSION["SHOP"]["BASKET"]->items = $items;
697 lars 100
    }
340 lars 101
    $sql = "
102
        SELECT
103
            *
104
        FROM
105
            i18n_de
106
    ";
405 lars 107
    if ( Schema::hasTable( 'i18n_de' ) )
108
    {
109
        $langstrings = DB::select( $sql );
110
    }
111
    else
112
    {
113
        $langstrings = DB::connection( "old" )->select( $sql );
114
    }
340 lars 115
    foreach ( $langstrings as $langstring )
116
    {
355 lars 117
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 118
    }
355 lars 119
 
367 lars 120
    function parseCMSPage( $url ): array
355 lars 121
    {
375 lars 122
        $menu = "";
123
        $content = "";
365 lars 124
        $dom = new Dom;
366 lars 125
        try
126
        {
127
            $dom->loadFromUrl( $url );
375 lars 128
            $menu = $dom->getElementById( 'menu' )->innerHtml;
129
            $menu = str_replace( "/typo3", "/cms", $menu );
130
            $content = $dom->getElementById( 'content' )->innerHtml;
131
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
132
            $content = str_replace( "ce-textpic", "", $content );
366 lars 133
        }
375 lars 134
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
366 lars 135
        {
136
        }
355 lars 137
        return array( "menu" => $menu, "content" => $content, );
138
    }
139
 
333 lars 140
    function getConfig()
141
    {
142
        define( '__SITE__', env( 'site' ) );
143
        define( '__SHOP__', env( 'shop' ) );
144
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 145
 
333 lars 146
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
147
        if ( !file_exists( $cfg_file ) )
148
        {
149
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
150
        }
151
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
152
        $ini = json_decode( json_encode( $xml ), true );
153
        foreach ( $ini as $key => $wert )
154
        {
155
            if ( $wert == array() )
156
            {
355 lars 157
                $ini[$key] = "";
333 lars 158
            }
159
            elseif ( is_array( $wert ) )
160
            {
161
                foreach ( $wert as $key2 => $wert2 )
162
                {
163
                    if ( $wert2 == array() )
164
                    {
355 lars 165
                        $ini[$key][$key2] = "";
333 lars 166
                    }
176 lars 167
                }
168
            }
169
        }
170
 
333 lars 171
        $v_file = __CFG_PATH__ . "/versand.xml";
172
        if ( file_exists( $v_file ) )
173
        {
174
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 175
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
176
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 177
            {
178
                if ( $wert == array() )
179
                {
355 lars 180
                    $ini["shipping"][$key] = "";
333 lars 181
                }
182
                elseif ( is_array( $wert ) )
183
                {
184
                    foreach ( $wert as $key2 => $wert2 )
185
                    {
186
                        if ( $wert2 == array() )
187
                        {
355 lars 188
                            $ini["shipping"][$key][$key2] = "";
333 lars 189
                        }
176 lars 190
                    }
191
                }
192
            }
193
        }
333 lars 194
        return $ini;
177 lars 195
    }
196
 
1586 lars 197
    if ( !isset( $_SESSION["navigation"]["position"] ) )
198
    {
199
        $_SESSION["navigation"]["position"] = null;
200
    }
333 lars 201
    $nav = new Directory();
848 lars 202
    $menu = $nav->nav_menu();
1582 lars 203
    $shopPosition = $nav->shopPosition();
368 lars 204
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
852 lars 205
    $data = [
206
        "nav"               => $menu,
207
        "serviceCenterMenu" => $sc["menu"],
1582 lars 208
        "shopPosition"      => $shopPosition,
852 lars 209
        "langstrings"       => $GLOBALS["langstrings"],
210
        "ini"               => $GLOBALS["INI"],
211
    ];
212
    \View::share( $data );
848 lars 213
 
333 lars 214
    /* Mobile Weiche */
355 lars 215
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 216
    {
375 lars 217
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
333 lars 218
        {
88 lars 219
 
355 lars 220
            $_SESSION['isMobile'] = false;
221
            $GLOBALS['isMobile'] = false;
88 lars 222
 
853 lars 223
            $pattern = "/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|iPad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i";
224
            if ( preg_match( $pattern, $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 225
            {
88 lars 226
 
355 lars 227
                $_SESSION['isMobile'] = true;
228
                $GLOBALS['isMobile'] = true;
333 lars 229
            }
230
 
88 lars 231
        }
232
    }
1674 lars 233
    Route::get( "/preisagentur/{filename}", [ PriceAgencyController::class, "download" ] );
405 lars 234
    Route::get( "/addItemToBasket", function ()
385 lars 235
    {
697 lars 236
        $_SESSION["SHOP"]["BASKET"]->addItem();
848 lars 237
        return view( 'header_wk' );
405 lars 238
    } );
745 lars 239
    Route::get( "/editItem/{id}/{menge}", function ()
240
    {
241
        $_SESSION["SHOP"]["BASKET"]->editItem();
765 lars 242
        return redirect( "/basket.html" );
745 lars 243
    } )->where( [ "id" => "[0-9a-f]{40}", "menge" => "[0-9]+" ] );
244
    Route::get( "/delItem/{id}", function ()
245
    {
246
        $_SESSION["SHOP"]["BASKET"]->delItem();
765 lars 247
        return redirect( "/basket.html" );
745 lars 248
    } )->where( "id", "[0-9a-f]{40}" );
766 lars 249
    Route::post( "/login", [ UserController::class, "login" ] );
809 lars 250
    Route::post( "/logout", [ UserController::class, "logout" ] );
814 lars 251
    Route::post( "/send_pw", [ UserController::class, "forgot_pw" ] );
777 lars 252
    Route::get( "/favoriten", function ()
253
    {
848 lars 254
        return view( 'login_center' );
777 lars 255
    } );
776 lars 256
    Route::get( "/forgot_pw", function ()
257
    {
848 lars 258
        return view( 'login_center' );
776 lars 259
    } );
765 lars 260
    Route::get( "/login", function ()
762 lars 261
    {
848 lars 262
        return view( 'login_center' );
765 lars 263
    } );
775 lars 264
    Route::get( "/register", function ()
265
    {
848 lars 266
        return view( 'login_center' );
775 lars 267
    } );
890 lars 268
    Route::get( "/update_versand", [ ShippingController::class, "updateShipping" ] );
891 lars 269
    Route::get( "/checkLand.php", function ()
890 lars 270
    {
271
        $_SESSION['SHOP']["BASKET"]->getShippingCountries();
272
        $valid = 1;
893 lars 273
        if ( !in_array( $_GET["land"], array_keys( $_SESSION["SHOP"]["BASKET"]->shippingCountries ) ) )
890 lars 274
        {
275
            $valid = 0;
276
        }
899 lars 277
        echo $valid;
890 lars 278
        return $valid;
279
    } );
658 lars 280
    Route::get( '/setSessionVars', function ()
281
    {
282
        foreach ( $_GET as $key => $value )
283
        {
284
            if ( $value == "false" )
285
            {
286
                unset( $_SESSION[$key] );
287
            }
288
            else
289
            {
290
                $_SESSION[$key] = $value;
291
            }
292
        }
293
    } );
765 lars 294
    Route::post( "/setSessionVars", function ()
295
    {
762 lars 296
        foreach ( $_POST as $key => $value )
297
        {
298
            if ( $value == "false" )
299
            {
300
                unset( $_SESSION[$key] );
301
            }
302
            else
303
            {
304
                $_SESSION[$key] = $value;
305
            }
306
        }
765 lars 307
    } );
308
    Route::post( "/updateSession", function ()
756 lars 309
    {
310
    } );
355 lars 311
    Route::get( "/cms/{slug}", function ( $slug )
312
    {
359 lars 313
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 314
        $arr = parseCMSPage( $url );
355 lars 315
        $content = $arr["content"];
361 lars 316
        return view( 'service_center_content', [
848 lars 317
            "serviceContent" => $content,
355 lars 318
        ] );
319
    } );
925 lars 320
    Route::get( "/bestellen_seite_{step}.html", function ( $step )
376 lars 321
    {
925 lars 322
        return view( 'buy_' . $step, [
924 lars 323
            "pagetype"      => "Bestellvorgang1",
848 lars 324
            "Laender"       => getRechnungsLaender(),
325
            "defaultLandID" => 47,
376 lars 326
        ] );
925 lars 327
    } )->where( 'step', '[1-4][ab]{0,1}' );
328
    Route::post( "/bestellen_seite_{step}.html", [ BuyController::class, 'step1' ] )->where( 'step', '[1-4][ab]{0,1}' );
349 lars 329
    Route::get( "basket.html", function ()
330
    {
678 lars 331
 
848 lars 332
        return view( 'basket' );
349 lars 333
    } );
1564 lars 334
    Route::get( "{item:slug}.html", function ( Item $item )
333 lars 335
    {
1564 lars 336
        //$item->load( 'price', 'medium.medium', 'manufacturer' );
337
        return view( 'item', [
338
            "item" => $item,
339
        ] );
340
    } );
1568 lars 341
    Route::get( "/directory/{id}", function ( $id )
1564 lars 342
    {
333 lars 343
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
1586 lars 344
        $_SESSION["navigation"]["position"] = $dirId;
1476 lars 345
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
346
            0,
347
            99
348
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
1605 lars 349
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
1581 lars 350
        $subdir = Directory::with( 'medium.medium', 'template.template', 'manufacturer' )->find( $dirId );
1619 lars 351
        $subdir["subdirs"] = $dirs->reject( function ( $value )
1572 lars 352
        {
1573 lars 353
            return $value->articlemaster == 1;
1572 lars 354
        } );
355 lars 355
        $subdir["items"] = $items;
1582 lars 356
        $template = 'subdir';
357
        if ( $subdir->articlemaster == 1 )
358
        {
359
            $template = 'artstamm';
360
        }
634 lars 361
        $artstaemmeItems = array();
631 lars 362
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 363
        {
675 lars 364
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
1569 lars 365
        }
366
        foreach ( $dirs as $dir )
367
        {
368
            if ( $dir->articlemaster == 1 )
634 lars 369
            {
1616 lars 370
                $preise = array();
371
                $items = Item::with( 'price' )->where( "directory_id", $dir->id )->whereIn( "status", [ 0, 2 ] )->get();
1620 lars 372
                $dir->anz = count( $items );
1621 lars 373
                foreach ( $items as $item )
1616 lars 374
                {
1621 lars 375
                    $preise[] = $item->price[0]->preis;
376
                }
377
                if ( $preise )
378
                {
1616 lars 379
                    $startPrice = min( $preise );
380
                    $dir->mehrerePreise = count( array_unique( $preise ) ) > 1;
381
                    $dir->startpreis_tpl = $startPrice;
382
                }
1619 lars 383
                $subdir["items"] = $dirs->filter( function ( $value )
1580 lars 384
                {
1620 lars 385
                    return $value->articlemaster == 1 && $value->anz > 0;
1613 lars 386
                } );
1580 lars 387
                /*$artstaemmeItems[$dir->id] = $dir;
388
                $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();*/
634 lars 389
            }
628 lars 390
        }
391
        return view( $template, [
848 lars 392
            "subdir"          => $subdir,
393
            "artstaemmeItems" => $artstaemmeItems,
333 lars 394
        ] );
395
    } );
396
    Route::get( '/', function ()
397
    {
405 lars 398
        $date = date( "Y-m-d" );
399
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 400
        return view( 'startpage', [
848 lars 401
            "pagetype" => "Startseite",
402
            "aktion"   => $aktion,
333 lars 403
        ] );
404
    } );
685 lars 405
 
406
 
703 lars 407
    function getRechnungsLaender(): array
685 lars 408
    {
687 lars 409
        $arr = array();
1619 lars 410
        $laender = DB::connection( 'cms' )->select( 'SELECT id,name_de FROM content_management.countries WHERE `rank` > 0 ORDER BY `rank`' );
687 lars 411
        foreach ( $laender as $land )
412
        {
413
            $arr[$land->id] = $land->name_de;
414
        }
415
        return $arr;
730 lars 416
    }
964 lars 417
 
1144 lars 418
    //require_once __DIR__.'/admin.php';