Created
July 9, 2013 09:06
-
-
Save ozinal/5955859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!defined('BASEPATH')) { header('Location: http://'. getenv('SERVER_NAME') .'/'); } | |
/** | |
* @package | |
* @author | |
**/ | |
class xml extends Public_Controller { | |
/* | |
* #### | |
* file_put_contents("Tmpfile.zip", file_get_contents("http://someurl/file.zip")); | |
* | |
* #### | |
* $file = 'http://www.domain.com/somefile.jpg'; | |
* $file_headers = @get_headers($file); | |
* if($file_headers[0] == 'HTTP/1.1 404 Not Found') { | |
* $exists = false; | |
* } | |
* else { | |
* $exists = true; | |
* } | |
* | |
* ### curl solution | |
* function url_exists($url) { | |
* if (!$fp = curl_init($url)) return false; | |
* return true; | |
* } | |
*/ | |
public function index() | |
{ | |
// define('database_hostname', 'localhost'); | |
// define('database_username', 'xxx_user'); | |
// define('database_password', 'xxx'); | |
// define('database_database', 'xxx_db'); | |
// // Create connection | |
// $con = mysqli_connect(database_hostname,database_username,database_password,database_database); | |
// // Check connection | |
// if (mysqli_connect_errno($con)) | |
// { | |
// echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
// exit; | |
// } | |
### curl solution | |
function url_exists($url) { | |
$headers = @get_headers($url); | |
if(strpos($headers[0],'200')===false) | |
{ | |
return FALSE; | |
} else { | |
return TRUE; | |
} | |
} | |
$xml = simplexml_load_file('urunler.xml'); | |
echo $xml->getName() . "<br>"; | |
foreach($xml->children() as $child) | |
{ | |
echo $child->getName() . "-> ".$child->urun_aktif->getName()." -> " . $child->urun_aktif . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_kod->getName()." -> " . $child->urun_kod . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ad->getName()." -> " . $child->urun_ad . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ust_kategori_kod->getName()." -> " . $child->urun_ust_kategori_kod . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ust_kategori_ad->getName()." -> " . $child->urun_ust_kategori_ad . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_kategori_kod->getName()." -> " . $child->urun_kategori_kod . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_kategori_ad->getName()." -> " . $child->urun_kategori_ad . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_marka_kod->getName()." -> " . $child->urun_marka_kod . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_marka_ad->getName()." -> " . $child->urun_marka_ad . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik1_baslik->getName()." -> " . $child->urun_ozellik1_baslik . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik1_detay->getName()." -> " . $child->urun_ozellik1_detay . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik2_baslik->getName()." -> " . $child->urun_ozellik2_baslik . "<br>"; # renk | |
echo $child->getName() . "-> ".$child->urun_ozellik2_detay->getName()." -> " . $child->urun_ozellik2_detay . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik3_baslik->getName()." -> " . $child->urun_ozellik3_baslik . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik3_detay->getName()." -> " . $child->urun_ozellik3_detay . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik4_baslik->getName()." -> " . $child->urun_ozellik4_baslik . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik4_detay->getName()." -> " . $child->urun_ozellik4_detay . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik5_baslik->getName()." -> " . $child->urun_ozellik5_baslik . "<br>"; | |
echo $child->getName() . "-> ".$child->urun_ozellik5_detay->getName()." -> " . $child->urun_ozellik5_detay. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_tanim->getName()." -> " . $child->urun_tanim. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_aciklama->getName()." -> " . $child->urun_aciklama. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_resim1->getName()." -> " . $child->urun_resim1. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_resim2->getName()." -> " . $child->urun_resim2. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_resim3->getName()." -> " . $child->urun_resim3. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_fiyat->getName()." -> " . $child->urun_fiyat. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_fiyat_TL->getName()." -> " . $child->urun_fiyat_TL. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_fiyat_son_kullanici->getName()." -> " . $child->urun_fiyat_son_kullanici. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_fiyat_bayi_ozel->getName()." -> " . $child->urun_fiyat_bayi_ozel. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_doviz->getName()." -> " . $child->urun_doviz. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_kdv->getName()." -> " . $child->urun_kdv. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_stok->getName()." -> " . $child->urun_stok. "<br>"; | |
echo $child->getName() . "-> ".$child->urun_garanti->getName()." -> " . $child->urun_garanti. "<br>"; | |
$nexttime = mktime(23, 24, 0, 11, 3, 2020); | |
#$features = explode(' ', $child->urun_ozellik1_detay); | |
$features = preg_split('/\s+/', $child->urun_ozellik1_detay); | |
$imgdir1 = 'data/'.end(explode("/", $child->urun_resim1)); | |
$imgdir2 = 'data/'.end(explode("/", $child->urun_resim2)); | |
$imgdir3 = 'data/'.end(explode("/", $child->urun_resim3)); | |
# proccess | |
for ($i=1; $i <= 3; $i++) { | |
if($i == 1) { $imgurl = $child->urun_resim1; } | |
if($i == 2) { $imgurl = $child->urun_resim2; } | |
if($i == 3) { $imgurl = $child->urun_resim3; } | |
if(url_exists($imgurl)) | |
{ | |
$newfilename = 'data/'.end(explode("/", $imgurl)); | |
if(!file_exists($newfilename)) { | |
file_put_contents($newfilename, file_get_contents($imgurl)); | |
} | |
} | |
} | |
# check brand | |
$qbrand = $this->db->get_where('manufacturer',array('name' => "$child->urun_marka_ad")); | |
if($qbrand->num_rows()) | |
{ | |
$manufacturer_id = $qbrand->row()->manufacturer_id; | |
} else { | |
$brandall = array( | |
'name' => "$child->urun_marka_ad", | |
'image' => NULL, | |
'meta_description' => strtolower($child->urun_marka_ad), | |
'meta_keywords' => strtolower($child->urun_marka_ad), | |
'description' => strtolower($child->urun_marka_ad), | |
'seo' => strtolower($child->urun_marka_ad), | |
'status' => 1, | |
'sort_order' => 2, | |
'date_added' => date('Y-m-d H:i:s'), | |
'date_modified' => date('Y-m-d H:i:s') | |
); | |
$brandproccess = $this->db->insert('manufacturer',$brandall); | |
if(!$brandproccess) | |
{ | |
die('something happened wrong! during manufacturer'); | |
} | |
$manufacturer_id = $this->db->insert_id(); | |
} | |
# check cat | |
$qcategory = $this->db->get_where('category_description',array('name' => "$child->urun_kategori_ad")); | |
if($qcategory->num_rows()) | |
{ | |
$category_id = $qcategory->row()->category_id; | |
} else { | |
$categoryall = array( | |
'name' => "$child->urun_marka_ad", | |
'image' => NULL, | |
'meta_description' => strtolower($child->urun_marka_ad), | |
'meta_keywords' => strtolower($child->urun_marka_ad), | |
'description' => strtolower($child->urun_marka_ad), | |
'seo' => strtolower($child->urun_marka_ad), | |
'status' => 1, | |
'sort_order' => 2, | |
'date_added' => date('Y-m-d H:i:s'), | |
'date_modified' => date('Y-m-d H:i:s') | |
); | |
$brandproccess = $this->db->insert('manufacturer',$brandall); | |
if(!$brandproccess) | |
{ | |
die('something happened wrong! during manufacturer'); | |
} | |
$manufacturer_id = $this->db->insert_id(); | |
} | |
#### CAT ID is standard = 193; | |
$cat_id = 193; | |
# to table | |
$nrows = $this->db->get_where('product', array('model' => $child->urun_kod)); | |
$alldata = array( | |
'model' => $child->urun_kod, | |
'quantity' => $child->urun_stok, | |
'stock_status_id' => 0, | |
'image' => $imgdir1, | |
'manufacturer_id' => $manufacturer_id, | |
'price' => $cat_id->urun_fiyat, | |
'price_type' => 1, # 1st TRY | |
'stock_type' => NULL, # Standard 12 in db | |
'tax' => substr($child->urun_kdv, -2), | |
'date_available' => $nexttime, | |
'status' => 0, | |
'show_homepage' => 0, | |
'new_product' => 0, | |
'feature_status' => 0, | |
'cargo_required' => 0, | |
'cargo_multiply_required' => 0, | |
'date_added' => time(), | |
'date_modified' => time(), | |
'viewed' => 0, | |
'color_id' => 0, | |
'sort_order' => 0, | |
'minimum' => 1, | |
'cost' => '0.0000', | |
'length' => '0.00', | |
'width' => '0.00', | |
'height' => '0.00', | |
'length_class_id' => 0, | |
'weight' => '0.00', | |
'weight_class_id' => 0, | |
'subtract' => 1 | |
); | |
if($nrows->num_rows()) | |
{ | |
#$this->db->update('product',$alldata); | |
#$this->db->get_where('product_to_category',array('product_id' => $nrows->row()->product_id,'category_id' => $cat_id)); | |
} else { | |
$product_id = $this->db->insert('product',$alldata); | |
$cat_check = $this->db->get_where('product_to_category',array('product_id' => $product_id,'category_id' => $cat_id)); | |
if(!$cat_check->num_rows()) | |
{ | |
$this->db->insert('product_to_category',array('product_id' => $product_id,'category_id' => $cat_id)); | |
} | |
# other images | |
for ($s=2; $s <=3 ; $s++) { | |
if($s == 2) { $sub_img = $imgdir2; } | |
if($s == 2) { $sub_img = $imgdir3; } | |
$this->db->insert('product_image',array('product_id' => $product_id, 'image' => $sub_img)); | |
} | |
# add options to product | |
foreach ($features as $val) { | |
# for relationship of product | |
$option_n = substr($val, 0, strpos($val, '|')); | |
$check_sub = $this->db->get_where('option_value_description',array('name' => $option_n)); | |
if($check_sub->num_rows()) | |
{ | |
$option_id = $check_sub->row()->option_id; | |
} | |
$p_option_data = array( | |
'product_id' => $product_id, | |
'option_id' => $option_id, | |
'option_value' => 'non', | |
'required' => 1, | |
'character_limit' => 0 | |
); | |
$this->db->insert('product_option',$p_option_data); | |
} | |
} | |
echo "<br/><br/>"; | |
exit; | |
} # foreach | |
} # index | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment