public function processItemAfterId(&$item, $params = null) { //if item is not configurable, nothing to do if ($item["type"] !== "configurable") { if ($this->getParam("CFGR:simplesbeforeconf") == 1) { $this->_currentsimples[] = $item["sku"]; } return true; } //check for explicit configurable attributes if (isset($item["configurable_attributes"])) { $confopts = explode(",", $item["configurable_attributes"]); for ($i = 0; $i < count($confopts); $i++) { $confopts[$i] = trim($confopts[$i]); } } else { $asconfopts = $this->getConfigurableOptsFromAsId($params["asid"]); //limit configurable options to ones presents & defined in item $confopts = array(); foreach ($asconfopts as $confopt) { if (in_array($confopt, array_keys($item)) && trim($item[$confopt]) != "") { $confopts[] = $confopt; } } unset($asconfotps); } //if no configurable attributes, nothing to do if (count($confopts) == 0) { $this->log("No configurable attributes found for configurable sku: " . $item["sku"] . " cannot link simples.", "warning"); return true; } //set product to have options & required $tname = $this->tablename('catalog_product_entity'); $sql = "UPDATE {$tname} SET has_options=1,required_options=1 WHERE entity_id=?"; $this->update($sql, $params["product_id"]); //matching mode //if associated skus $matchmode = $this->getMatchMode($item); //check if item has exising options $pid = $params["product_id"]; $cpsa = $this->tablename("catalog_product_super_attribute"); $cpsal = $this->tablename("catalog_product_super_attribute_label"); //process configurable options $ins_sa = array(); $data_sa = array(); $ins_sal = array(); $data_sal = array(); $idx = 0; foreach ($confopts as $confopt) { $attrinfo = $this->getAttrInfo($confopt); $attrid = $attrinfo["attribute_id"]; $psaid = NULL; //try to get psaid for attribute $sql = "SELECT product_super_attribute_id as psaid FROM `{$cpsa}` WHERE product_id=? AND attribute_id=?"; $psaid = $this->selectOne($sql, array($pid, $attrid), "psaid"); //if no entry found, create one if ($psaid == NULL) { $sql = "INSERT INTO `{$cpsa}` (`product_id`,`attribute_id`,`position`) VALUES (?,?,?)"; //inserting new options $psaid = $this->insert($sql, array($pid, $attrid, $idx)); } //for all stores defined for the item $sids = $this->getItemStoreIds($item, 0); $data = array(); $ins = array(); foreach ($sids as $sid) { $data[] = $psaid; $data[] = $sid; $data[] = $attrinfo['frontend_label']; $ins[] = "(?,?,1,?)"; } if (count($ins) > 0) { //insert/update attribute value for association $sql = "INSERT INTO `{$cpsal}` (`product_super_attribute_id`,`store_id`,`use_default`,`value`) VALUES " . implode(",", $ins) . "ON DUPLICATE KEY UPDATE value=VALUES(`value`)"; $this->insert($sql, $data); } //if we have price info for this attribute if (isset($this->_optpriceinfo[$confopt])) { $cpsap = $this->tablename("catalog_product_super_attribute_pricing"); $wsids = $this->getItemWebsites($item); //if admin set as store, website force to 0 if (in_array(0, $sids)) { $wsids = array(0); } $data = array(); $ins = array(); foreach ($this->_optpriceinfo[$confopt] as $opdef) { //if optpriceinfo has no is_percent, force to 0 $opinf = explode(":", $opdef); $optids = $this->getOptionIds($attrid, 0, explode("//", $opinf[0])); foreach ($optids as $optid) { //generate price info for each given website foreach ($wsids as $wsid) { if (count($opinf) < 3) { $opinf[] = 0; } $data[] = $psaid; $data[] = $optid; $data[] = $opinf[1]; $data[] = $opinf[2]; $data[] = $wsid; $ins[] = "(?,?,?,?,?)"; } } } $sql = "INSERT INTO {$cpsap} (`product_super_attribute_id`,`value_index`,`pricing_value`,`is_percent`,`website_id`) VALUES " . implode(",", $ins) . " ON DUPLICATE KEY UPDATE pricing_value=VALUES(pricing_value),is_percent=VALUES(is_percent)"; $this->insert($sql, $data); unset($data); } $idx++; } unset($confopts); switch ($matchmode) { case "none": break; case "auto": //destroy old associations $this->autoLink($pid); $this->updSimpleVisibility($pid); break; case "cursimples": $this->fixedLink($pid, $this->_currentsimples); $this->updSimpleVisibility($pid); break; case "fixed": $sskus = explode(",", $item["simples_skus"]); trimarray($sskus); $this->fixedLink($pid, $sskus); $this->updSimpleVisibility($pid); unset($item["simples_skus"]); break; default: break; } //always clear current simples if (count($this->_currentsimples) > 0) { unset($this->_currentsimples); $this->_currentsimples = array(); } return true; }
function trimarray($o) { if (!is_array($o)) { return trim($o); } foreach ($o as $k => $v) { $o[$k] = trimarray($v); } return $o; }
public function checkItemStores($scodes) { if ($scodes == "admin") { return $scodes; } $scarr = explode(",", $scodes); trimarray($scarr); $rscode = array(); $sql = "SELECT code FROM " . $this->tablename("core_store") . " WHERE code IN (" . $this->arr2values($scarr) . ")"; $result = $this->selectAll($sql, $scarr); $rscodes = array(); foreach ($result as $row) { $rscodes[] = $row["code"]; } $diff = array_diff($scarr, $rscodes); $out = ""; if (count($diff) > 0) { $out = "Invalid store code(s) found:" . implode(",", $diff); } if ($out != "") { if (count($rscodes) == 0) { $out .= ", NO VALID STORE FOUND"; } $this->log($out, "warning"); } return implode(",", $rscodes); }
/** * Register handle function. * Usertype: Student */ public function register_() { try { $this->assign('waitSecond', 2); $data['username'] = safepost('username'); $pwd = safepost('password'); if (!DBModel::existUser('cernet_user', $data) && !DBModel::existUser('second_user', $data)) { $data = trimarray($_POST); unset($data['__hash__']); $data['password'] = encrypt($pwd); $data['id'] = $this->generateStudentId(); DBModel::insertDB('cernet_user', $data); $this->success(Success('register'), '__ROOT__'); } else { # Error Tips $this->error(Error('register'), lastpage()); } } catch (Exception $e) { throw_exception($e->getMessage()); } }