Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1643 | Revision 1645 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
151 lars 1
<?php
2
 
1623 lars 3
    namespace App\Console\Commands;
151 lars 4
 
1623 lars 5
    use Illuminate\Console\Command;
1635 lars 6
    use App\Models\Item;
1623 lars 7
    use App\Models\PriceAgency;
151 lars 8
 
1623 lars 9
    class dump extends Command
10
    {
11
        /**
12
         * The name and signature of the console command.
13
         *
14
         * @var string
15
         */
16
        protected $signature = 'command:dump';
151 lars 17
 
1623 lars 18
        /**
19
         * The console command description.
20
         *
21
         * @var string
22
         */
23
        protected $description = 'Erstellt CSV-Dateien für Preisagenturen';
151 lars 24
 
1623 lars 25
        /**
26
         * Execute the console command.
27
         *
1634 lars 28
         * @return void
1623 lars 29
         */
1634 lars 30
        public function handle(): void
1623 lars 31
        {
1634 lars 32
            $items = Item::with( 'price', 'medium.medium', "manufacturer" )->where( 'status', 0 )->get();
1633 lars 33
            $agencies = PriceAgency::where( 'shop_id', $GLOBALS["INI"]["shops_ID"] )->where( "status", "1" )->get();
1623 lars 34
            foreach ( $agencies as $agency )
35
            {
1634 lars 36
                $content = array();
1640 lars 37
                $prefix = "";
38
                $suffix = "";
1623 lars 39
                $this->info( $agency["name"] );
1631 lars 40
                if ( !$agency["config"] )
41
                {
42
                    $this->warn( "Agentur nicht komplett konfiguriert!" );
1632 lars 43
                    continue;
1631 lars 44
                }
1641 lars 45
                $configFile = storage_path( "config/" ) . $agency["config"];
1630 lars 46
                if ( file_exists( $configFile ) )
47
                {
48
                    require $configFile;
49
                }
50
                else
51
                {
52
                    $this->error( "Konfigdatei " . $configFile . " existiert nicht!" );
1634 lars 53
                    continue;
1630 lars 54
                }
1634 lars 55
                $fName = basename( parse_url( $agency["csv_url"], PHP_URL_PATH ) );
56
                $fName = storage_path() . "/" . $fName;
57
                $f = fopen( $fName, "w" );
1639 lars 58
                if ( $prefix )
59
                {
60
                    fwrite( $f, $prefix . "\n" );
61
                }
1634 lars 62
                foreach ( $items as $item )
63
                {
1641 lars 64
                    $item->itemLink = "https://www." . env( 'shop' ) . "/" . $item->slug;
1642 lars 65
                    $item->herstellerName = "";
66
                    if ( $item->manufacturer )
67
                    {
68
                        $item->herstellerName = $item->manufacturer->name;
69
                    }
1644 lars 70
                    if ( !$item->price )
71
                    {
72
                        continue;
73
                    }
1643 lars 74
                    $item->preis = number_format( $item->price[0]->preis, 2, ',', '.' );
1639 lars 75
                    $buffer = array();
1636 lars 76
                    $item->beschreibung_pagentur = $item->description;
1640 lars 77
                    $item->beschreibung_pagentur = str_replace( " & nbsp;", " ", $item->beschreibung_pagentur );
78
                    $item->beschreibung_pagentur = str_replace( " < p>", " ", $item->beschreibung_pagentur );
79
                    $item->beschreibung_pagentur = str_replace( " </p > ", " ", $item->beschreibung_pagentur );
80
                    $item->beschreibung_pagentur = str_replace( " < li>", "", $item->beschreibung_pagentur );
81
                    $item->beschreibung_pagentur = str_replace( " </li > ", ", ", $item->beschreibung_pagentur );
82
                    $item->beschreibung_pagentur = str_replace( " </td > \r\n", " </td > ", $item->beschreibung_pagentur );
83
                    $item->beschreibung_pagentur = str_replace( "</tr > \r\n", " </tr > ", $item->beschreibung_pagentur );
84
                    $item->beschreibung_pagentur = str_replace( "<tr > \r\n", " < tr>", $item->beschreibung_pagentur );
85
                    $item->beschreibung_pagentur = str_replace( " < td>\r\n", " < td>", $item->beschreibung_pagentur );
86
                    $item->beschreibung_pagentur = str_replace( " </td > \n", " </td > ", $item->beschreibung_pagentur );
87
                    $item->beschreibung_pagentur = str_replace( "</tr > \n", " </tr > ", $item->beschreibung_pagentur );
88
                    $item->beschreibung_pagentur = str_replace( "<tr > \n", " < tr>", $item->beschreibung_pagentur );
89
                    $item->beschreibung_pagentur = str_replace( " < td>\n", " < td>", $item->beschreibung_pagentur );
90
                    $item->beschreibung_pagentur = str_replace( " </td ></tr ><tr ><td > ", " / ", $item->beschreibung_pagentur );
91
                    $item->beschreibung_pagentur = str_replace( "</td ><td > ", " - ", $item->beschreibung_pagentur );
92
                    $item->beschreibung_pagentur = str_replace( "<td > ", "", $item->beschreibung_pagentur );
93
                    $item->beschreibung_pagentur = str_replace( " </td > ", ", ", $item->beschreibung_pagentur );
1636 lars 94
                    $item->beschreibung_pagentur = str_replace( '"', '', preg_replace( "/[\r\n\t" . $trenner . "]/", "", strip_tags( $item->beschreibung_pagentur ) ) );
95
                    $item->beschreibung_pagentur = rtrim( $item->beschreibung_pagentur, ", " );
1637 lars 96
                    //$item->beschreibung_pagentur = removeSpaces( $item->beschreibung_pagentur, true, true, false );
1636 lars 97
                    $item->beschreibung_pagentur = preg_replace( "/[\s]{2,}/", " ", $item->beschreibung_pagentur );
98
                    $artikel["kurzbeschreibung_pagentur"] = substr( $item->beschreibung_pagentur, 0, 200 );
1638 lars 99
                    $item->beschreibung_pagentur = substr( $item->beschreibung_pagentur, 0, 5000 );
1634 lars 100
                    foreach ( $content as $c )
101
                    {
102
                        list( $col, $required ) = $c;
103
 
104
                        // Inhalt ist vorhanden oder muss ausgewertet werden?
105
                        if ( isset( $item->$col ) )
106
                        {
107
                            $col = $item->$col;
108
                        }
109
                        elseif ( !stristr( $col, "return" ) )
110
                        {
111
                            $col = "";
112
                        }
113
                        else
114
                        {
115
                            $col = @eval( $col );
116
                        }
117
 
118
                        // Inhalt mit required vergleichen
119
                        /*
120
                        required
121
                        true: Wert muss vorhanden sein
122
                        false: Wert muss nicht vorhanden sein
123
                        string: Ausdruck muss string ergeben
124
                        */
125
 
126
                        if ( is_bool( $required ) )
127
                        {
128
                            if ( ( $required === true ) && ( !$col ) )
129
                            {
130
                                continue 2;
131
                            }
132
                        }
133
                        else
134
                        {
135
                            if ( !@eval( $required ) )
136
                            {
137
                                continue 2;
138
                            }
139
                        }
140
 
141
                        $buffer[] = $quote . $col . $quote;
142
                    } // foreach
143
                    fwrite( $f, implode( $trenner, $buffer ) . "\n" );
144
                }
1640 lars 145
                if ( $suffix )
146
                {
147
                    fwrite( $f, $suffix . "\n" );
148
                }
1634 lars 149
                fclose( $f );
1623 lars 150
            }
151
        }
151 lars 152
    }