public function testItemFlags() { $config = FannieConfig::factory(); $connection = FannieDB::get($config->OP_DB); /** Setup preconditions for the test */ $upc = BarcodeLib::padUPC('16'); $product = new ProductsModel($connection); $product->upc($upc); $product->store_id(0); $product->load(); if ($product->numflag() != 0) { $product->numflag(0); } $product->save(); $module = new ItemFlagsModule(); $module->setConnection($connection); $module->setConfig($config); $form = new \COREPOS\common\mvc\ValueContainer(); $module->setForm($form); $saved = $module->saveFormData($upc); $this->assertEquals(true, $saved, 'Handled empty input'); $product->reset(); $product->upc($upc); $product->load(); $this->assertEquals(0, $product->numflag(), 'Wrong numflag value ' . $product->numflag()); /** Simulate real form input */ $form = new \COREPOS\common\mvc\ValueContainer(); $form->flags = array(1, 3); // 0b101 == 5 $module->setForm($form); $saved = $module->saveFormData($upc); $this->assertEquals(true, $saved, 'Saving item flags failed'); $product->reset(); $product->upc($upc); $product->load(); $this->assertEquals(5, $product->numflag(), 'Wrong numflag value ' . $product->numflag()); /* put record back to normal */ $product->numflag(0); $product->save(); $form = new \COREPOS\common\mvc\ValueContainer(); $form->flags = 'not_an_array'; $module->setForm($form); $saved = $module->saveFormData($upc); $this->assertEquals(false, $saved, 'Accepted invalid input'); }
public function get_id_break_handler() { $dbc = FannieDB::get($this->config->get('OP_DB')); $model = new VendorBreakdownsModel($dbc); $model->vendorID($this->id); $original = new VendorItemsModel($dbc); $product = new ProductsModel($dbc); foreach ($model->find() as $obj) { $original->vendorID($this->id); $original->sku($obj->sku()); if (!$original->load()) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'Vendor SKU #" . $obj->sku() . " not found');\n"); continue; } $split_factor = false; $unit_size = ''; if (preg_match('/^\\d+$/', $original->size())) { $split_factor = $original->size(); } elseif (preg_match('/(\\d+)\\s*\\/\\s*(.+)/', $original->size(), $matches)) { $split_factor = $matches[1]; $unit_size = $matches[2]; } elseif (preg_match('/(\\d+)\\s*CT/', $original->size(), $matches)) { $split_factor = $matches[1]; } elseif (preg_match('/(\\d+)\\s*PKT/', $original->size(), $matches)) { $split_factor = $matches[1]; } if (!$split_factor) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'Vendor SKU #" . $original->size() . " cannot be broken down');\n"); continue; } // add an entry using the store UPC/PLU in place of the vendor SKU // since two records from the same vendor with same SKU are not // permitted in the table $original->sku($obj->upc()); $original->upc($obj->upc()); $original->units(1); $original->size($unit_size); $original->cost($original->cost() / $split_factor); $original->saleCost($original->saleCost() / $split_factor); if ($original->save()) { // update cost in products table, too $product->reset(); $product->upc($obj->upc()); foreach ($product->find('store_id') as $p) { if ($p->load() && $p->default_vendor_id() == $this->id) { $p->cost($original->cost()); $p->save(); $original->description($p->description()); $original->save(); } } } else { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'success', 'Error saving vendor SKU #" . $obj->sku() . "');\n"); } } return true; }
public function post_id_handler() { $dbc = FannieDB::get($this->config->get('OP_DB')); $new = FormLib::get('new-upc'); if ($new == '') { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'New UPC cannot be blank');\n"); return true; } $new = BarcodeLib::padUPC($new); $model = new ProductsModel($dbc); $model->upc($new); if ($model->load()) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'New item {$new} already exists');\n"); return true; } $model->reset(); $model->upc(BarcodeLib::padUPC($this->id)); if (!$model->load()) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'Source item " . $model->upc() . " not found');\n"); return true; } $model->upc($new); $description = substr('CLONE ' . $model->description(), 0, 30); $model->description($description); $model->store_id(1); $model->save(); if ($dbc->tableExists('prodExtra')) { $extra = new ProdExtraModel($dbc); $extra->upc(BarcodeLib::padUPC($this->id)); $extra->load(); $extra->upc($new); $extra->save(); } if ($dbc->tableExists('productUser')) { $user = new ProductUserModel($dbc); $user->upc(BarcodeLib::padUPC($this->id)); $user->load(); $user->upc($new); $user->save(); } header('Location: ItemEditorPage.php?searchupc=' . $new); return false; }
function process_file($linedata) { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); if (!isset($_SESSION['vid'])) { $this->error_details = 'Missing vendor setting'; return False; } $VENDOR_ID = $_SESSION['vid']; $p = $dbc->prepare_statement("SELECT vendorID,vendorName FROM vendors WHERE vendorID=?"); $idR = $dbc->exec_statement($p, array($VENDOR_ID)); if ($dbc->num_rows($idR) == 0) { $this->error_details = 'Cannot find vendor'; return False; } $idW = $dbc->fetch_row($idR); $vendorName = $idW['vendorName']; $SKU = $this->get_column_index('sku'); $BRAND = $this->get_column_index('brand'); $DESCRIPTION = $this->get_column_index('desc'); $QTY = $this->get_column_index('qty'); $SIZE1 = $this->get_column_index('size'); $UPC = $this->get_column_index('upc'); $CATEGORY = $this->get_column_index('vDept'); $REG_COST = $this->get_column_index('cost'); $NET_COST = $this->get_column_index('saleCost'); $REG_UNIT = $this->get_column_index('unitCost'); $NET_UNIT = $this->get_column_index('unitSaleCost'); $SRP = $this->get_column_index('srp'); // PLU items have different internal UPCs // map vendor SKUs to the internal PLUs $SKU_TO_PLU_MAP = array(); $skusP = $dbc->prepare('SELECT sku, upc FROM vendorSKUtoPLU WHERE vendorID=?'); $skusR = $dbc->execute($skusP, array($VENDOR_ID)); while ($skusW = $dbc->fetch_row($skusR)) { $SKU_TO_PLU_MAP[$skusW['sku']] = $skusW['upc']; } $itemP = $dbc->prepare("\n INSERT INTO vendorItems (\n brand, \n sku,\n size,\n upc,\n units,\n cost,\n description,\n vendorDept,\n vendorID,\n saleCost,\n modified,\n srp\n ) VALUES (\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?\n )"); $srpP = false; if ($dbc->tableExists('vendorSRPs')) { $srpP = $dbc->prepare_statement("INSERT INTO vendorSRPs (vendorID, upc, srp) VALUES (?,?,?)"); } $pm = new ProductsModel($dbc); foreach ($linedata as $data) { if (!is_array($data)) { continue; } if (!isset($data[$UPC])) { continue; } // grab data from appropriate columns $sku = $data[$SKU]; $brand = $BRAND === false ? $vendorName : substr($data[$BRAND], 0, 50); $description = substr($data[$DESCRIPTION], 0, 50); if ($QTY === false) { $qty = 1.0; } else { $qty = $data[$QTY]; if (!is_numeric($qty)) { $qty = 1.0; } } $size = $SIZE1 === false ? '' : substr($data[$SIZE1], 0, 25); $upc = $data[$UPC]; $upc = str_replace(' ', '', $upc); $upc = str_replace('-', '', $upc); if (strlen($upc) > 13) { $upc = substr($upc, -13); } else { $upc = str_pad($upc, 13, '0', STR_PAD_LEFT); } // zeroes isn't a real item, skip it if ($upc == "0000000000000") { continue; } if ($_SESSION['vUploadCheckDigits']) { $upc = '0' . substr($upc, 0, 12); } if (isset($SKU_TO_PLU_MAP[$sku])) { $upc = $SKU_TO_PLU_MAP[$sku]; } $category = $CATEGORY === false ? 0 : $data[$CATEGORY]; $reg_unit = ''; if ($REG_UNIT !== false) { $reg_unit = trim($data[$REG_UNIT]); $reg_unit = $this->priceFix($reg_unit); } if (!is_numeric($reg_unit) && $REG_COST !== false) { $reg = trim($data[$REG_COST]); $reg = $this->priceFix($reg); if (is_numeric($reg)) { $reg_unit = $reg / $qty; } } // skip the item if prices aren't numeric // this will catch the 'label' line in the first CSV split // since the splits get returned in file system order, // we can't be certain *when* that chunk will come up // can't process items w/o price (usually promos/samples anyway) if (empty($reg_unit) || !is_numeric($reg_unit)) { continue; } $net_unit = ''; if ($NET_UNIT !== false) { $net_unit = trim($data[$NET_UNIT]); $net_unit = $this->priceFix($net_unit); } if (!is_numeric($net_unit) && $NET_COST !== false) { $net = trim($data[$NET_COST]); $net = $this->priceFix($net); if (is_numeric($net)) { $net_unit = $net / $qty; } } // blank spreadsheet cell if (empty($net_unit)) { $net_unit = 0.0; } $srp = $SRP === false ? 0.0 : trim($data[$SRP]); if ($net_unit == $reg_unit) { $net_unit = 0.0; // not really a sale } // syntax fixes. kill apostrophes in text fields, // trim $ off amounts as well as commas for the // occasional > $1,000 item $srp = $this->priceFix($srp); if (!is_numeric($srp)) { $srp = 0; } $brand = str_replace("'", "", $brand); $description = str_replace("'", "", $description); $args = array($brand, $sku, $size, $upc, $qty, $reg_unit, $description, $category, $VENDOR_ID, $net_unit, date('Y-m-d H:i:s'), $srp); $dbc->execute($itemP, $args); if ($srpP) { $dbc->exec_statement($srpP, array($VENDOR_ID, $upc, $srp)); } if ($_SESSION['vUploadChangeCosts']) { $pm->reset(); $pm->upc($upc); $pm->default_vendor_id($VENDOR_ID); foreach ($pm->find('store_id') as $obj) { $obj->cost($reg_unit); $obj->save(); } } } return true; }
public function post_id_sku_field_value_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $item = new VendorItemsModel($dbc); $item->vendorID($this->id); $item->sku($this->sku); $ret = array('error' => 0); if ($this->field === 'brand') { $item->brand($this->value); } elseif ($this->field === 'description') { $item->description($this->value); } elseif ($this->field === 'unitSize') { $item->size($this->value); } elseif ($this->field === 'caseQty') { $item->units($this->value); } elseif ($this->field === 'cost') { $item->cost($this->value); } else { $ret['error'] = 1; $ret['error_msg'] = 'Unknown field'; } if ($ret['error'] == 0) { $saved = $item->save(); if (!$saved) { $ret['error'] = 1; $ret['error_msg'] = 'Save failed'; } else { /** If cost was updated, update the corresponding product cost */ $prodP = $dbc->prepare(' SELECT p.upc FROM products AS p INNER JOIN vendorItems AS v ON p.upc=v.upc AND p.default_vendor_id=v.vendorID WHERE v.vendorID=? AND v.sku=?'); $prodR = $dbc->execute($prodP, array($this->id, $this->sku)); $model = new ProductsModel($dbc); while ($prodW = $dbc->fetch_row($prodR)) { $model->reset(); $model->upc($prodW['upc']); foreach ($model->find('store_id') as $obj) { $obj->cost($this->value); $obj->save(); } } } } echo json_encode($ret); return false; }
public function run() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $now = date('Y-m-d 00:00:00'); $sale_upcs = array(); // ensure likecode items are mixmatch-able if ($dbc->dbms_name() == 'mssql') { $dbc->query("UPDATE products\n SET mixmatchcode=convert(varchar,u.likecode+500)\n FROM \n products AS p\n INNER JOIN upcLike AS u\n ON p.upc=u.upc"); } else { $dbc->query("UPDATE products AS p\n INNER JOIN upcLike AS u ON p.upc=u.upc\n SET p.mixmatchcode=convert(u.likeCode+500,char)"); } $likeP = $dbc->prepare('SELECT u.upc FROM upcLike AS u INNER JOIN products AS p ON u.upc=p.upc WHERE likeCode=?'); $product = new ProductsModel($dbc); $b_def = $dbc->tableDefinition('batches'); // lookup current batches $query = 'SELECT l.upc, l.batchID, l.pricemethod, l.salePrice, l.groupSalePrice, l.quantity, b.startDate, b.endDate, b.discounttype ' . (isset($b_def['transLimit']) ? ',b.transLimit' : ',0 AS transLimit') . ' FROM batches AS b INNER JOIN batchList AS l ON b.batchID = l.batchID WHERE b.discounttype <> 0 AND b.startDate <= ? AND b.endDate >= ? ORDER BY l.upc, l.salePrice DESC'; $t_def = $dbc->tableDefinition('batchList'); if (!isset($t_def['groupSalePrice'])) { $query = str_replace('l.groupSalePrice', 'NULL AS groupSalePrice', $query); } /** In HQ mode, join on junction table to get UPC+storeID rows when applying sale pricing */ if ($this->config->get('STORE_MODE') === 'HQ') { $query = str_replace('WHERE', ' LEFT JOIN StoreBatchMap AS s ON b.batchID=s.batchID WHERE ', $query); $query = str_replace('SELECT', 'SELECT s.storeID,', $query); } $prep = $dbc->prepare($query); $result = $dbc->execute($prep, array($now, $now)); while ($row = $dbc->fetch_row($result)) { // all items affected by this bathcList record // could be more than one in the case of likecodes $item_upcs = array(); // use products column names for readability below $special_price = $row['salePrice']; $specialpricemethod = $row['pricemethod']; if ($row['groupSalePrice'] != null) { $specialgroupprice = $row['groupSalePrice']; } else { $specialgroupprice = abs($row['salePrice']); } $specialquantity = $row['quantity']; $special_limit = $row['transLimit']; $start_date = $row['startDate']; $end_date = $row['endDate']; $discounttype = $row['discounttype']; $batchID = $row['batchID']; // pricemethod 3 and 4 (AB pricing, typically) // has some overly complicated rules $mixmatch = false; if ($specialpricemethod == 3 || $specialpricemethod == 4) { if ($special_price >= 0) { $mixmatch = $row['batchID']; } else { $mixmatch = -1 * $row['batchID']; } } // unpack likecodes, if needed if (substr($row['upc'], 0, 2) == 'LC') { $likeCode = substr($row['upc'], 2); $likeR = $dbc->execute($likeP, array($likeCode)); while ($likeW = $dbc->fetch_row($likeR)) { $item_upcs[] = $likeW['upc']; if ($mixmatch !== false) { $mixmatch = $likeCode + 500; } } } else { $item_upcs[] = $row['upc']; } // check each item to see if it is on // sale with the correct parameters foreach ($item_upcs as $upc) { $product->reset(); $product->upc($upc); $this->cronMsg('Checking item ' . $upc, FannieLogger::INFO); /** Transistion mechanism. A batch that is set to apply to zero stores really should apply to zero stores. For now it fails over to using the local store's ID */ if ($this->config->get('STORE_MODE') === 'HQ') { $storeID = $row['storeID']; if ($storeID == null) { $storeID = $this->config->get('STORE_ID'); } $product->store_id($storeID); } if (!$product->load()) { $this->cronMsg("\tError: item does not exist in products", FannieLogger::NOTICE); continue; } // list of UPCs that should be on sale $sale_upcs[] = $upc; $changed = false; if ($product->special_price() != $special_price) { $changed = true; $product->special_price($special_price); } if ($product->specialpricemethod() != $specialpricemethod) { $changed = true; $product->specialpricemethod($specialpricemethod); } if ($product->specialgroupprice() != $specialgroupprice) { $changed = true; $product->specialgroupprice($specialgroupprice); } if ($product->specialquantity() != $specialquantity) { $changed = true; $product->specialquantity($specialquantity); } if ($product->special_limit() != $special_limit) { $changed = true; $product->special_limit($special_limit); } if ($product->start_date() != $start_date) { $changed = true; $product->start_date($start_date); } if ($product->end_date() != $end_date) { $changed = true; $product->end_date($end_date); } if ($product->discounttype() != $discounttype) { $changed = true; $product->discounttype($discounttype); } if ($mixmatch !== false && $product->mixmatchcode() != $mixmatch) { $changed = true; $product->mixmatchcode($mixmatch); } if ($product->batchID() != $batchID) { $changed = true; $product->batchID($batchID); } if ($changed) { $product->save(); $this->cronMsg("\tUpdated item", FannieLogger::INFO); } } // end loop on batchList record items } // end loop on batchList records // No sale items; need a filler value for // the query below if (count($sale_upcs) == 0) { $this->cronMsg('Notice: nothing is currently on sale', FannieLogger::WARNING); $sale_upcs[] = 'notValidUPC'; } // now look for anything on sale that should not be // and take those items off sale $upc_in = ''; foreach ($sale_upcs as $upc) { $upc_in .= '?,'; } $upc_in = substr($upc_in, 0, strlen($upc_in) - 1); $lookupQ = 'SELECT p.upc FROM products AS p WHERE upc NOT IN (' . $upc_in . ') AND ( p.discounttype <> 0 OR p.special_price <> 0 OR p.specialpricemethod <> 0 OR p.specialgroupprice <> 0 OR p.specialquantity <> 0 )'; $lookupP = $dbc->prepare($lookupQ); $lookupR = $dbc->execute($lookupP, $sale_upcs); while ($lookupW = $dbc->fetch_row($lookupR)) { $this->cronMsg('Taking ' . $lookupW['upc'] . ' off sale', FannieLogger::INFO); $product->reset(); if ($this->config->get('STORE_MODE') === 'HQ') { $product->store_id($this->config->get('STORE_ID')); } $product->upc($lookupW['upc']); $product->discounttype(0); $product->special_price(0); $product->specialgroupprice(0); $product->specialquantity(0); $product->start_date(''); $product->end_date(''); $product->batchID(0); $product->save(); } }
$dbc->exec_statement($prep, array($upc)); $ruleProd = new ProductsModel($dbc); $prod = new ProductsModel($dbc); $prod->upc($upc); foreach ($prod->find('store_id') as $p) { $ruleID = 0; // remove the rule but save its ID if ($p->price_rule_id() != 0) { $ruleID = $p->price_rule_id(); $p->price_rule_id(0); } $p->save(); // make sure no other item is using the same // rule before deleting it if ($ruleID > 1) { $ruleProd->reset(); $ruleProd->price_rule_id($ruleID); if (count($ruleProd->find()) == 0) { // no products are using this rule $rule = new PriceRulesModel($dbc); $rule->priceRuleID($ruleID); $rule->delete(); } } } break; case 'newPrice': $vid = FormLib::get_form_value('vendorID'); $bid = FormLib::get_form_value('batchID'); $sid = FormLib::get_form_value('queueID', 0); if ($sid == 99) {
} else { $prod = new ProductsModel($sql); $prod->upc($upc); $prod->store_id(1); $prod->load(); $ruleID = 0; // remove the rule but save its ID if ($prod->price_rule_id() != 0) { $ruleID = $prod->price_rule_id(); $prod->price_rule_id(0); } $prod->save(); // make sure no other item is using the same // rule before deleting it if ($ruleID > 1) { $prod->reset(); $prod->price_rule_id($ruleID); if (count($prod->find()) == 0) { // no products are using this rule $rule = new PriceRulesModel($sql); $rule->priceRuleID($ruleID); $rule->delete(); } } } break; } echo $out; return; } //Get buyID from index form. Set to 99 (all buyers) if not set.
function process_file($linedata) { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $defaults_table = array(); $defQ = $dbc->prepare_statement("SELECT dept_no,dept_tax,dept_fs,dept_discount FROM departments"); $defR = $dbc->exec_statement($defQ); while ($defW = $dbc->fetch_row($defR)) { $defaults_table[$defW['dept_no']] = array('tax' => $defW['dept_tax'], 'fs' => $defW['dept_fs'], 'discount' => $defW['dept_discount']); } $upc_index = $this->get_column_index('upc'); $desc_index = $this->get_column_index('desc'); $price_index = $this->get_column_index('price'); $dept_index = $this->get_column_index('dept'); $ret = true; $linecount = 0; $checks = FormLib::get_form_value('checks') == 'yes' ? true : false; $skipExisting = FormLib::get('skipExisting', 0); $model = new ProductsModel($dbc); foreach ($linedata as $line) { // get info from file and member-type default settings // if applicable $upc = $line[$upc_index]; $desc = $line[$desc_index]; $price = $line[$price_index]; $price = str_replace('$', '', $price); $price = trim($price); $dept = $dept_index !== false ? $line[$dept_index] : 0; $tax = 0; $fs = 0; $discount = 1; if ($dept_index !== false) { if (isset($defaults_table[$dept]['tax'])) { $tax = $defaults_table[$dept]['tax']; } if (isset($defaults_table[$dept]['discount'])) { $discount = $defaults_table[$dept]['discount']; } if (isset($defaults_table[$dept]['fs'])) { $fs = $defaults_table[$dept]['fs']; } } // upc cleanup $upc = str_replace(" ", "", $upc); $upc = str_replace("-", "", $upc); if (!is_numeric($upc)) { continue; } // skip header(s) or blank rows if ($checks) { $upc = substr($upc, 0, strlen($upc) - 1); } $upc = BarcodeLib::padUPC($upc); if (strlen($desc) > 35) { $desc = substr($desc, 0, 35); } $model->reset(); $model->upc($upc); $model->store_id(1); if ($model->load() && $skipExisting) { continue; } $model->description($desc); $model->normal_price($price); $model->department($dept); $model->tax($tax); $model->foodstamp($fs); $model->discount($discount); // fully init new record $model->pricemethod(0); $model->special_price(0); $model->specialpricemethod(0); $model->specialquantity(0); $model->specialgroupprice(0); $model->advertised(0); $model->tareweight(0); $model->start_date('0000-00-00'); $model->end_date('0000-00-00'); $model->discounttype(0); $model->wicable(0); $model->inUse(1); $try = $model->save(); if ($try) { $this->stats['imported']++; } else { $this->stats['errors'][] = 'Error importing UPC ' . $upc; } if ($linecount++ % 100 == 0) { set_time_limit(30); } } return $ret; }
/** Import Hobart Data into scaleItems table This one is for "expanded text" data @param $filename [string] scale-exported data CSV @return [int] number of items imported */ public static function readTextsFromFile($filename) { $dbc = \FannieDB::get(\FannieConfig::factory()->get('OP_DB')); $product = new \ProductsModel($dbc); $scaleItem = new \ScaleItems($dbc); $number_index = -1; $text_index = -1; $fp = fopen($filename, 'r'); $headers = fgetcsv($fp); for ($i = 0; $i < count($headers); $i++) { $header = $headers[$i]; if ($header == 'Expanded Text Number') { $number_index = $i; } else { if ($header == 'Expanded Text') { $text_index = $i; } } } if ($text_index == -1 || $number_index == -1) { // no valid data return 0; } $item_count = 0; while (!feof($fp)) { $line = fgetcsv($fp); $plu = $line[$number_index]; $upc = self::scalePluToUpc($plu); $product->reset(); $product->upc($upc); if (!$product->load()) { // no entry in products table // should one be created? continue; } $scaleItem->reset(); $scaleItem->plu($upc); $scaleItem->text($line[$text_index]); $scaleItem->save(); $item_count++; } fclose($fp); return $item_count; }
function SaveFormData($upc) { $lc = FormLib::get_form_value('likeCode'); $dbc = $this->db(); $delP = $dbc->prepare_statement('DELETE FROM upcLike WHERE upc=?'); $delR = $dbc->exec_statement($delP, array($upc)); if ($lc == -1) { return $delR === False ? False : True; } $insP = 'INSERT INTO upcLike (upc,likeCode) VALUES (?,?)'; $insR = $dbc->exec_statement($insP, array($upc, $lc)); if (FormLib::get_form_value('LikeCodeNoUpdate') == 'noupdate') { return $insR === False ? False : True; } /* get values for current item */ $valuesP = $dbc->prepare_statement('SELECT normal_price,pricemethod,groupprice,quantity, department,scale,tax,foodstamp,discount,qttyEnforced,local,wicable FROM products WHERE upc=?'); $valuesR = $dbc->exec_statement($valuesP, array($upc)); if ($dbc->num_rows($valuesR) == 0) { return False; } $values = $dbc->fetch_row($valuesR); /* apply current values to other other items in the like code */ $upcP = $dbc->prepare_statement('SELECT upc FROM upcLike WHERE likeCode=? AND upc<>?'); $upcR = $dbc->exec_statement($upcP, array($lc, $upc)); $isHQ = FannieConfig::config('STORE_MODE') == 'HQ' ? true : false; $stores = new StoresModel($dbc); $stores = array_map(array_filter($stores->find(), function ($obj) { return $obj->hasOwnItems(); }), function ($obj) { return $obj->storeID(); }); $model = new ProductsModel($dbc); $model->upc($upc); $model->mixmatchcode($lc + 500); if ($isHQ) { foreach ($stores as $store_id) { $model->store_id($store_id); $model->save(); } } else { $model->save(); } while ($upcW = $dbc->fetch_row($upcR)) { $model->reset(); $model->upc($upcW['upc']); $model->normal_price($values['normal_price']); $model->pricemethod($values['pricemethod']); $model->groupprice($values['groupprice']); $model->quantity($values['quantity']); $model->department($values['department']); $model->scale($values['scale']); $model->tax($values['tax']); $model->foodstamp($values['foodstamp']); $model->discount($values['discount']); $model->qttyEnforced($values['qttyEnforced']); $model->local($values['local']); $model->wicable($values['wicable']); $model->mixmatchcode($lc + 500); if ($isHQ) { foreach ($stores as $store_id) { $model->store_id($store_id); $model->save(); } } else { $model->save(); } updateProductAllLanes($upcW['upc']); } return true; }