public function process_file($linedata) { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $upc_index = $this->get_column_index('upc'); $desc_index = $this->get_column_index('desc'); $size_index = $this->get_column_index('size'); $brand_index = $this->get_column_index('brand'); $sku_index = $this->get_column_index('sku'); if ($desc_index === false && $brand_index === false) { $this->error_details = 'Neither brand nor description provided; nothing to import!'; return false; } $ret = true; $checks = FormLib::get_form_value('checks') == 'yes' ? true : false; $normalize = FormLib::get_form_value('norm') == 'yes' ? true : false; $model = new ProductUserModel($dbc); $verifyP = $dbc->prepare(' SELECT p.upc FROM products AS p WHERE p.upc = ? '); $skuP = $dbc->prepare(' SELECT p.upc FROM vendorItems AS v INNER JOIN products AS p ON v.upc=p.upc AND p.default_vendor_id=v.vendorID WHERE v.sku = ? '); foreach ($linedata as $line) { $upc = $line[$upc_index]; // upc cleanup $upc = str_replace(" ", "", $upc); $upc = str_replace("-", "", $upc); if (!is_numeric($upc)) { continue; } // skip header(s) or blank rows $this->stats['total']++; if ($checks) { $upc = substr($upc, 0, strlen($upc) - 1); } $upc = BarcodeLib::padUPC($upc); $verifyR = $dbc->execute($verifyP, array($upc)); if ($dbc->num_rows($verifyR) == 0) { if ($sku_index !== false) { $skuR = $dbc->execute($skuP, array($line[$sku_index])); if ($dbc->num_rows($skuR) == 0) { // no UPC match, no vendor sku match continue; } else { $skuW = $dbc->fetch_row($skuR); $upc = $skuW['upc']; } } else { // item does not exist, no vendor sku provided continue; } } $model->reset(); $model->upc($upc); $model->load(); $changed = false; if ($model->brand() == '' && $brand_index !== false && !empty($line[$brand_index])) { $brand = $line[$brand_index]; if ($normalize) { $brand = ucwords(strtolower($brand)); } $model->brand($brand); $changed = true; } if ($model->description() == '' && $desc_index !== false && !empty($line[$desc_index])) { $desc = $line[$desc_index]; if ($normalize) { $desc = ucwords(strtolower($desc)); } $model->description($desc); if ($upc == '0002529300278') { var_dump($model->description()); } $changed = true; } if ($model->sizing() == '' && $size_index !== false && !empty($line[$size_index])) { $size = $line[$size_index]; $model->sizing($size); $changed = true; } // possible that columns exist for brand and/or description // but are blank for the given row. No need to update. if ($changed) { $model->save(); $this->stats['here']++; } } return $ret; }