Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function executeTransferAvtera(){
- global $db;
- $xml = new XMLReader();
- $xml->open(APP_PATH_OWA."/trnUpload/TRNavteraData.xml");
- while($xml->read()){
- //get products
- if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'table'){
- $product = array();
- }
- if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'ident'){
- $xml->read();
- $product['id'] = $xml->value;
- }
- if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'title'){
- $xml->read();
- $product['title'] = $xml->value;
- }
- if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'classtitle'){
- $xml->read();
- $product['classtitle'] = $xml->value;
- }
- if($xml->nodeType == XMLREADER::ELEMENT && $xml->localName == 'computed'){
- $xml->read();
- $product['computed'] = $xml->value;
- $products[] = $product;
- }
- }
- foreach($products as $product){
- $productCategoryID = 999;
- $strEx = explode('\\', $product['classtitle'] , 3);
- $first = $strEx[0];
- $second = $strEx[1];
- $third = $strEx[2];
- if($second == "Prenosni računalniki"){
- switch ($first){
- case "Acer":{
- $productCategoryID = 2;
- }
- break;
- case "Asus":{
- $productCategoryID = 3;
- }
- break;
- case "Dell":{
- $productCategoryID = 4;
- }
- break;
- case "HP":{
- $productCategoryID = 5;
- }
- break;
- default:{
- $productCategoryID = 1;
- }
- }
- }
- if($second == "Namizni računalniki"){
- switch ($first){
- case "HP":{
- $productCategoryID = 7;
- }
- break;
- case "DELL":{
- $productCategoryID = 8;
- }
- break;
- default:
- $productCategoryID = 9;
- }
- }
- $productTitle = $product['title'];
- $productID = $product['id'];
- $productImageUrl = "www.mysite.com/picture.jpg"; // I changed it so I wont break rules
- $productAttrHtml = $product['computed'];
- // DB - START
- $productsAllSql = array(
- 'products_active' => 2
- );
- $db->update('products',$productsAllSql,'products_transfer_name = \'AVTERA\'');
- $selectProduct = $db->select()
- ->from('products',
- array('products_id', 'products_transfer_id'))
- ->where('products_transfer_id = \'avtera_'.$productID.'\'')
- ->order('products_id ASC');
- $selectProductRes = $selectProduct->query();
- $numrowsProduct = count($selectProductRes->fetchAll());
- $selectProductRes = $selectProduct->query();
- if($numrowsProduct > 0) {
- //update
- $productSql = array(
- 'products_categories_id' => $productCategoryID,
- 'products_categories_all' => add_nulls($productCategoryID),
- 'products_price_neto' => 0,
- 'products_price_bruto' => 0,
- 'products_price_discount'=>0,
- 'products_price_discount_type'=>0,
- 'products_tax_class_id' => 22,
- 'products_quantity' => 0,
- 'products_date_modified' => date("Y-m-d H:i:s"),
- 'products_manufacturer_id' => 0,
- 'products_front_page_status' => 0,
- 'products_in_shop' => 1,
- 'products_transfer_name' => 'AVTERA',
- 'products_transfer_id' => 'avtera_'.$productID,
- 'products_active' => 1
- );
- $db->update('products',$productSql,'products_transfer_id = \'avtera_'.$productID.'\'');
- $insertProdID = $db->lastInsertId();
- $productDataSql = array(
- 'products_data_title' => $productTitle,
- 'products_data_products_id' => $insertProdID,
- 'products_img_url' => $productImageUrl,
- 'products_details' => 0,
- 'products_attributes_html' => $productAttrHtml
- );
- //$db->update('products_data1',$productDataSql,'products_transfer_id = \''.$productID.'\'');
- } else {
- //insert
- $productSql = array(
- 'products_categories_id' => $productCategoryID,
- 'products_categories_all' => add_nulls($productCategoryID),
- 'products_price_neto' => 0,
- 'products_price_bruto' => 0,
- 'products_price_discount'=>0,
- 'products_price_discount_type'=>0,
- 'products_tax_class_id' => 22,
- 'products_quantity' => 0,
- 'products_date_modified' => date("Y-m-d H:i:s"),
- 'products_manufacturer_id' => 0,
- 'products_front_page_status' => 0,
- 'products_in_shop' => 1,
- 'products_transfer_name' => 'AVTERA',
- 'products_transfer_id' => 'avtera_'.$productID,
- 'products_active' => 1
- );
- $db->insert('products', $productSql);
- $insertProdID = $db->lastInsertId();
- $productDataSql = array(
- 'products_data_title' => $productTitle,
- 'products_data_products_id' => $insertProdID,
- 'products_img_url' => $productImageUrl,
- 'products_attributes_html' => $productAttrHtml
- );
- $db->insert('products_data', $productDataSql);
- $insertProdDataID = $db->lastInsertId();
- }
- $productsAllSql = array(
- 'products_active' => 0
- );
- /*echo "id:".$product['id']."<br>";
- echo "title:".$product['title']."<br>";
- echo "catID:".$productCategoryID."<br>";
- echo "computed:".$product['computed']."<br>----------------<br>";*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement