public function import_make() { if ($this->modules->users->is("dev_mode")) { //$this->removeDirectory(ROOT_PATH."test.interline.ua/thumbs/"); $this->database->query("DROP TABLE products_import_new"); $this->database->query("CREATE TABLE products_import_new LIKE products"); $this->database->query("DROP TABLE products_import_new_tmp"); $this->database->query("CREATE TABLE products_import_new_tmp LIKE products"); //$this->database->query('TRUNCATE TABLE products_import'); $this->database->query("INSERT INTO products_import_new SELECT * FROM products"); $this->database->query("INSERT INTO products_import_new_tmp SELECT * FROM products"); //$this->database->query("TRUNCATE TABLE products_import"); ini_set('memory_limit', '1024M'); ini_set("max_execution_time", 0); $xml = $this->request->post('xml'); $dbf = dbase_open($xml, 0); $records_count = dbase_numrecords($dbf); $actual_products = array(); $list['records_count'] = $records_count; $list['unrecognized'] = 0; $list['products'] = array(); $list['added'] = 0; $list['updated'] = 0; $list['down'] = 0; $list['deactual'] = 0; for ($i = 1; $i <= $records_count; $i++) { $r = dbase_get_record_with_names($dbf, $i); $article = iconv('cp866', 'utf-8', trim($r['CODE'])); $type = iconv('cp866', 'utf-8', trim($r['TYPE'])); $brand = iconv('cp866', 'utf-8', trim($r['FIRM'])); $mark = iconv('cp866', 'utf-8', trim($r['DESCR'])); // bad or discounted $name = iconv('cp866', 'utf-8', trim($r['NAME'])); $name .= empty($mark) ? '' : '-markdown'; $price = trim($r['PRICE']); $sk0 = trim($r['SK']) != '' ? 1 : 0; $sk1 = trim($r['SK1']) != '' ? 1 : 0; $sk2 = trim($r['SK2']) != '' ? 1 : 0; $actual = $sk0 || $sk1 || $sk2 ? 1 : -1; $is_down = $mark ? "!= ''" : "= ''"; if (!$type || $brand != 'INTERLINE') { continue; } if ($mark) { $list['down']++; } if (!$actual) { $list['deactual']++; } $cat_id = empty($mark) ? $this->get_category_by_type($type) : 8; $list['unrecognized'] += $cat_id ? 0 : 1; $isset_product = $this->database->query("SELECT id\n\t\t FROM products_import_new_tmp\n\t\t WHERE articul = '" . trim($article) . "'\n\t\t AND mark {$is_down}")->one(); if (empty($isset_product)) { $this->database->query("INSERT INTO products_import_new_tmp\n\t\t SET\n\t\t 1Cname = '" . addslashes(trim($type)) . "',\n\t\t name_rus = '" . addslashes(trim($name)) . "',\n\t\t href = '" . safe_upload_name($name) . "',\n\t\t articul = '" . addslashes(trim($article)) . "',\n\t\t price = '" . (int) $price . "',\n\t\t mark = '" . addslashes(trim($mark)) . "',\n\t\t product_instock = '" . addslashes(trim($actual)) . "',\n\t\t active = '" . addslashes(trim($actual)) . "',\n\t\t "); $list['added']++; } else { $this->database->query("UPDATE products_import_new_tmp\n\t\t SET\n\t\t 1Cname = '" . addslashes(trim($type)) . "',\n\t\t price = '" . (int) $price . "',\n\t\t mark = '" . addslashes(trim($mark)) . "',\n\t\t articul = '" . addslashes(trim($article)) . "',\n\t\t product_instock = '" . $actual . "',\n\t\t active = '" . $actual . "'\n\t\t WHERE id = '" . $isset_product . "'"); $list['updated']++; } $list['products'][] = array('article' => $article, 'name' => $name, 'actual' => $actual, 'new' => empty($isset_product) ? 1 : 0); $actual_products[] = $isset_product; } $actual_products = implode(",", $actual_products); $deactual_products = $this->database->query("SELECT\n\t\t id,\n\t\t article,\n\t\t name_rus\n\t\t FROM products_import_new_tmp\n\t\t WHERE\n\t\t id NOT IN (" . $actual_products . ")\n\t\t AND product_instock = '1' AND active = '1'\n\t\t ")->resultArray(); $this->database->query("UPDATE products_import_new_tmp\n\t\t SET product_instock = '-1', active = '-1'\n\t\t WHERE id NOT IN (" . $actual_products . ")\n\t\t "); if ($deactual_products) { foreach ($deactual_products as $item) { $list['products'][] = array('article' => $item['articul'], 'name' => $item['name_rus'], 'actual' => 0, 'new' => 0); $list['deactual']++; } } dbase_close($dbf); //$this->model->catalog()->treeRefresh(); //$this->rrmcache(ROOT_PATH . 'test.interline.ua/storage/460x460'); $this->session->set('interline_import', true); $this->database->query('TRUNCATE TABLE products'); $this->database->query('INSERT INTO products SELECT * FROM products_import_new_tmp'); jsonout(array("ok" => $this->dwoo->get("cms/import-ok.php"))); } }
public function propertyUpdate() { $property = $this->database->query("SELECT * FROM fend_mod_property_test")->resultArray(); foreach ($property as $one) { $this->database->insert("property", array("sys_name" => safe_upload_name($one['property_name']), "name_rus" => $one['property_name'], "unit" => $one['property_unit'], "active" => '1')); } }