Subversion-Projekte lars-tiefland.laravel_shop

Revision

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