Execute("select products_id from " . TABLE_PRODUCTS . " where products_model = '" . $model . "'"); $check_xsell = $db->Execute("select count(products_id) as records from " . TABLE_PRODUCTS_XSELL . " where products_id = '" . $products_id . "' and xsell_id = '" . $cross_product->fields['products_id'] . "'"); if ($check_xsell->fields['records'] > 0) { $messageStack->add_session(sprintf(CROSS_SELL_MODEL_ALREADY_ADDED, $model, $_POST['cross_product_model']), 'error'); } else { $insert_array = array('products_id' => $products_id, 'xsell_id' => $cross_product->fields['products_id'], 'sort_order' => '1' ); zen_db_perform(TABLE_PRODUCTS_XSELL, $insert_array); $messageStack->add_session(sprintf(CROSS_SELL_MODEL_ADDED, $model, $_POST['cross_product_model']), 'success'); } } switch($_GET['action']){ case 'confirm_delete_product': $db->Execute("delete from " . TABLE_PRODUCTS_XSELL . " where products_id = '" . (int)$_GET['cID'] . "'"); $messageStack->add(CROSS_SELL_PRODUCT_DELETETION_SUCCESS, 'success'); zen_redirect(zen_href_link(FILENAME_XSELL_ADVANCED, zen_get_all_get_params(array('action')))); break; case 'newcross_sell': if (!isset($_POST['cross_product_id']) ) { $product_lookup = $db->Execute("select p.products_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd " . "where p.products_id = pd.products_id and pd.language_id ='".(int)$languages_id."' and p.products_model = '" . zen_db_prepare_input($_POST['cross_product_model']) . "'"); switch ($product_lookup->RecordCount()) { case '0': $messageStack->add_session(sprintf(CROSS_SELL_NO_MODEL_FOUND, $_POST['cross_product_model']), 'error'); zen_redirect(FILENAME_XSELL_ADVANCED); break; case '1': $products_id = $product_lookup->fields['products_id']; if (isset($_POST['product_model']) ) { foreach ($_POST['product_model'] as $id => $model) { if (zen_not_null($model) ) { add_new_cross_product($products_id, $model); } } } break; } } else { $products_id = $_POST['cross_product_id']; if (isset($_POST['product_model']) ) { foreach ($_POST['product_model'] as $id => $model) { if (zen_not_null($model) ) { add_new_cross_product($products_id, $model); } } } } zen_redirect(zen_href_link(FILENAME_XSELL_ADVANCED, 'cID=' . $products_id . '&action=edit')); break; case 'delete_cross': if (isset($_GET['xID']) ) { $db->Execute("delete from " . TABLE_PRODUCTS_XSELL . " where ID = '" . zen_db_prepare_input($_GET['xID']) . "'"); $messageStack->add_session(CROSS_SELL_PRODUCT_DELETED, 'success'); zen_redirect(zen_href_link(FILENAME_XSELL_ADVANCED, 'cID=' . $_GET['cID'] . '&action=edit')); } break; case 'editcross_sell': $product_lookup = $db->Execute("select p.products_id from " . TABLE_PRODUCTS . " p " . "where p.products_model = '" . zen_db_prepare_input($_POST['cross_product_model']) . "'"); if ($product_lookup->RecordCount() > 0) { zen_redirect(zen_href_link(FILENAME_XSELL_ADVANCED, 'cID=' . $product_lookup->fields['products_id'] . '&action=edit')); } $messageStack->add(sprintf(CROSS_SELL_PRODUCT_NOT_FOUND, $_POST['cross_product_model']), 'warning'); break; case 'update': $products_id = $_POST['cross_product_id']; if (isset($_POST['product_model']) ) { foreach ($_POST['product_model'] as $id => $model) { if (zen_not_null($model) ) { add_new_cross_product($products_id, $model); } } } zen_redirect(zen_href_link(FILENAME_XSELL_ADVANCED, 'cID=' . $products_id . '&action=edit')); break; case 'update_cross' : if ($_POST['product']){ foreach ($_POST['product'] as $temp_prod){ $db->execute('delete from ' . TABLE_PRODUCTS_XSELL . ' where xsell_id = "'.$temp_prod.'" and products_id = "'.$_GET['add_related_product_ID'].'"'); } } $sort_start_query = $db->execute('select sort_order from ' . TABLE_PRODUCTS_XSELL . ' where products_id = "'.$_GET['add_related_product_ID'].'" order by sort_order desc limit 1'); $sort_start = $sort_start_query->fields ; $sort = (($sort_start['sort_order'] > 0) ? $sort_start['sort_order'] : '0'); if ($_POST['cross']){ foreach ($_POST['cross'] as $temp){ $sort++; $insert_array = array(); $insert_array = array('products_id' => $_GET['add_related_product_ID'], 'xsell_id' => $temp, 'sort_order' => $sort); zen_db_perform(TABLE_PRODUCTS_XSELL, $insert_array); } } $messageStack->add(CROSS_SELL_SUCCESS, 'success'); break; case 'update_sort' : foreach ($_POST as $key_a => $value_a){ $db->execute('update ' . TABLE_PRODUCTS_XSELL . ' set sort_order = "' . $value_a . '" where xsell_id = "' . $key_a . '"'); } $messageStack->add(SORT_CROSS_SELL_SUCCESS, 'success'); break; } ?> >