<?php
class ControllerToolUrlAliasSave extends Controller{

    public function index()
    {
        die();
        $products = $this->db->query("SELECT product_id, image FROM ps_product WHERE model LIKE '%ss%' AND `image` LIKE '%new iphone 11 and blue%' ")->rows;

        //var_dump(count($products)); die();
        foreach ($products as $product){ //var_dump($product); die();
            $images = $this->db->query("SELECT * FROM ps_product_image WHERE `image` LIKE '%new iphone 11 and blue%' AND product_id = '". $product['product_id'] ."' ")->rows;

            $find_rep = str_replace('new iphone 11 and blue', 'seyma', $product['image']);

            $this->db->query("UPDATE ps_product SET image = '". $this->db->escape($find_rep) ."' WHERE product_id = '". $product['product_id'] ."' ");

            foreach ($images as $image){
                $find_rep = str_replace('new iphone 11 and blue', 'seyma', $image['image']);
                $this->db->query("UPDATE ps_product_image SET image = '". $this->db->escape($find_rep) ."' WHERE product_image_id = '". $image['product_image_id'] ."' ");
            }

            //var_dump($find_rep); die();

        }


        /*
        şeffaf koleksyion 		-> şeffaf -> 29.576271186440678 - 197,262
        neon koleksyiyon 		-> violet -> 50.76271186440678  - 180,190
        neon koleksyiyon 		-> green -> 50.76271186440678  - 180,191
        neon koleksyiyon 		-> turuncu -> 50.76271186440678  - 180,192
        aqua koleksyiyon 		-> siyah -> 38.05084745762712  - 193,195
        aqua koleksyiyon 		-> pembe -> 38.05084745762712  - 193,194
        aqua koleksyiyon 		-> gri -> 38.05084745762712  - 193,196
        renkli slikon 			-> siyah -> 33.813559322033896  - 199,200
        renkli slikon 			-> kırmızı -> 33.813559322033896  - 199,201
        renkli slikon 			-> pembe -> 33.813559322033896  - 199,202
        renkli slikon 			-> sarı -> 33.813559322033896  - 199,203
        Glossy					-> popsoketli -> 42.28813559322034  - 253,277
        Glossy					-> popsoketsiz -> 33.813559322033896  - 253,276
        Glossy					-> şeffaf -> 33.813559322033896  - 253,274
        */

        /*
        $price = 33.813559322033896;

        $products = $this->db->query("SELECT * FROM ps_product_attribute WHERE attribute_id IN(253,276) GROUP BY product_id")->rows;

        //var_dump(count($products)); die();
        //var_dump($products[545]); die();

        foreach ($products as $product){
            $this->db->query("UPDATE ps_product SET price = '". $price ."' WHERE product_id = '". $product['product_id'] ."' ");
        }

        */


    }

    private function microtimeMinus($start, $end) {
        list($s_usec, $s_sec) = explode(" ", $start);
        list($e_usec, $e_sec) = explode(" ", $end);
        $diff = ((int) $e_sec - (int) $s_sec) * 1000000 + ((float) $e_usec - (float) $s_usec) * 1000000;
        return $diff;
    }

}