/** * Create a new product in database * @param Int $category_id * @param Float $products_price * @param Float $products_weight * @param String $pname * @param String $pdesc * @param Int $brand_id * @parmm Boolean $is_wholesale * @return Int New Product ID */ public static function createNewProduct($category_id, $products_price, $products_weight, $pname, $pdesc, $brand_id, $is_wholesale = false) { $cat = new Category($category_id); $prefix = $cat->getProductCodePrefix(); $conflict = true; while ($conflict) { //CONSTRUCT PRODUCT CODE $randno = rand(1, 9) . rand(1, 9); $products_model = $prefix . date('m' . $randno . 'dy'); $check_duplication = tep_db_query("SELECT products_id," . " products_model FROM products WHERE products_model =" . " '{$products_model}'"); $conflict = tep_db_num_rows($check_duplication) >= 1; } $pda = array(); $pda['categories_top_id'] = $cat->getCategoryTop()->id; $pda['products_model'] = $products_model; $pda['products_price'] = $products_price; $pda['products_weight'] = $products_weight; $pda['products_brand_id'] = $brand_id; $pda['is_wholesale'] = $is_wholesale ? '1' : '0'; $pda['products_date_added'] = date('Y-m-d H:i:s'); tep_db_perform('products', $pda); $product_id = tep_db_insert_id(); $ptc = array('products_id' => $product_id, 'categories_id' => $cat->id); tep_db_perform('products_to_categories', $ptc); $pdda = array(); $pdda['products_id'] = $product_id; $pdda['language_id'] = '2'; $pdda['products_name'] = $pname; $pdda['products_description'] = $pdesc; tep_db_perform('products_description', $pdda); return $product_id; }
$parent_name = ''; $cat_prefix = ''; $ctid = tep_db_prepare_input($_GET['ctid']); $ct = new CategoryTop($ctid); $mod_title = 'Create New Category - ' . $ct->name; } else { $cat = new Category($cat_id); $ct = $cat->getCategoryTop(); $ctid = $ct->id; $parent = $cat->getParent(); if ($parent === false) { $parent_name = ''; } else { $parent_name = $parent->getName($default_lid); } $cat_prefix = $cat->getProductCodePrefix(); $mod_title = 'Manage Category Detail - ' . $ct->name; } /* SUB CATEGORIES IS NO LONGER SUPPORTED $categories_query = "SELECT c.categories_id, c.parent_id, cd.categories_name, IF(c.parent_id=0, c.categories_id, c.parent_id) AS parent_grouping FROM categories c"; $categories_query .= " LEFT JOIN categories_description cd ON cd.categories_id=c.categories_id AND cd.language_id=$default_lid"; $categories_query .= " ORDER BY parent_grouping, c.parent_id"; $categories_result = tep_db_query($categories_query); $categories = array(); while ($row = tep_db_fetch_array($categories_result)) { if ($row['categories_id'] == $cat_id) { $parent_id = $row['parent_id']; } else { $categories[] = $row; } }