<?php
class ModelCatalogAddProduct extends Model
{
    private $markalarim=array('nikadu','woodhub','teknotrust','teknotrust','NIDAGE','MEDITERIAN');


    public function get_products($main_url,$user)
    {



        $products=array();

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $main_url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

        $datam = curl_exec($curl);


        $content = json_decode($datam, 1);


        curl_close($curl);


        if (!isset($content['error'])) {


            foreach ($content['result']['products'] as $product) {

                //print_r($product);return


                // if (isset($product['ratingScore'])) {
                $url = explode('?', $product['url'])[0];
                $url_info = $this->db->query("select *  from product_url where  url like  '" . $this->db->escape($url) . "'")->row;

                $product['url_info'] = $url_info;
                $product['url']=$url;


                if (!in_array($product['name'], $products)) {
                    if (!$url_info) {
                        if (!in_array($product['brand']['name'], $this->markalarim)) {


                            $products[] = $product['name'];

                        }

                    } else {


                        //if($this->db->query("select count(*) as total from product_url where barcode like ='%".$product."%'"))
                        if ($url_info['user_id'] == $user['user_id']) {
                            if (!in_array($product['brand']['name'], $this->markalarim)) {
                                if (!$url_info['hb'] or !$url_info['ty']) {
                                    $products[] = $product['name'];
                                }


                            }


                        }
                    }
                    // }
                }

            }
        }


    }

}