Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1659 | Revision 1667 | 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
        {
1649 lars 32
            @mkdir( public_path( "preisagentur" ), 0755, true );
1634 lars 33
            $items = Item::with( 'price', 'medium.medium', "manufacturer" )->where( 'status', 0 )->get();
1633 lars 34
            $agencies = PriceAgency::where( 'shop_id', $GLOBALS["INI"]["shops_ID"] )->where( "status", "1" )->get();
1623 lars 35
            foreach ( $agencies as $agency )
36
            {
1651 lars 37
                $locked_manufacturers = json_decode( $agency->locked_manufacturers, true );
1650 lars 38
                $records = 0;
1634 lars 39
                $content = array();
1640 lars 40
                $prefix = "";
41
                $suffix = "";
1623 lars 42
                $this->info( $agency["name"] );
1631 lars 43
                if ( !$agency["config"] )
44
                {
45
                    $this->warn( "Agentur nicht komplett konfiguriert!" );
1632 lars 46
                    continue;
1631 lars 47
                }
1641 lars 48
                $configFile = storage_path( "config/" ) . $agency["config"];
1630 lars 49
                if ( file_exists( $configFile ) )
50
                {
51
                    require $configFile;
52
                }
53
                else
54
                {
1665 lars 55
                    $this->error( "Konfigurationsdatei " . $configFile . " existiert nicht!" );
1634 lars 56
                    continue;
1630 lars 57
                }
1634 lars 58
                $fName = basename( parse_url( $agency["csv_url"], PHP_URL_PATH ) );
59
                $fName = storage_path() . "/" . $fName;
60
                $f = fopen( $fName, "w" );
1639 lars 61
                if ( $prefix )
62
                {
63
                    fwrite( $f, $prefix . "\n" );
64
                }
1634 lars 65
                foreach ( $items as $item )
66
                {
1656 lars 67
                    $item->itemLink = "https://www." . env( 'shop' ) . "/" . $item->slug . ".html";
1659 lars 68
                    $item->path = getPath( $item->directory_id );
69
                    if ( !count( $item->path ) )
70
                    {
71
                        continue;
72
                    }
1656 lars 73
                    if ( isset( $from ) && $from )
74
                    {
75
                        $item->itemLink .= "?from=" . $from;
76
                    }
1642 lars 77
                    $item->herstellerName = "";
1646 lars 78
                    $item->hersteller_kurzbezeichnung = $item->name;
1642 lars 79
                    if ( $item->manufacturer )
80
                    {
1654 lars 81
                        if ( count( $locked_manufacturers ) && in_array( $item->manufacturer->id, $locked_manufacturers ) )
1651 lars 82
                        {
83
                            continue;
84
                        }
1642 lars 85
                        $item->herstellerName = $item->manufacturer->name;
1646 lars 86
                        $item->hersteller_kurzbezeichnung = $item->herstellerName . " " . $item->hersteller_kurzbezeichnung;
1642 lars 87
                    }
1651 lars 88
                    if ( !isset( $item->price[0] ) || $item->price[0]->preis < $agency->min_price )
1644 lars 89
                    {
90
                        continue;
91
                    }
1643 lars 92
                    $item->preis = number_format( $item->price[0]->preis, 2, ',', '.' );
1639 lars 93
                    $buffer = array();
1636 lars 94
                    $item->beschreibung_pagentur = $item->description;
1640 lars 95
                    $item->beschreibung_pagentur = str_replace( " & nbsp;", " ", $item->beschreibung_pagentur );
96
                    $item->beschreibung_pagentur = str_replace( " < p>", " ", $item->beschreibung_pagentur );
97
                    $item->beschreibung_pagentur = str_replace( " </p > ", " ", $item->beschreibung_pagentur );
98
                    $item->beschreibung_pagentur = str_replace( " < li>", "", $item->beschreibung_pagentur );
99
                    $item->beschreibung_pagentur = str_replace( " </li > ", ", ", $item->beschreibung_pagentur );
100
                    $item->beschreibung_pagentur = str_replace( " </td > \r\n", " </td > ", $item->beschreibung_pagentur );
101
                    $item->beschreibung_pagentur = str_replace( "</tr > \r\n", " </tr > ", $item->beschreibung_pagentur );
102
                    $item->beschreibung_pagentur = str_replace( "<tr > \r\n", " < tr>", $item->beschreibung_pagentur );
103
                    $item->beschreibung_pagentur = str_replace( " < td>\r\n", " < td>", $item->beschreibung_pagentur );
104
                    $item->beschreibung_pagentur = str_replace( " </td > \n", " </td > ", $item->beschreibung_pagentur );
105
                    $item->beschreibung_pagentur = str_replace( "</tr > \n", " </tr > ", $item->beschreibung_pagentur );
106
                    $item->beschreibung_pagentur = str_replace( "<tr > \n", " < tr>", $item->beschreibung_pagentur );
107
                    $item->beschreibung_pagentur = str_replace( " < td>\n", " < td>", $item->beschreibung_pagentur );
108
                    $item->beschreibung_pagentur = str_replace( " </td ></tr ><tr ><td > ", " / ", $item->beschreibung_pagentur );
109
                    $item->beschreibung_pagentur = str_replace( "</td ><td > ", " - ", $item->beschreibung_pagentur );
110
                    $item->beschreibung_pagentur = str_replace( "<td > ", "", $item->beschreibung_pagentur );
111
                    $item->beschreibung_pagentur = str_replace( " </td > ", ", ", $item->beschreibung_pagentur );
1636 lars 112
                    $item->beschreibung_pagentur = str_replace( '"', '', preg_replace( "/[\r\n\t" . $trenner . "]/", "", strip_tags( $item->beschreibung_pagentur ) ) );
113
                    $item->beschreibung_pagentur = rtrim( $item->beschreibung_pagentur, ", " );
1637 lars 114
                    //$item->beschreibung_pagentur = removeSpaces( $item->beschreibung_pagentur, true, true, false );
1665 lars 115
                    $item->beschreibung_pagentur = preg_replace( "/\s{2,}/", " ", $item->beschreibung_pagentur );
116
                    $item->kurzbeschreibung_pagentur = substr( $item->beschreibung_pagentur, 0, 200 );
1638 lars 117
                    $item->beschreibung_pagentur = substr( $item->beschreibung_pagentur, 0, 5000 );
1634 lars 118
                    foreach ( $content as $c )
119
                    {
120
                        list( $col, $required ) = $c;
121
 
122
                        // Inhalt ist vorhanden oder muss ausgewertet werden?
123
                        if ( isset( $item->$col ) )
124
                        {
125
                            $col = $item->$col;
126
                        }
127
                        elseif ( !stristr( $col, "return" ) )
128
                        {
129
                            $col = "";
130
                        }
131
                        else
132
                        {
133
                            $col = @eval( $col );
134
                        }
135
 
136
                        // Inhalt mit required vergleichen
137
                        /*
138
                        required
139
                        true: Wert muss vorhanden sein
140
                        false: Wert muss nicht vorhanden sein
141
                        string: Ausdruck muss string ergeben
142
                        */
143
 
144
                        if ( is_bool( $required ) )
145
                        {
146
                            if ( ( $required === true ) && ( !$col ) )
147
                            {
148
                                continue 2;
149
                            }
150
                        }
151
                        else
152
                        {
153
                            if ( !@eval( $required ) )
154
                            {
155
                                continue 2;
156
                            }
157
                        }
158
 
159
                        $buffer[] = $quote . $col . $quote;
160
                    } // foreach
161
                    fwrite( $f, implode( $trenner, $buffer ) . "\n" );
1647 lars 162
                    $records++;
1634 lars 163
                }
1640 lars 164
                if ( $suffix )
165
                {
166
                    fwrite( $f, $suffix . "\n" );
167
                }
1634 lars 168
                fclose( $f );
1647 lars 169
                rename( $fName, public_path( "preisagentur/" ) . basename( $fName ) );
170
                $agency->records = $records;
1655 lars 171
                $agency->last_updated_at = date( "Y-m-d H:i:s" );
1647 lars 172
                $agency->save();
1623 lars 173
            }
174
        }
151 lars 175
    }