Advertisement
Guest User

function

a guest
Sep 11th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.23 KB | None | 0 0
  1. function executeTransferAvtera(){
  2.             global $db;
  3.            
  4.             $xml = new XMLReader();
  5.             $xml->open(APP_PATH_OWA."/trnUpload/TRNavteraData.xml");
  6.        
  7.             while($xml->read()){
  8.                 //get products
  9.                 if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'table'){
  10.                     $product = array();
  11.                 }
  12.                
  13.                 if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'ident'){
  14.                     $xml->read();
  15.                     $product['id'] = $xml->value;
  16.                 }
  17.                
  18.                 if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'title'){
  19.                     $xml->read();
  20.                     $product['title'] = $xml->value;
  21.                 }
  22.                
  23.                 if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'classtitle'){
  24.                     $xml->read();
  25.                     $product['classtitle'] = $xml->value;
  26.                 }
  27.                
  28.                 if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'computed'){
  29.                     $xml->read();
  30.                     $product['computed'] = $xml->value;
  31.                     $products[] = $product;
  32.                 }
  33.             }
  34.            
  35.             foreach($products as $product){
  36.                
  37.                 $productCategoryID = 999;
  38.                
  39.                 $strEx = explode('\\', $product['classtitle'] , 3);
  40.                 $first = $strEx[0];
  41.                 $second = $strEx[1];
  42.                 $third = $strEx[2];
  43.                
  44.                 if($second == "Prenosni računalniki"){
  45.                 switch ($first){
  46.                     case "Acer":{
  47.                         $productCategoryID = 2;
  48.                     }
  49.                     break;
  50.                     case "Asus":{
  51.                         $productCategoryID = 3;
  52.                     }
  53.                     break;
  54.                     case "Dell":{
  55.                         $productCategoryID = 4;
  56.                     }
  57.                     break;
  58.                     case "HP":{
  59.                         $productCategoryID = 5;
  60.                     }
  61.                     break;
  62.                     default:{
  63.                         $productCategoryID = 1;
  64.                         }
  65.                     }
  66.                 }
  67.                    
  68.             if($second == "Namizni računalniki"){
  69.                 switch ($first){
  70.                     case "HP":{
  71.                         $productCategoryID = 7;
  72.                     }
  73.                     break;
  74.                     case "DELL":{
  75.                         $productCategoryID = 8;
  76.                     }
  77.                     break;
  78.                     default:
  79.                         $productCategoryID = 9;
  80.                     }
  81.             }
  82.                
  83.                 $productTitle = $product['title'];
  84.                 $productID = $product['id'];
  85.                 $productImageUrl = "www.mysite.com/picture.jpg"; // I changed it so I wont break rules
  86.                 $productAttrHtml = $product['computed'];
  87.                 // DB - START
  88.                 $productsAllSql = array(
  89.                     'products_active' => 2
  90.                 );
  91.                
  92.                 $db->update('products',$productsAllSql,'products_transfer_name = \'AVTERA\'');
  93.                
  94.                 $selectProduct = $db->select()
  95.                     ->from('products',
  96.                         array('products_id', 'products_transfer_id'))
  97.                     ->where('products_transfer_id = \'avtera_'.$productID.'\'')
  98.                     ->order('products_id ASC');
  99.                 $selectProductRes = $selectProduct->query();
  100.                 $numrowsProduct = count($selectProductRes->fetchAll());
  101.                 $selectProductRes = $selectProduct->query();
  102.                
  103.                
  104.  
  105.                 if($numrowsProduct > 0) {
  106.                     //update
  107.                     $productSql = array(
  108.                         'products_categories_id' => $productCategoryID,
  109.                         'products_categories_all' => add_nulls($productCategoryID),
  110.                         'products_price_neto' => 0,
  111.                         'products_price_bruto' => 0,
  112.                         'products_price_discount'=>0,
  113.                         'products_price_discount_type'=>0,
  114.                         'products_tax_class_id' => 22,
  115.                         'products_quantity' => 0,
  116.                         'products_date_modified' => date("Y-m-d H:i:s"),
  117.                         'products_manufacturer_id' => 0,
  118.                         'products_front_page_status' => 0,
  119.                         'products_in_shop' => 1,
  120.                         'products_transfer_name' => 'AVTERA',
  121.                         'products_transfer_id' => 'avtera_'.$productID,
  122.                         'products_active' => 1
  123.                     );
  124.                    
  125.                     $db->update('products',$productSql,'products_transfer_id = \'avtera_'.$productID.'\'');
  126.                     $insertProdID = $db->lastInsertId();
  127.                    
  128.                     $productDataSql = array(
  129.                         'products_data_title' => $productTitle,
  130.                         'products_data_products_id' => $insertProdID,
  131.                         'products_img_url' => $productImageUrl,
  132.                         'products_details' => 0,
  133.                         'products_attributes_html' => $productAttrHtml
  134.                     );
  135.                     //$db->update('products_data1',$productDataSql,'products_transfer_id = \''.$productID.'\'');
  136.                 } else {
  137.                     //insert
  138.                     $productSql = array(
  139.                         'products_categories_id' => $productCategoryID,
  140.                         'products_categories_all' => add_nulls($productCategoryID),
  141.                         'products_price_neto' => 0,
  142.                         'products_price_bruto' => 0,
  143.                         'products_price_discount'=>0,
  144.                         'products_price_discount_type'=>0,
  145.                         'products_tax_class_id' => 22,
  146.                         'products_quantity' => 0,
  147.                         'products_date_modified' => date("Y-m-d H:i:s"),
  148.                         'products_manufacturer_id' => 0,
  149.                         'products_front_page_status' => 0,
  150.                         'products_in_shop' => 1,
  151.                         'products_transfer_name' => 'AVTERA',
  152.                         'products_transfer_id' => 'avtera_'.$productID,
  153.                         'products_active' => 1
  154.                     );
  155.                    
  156.                     $db->insert('products', $productSql);
  157.                     $insertProdID = $db->lastInsertId();
  158.  
  159.                     $productDataSql = array(
  160.                         'products_data_title' => $productTitle,
  161.                         'products_data_products_id' => $insertProdID,
  162.                         'products_img_url' => $productImageUrl,
  163.                         'products_attributes_html' => $productAttrHtml
  164.                     );
  165.                    
  166.                     $db->insert('products_data', $productDataSql);
  167.                     $insertProdDataID = $db->lastInsertId();
  168.                 }
  169.                
  170.                 $productsAllSql = array(
  171.                     'products_active' => 0
  172.                 );
  173.                
  174.                 /*echo "id:".$product['id']."<br>";
  175.                 echo "title:".$product['title']."<br>";
  176.                 echo "catID:".$productCategoryID."<br>";
  177.                 echo "computed:".$product['computed']."<br>----------------<br>";*/
  178.             }
  179.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement