<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class OpencartReloadCache extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'op:realod';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {

        /*
                $urunara = $veri_site->prepare("SELECT DISTINCT product_id FROM oc_product_option_value");
                $urunara->execute();
                while (false !== $urunler = $urunara->fetch(PDO::FETCH_OBJ)) {

                    $toplamstokyap = $veri_site->prepare("select sum(quantity) AS toplamrakam from oc_product_option_value where product_id=:product_id");
                    $toplamstokyap->bindValue(":product_id",$urunler->product_id,PDO::PARAM_STR);
                    $toplamstokyap->execute();
                    $toplamstoks = $toplamstokyap->fetch(PDO::FETCH_OBJ);
                    $toplamstok = $toplamstoks->toplamrakam;

                    if ($toplamstok<="0"){

                        $guncelle = $veri_site->prepare("update oc_product set quantity=:quantity,status=:status where product_id=:product_id limit 1");
                        $guncelle->bindValue(":product_id",$urunler->product_id,PDO::PARAM_STR);
                        $guncelle->bindValue(":quantity","0",PDO::PARAM_STR);
                        $guncelle->bindValue(":status","0",PDO::PARAM_STR);
                        $guncelle->execute();

                        echo $urunler->product_id."<br>";


                    }

                }



                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, 'https://mk.tudors.com/admin/index.php?route=common/login&clearJournal=1');
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $sonuc = curl_exec($ch);
                curl_close($ch);



                $urunkontrol = $veri_site->prepare("select * from oc_productoption_newvalue");
                $urunkontrol->execute();
                while ($ops=$urunkontrol->fetch(PDO::FETCH_OBJ)) {


                    $guncelle = $veri_site->prepare("update oc_product set sku=:sku where product_id=:product_id limit 1");
                    $guncelle->bindValue(":product_id",$ops->product_id,PDO::PARAM_STR);
                    $guncelle->bindValue(":sku","",PDO::PARAM_STR);
                    $guncelle->execute();
                    continue;

                    $guncelle = $veri_site->prepare("update oc_product set ean=:ean where product_id=:product_id limit 1");
                    $guncelle->bindValue(":product_id",$ops->product_id,PDO::PARAM_STR);
                    $guncelle->bindValue(":ean","",PDO::PARAM_STR);
                    $guncelle->execute();
                    continue;
                }

                $urunkontrol = $veri_site->prepare("select * from oc_productoption_newvalue");
                $urunkontrol->execute();
                while ($ops=$urunkontrol->fetch(PDO::FETCH_OBJ)) {

                    $guncelle = $veri_site->prepare("update oc_product set ean=:ean where product_id=:product_id limit 1");
                    $guncelle->bindValue(":product_id",$ops->product_id,PDO::PARAM_STR);
                    $guncelle->bindValue(":ean","",PDO::PARAM_STR);
                    $guncelle->execute();
                    continue;
                }

                $url = 'http://'.$_SERVER['SERVER_NAME'];


                $urunara = $veri_site->prepare("SELECT DISTINCT product_id FROM oc_product_option_value");
                $urunara->execute();
                while (false !== $urunler = $urunara->fetch(PDO::FETCH_OBJ)) {

                    $toplamstokyap = $veri_site->prepare("select sum(quantity) AS toplamrakam from oc_product_option_value where product_id=:product_id");
                    $toplamstokyap->bindValue(":product_id",$urunler->product_id,PDO::PARAM_STR);
                    $toplamstokyap->execute();
                    $toplamstoks = $toplamstokyap->fetch(PDO::FETCH_OBJ);
                    $toplamstok = $toplamstoks->toplamrakam;

                    if ($toplamstok<="0"){

                        $guncelle = $veri_site->prepare("update oc_product set quantity=:quantity,status=:status where product_id=:product_id limit 1");
                        $guncelle->bindValue(":product_id",$urunler->product_id,PDO::PARAM_STR);
                        $guncelle->bindValue(":quantity","0",PDO::PARAM_STR);
                        $guncelle->bindValue(":status","0",PDO::PARAM_STR);
                        $guncelle->execute();

                        echo $urunler->product_id."<br>";


                    }

                }



                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, 'https://rs.tudors.com/admin/index.php?route=common/login&clearJournal=1');
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $sonuc = curl_exec($ch);
                curl_close($ch);
                */
        return 0;
    }
}
