Пример #1
0
        $del = $dbc->prepare("DELETE FROM productExpires WHERE upc=?");
        $dbc->execute($del, array($upc));
    } else {
        $dbs[] = $dbc;
        $del = $dbc->prepare("DELETE FROM products WHERE upc=?");
        $dbc->execute($del, array($upc));
        $query99 = $dbc->prepare("INSERT INTO products (upc,description,normal_price,pricemethod,groupprice,quantity,special_price,specialpricemethod,\n                specialgroupprice,specialquantity,start_date,end_date,department,size,tax,foodstamp,scale,scaleprice,mixmatchcode,\n                modified,tareweight,discount,discounttype,unitofmeasure,wicable,qttyEnforced,idEnforced,cost,inUse,numflag,\n                subdept,deposit,local)\n                VALUES(?,?,?,0,0.00,0,?,0,0.00,0,'','',?,0,?,?,?,0,0,now(),0,?,\n                ?,0,0,0,0,0.00,1,\n                0,0,0.00,?)");
        $dbc->execute($query99, array($upc, $descript, $price, $w['special_price'], $dept, $tax, $FS, $Scale, $NoDisc, $w['discounttype'], $local));
    }
    foreach ($dbs as $con) {
        $char = strstr($utext, "start");
        $pu_model = new ProductUserModel($con);
        $pu_model->upc($upc);
        $pu_model->brand($ubrand);
        $pu_model->description($udesc);
        $pu_model->sizing($usize);
        $pu_model->long_text($utext);
        $pu_model->enableOnline($uonline);
        $pu_model->save();
        $prep = $con->prepare("SELECT * FROM productExpires WHERE upc=?");
        $chk = $con->execute($prep, array($upc));
        if ($con->num_rows($chk) == 0) {
            $ins = $con->prepare("INSERT INTO productExpires (upc,expires) VALUES (?, ?)");
            $con->execute($ins, array($upc, $uexpires));
        } else {
            $up = $con->prepare("UPDATE productExpires SET expires=? WHERE upc=?");
            $con->execute($up, array($uexpires, $upc));
        }
    }
}
if (!empty($likeCode)) {
Пример #2
0
 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;
 }