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"; }
$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; $importCount += 1; continue; } try { $product = $provider->getProductBySTNSKU($sku); if (!empty($product)) { $product_id = importProduct($product, $provider, $categories); $changes = array('sku' => $importable['POSItemNumber'], 'quantity' => $importable['QOH']); $failed = array(); Product::update($product_id, $changes, $failed); if (!empty($failed)) { throw new Exception('Saving product data failed.'); } Product::setPrice($product_id, $importable['RegularPrice']);