function import_mfgs($type = 'stn', $mfgMap) { global $pdo, $dbs; global $mosConfig_absolute_path; $pSkuList = get_skus_from_matchup_results(); STN::depend('Mfg'); $results = array(); $fails = array(); $unmapped = 0; $imported = 0; foreach ($mfgMap as $remoteId => $localId) { if (is_numeric($localId)) { $sql = "SELECT * FROM `jos_vm_stn_mf_map` WHERE stn_mf_id =:remoteId"; $check = $pdo->prepare($sql); $check->bindParam(':remoteId', $remoteId, PDO::PARAM_INT); $check->execute(); $count = $check->rowCount(); if ($count > 0) { $sql = "DELETE FROM `jos_vm_stn_mf_map` WHERE `jos_vm_stn_mf_map`.`stn_mf_id` = {$remoteId}"; $check = $pdo->prepare($sql); $check->execute(); } $result = Mfg::map($remoteId, $localId, $type); if ($result !== false) { $results[] = array('remote' => $remoteId, 'local' => $localId, 'result' => $result); } } elseif ($localId === 'NULL') { Mfg::unmap($remoteId, $type); $unmapped += 1; } elseif ($localId === '{import}') { //STN::depend('Site'); $sql = "SELECT * FROM `jos_vm_stn_mf_map` WHERE stn_mf_id =:remoteId"; $check = $pdo->prepare($sql); $check->bindParam(':remoteId', $remoteId, PDO::PARAM_INT); $check->execute(); $count = $check->rowCount(); if ($count > 0) { $sql = "DELETE FROM `jos_vm_stn_mf_map` WHERE `jos_vm_stn_mf_map`.`stn_mf_id` = {$remoteId}"; $check = $pdo->prepare($sql); $check->execute(); } $stmt = $dbs->prepare("\r\n\t\t\t\tSELECT *\r\n\t\t\t\t\tFROM `mfg`\r\n\t\t\t\t\tWHERE `ID`=:remoteId\r\n\t\t\t"); $stmt->bindParam(':remoteId', $remoteId, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); //$row = array(); foreach ($result as $row) { //import and map mfgs $values = array($row['mf_name'], $row['mf_email'], $row['mf_desc'], $row['mf_category_id'], $row['mf_url'], $row['mf_ref_table'], $row['mf_type']); $sql = "\r\n\t\t\t\tINSERT INTO `jos_vm_manufacturer`(\r\n\t\t\t\t\t\t`mf_name`,\r\n\t\t\t\t\t\t`mf_email`,\r\n\t\t\t\t\t\t`mf_desc`,\r\n\t\t\t\t\t\t`mf_category_id`,\r\n\t\t\t\t\t\t`mf_url`,\r\n\t\t\t\t\t\t`mf_code`,\r\n\t\t\t\t\t\t`mf_type`\r\n\t\t\t\t\t)\r\n\t\t\t\t\tVALUES (?,?,?,?,?,?,?)"; $result = $pdo->prepare($sql); if ($result->execute($values)) { $result = Mfg::map($remoteId, $pdo->lastInsertId(), $type); if ($result !== false) { $results[] = array('remote' => $remoteId, 'local' => $localId, 'result' => $result); } $imported += 1; } else { trigger_error("Failed to import Manufacturer (id:{$row['ID']}) with error: " . $results->errorInfo()); trigger_error("\tGenerated SQL: {$sql}"); } } } } require "{$mosConfig_absolute_path}/administrator/components/com_stn_matchup/view/matchup_mfg_results.php"; }
define('_VALID_MOS', 1); require_once '../../../../configuration.php'; require_once '../../../../includes/ajax.php'; require_once '../../../../includes/STN.class.php'; require_once '../../com_virtuemart/ajax/acl.php'; require_once "../../com_importer/ajax/lib.php"; ajaxACL(__FILE__, array('administrator', 'super administrator')); $pdo = STN::getPDO(); $results = $pdo->query("\n\tSELECT *\n\t\tFROM `stn_matchup_results`\n\t\tWHERE `import_status` = 'Y' AND `dup_field` != 'no'\n\t;\n"); $rowCount = $results->rowCount(); include_once "{$mosConfig_absolute_path}/administrator/components/com_virtuemart/virtuemart.cfg.php"; $error = array(); $errorSkus = array(); $alreadyImported = array(); $markImported = $pdo->prepare("\n\tUPDATE `stn_matchup_results`\n\t\tSET `import_status`='AI'\n\t\tWHERE `ID`=:id\n\t;\n"); STN::depend('ProductDataProvider'); $processedSkus = array(); try { belongsToGroup($_SESSION, 'super administrator'); $provider = getProvider('STN'); $categories = $provider->getCategories(); $unImportable = array(); $importedCount = 0; foreach ($results->fetchAll(PDO::FETCH_ASSOC) as $importable) { $sku = $importable['stn_sku_match']; if (empty($sku)) { $error[] = 'No import candidate for item number: ' . $importable['POSItemNumber'] . ' missing SKU.'; continue; } if (productExistsLocally($sku, STN::getPDO())) { $alreadyImported[] = $sku;