Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 728 | Revision 1693 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
108 lars 1
<?php
2
 
3
namespace App\Http\Controllers;
4
 
5
use Illuminate\Http\Request;
6
 
728 lars 7
class DirectoryController extends Controller
108 lars 8
{
9
    //
1692 lars 10
    public function index($id)
11
    {
12
        $_SESSION["navigation"]["position"] = $id;
13
        $subdir = Directory::with( 'medium.medium', 'template.template', 'manufacturer' )->where( "id", $id )->firstOrFail();
14
        $dirs = Directory::with( 'medium.medium','manufacturer' )->where( "directory_id", $id )->whereIn( 'status', [
15
            0,
16
            99
17
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
18
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $id )->where( 'status', '=', 0 )->get();
19
        $subdir["subdirs"] = $dirs->reject( function ( $value )
20
        {
21
            return $value->articlemaster == 1;
22
        } );
23
        $subdir["items"] = $items;
24
        $template = 'subdir';
25
        if ( $subdir->articlemaster == 1 )
26
        {
27
            $template = 'artstamm';
28
        }
29
        $artstaemmeItems = array();
30
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
31
        {
32
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
33
        }
34
        foreach ( $dirs as $dir )
35
        {
36
            if ( $dir->articlemaster == 1 )
37
            {
38
                $preise = array();
39
                $items = Item::with( 'price' )->where( "directory_id", $dir->id )->whereIn( "status", [ 0, 2 ] )->get();
40
                $dir->anz = count( $items );
41
                foreach ( $items as $item )
42
                {
43
                    $preise[] = $item->price[0]->preis;
44
                }
45
                if ( $preise )
46
                {
47
                    $startPrice = min( $preise );
48
                    $dir->mehrerePreise = count( array_unique( $preise ) ) > 1;
49
                    $dir->startpreis_tpl = $startPrice;
50
                }
51
                $subdir["items"] = $dirs->filter( function ( $value )
52
                {
53
                    return $value->articlemaster == 1 && $value->anz > 0;
54
                } );
55
                /*$artstaemmeItems[$dir->id] = $dir;
56
                $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();*/
57
            }
58
        }
59
        return view( $template, [
60
            "subdir"          => $subdir,
61
            "artstaemmeItems" => $artstaemmeItems,
62
        ] );
63
    }
108 lars 64
}