$this->log('getImages() - Getting product images.');
$qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "ebay_image_import`");
if($qry->num_rows) {
foreach ($qry->rows as $img) {
$this->log('Image: '.$img['name']);
//check if the supersize version exists
$img_large = str_replace(array('$_1.JPG', '$_01.JPG'), '$_57.JPG', $img['image_original']);
//if not get the one supplied
$ch = curl_init($img_large);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$header_response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($header_response == 200) {
$img_used = $img_large;
} else {
$img_used = $img['image_original'];
}
$handle = @fopen($img_used,'r');
if($handle !== false){
if(!@copy($img_used, $img['image_new'])){
$this->log('getImages() - FAILED COPY: '.$img_used);
}else{
$this->log('getImages() - Copy OK : '.$img_used);
}
}else{
$this->log('getImages() - URL not found : '.$img_used);
}
if($img['imgcount'] == 0) {
$this->db->query("UPDATE `" . DB_PREFIX . "product` SET `image` = 'data/".$this->db->escape($img['name'])."' WHERE `product_id` = '".(int)$img['product_id']."' LIMIT 1");
}else{
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_image` SET `product_id` = '".(int)$img['product_id']."', `image` = 'data/".$this->db->escape($img['name'])."', `sort_order` = '".(int)$img['imgcount']."'");
}
$this->db->query("DELETE FROM `" . DB_PREFIX . "ebay_image_import` WHERE `id` = '".(int)$img['id']."' LIMIT 1");
}
}